|
ginnOS
The reference: libc, the libraries and the kernel
|
Go to the source code of this file.
Functions | |
| bool | user_access_ok (const void *ptr, size_t len, bool write) |
| safe access to user memory from syscalls. | |
| kerr_t | copy_from_user (void *dst, const void *user_src, size_t len) |
| copy bytes from user memory into a kernel buffer. | |
| kerr_t | copy_to_user (void *user_dst, const void *src, size_t len) |
| copy bytes from a kernel buffer into user memory. | |
| int32_t | strncpy_from_user (char *dst, const char *user_src, size_t size) |
| copy a NUL-terminated user string into a kernel buffer, checking each page as the copy reaches it. | |
safe access to user memory from syscalls.
a pointer from user space can be anything: unmapped, kernel memory, or a buffer that runs off the end of a mapping. touching it blindly page-faults in the kernel (a panic) or lets a program read or write kernel memory. these helpers check the current process's page tables first, so a bad pointer becomes KERR_FAULT (-EFAULT) instead. pages an area allows but that are not backed yet (demand paging) are backed before the access.
the check and the access are not atomic, which is fine for now: there is one CPU and one thread per address space, and only the process itself can change its mappings, never while it is inside a syscall. check that the current process could access a whole user range.
| ptr | start of the range (a user address). |
| len | length in bytes; 0 is always accessible. |
| write | true if the kernel will write to the range. |
copy bytes from user memory into a kernel buffer.
| dst | kernel destination. |
| user_src | user source. |
| len | number of bytes. |
copy bytes from a kernel buffer into user memory.
| user_dst | user destination (must be writable). |
| src | kernel source. |
| len | number of bytes. |
copy a NUL-terminated user string into a kernel buffer, checking each page as the copy reaches it.
| dst | kernel destination. |
| user_src | user string. |
| size | size of dst, including room for the NUL. |