0

I am trying to call the nanosleep syscall in assembly on the mac m1 architecture, but when I run it, I get an unexpected error. Link to the C code I try to get working in assembly. I have changed bl nanosleep with

mov x16, 0x65
svc 0x80

Where 0x65 is the syscall for nanosleep according to this

mov x0, 2
str x0, [sp, 56]
str xzr, [sp, 48]
ldr x0, [sp, 56]
str x0, [sp, 24]
ldr x0, [sp, 48]
str x0, [sp, 32]
add x0, sp, 24
mov x1, 0
mov x16, 0x65
svc 0x80

Error

terminated by signal SIGSYS (Bad system call)
Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
jevoso5871
  • 11
  • 3
  • On MacOS or Linux? The URL you linked (https://chromium.googlesource.com/chromiumos/docs/+/HEAD/constants/syscalls.md#arm-32_bit_EABI) is a table of call numbers for Linux. Also, the specific part you linked was the 32-bit ARM table, not AArch64 aka ARM64. – Peter Cordes Jun 17 '22 at 01:55
  • 1
    Find a table for macOS. System calls are different for each architecture and each operating system. The best way to do the system call is to call the `nanosleep` function in the libc. The second best way is to find a resource that applies to your system. – fuz Jun 17 '22 at 02:03
  • Does this answer your question? [iOS ARM64 Syscalls](https://stackoverflow.com/questions/56985859/ios-arm64-syscalls) – Siguza Jun 17 '22 at 11:54
  • I am using macOS, not iOS. Is there a system call table also there? And looking at the assembly generated from c: it uses `bl _nanosleep` instead. Is there a table also for these names? – jevoso5871 Jun 17 '22 at 12:34

0 Answers0