2013-12-16 75 views
2

我發現系統調用的列表X86-64模式(參數): http://filippo.io/linux-syscall-table/ 但我在哪裏可以得到這個系統調用的詳細說明嗎?的系統調用Linux的x86-64的NASM(YASM)詳細說明

例如下面,其標誌可以用於「開放式」系統調用除了0102o(RW,創建),在其他情況下: 只讀,只寫等

SECTION .data 
    message: db 'Hello, world!',0x0a  
    length: equ $-message   
    fname db "result" 
    fd  dq 0 

SECTION .text 
global _start 
_start: 
     mov rax, 2   ; 'open' syscall 
     mov rdi, fname  ; file name 
     mov rsi, 0102o  ; read and write mode, create if not 
     mov rdx, 0666o  ; permissions set 
     syscall 

     mov [fd], rax 

     mov rax, 1   ; 'write' syscall 
     mov rdi, [fd]  ; file descriptor 
     mov rsi, message ; message address 
     mov rdx, length  ; message string length 
     syscall 

     mov rax, 3    ; 'close' syscall 
     mov rdi, [fd]   ; file descriptor 
     syscall 

     mov rax, 60   
     mov rdi, 0   
     syscall 

基於源(可能是) https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/fs/open.c 如何理解它,哪些(所有打開的)列表可以使用?

回答

1

syscalls的文檔位於手冊頁的第2部分和/或源代碼中的註釋中。

手冊頁開頭:

#include <sys/types.h> 
    #include <sys/stat.h> 
    #include <fcntl.h> 

    int open(const char *pathname, int flags); 
    int open(const char *pathname, int flags, mode_t mode); 

的論點標誌必須包括下列訪問模式之一:O_RDONLYO_WRONLY,或O_RDWR。這些請求分別打開文件只讀,只寫或讀/寫。

另外,零個或多個文件創建標誌和文件狀態標誌可以在標誌中按位或置位。該文件創建標誌O_CREATO_EXCLO_NOCTTY,並O_TRUNC

這些值是在系統頭文件中查找的。

+0

grep -i 0102 /usr/include/asm/unistd_64.h-無。如何服用? – Alex0102o

+0

@ Alex0102o:我不明白。該文件是syscall條目號的列表:與* flags *參數無關。這些標誌位於'/ usr/include/bits/fcntl.h'中,其中0102顯然是'O_RDWR | O_CREAT'(至少在Fedora 17-64中)。 – wallyk

+0

wallyk,在/usr/include/bits/fcntl.h中是這樣的(Debian Lenny 64bit)謝謝! (對不起我的英文不好)0102我從32位nasm拿走。 – Alex0102o