Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Syscalls for x86-64 Linux NASM(YASM) detailed description

I found the list of syscalls for x86-64 mode (with arguments): http://filippo.io/linux-syscall-table/ but where can I get detailed description of this syscalls?

For example below, which flags can be used for 'open' syscall except 0102o (rw, create), in other cases: read only, write only, etc.

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

Based on source (may be) https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/fs/open.c how to understand it, which (list of all for open) flags can be used?

like image 928
Alex0102o Avatar asked Dec 16 '13 20:12

Alex0102o


1 Answers

The documentation for the syscalls is in section 2 of the man pages and/or in the comments in the source code.

The man page begins with:

   #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);

The argument flags must include one of the following access modes: O_RDONLY, O_WRONLY, or O_RDWR. These request opening the file read-only, write-only, or read/write, respectively.

In addition, zero or more file creation flags and file status flags can be bitwise-or'd in flags. The file creation flags are O_CREAT, O_EXCL, O_NOCTTY, and O_TRUNC.

The values for these are trivially looked up in the system header files.

like image 86
wallyk Avatar answered Oct 20 '22 16:10

wallyk