flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
baldr
asmmsa wrote: i think (since you load a selector in IA32_STAR[47:32]), stack pointer isnt changed at all… |
|||
![]() |
|
asmmsa
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. |
|||
![]() |
|
baldr
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? |
|||
![]() |
|
smiddy
!rolling
|
|||
![]() |
|
asmmsa
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? |
|||
![]() |
|
revolution
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.
|
|||
![]() |
|
asmmsa
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? |
|||
![]() |
|
revolution
asmmsa wrote: does syscall/sysret work on multitasking os or not? |
|||
![]() |
|
asmmsa
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. |
|||
![]() |
|
revolution
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.
|
|||
![]() |
|
asmmsa
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.
|
|||
![]() |
|
revolution
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.
|
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.
Website powered by rwasa.