【问题标题】:Syscalls for x86-64 Linux NASM(YASM) detailed descriptionSyscalls for x86-64 Linux NASM(YASM) 详细描述
【发布时间】:2014-01-04 08:54:18
【问题描述】:

我找到了 x86-64 模式(带参数)的系统调用列表: http://filippo.io/linux-syscall-table/ 但是我在哪里可以得到这个系统调用的详细描述?

例如下面,除了 0102o (rw, create) 之外,哪些标志可以用于 'open' 系统调用,在其他情况下: 只读、只写等。

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 怎么理解,可以使用哪些(打开的所有列表)标志?

【问题讨论】:

    标签: linux x86-64 nasm system-calls


    【解决方案1】:

    系统调用的文档位于手册页的第 2 节和/或源代码的 cmets 中。

    手册页开头为:

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

    flags 参数必须包含以下访问模式之一:O_RDONLYO_WRONLYO_RDWR。这些请求分别以只读、只写或读/写方式打开文件。

    此外,零个或多个文件创建标志和文件状态标志可以在标志中进行按位或运算。文件创建标志是 O_CREATO_EXCLO_NOCTTYO_TRUNC

    这些值在系统头文件中很容易找到。

    【讨论】:

    • grep -i 0102 /usr/include/asm/unistd_64.h -nothing。如何服用?
    • @Alex0102o:我不明白。该文件是系统调用条目号的列表:与 flags 参数无关。标志位于 /usr/include/bits/fcntl.h 中,其中 0102 显然是 O_RDWR | O_CREAT(至少在 Fedora 17-64 中)。
    • wallyk,在 /usr/include/bits/fcntl.h 中是的,这是(Debian Lenny 64 位)谢谢! (对不起,我的英语不好)0102 我从 32 位 nasm 中获取。
    • @Alex0102o:不客气。请务必通过单击我的答案旁边的复选标记来“接受”我的答案。当您有足够的声誉时,您还可以对好的答案投赞成票(对不好的答案投反对票)。
    • @wallyk #include 是关于 c,而不是 asm。有没有办法在 nasm 中包含这些符号? SO中的其他答案也说“使用名称,而不是数字”,但nasm当然不能识别O_RDONLY。
    猜你喜欢
    • 2012-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-12
    • 2012-07-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多