Issue
is that allowed to allocate user space memory from kernel space? I know that process in Linux uses virtual memory and virtual addresses. And there is a protection which can`t allow using of memory of different process (it raises segmentation fault). So, there is no way to allocate a buffer and return a valid pointer to it to user space process?
Solution
is that allowed to allocate user space memory from kernel space? I know that process in Linux uses virtual memory and virtual addresses. And there is a protection which can`t allow using of memory of different process (it raises segmentation fault). So, there is no way to allocate a buffer and return a valid pointer to it to user space process?
Memory allocation routines have normally a return value, which is the pointer (in virtual memory coordinates) that the kernel has allocated the value. If the user is not asking for new memory, it's not normall to allocate memory for him in user space without telling where it has been allocated....
But you can do it. I think the best way to know how to do it is to study how the mmap(2)
system call works (as it maps allocated memory to user space, and returns a user space pointer for the user to know where it has been allocated), and use the internal kernel function used to allocate user memory. The kernel malloc group of routines need to know how to map (even for the kernel virtual space, as the kernel also runs in a virtual address memory space) memory pages into virtual memory addresses. Not doing that leads to unaccessable memory.
Answered By - Luis Colorado Answer Checked By - Gilberto Lyons (WPSolving Admin)