linux下系统调用接口,LINUX系统调用

系统调用是用户程序和linux内核交互的接口,linux的系统调用有下面三种方式:

int 80

在x86与x86_64的系统中,都可以使用int $0x80指令来执行系统调用,参数使用如下:

调用号

参数1

参数2

参数3

参数4

参数5

参数6

返回值

eax

ebx

ecx

edx

esi

edi

ebp

eax

syscall

x86_64引入了一个新指令syscall来执行系统调用,参数使用如下:

调用号

参数1

参数2

参数3

参数4

参数5

参数6

返回值

rax

rdi

rsi

rdx

r10

r8

r9

rax

库函数

正常调用库函数(man 3 execve),传参方式见x86 调用约定

查看调用号与参数

查看调用号:头文件/usr/include/asm/unistd.h内容如下,所以32位和64位的调用号可以分别在unistd_32.h和unistd_64.h中找到

/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */

#ifndef _ASM_X86_UNISTD_H

#define _ASM_X86_UNISTD_H

/* x32 syscall flag bit */

#define __X32_SYSCALL_BIT 0x40000000UL

# ifdef __i386__

# include

# elif defined(__ILP32__)

# include

# else

# include

# endif

#endif /* _ASM_X86_UNISTD_H */

查看参数:man 2 execve

示例

以execve为例,man 2 execve查看其接口如下:int execve(const char *pathname, char *const argv[], char *const envp[]);

下面汇编实现了execve("/bin/sh", 0, 0):

32位:

xor ecx, ecx

push 0x0b

pop eax

cdq

push 0x68732f

push 0x6e69622f

mov ebx, esp

int 0x80

64位:

mov rdx, 0x68732f6e69622f

push rdx

push rsp

pop rdi

xor rsi, rsi

xor rdx, rdx

push 59

pop rax

syscall

参考

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值