Using System Calls

来源:互联网 发布:清华北大抢人 知乎 编辑:程序博客网 时间:2024/06/05 19:31

The Linux system calls are located at interrupt 0x80. 

When the INT instruction is performed, all operations transfer to the system call handler in the kernel. When the system call is complete, execution

transfers back to the next instruction after the INT instruction (unless, of course, the exit system call is performed).

the EAX register is used to hold the system call value. 

This value defines which system call is used from the list of system calls supported by the kernel.

movl $1, %eaxint 0x80

After placing the system call value in the EAX register,
the INT instruction is performed, using the vector value for the kernel system calls (0x80).

System call input values

The order in which the system calls expect input values is as follows:
. EBX (first parameter)
. ECX (second parameter)
. EDX (third parameter)
. ESI (fourth parameter)
. EDI (fifth parameter)
 
System calls that require more than six input parameters use a different method of passing the parameters to the system call. 
The EBX register is used to contain a pointer to the memory location of the input
parameters, stored in sequential order.
The system call uses the pointer to access the memory location to read the parameters.

ssize_t write(int fd, const void *buf, size_t count);
Using this convention, the input values would be assigned to the following registers:
❑ EBX: The integer file descriptor
❑ ECX: The pointer (memory address) of the string to display
❑ EDX: The size of the string to display
.section .dataoutput:.ascii “This is a test message.\n”output_end:.equ len, output_end - output.section .text.globl _start_start:movl $4, %eaxmovl $1, %ebxmovl $output, %ecxmovl $len, %edxint $0x80movl $1, %eaxmovl $0, %ebxint $0x80
The file descriptor value for the output location is placed in the EBX. Linux systems contain three special
file descriptors:
❑ 0 (STDIN): The standard input for the terminal device (normally the keyboard)
❑ 1 (STDOUT): The standard output for the terminal device (normally the terminal screen)
❑ 2 (STDERR): The standard error output for the terminal device (normally the terminal screen)


原创粉丝点击