Should kernel code be readable from user space?
Posted: Tue Jul 10, 2012 11:47 pm
Hi all, I'm studying the JamesM kernel tutorials and adding functionality to my kernel. Right now I'm a bit confused by the following snippet in initialise_paging() in paging.c:
The author mentioned in the last lines of the last tutorial that the kernel code needs to be accessible from user space, since the main() funciton in the kernel executes code (in the user space) after the
line.
If I allocate frames with the supervisor (is_kernel) flag set to true (which I guess should be the correct way for protection), no other statement can be executed after that line. So I'm not sure how to make the switch and do some subsequent call to, say, spawn a shell in the user mode.
Any help would be appreciated. Thanks!
Code: Select all
while (i < placement_address + 0x1000) {
// Kernel code is readable but not writeable from userspace.
alloc_frame(get_page(i, TRUE, kernel_directory), FALSE /* is_kernel */, FALSE /* is_writable */);
i += 0x1000;
}
Code: Select all
// code
switch_to_user_mode();
// other code
If I allocate frames with the supervisor (is_kernel) flag set to true (which I guess should be the correct way for protection), no other statement can be executed after that line. So I'm not sure how to make the switch and do some subsequent call to, say, spawn a shell in the user mode.
Any help would be appreciated. Thanks!