flat assembler
Message board for the users of flat assembler.
Index
> OS Construction > syscall/sysret stack |
Author |
|
baldr 16 Feb 2010, 20:56
asmmsa wrote: i think (since you load a selector in IA32_STAR[47:32]), stack pointer isnt changed at all… |
|||
16 Feb 2010, 20:56 |
|
asmmsa 16 Feb 2010, 21:53
hmmm.. so i can deallocate stack while kernel is accessing it?
i can do that from cpl = 3, os will page fault in cpl = 0, and thats not good i guess? or kernel before accessing arguments must use something like MmProbeAndLockPages() on stack (create mdl first ofc), then access it? Also i can pass sensitive read only address (there is that in windows, containing systemroot path, ticks and other stuff)? syscall/sysret are newer than sysenter/sysexit, are they better? how to handle stack (no)switch? And how does it know the size of allocation, or limit? i can do whatever i want. |
|||
16 Feb 2010, 21:53 |
|
baldr 16 Feb 2010, 22:56
asmmsa wrote: hmmm.. so i can deallocate stack while kernel is accessing it? Locked pages are entirely another issue. syscall is just as it is, fast transfer to ring 0 without excessive checks. When in doubt, RTFM. I'll collaborate, but only in constructive cases, OK? |
|||
16 Feb 2010, 22:56 |
|
smiddy 16 Feb 2010, 23:52
!rolling
|
|||
16 Feb 2010, 23:52 |
|
asmmsa 17 Feb 2010, 11:03
ive found about swapgs instruction, wich can be used to replace GS base with address of data.
ok, what about preemption? thread execute syscall, swapgs, and gets preempted? MSR holding kernel struct is swapped with propably 0 from GS, and next thread will want to swapgs = what? or maybe context switching also save this msr? |
|||
17 Feb 2010, 11:03 |
|
revolution 17 Feb 2010, 11:53
asmmsa: Preemption is controlled by the OS. It is not an automatic hardware function. If the OS wants to run another task then it switches when it is ready.
|
|||
17 Feb 2010, 11:53 |
|
asmmsa 17 Feb 2010, 19:35
ok but how context scheduler knows, when GS was swapped, and when it wasnt?
when for example timer interrupt fires, this scheduler checks if thread has any time left, and if it does not have, its switched. And when its switched, MSR of GS is not saved or changed, wich leads to my question. does syscall/sysret work on multitasking os or not? |
|||
17 Feb 2010, 19:35 |
|
revolution 18 Feb 2010, 02:07
asmmsa wrote: does syscall/sysret work on multitasking os or not? |
|||
18 Feb 2010, 02:07 |
|
asmmsa 18 Feb 2010, 09:45
linux pass arguments in registers so its nor really a problem.
windows use stack, so what about it? swapgs cant be used to get pointer to kernel stack because it destroy MSR holding gs base. you dont know, right? maybe syscall/sysret are not designed to support stack switching? if so, they suck badly and i wonder why they are used. sysenter/sysexit are way better. |
|||
18 Feb 2010, 09:45 |
|
revolution 18 Feb 2010, 09:51
Just compare the value in GS to see if you have the kernel value or some other value. This is not supposed to be a problem when writing an OS and the syscall/sysret can absolutely 100% support all type of multitasking and stack switching in any way you want to implement it. You just have to use them properly.
|
|||
18 Feb 2010, 09:51 |
|
asmmsa 18 Feb 2010, 10:01
so, before making task switch, i must check if my GS base is = predefined kernel value, and if it is, execute swapgs and save somewere information that gs was swapped. when switching to new task, read this information and if set, swapgs.
|
|||
18 Feb 2010, 10:01 |
|
revolution 18 Feb 2010, 10:17
It just depends upon how you write your OS kernel. Without knowledge of your code no one else can say what will work for you in you code.
|
|||
18 Feb 2010, 10:17 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.