Alex0102o Alex0102o - 1 year ago 152
Linux Question

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

I found the list of syscalls for x86-64 mode (with arguments):
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.

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

global _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

mov [fd], rax

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

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

mov rax, 60
mov rdi, 0

Based on source (may be)
how to understand it, which (list of all for open) flags can be used?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download