首页 | 资讯动态 | linux基础 | 系统管理 | 网络管理 | 编程开发 | linux数据库 | linux相关 | linux认证 | 下载中心 | 专题
oklinux
 系统管理:中文环境 系统管理 桌面应用 内核技术 Linux基础:安装配置 常用命令 经验技巧 软件应用 Linux数据库:Mysql POSTGRE
 网络管理:网络安全 网络应用 Linux服务器 编程开发:PHP CC++ Python Perl SHELL 嵌入式开发 | PHP基础 PHP技巧 PHP应用 PHP文摘
 首页 linux资讯动态 Linux专题 | 其他Unix Linux解决方案 硬件相关 Linux认证 企业应用 Apache | 相关下载:资料 参考手册 开发工具
 → 当前位置:首页>系统管理>内核技术>正文

Kernel command using Linux system calls

OKLinux www.oklinux.cn 2007-03-28 来源:IBM developerWorks Worldwide 会员收藏 游客收藏

. You can also test whether a user-space pointer is valid through a call to access_ok. These functions are defined in linux/include/asm/uaccess.h.

You use the access_ok macro to validate a user-space pointer for a given operation. This function takes the type of access (VERIFY_READ or VERIFY_WRITE), the pointer to the user-space memory block, and the size of the block (in bytes). The function returns zero on success:

int access_ok( type, address, size );

Moving simple types between the kernel and user-space (such as ints or longs) is accomplished easily with get_user and put_user. These macros each take a value and a pointer to a variable. The get_user function moves the value that the user-space address specifies (ptr) into the kernel variable specified (var). The put_user function moves the value that the kernel variable (var) specifies into the user-space address (ptr). The functions return zero on success:

int get_user( var, ptr );
int put_user( var, ptr );

To move larger objects, such as structures or arrays, you can use the copy_from_user and copy_to_user functions. These functions move an entire block of data between user-space and the kernel. The copy_from_user function moves a block of data from user-space into kernel-space, and copy_to_user moves a block of data from the kernel into user-space:

unsigned long copy_from_user( void *to, const void __user *from, unsigned long n );
unsigned long copy_to_user( void *to, const void __user *from, unsigned long n );

Finally, you can copy a NULL-terminated string from user-space to the kernel by using the strncpy_from_user function. Before calling this function, you can get the size of the user-space string with a call to the strlen_user macro:

long strncpy_from_user( char *dst, const char __user *src, long count );
strlen_user( str );

These functions provide the basics for memory movement between the kernel and user-space. Some additional functions exist (such as those that reduce the amount of checking performed). You can find these functions in uaccess.h.



Back to top


Using the system call

Now that kernel is updated with a few new system calls, let's look at what's necessary to use them from a user-space application. There are two ways that you can use new kernel system calls. The first is a convenience method (not something that you'd probably want to do in production code), and the second is the traditional method that requires a bit more work.

共8页: 上一页 [1] [2] [3] 4 [5] [6] [7] [8] 下一页
上一篇:Novell称微软专利许可观点“强奸民意”   下一篇:Linux and symmetric multiprocessing

收藏于收藏夹】 【评论】 【推荐】 【投稿】 【打印】 【关闭

相关文章
·Linux and symmetric multiprocessing
·通过Linux内核观察/proc/pid/statm
·Linux内核源代码的目录结构简单介绍
·按需对Linux系统内核进行定制和修改
·将驱动及应用软件移植到Linux2.6内核
·全面了解Linux操作系统核心配置文件
·三分钟编译支持NTFS的Linux系统模块
·linux内核启动地址的确定
·ubuntu 6.10 下编译2.6.19内核并安装NVIDIA
·教菜鸟编译自己的内核2.6.19
发表评论
密码: 匿名评论
评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。)
站内搜索
阅读排行榜
·基于S3C44B0微处理器的uCl
· 深入理解LINUX内核中文版
·Linux操作系统的内核编译
·Process priority and con
·Linux 2.6内核如何武装Fed
·通过振动向Linux ThinkPad
·主流嵌入式Linux系统下GUI
·推荐:Linux用户态与内核
·用命令行加挂Linux的文件
·Linux系统内核接收以太帧
最新文章
·用Tftp向目标板烧写Linux
·交叉编译Linux内核(2.6.22
·UNIX操作系统的加锁解锁:
·基于2.6.9内核小型Linux系
·Linux系统中使用GCC CPU参
·Linux系统的引导过程详细
·Linux系统的内核初始化过
·Linux系统高手之路 内核编
·Linux高手之内核编译过程
·Linux系统内核模块和驱动
·Linux系统下编译支持NTFS
·Linux系统中用内核KHTTPD
·Linux系统内核分析 使用GD
·Linux操作系统的内核解读
·通过Linux系统的内核观察/

设为首页 - 加入收藏 - 版权声明 - 广告服务 - 关于我们 - 联系我们 - 友情连接
Copyright © 2007 All rights reserved OKLinux.Cn 版权所有
合作联系 QQ:18743986 Email:arlan8005#163.com