linux 系统调用示例
2013-03-01 16:02
225 查看
#include <stdio.h>
#include <errno.h>
#define __NR_mysyscall 341
#define _syscall0(type, name) \
type name(void) \
{ \
long __res; \
__asm__ __volatile__("int $0x80":"=a"(__res) :"a"(__NR_##name)); \
if (__res >= 0) \
return (type) __res; \
errno = -__res; \
return -1; \
}
_syscall0(int, mysyscall)
int main(int argc, char* argv[])
{
int res;
res = mysyscall();
if (res < 0)
printf("call mysyscall res=%d, strerror(%d)=%s\n", res, errno, strerror(errno));
else
printf("call mysyscall ok res=%d\n", res);
return 0;
}
#include <errno.h>
#define __NR_mysyscall 341
#define _syscall0(type, name) \
type name(void) \
{ \
long __res; \
__asm__ __volatile__("int $0x80":"=a"(__res) :"a"(__NR_##name)); \
if (__res >= 0) \
return (type) __res; \
errno = -__res; \
return -1; \
}
_syscall0(int, mysyscall)
int main(int argc, char* argv[])
{
int res;
res = mysyscall();
if (res < 0)
printf("call mysyscall res=%d, strerror(%d)=%s\n", res, errno, strerror(errno));
else
printf("call mysyscall ok res=%d\n", res);
return 0;
}
相关文章推荐
- linux下 hook 系统调用示例
- linux中直接进行系统调用和通过C库调用的示例
- linux文件编程-系统调用
- (转)Linux系统调用--getrlimit/setrlimit函数
- Linux系统编程——Linux系统调用
- PHPCMS中GET标签概述、 get 标签语法、get 标签创建工具、get 调用本系统示例、get 调用其他系统示例
- 关于linux系统调用fork()的一道面试题
- Linux系统下Git的基本配置和使用示例
- linux 系统调用执行过程
- 【Linux编程】中断的系统调用
- linux系统调用
- 使用 Linux 系统调用的内核命令
- Linux进程相关系统调用(三)
- Linux系统调用的内核命令 : 探究SCI并添加自己的调用
- 带着O_CREAT和O_RDWR进入linux系统调用open函数
- Linux下C编程,进程通信之标准流管道通信(即系统调用)
- 中科院ICTCLAS系统,ICTCLAS.dll的函数调用示例(C语言)
- linux 系统调用接口
- Linux下文件的堵塞与非堵塞对部分系统调用的影响
- 64位Linux系统调用的添加以及系统调用的原理