Allocating memory for user space from kernel thread

前端 未结 1 746
情歌与酒
情歌与酒 2020-12-11 19:15

My question is about passing data from kernel to a user space program. I want to implement a system call \"get_data(size, char *buff, char **meta_buf)\". In this call, buff

相关标签:
1条回答
  • 2020-12-11 20:00

    Don't attempt to allocate memory for userspace from the kernel - this is a huge violation of the kernel's abstraction layering. Instead, consider a few other options:

    • Have userspace ask how much space it needs. Userspace allocates, then grabs the memory from the kernel.
    • Have userspace mmap pages owned by your driver directly into its address space.
    • Set an upper bound on the amount of data needed. Just allocate that much.

    It's hard to say more without knowing why this has to be atomic. Actually allocating memory's going to need to be interruptible anyway (or you're unlikely to succeed), so it's unlikely that going out of and back into the kernel is going to hurt much. In fact, any write to userspace memory must be interruptible, as there's the potential for page faults requiring IO.

    0 讨论(0)
提交回复
热议问题