| 6 | #include "openat.h" |
| 7 | #define STR_HELPER(x) #x |
| 8 | #define STR(x) STR_HELPER(x) |
| 9 | intptr_t openAt(intptr_t fd, const char *path, intptr_t flag) { |
| 10 | #if defined(__arm__) |
| 11 | intptr_t r; |
| 12 | __asm__ volatile( |
| 13 | #ifndef OPTIMIZE_ASM |
| 14 | "mov r0, %1\n\t" |
| 15 | "mov r1, %2\n\t" |
| 16 | "mov r2, %3\n\t" |
| 17 | #endif |
| 18 | "mov ip, r7\n\t" |
| 19 | ".cfi_register r7, ip\n\t" |
| 20 | "ldr r7, =" STR(__NR_openat) "\n\t" |
| 21 | "svc #0\n\t" |
| 22 | "mov r7, ip\n\t" |
| 23 | ".cfi_restore r7\n\t" |
| 24 | #ifndef OPTIMIZE_ASM |
| 25 | "mov %0, r0\n\t" |
| 26 | #endif |
| 27 | : "=r" (r) |
| 28 | : "r" (fd), "r" (path), "r" (flag)); |
| 29 | return r; |
| 30 | #elif defined(__aarch64__) |
| 31 | intptr_t r; |
| 32 | __asm__ volatile( |
| 33 | #ifndef OPTIMIZE_ASM |
| 34 | "mov x0, %1\n\t" |
| 35 | "mov x1, %2\n\t" |
| 36 | "mov x2, %3\n\t" |
| 37 | #endif |
| 38 | "mov x8, " STR(__NR_openat) "\n\t" |
| 39 | "svc #0\n\t" |
| 40 | #ifndef OPTIMIZE_ASM |
| 41 | "mov %0, x0\n\t" |
| 42 | #endif |
| 43 | : "=r" (r) |
| 44 | : "r" (fd), "r" (path), "r" (flag)); |
| 45 | return r; |
| 46 | #else |
| 47 | return (intptr_t) syscall(__NR_openat, fd, path, flag); |
| 48 | #endif |
| 49 | } |
| 50 |