深入理解linux内核笔记六:linux系统调用
一般情况下,进程不能存取系统内核的,只有系统调用是一个例外,在intel结构的计算机中,是通过中断0x80实现的
进程可以可以跳转到内核中的位置是system_call。在此检查系统调用号,它告诉内核进程请求何种服务,然后查找系统调用表sys_call_table,找到希望调用的内核地址函数,调用此函数,然后返回。
1、 宏定义(unistd.h)
_syscallN(type,name,x…),N是系统调用所需参数数目,type是返回类型,name是面向用户的系统调用函数名,x…是参数,个数为N
如:#define _syscall1(type,name,type1,arg1) \
type name(type1 arg1) \
{ \
long __res; \
__asm__ volatile ("push %%ebx ; movl %2,%%ebx ; int $0x80 ; pop %%ebx" \
: "=a" (__res) \
: "0" (__NR_##name),"ri" ((long)(arg1)) : "memory"); \
__syscall_return(type,__res); \
}
分析:
ouput: _res 0% __NR##name “=a”表示存放在eax寄存器
也就是表示把变量_res存放在eax中,“0”表示把_NR##name关联到0%即_res.返回值也存放在eax中.
#define _syscall2(type,name,type1,arg1,type2,arg2) \
type name(type1 arg1,type2 arg2) \
{ \
long __res; \
__asm__ volatile ("push %%ebx ; movl %2,%%ebx ; int $0x80 ; pop %%ebx" \
: "=a" (__res) \
: "0" (__NR_##name),"ri" ((long)(arg1)),"c" ((long)(arg2)) \
: "memory"); \
__syscall_return(type,__res); \
}
同理可以知道arg1存放在eax中,arg2存放在ebx中
当我们在程序中用到系统调用时,对于linux预定义的系统调用,编译器会在预处理时自动加入宏_syscallN()并将其展开,对于自己添加的系统调用,需要在程序中显示地调用宏_syscallN.
2 系统调用入口函数
在_syscallN()中执行了int 0x80后,程序进入内核态,我们在陷阱门和系统门的初始化里做了如下设置
set_system_gate(SYSCALL_VECTOR,&system_call);
程序跳到system_call(entry.s)处
ENTRY(system_call)
&nb
相关文档:
Service Discovery Protocol(SDP)提供一种能力,让应用程序有方法发现哪种服务可用以及这种服务的特性。
服务发现协议(SDP或Bluetooth SDP)在蓝牙协议栈中对蓝牙环境中的应用程序有特殊的含意,发现哪个服务是可用的和确定这些可用服务的特征。SDP定义了bluetooth client发现可用bluetooth server服务和它们的特征的方法。 ......
Linux下CHM查看工具汇总
http://www.ossw.com.cn/bbs/bencandy.php?id=2252&l_page=1
1. chmsee
homepage: http://211.92.88.40/~zhong/
requires: gtkhtml, libgnomevfs
......
PostgreSQL Linux
安装及使用,简易手册
一,配置方法:
1
,首先下载任意版本的PostgreSQL For Linux X86_64
wget http://downloads.enterprisedb.com/postgresql/postgresql-8.4.1-1-linux-x64.bin
2
,文本模式安装
[root@imdba.cn ~]# ./postgresql-8.4.1-1-linux-x64.bin –mode text
&mda ......
.tar
解包: tar xvf FileName.tar
打包:tar cvf FileName.tar DirName
(注:tar是打包,不是压缩!)
---------------------------------------------
.gz
解压1:gunzip FileName.gz
解压2:gzip -d FileName.gz
压缩:gzip FileName
.tar.gz
解压:tar zxvf FileName.tar.gz
压缩:tar zcvf FileName ......
Linux实验报告3
我的作业 2009 11-10
实验:VI编辑器
姓 名
张凯
实验地点
A605
实验时间
2009 11月10 星期二
一、实验目的
要求:运用编辑器熟练掌握文本编辑的命令
&nbs ......