Reputation: 4373
Why does the kernel use the copy_to_user
function?
Couldn't it just directly operate on data in the user space?
Upvotes: 0
Views: 1531
Reputation: 1
kernel and user-space applications have different address spaces, so copying to user space require an address space change. Each process has its own (user) address space.
Also, kernel should never crash when copying to user space, so the copy_to_user
function probably checks that the destination address is valid (perhaps that address should be paged-in, e.g. from swap space).
Read more about linux kernel, syscalls, processes, address space ...
Upvotes: 4
Reputation: 146053
If a given kernel were written for only one architecture this may or may not be a reasonable choice.
There are a lot of considerations that may vary per architecture and therefore require some sort of polymorphic operation...
protection ... the kernel may have too many or too few access rights, either way may require extra code on a given target
address space ... the user space and kernel space may overlap, and so a target-specific solution or temporary map would be needed
page fault management ... access to the user space can fault and this needs to be either avoided or allowed. Confining the access to a given specific place allows either extra setup or identification of the reason for the fault.
Upvotes: 4