x86: how to access data at "user-mode" address, from kernel?
Posted: Sat Apr 04, 2015 12:23 pm
Hi all,
I am dreaded that this has slipped my curiosity for so long. Granted, I am no expert at paging and protection yet, but I have done some extensive googling both on osdev wiki and even reaching some Quora pages, with more or less useful information there.
Say I have a kernel function exposed to user-mode processes through a system call. The "kernel-mode" function signature is as follows.
If this function were to fill the specified buffer, since the value of `buf` - the address - is supplied by the process itself and is probably a virtual address, how can kernel access the data at its physical address counterpart? The virtual address may be a statically allocated `char arr[1024]` in process data segment, for example. When `_foo` is executed by the kernel, the address space is different, is it not?
In other words, when a process ends up invoking `_foo` through a syscall mechanism, with `buf` being the virtual address of the abovementioned `arr`, say 0x1000, then for the kernel the same address value 0x1000 is something at a different physical memory location, no? I mean what for the invoking process is virtual address, is for kernel a physical address or virtual address that is subject to different translation parameters?
This is a homework thing, but I see no address conversion functions in the kernel I have in front of me, nothing like `copy_to_user`which Linux seems to be doing. This seems like a glaring hole I am supposed to fill, but I am a bit at loss here.
Just point me to a page in wiki, if this is obvious, but I could not find anything that would explain to me what's going on. Am I missing something obvious again? (tm)(c)(R)
I am dreaded that this has slipped my curiosity for so long. Granted, I am no expert at paging and protection yet, but I have done some extensive googling both on osdev wiki and even reaching some Quora pages, with more or less useful information there.
Say I have a kernel function exposed to user-mode processes through a system call. The "kernel-mode" function signature is as follows.
Code: Select all
int _foo(char* buf);
In other words, when a process ends up invoking `_foo` through a syscall mechanism, with `buf` being the virtual address of the abovementioned `arr`, say 0x1000, then for the kernel the same address value 0x1000 is something at a different physical memory location, no? I mean what for the invoking process is virtual address, is for kernel a physical address or virtual address that is subject to different translation parameters?
This is a homework thing, but I see no address conversion functions in the kernel I have in front of me, nothing like `copy_to_user`which Linux seems to be doing. This seems like a glaring hole I am supposed to fill, but I am a bit at loss here.
Just point me to a page in wiki, if this is obvious, but I could not find anything that would explain to me what's going on. Am I missing something obvious again? (tm)(c)(R)