gpt4 book ai didi

linux - copy_to_user 在哪里定义

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:00:24 26 4
gpt4 key购买 nike

copy_to_user 和 copy_from_user 函数在 Linux 系统的什么地方定义和实现?

最佳答案

它在 asm/uaccess.h 中定义,例如,在 /usr/src/linux-3.0.6-gentoo/include/asm-generic/uaccess.h 中:

static inline long copy_from_user(void *to,
const void __user * from, unsigned long n)
{
might_sleep();
if (access_ok(VERIFY_READ, from, n))
return __copy_from_user(to, from, n);
else
return n;
}

static inline long copy_to_user(void __user *to,
const void *from, unsigned long n)
{
might_sleep();
if (access_ok(VERIFY_WRITE, to, n))
return __copy_to_user(to, from, n);
else
return n;
}

__copy_to_user :

#ifndef __copy_to_user
static inline __must_check long __copy_to_user(void __user *to,
const void *from, unsigned long n)
{
if (__builtin_constant_p(n)) {
switch(n) {
case 1:
*(u8 __force *)to = *(u8 *)from;
return 0;
case 2:
*(u16 __force *)to = *(u16 *)from;
return 0;
case 4:
*(u32 __force *)to = *(u32 *)from;
return 0;
#ifdef CONFIG_64BIT
case 8:
*(u64 __force *)to = *(u64 *)from;
return 0;
#endif
default:
break;
}
}

memcpy((void __force *)to, from, n);
return 0;
}
#endif

关于linux - copy_to_user 在哪里定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13760278/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com