Page 1 of 1

kernel vs user space question

Posted: Fri Aug 21, 2020 4:28 am
by ITchimp
I have 2 gdt segments for kernel, one for code, the other for data

I have 2 gdt segments for user space, one for code, the other for data

all segments span the entire 4gb address space

Now my kernel data and code is mapped into virtual address space by setting the page table bit to supervisory only... (not accessed by all)

now I transitioned my kernel process into user mode and tries to make syscalls.... I got an error saying that page fault
for the stack I am trying to access...

The segment selector value is 0x23
last 2 bit is rpl which is segment selector indicates it is user mode... after switch to user mode, is my cpl 3?

what did I do wrong? I find that rpl, dpl and cpl confusing...

should I set kernel code and data to supervisory or to all? will that make user code able to execute kernel code??

I am drowning in questions ! pulling me out of my misery!!!

Re: kernel vs user space question

Posted: Fri Aug 21, 2020 6:43 am
by bellezzasolo
ITchimp wrote:I have 2 gdt segments for kernel, one for code, the other for data

I have 2 gdt segments for user space, one for code, the other for data

all segments span the entire 4gb address space

Now my kernel data and code is mapped into virtual address space by setting the page table bit to supervisory only... (not accessed by all)

now I transitioned my kernel process into user mode and tries to make syscalls.... I got an error saying that page fault
for the stack I am trying to access...

The segment selector value is 0x23
last 2 bit is rpl which is segment selector indicates it is user mode... after switch to user mode, is my cpl 3?

what did I do wrong? I find that rpl, dpl and cpl confusing...

should I set kernel code and data to supervisory or to all? will that make user code able to execute kernel code??

I am drowning in questions ! pulling me out of my misery!!!
Have you set up ESP0 of your TSS to a valid stack?

When transitioning from ring 3 to ring 0, the CPU loads the stack from the TSS, rather than executing an interrupt handler on a user stack.

Alternatively, if you haven't changed stack when transitioning from ring 0 to ring 3, then you'll be trying to access a ring 0 stack.