更新日期: 2022/06/01 来源: https://gitee.com/weharmony/kernel_liteos_a_note
strncpy_from_user.c 文件参考

浏览源代码.

函数

INT32 LOS_StrncpyFromUser (CHAR *dst, const CHAR *src, INT32 count)
 

函数说明

◆ LOS_StrncpyFromUser()

INT32 LOS_StrncpyFromUser ( CHAR dst,
const CHAR src,
INT32  count 
)

在文件 strncpy_from_user.c40 行定义.

41{
42 CHAR character;
43 INT32 i;
44 INT32 maxCount;
45 size_t offset = 0;
46
47 if ((!LOS_IsKernelAddress((VADDR_T)(UINTPTR)dst)) || (!LOS_IsUserAddress((VADDR_T)(UINTPTR)src)) || (count <= 0)) {
48 return -EFAULT;//判断是否在各自空间
49 }
50
51 maxCount = (LOS_IsUserAddressRange((VADDR_T)(UINTPTR)src, (size_t)count)) ? \
52 count : (INT32)(USER_ASPACE_TOP_MAX - (UINTPTR)src);//最大能拷贝的数据量,结束地址不能超过 USER_ASPACE_TOP_MAX
53 //USER_ASPACE_TOP_MAX 是用户空间能触及的最大虚拟内存空间地址
54 for (i = 0; i < maxCount; ++i) {//一个个字符拷贝
55 if (LOS_GetUser(&character, src + offset) != LOS_OK) {
56 return -EFAULT;
57 }
58 *(CHAR *)(dst + offset) = character;
59 if (character == '\0') {
60 return offset;
61 }
62 ++offset;
63 }
64
65 return offset;
66}
signed int INT32
Definition: los_typedef.h:60
unsigned long VADDR_T
Definition: los_typedef.h:208
unsigned long UINTPTR
Definition: los_typedef.h:68
char CHAR
Definition: los_typedef.h:63
STATIC INLINE BOOL LOS_IsKernelAddress(VADDR_T vaddr)
虚拟地址是否在内核空间
Definition: los_vm_map.h:213
STATIC INLINE BOOL LOS_IsUserAddressRange(VADDR_T vaddr, size_t len)
虚拟地址[vaddr,vaddr + len]是否在用户空间
Definition: los_vm_map.h:281
STATIC INLINE BOOL LOS_IsUserAddress(VADDR_T vaddr)
虚拟地址是否在用户空间
Definition: los_vm_map.h:275
函数调用图:
这是这个函数的调用关系图: