Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "ish_syscalls.h"
- long ish_read(
- int file_descriptor,
- void *buffer,
- unsigned long buffer_size
- )
- {
- register long result asm("x0");
- __asm__ __volatile__ (
- "mov x8, #0x3F\n\t"
- "svc #0x0"
- : "=r" (result)
- : : "x8"
- );
- return result;
- }
- int ish_chdir(const char *path)
- {
- register long result asm("x0");
- __asm__ __volatile__(
- "mov x8, #0x31\n\t"
- "svc #0x0"
- : "=r" (result)
- ::"x8"
- );
- return result;
- }
- void ish_exit(int status)
- {
- __asm__ __volatile__(
- "mov x8, #0x5D\n\t"
- "mov x0, #0x0\n\t"
- "svc #0x0"
- ::: "x8", "x0"
- );
- }
- int ish_stat(const char *path, void *stat_result)
- {
- /*
- `stat` doesn't work on aarch64 on Linux. The call should be
- implemented through `fstatat` with the first parameter set to
- AT_FDCWD (-100) to simulate the work of `stat`.
- */
- register long result asm("x0");
- __asm__ __volatile__(
- "mov x2, x1\n\t"
- "mov x1, x0\n\t"
- "mov x0, #-0x64\n\t"
- "mov x3, #0x0\n\t"
- "mov x8, #0x4F\n\t"
- "svc #0x0"
- : "=r" (result)
- ::"x1","x2","x3","x8"
- );
- return result;
- }
- int ish_open(const char *path, int flags)
- {
- /*
- `open` doesn't work on aarch64 on Linux. The call should be
- implemented through `openat` with the first parameter set to
- AT_FDCWD (-100) to simulate the work of `open`.
- */
- register long result asm("x0");
- __asm__ __volatile__(
- "mov x2, x1\n\t"
- "mov x1, x0\n\t"
- "mov x0, #-0x64\n\t"
- "mov x8, #0x38\n\t"
- "svc #0x0"
- : "=r" (result)
- ::"x1", "x2", "x8"
- );
- return result;
- }
- int ish_creat(const char *path, unsigned int mode)
- {
- /*
- `creat` doesn't work on aarch64 on Linux. The call should be
- implemented through `openat` with the first parameter set to
- AT_FDCWD (-100) to simulate the work of `creat`.
- */
- /* dir path flags mode*/
- register long result asm("x0");
- __asm__ __volatile__(
- "mov x2, #0x241\n\t"
- "mov x3, x1\n\t"
- "mov x1, x0\n\t"
- "mov x0, #-0x64\n\t"
- "mov x8, #0x128\n\t"
- "svc #0x0"
- : "=r" (result)
- ::"x1", "x2", "x3", "x8"
- );
- return result;
- }
- int ish_dup2(int old_file_descriptor, int new_file_descriptor)
- {
- /*
- `dup2` doesn't work on aarch64 on Linux. The call should be
- implemented through `dup3` with the last parameter set to zero to
- simulate the work of `dup2`.
- */
- register long result asm("x0");
- __asm__ __volatile__(
- "mov x2, #0x0\n\t"
- "mov x8, #0x18\n\t"
- "svc #0x0"
- : "=r" (result)
- ::"x1", "x2", "x8"
- );
- return result;
- }
- int ish_close(int file_descriptor)
- {
- register long result asm("x0");
- __asm__ __volatile__(
- "mov x8, #0x39\n\t"
- "svc #0x0"
- : "=r" (result)
- ::"x8"
- );
- return result;
- }
- int ish_fork()
- {
- /*
- `fork` doesn't work on aarch64 on Linux. The call should be
- implemented through `clone` with all parameters set to zero and the
- flags parameter set to SIGCHLD (17) to simulate the work of `fork`.
- */
- }
- int ish_execve(
- const char *path,
- char *const arguments[],
- char *const environment[]
- )
- {
- register long result asm("x0");
- __asm__ __volatile__(
- "mov x8, #0xDD\n\t"
- "svc #0x0"
- : "=r" (result)
- ::"x1", "x2", "x8"
- );
- return result;
- }
- int ish_waitpid(int pid, int *status, int options)
- {
- register int result asm("x0");
- __asm__ __volatile__ (
- "mov x3, #0\n\t"
- "mov x8, #0x104\n\t"
- "svc #0x0"
- : "=r" (result)
- :
- : "x8","x3"
- );
- }
- long ish_write(
- int file_descriptor,
- const void *buffer,
- unsigned long buffer_size
- )
- {
- register long result asm("x0");
- __asm__ __volatile__(
- "mov x8, #0x40\n\t"
- "svc #0x0"
- : "=r" (result)
- ::"x1", "x2", "x8"
- );
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement