how is the correct way to use copy_from_user?

后端 未结 2 1585
谎友^
谎友^ 2021-01-05 11:02

I am trying to copy a value from user space to kernel space with the function:

static ssize_t device_write(struct file *filp, const char *buff, size_t len, l         


        
2条回答
  •  日久生厌
    2021-01-05 11:47

    len does not exist in user-space. It is passed by value, so len is accessible as a normal variable in kernel-space. desp = (int)len is all you need. Note, however, that size_t is not the same as int, and on 64-bit platforms size_t is 8 bytes.

    copy_from_user() is for the buffer you're trying to write (called buffer in your user-space code, and buff in your kernel-space argument list). What's passed is a pointer to a memory address which only exists in user-space, so copy_from_user() copies that buffer to a kernel-space buffer.

提交回复
热议问题