2

I am working on a program that requires a lot of work in x86_64 assembly. Where is the official documentation on the available syscalls for 64-bit Linux? Most of the documentation I can find is either incomplete, for C system calls or is for 32-bit Linux (using int 0x80 rather than syscall).

Where might I find the documentation that will list the syscall numbers, as well as what values need to be in which registers in order to make the call work?

  • 1
    Which arguments go in which registers is defined by the [ABI](https://stackoverflow.com/questions/18133812/where-is-the-x86-64-system-v-abi-documented). Documentation isn't likely to specify that for each system call. – sj95126 Aug 22 '22 at 14:28
  • 3
    The "which registers" part is covered by the [calling convention](https://en.wikipedia.org/wiki/X86_calling_conventions#System_V_AMD64_ABI). For many syscalls the C wrappers use the same arguments, so `man` is usually fine. The [official list is of course in the kernel source](https://github.com/torvalds/linux/blob/master/arch/x86/entry/syscalls/syscall_64.tbl) but there are compiled versions on the [web](https://filippo.io/linux-syscall-table/). Also typically if you need syscalls that means you should be using C anyway. – Jester Aug 22 '22 at 14:29
  • 1
    "working in x86_64 assembly" and "needing syscalls" are orthogonal. – n. m. could be an AI Aug 22 '22 at 14:52
  • 1
    My recommendation: do not do direct system calls. Instead, call into the libc which has functions wrapping all system calls. This is the easiest, most compatible way of Linux systems programming and even has a good chance of making your code portable to other UNIX variants. To do so, have your program start with a `main` function and link through the C compiler driver. – fuz Aug 22 '22 at 16:46
  • Whilst I have answered your question below, @fuz has made a good suggestion. I would recommend taking such an approach over your current one – Salih MSA Aug 22 '22 at 17:05
  • `asm/unistd_64.h` has the call numbers. Man pages document when the kernel API differs from the glibc interface, The C documentation plus the calling convention tells you how to call from asm. See also [x86\_64 Linux syscall arguments](https://stackoverflow.com/q/22444526) – Peter Cordes Aug 24 '22 at 11:10

1 Answers1

1

With regards to syscalls, I found the x86-64 Linux system calls on google - it even has what registers to put the arguments in (you'll notice they're exactly as described above). Here you go: https://blog.rchapman.org/posts/Linux_System_Call_Table_for_x86_64/

As @fuz pointed out, the calling convention for syscalls (all syscalls that is) is not the same as regular function calls. Essentially, arguments get loaded into registers rdi, rsi, rdx, r10, r8 and r9 in that specific order.

Salih MSA
  • 120
  • 1
  • 7
  • 2
    Note that Linux system calls have a few divergences from the SysV ABI. It's not the exact same as for function calls. – fuz Aug 22 '22 at 16:45
  • Looked at the registers beyond arg 1 & 2 and you're right. Modified my answer above – Salih MSA Aug 22 '22 at 18:20