Makc
Makc

Reputation: 307

allocate user-space memory from kernel

I'm trying to call

sys_readlink(const char __user *path, char __user *buf, int bufsiz)

directly, but get EFAULT error code. This error appears because buf points to memory from kernel-space.

So, is there possible way to allocate user-space memory from kernel ?

kmalloc(size, GFP_USER) is similar to kmalloc(size, GFP_KERNEL) and returns pointer to kernel memory.

Upvotes: 5

Views: 5164

Answers (1)

Hasturkun
Hasturkun

Reputation: 36402

You can temporarily disable memory address validity checking by using set_fs

mm_segment_t old_fs;

old_fs = get_fs();
set_fs(KERNEL_DS);
/* Your syscall here */
set_fs(old_fs);

Upvotes: 9

Related Questions