📄 wstrncpy.c
字号:
/* * wstrncpy.c * * Copyright (C) 2006 Insigme Co., Ltd * * Authors: * - Lixing Chu * * This software has been developed while working on the Linux Unified Kernel * project (http://linux.insigma.com.cn) in the Insigma Reaserch Institute, * which is a subdivision of Insigma Co., Ltd (http://www.insigma.com.cn). * * The project is sponsored by Insigma Co., Ltd. * * The authors can be reached at linux@insigma.com.cn. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2 of the License, or (at your * option) any later version. * * Revision History: * Jan 2006 - Created. */ /* * wstrncpy.c: copy wchar string * Reference to Linux kernel code */#include <linux/module.h>#include <linux/string.h>#include <linux/nls.h>#include <linux/errno.h>#include <asm/uaccess.h>#ifdef CONFIG_UNIFIED_KERNEL/* * Copy a null terminated wide string from userspace. */#define __do_wstrncpy_from_user(dst,src,count,res) \do { \ int __d0, __d1, __d2; \ __asm__ __volatile__( \ " testl %1,%1\n" \ " jz 2f\n" \ "0: lodsw\n" \ " stosw\n" \ " testw %%ax,%%ax\n" \ " jz 1f\n" \ " decl %1\n" \ " jnz 0b\n" \ "1: subl %1,%0\n" \ "2:\n" \ ".section .fixup,\"ax\"\n" \ "3: movl %5,%0\n" \ " jmp 2b\n" \ ".previous\n" \ ".section __ex_table,\"a\"\n" \ " .align 4\n" \ " .long 0b,3b\n" \ ".previous" \ : "=d"(res), "=c"(count), "=&a" (__d0), "=&S" (__d1), \ "=&D" (__d2) \ : "i"(-EFAULT), "0"(count), "1"(count), "3"(src), "4"(dst) \ : "memory"); \} while (0)/*long __wstrncpy_from_user(wchar_t *dst, const wchar_t *src, long count){ long res; __do_wstrncpy_from_user(dst, src, count, res); return res;}*//* * copy a wide string into kernel-space */long wstrncpy_from_user(wchar_t *dst, const wchar_t *src, long count){ long res = -EFAULT; if (access_ok(VERIFY_READ, src, 2)) __do_wstrncpy_from_user(dst, src, count, res); return res;} /* end wcsncpy_from_user() *//* * return the size of a wide string (including the ending NUL) * - return 0 on exception, a value greater than N if too long */long wstrnlen_user(const wchar_t *s, long n){ unsigned long mask = -__addr_ok(s); unsigned long res, tmp; __asm__ __volatile__( " andl %0,%%ecx\n" "0: repne; scasw\n" " setne %%al\n" " subl %%ecx,%0\n" " addl %0,%%eax\n" "1:\n" ".section .fixup,\"ax\"\n" "2: xorl %%eax,%%eax\n" " jmp 1b\n" ".previous\n" ".section __ex_table,\"a\"\n" " .align 4\n" " .long 0b,2b\n" ".previous" :"=r" (n), "=D" (s), "=a" (res), "=c" (tmp) :"0" (n), "1" (s), "2" (0), "3" (mask) :"cc"); return res & mask;} /* end wcsnlen_user() */#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -