Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.54 KB | None | 0 0
  1. #include "ish_syscalls.h"
  2.  
  3. long ish_read(
  4.         int file_descriptor,
  5.         void *buffer,
  6.         unsigned long buffer_size
  7.      )
  8. {
  9.        register long result asm("x0");
  10.  
  11.             __asm__ __volatile__ (
  12.                 "mov x8, #0x3F\n\t"
  13.                 "svc #0x0"
  14.                 : "=r" (result)
  15.                 : : "x8"
  16.             );
  17.  
  18.             return result;
  19.  
  20. }
  21.  
  22. int ish_chdir(const char *path)
  23. {
  24.     register long result asm("x0");
  25.     __asm__ __volatile__(
  26.             "mov x8, #0x31\n\t"
  27.         "svc #0x0"
  28.         : "=r" (result)
  29.         ::"x8"
  30.      );
  31.     return result;
  32. }
  33.  
  34. void ish_exit(int status)
  35. {
  36.     __asm__ __volatile__(
  37.       "mov x8, #0x5D\n\t"
  38.       "mov x0, #0x0\n\t"
  39.       "svc #0x0"
  40.       ::: "x8", "x0"
  41.     );
  42. }
  43.  
  44. int ish_stat(const char *path, void *stat_result)
  45. {
  46.         /*
  47.             `stat` doesn't work on aarch64 on Linux. The call should be
  48.             implemented through `fstatat` with the first parameter set to
  49.             AT_FDCWD (-100) to simulate the work of `stat`.
  50.         */
  51.  
  52.     register long result asm("x0");
  53.  
  54.     __asm__ __volatile__(
  55.             "mov x2, x1\n\t"
  56.         "mov x1, x0\n\t"
  57.         "mov x0, #-0x64\n\t"
  58.         "mov x3, #0x0\n\t"
  59.         "mov x8, #0x4F\n\t"
  60.         "svc #0x0"
  61.             : "=r" (result)
  62.         ::"x1","x2","x3","x8"
  63.         );
  64.         return result;
  65. }
  66.  
  67. int ish_open(const char *path, int flags)
  68. {
  69.         /*
  70.             `open` doesn't work on aarch64 on Linux. The call should be
  71.             implemented through `openat` with the first parameter set to
  72.             AT_FDCWD (-100) to simulate the work of `open`.
  73.         */
  74.     register long result asm("x0");
  75.  
  76.     __asm__ __volatile__(
  77.         "mov x2, x1\n\t"
  78.         "mov x1, x0\n\t"
  79.         "mov x0, #-0x64\n\t"
  80.         "mov x8, #0x38\n\t"
  81.         "svc #0x0"
  82.         : "=r" (result)
  83.         ::"x1", "x2", "x8"
  84.     );
  85.         return result;
  86. }
  87.  
  88. int ish_creat(const char *path, unsigned int mode)
  89. {
  90.         /*
  91.             `creat` doesn't work on aarch64 on Linux. The call should be
  92.             implemented through `openat` with the first parameter set to
  93.             AT_FDCWD (-100) to simulate the work of `creat`.
  94.         */
  95.     /* dir path flags mode*/
  96.     register long result asm("x0");
  97.  
  98.         __asm__ __volatile__(
  99.                 "mov x2, #0x241\n\t"
  100.                 "mov x3, x1\n\t"
  101.         "mov x1, x0\n\t"
  102.         "mov x0, #-0x64\n\t"
  103.                 "mov x8, #0x128\n\t"
  104.                 "svc #0x0"
  105.                 : "=r" (result)
  106.                 ::"x1", "x2", "x3", "x8"
  107.         );
  108.         return result;
  109. }
  110.  
  111. int ish_dup2(int old_file_descriptor, int new_file_descriptor)
  112. {
  113.         /*
  114.             `dup2` doesn't work on aarch64 on Linux. The call should be
  115.             implemented through `dup3` with the last parameter set to zero to
  116.             simulate the work of `dup2`.
  117.         */
  118.     register long result asm("x0");
  119.  
  120.         __asm__ __volatile__(
  121.                 "mov x2, #0x0\n\t"
  122.                 "mov x8, #0x18\n\t"
  123.                 "svc #0x0"
  124.                 : "=r" (result)
  125.                 ::"x1", "x2", "x8"
  126.         );
  127.         return result;
  128. }
  129.  
  130. int ish_close(int file_descriptor)
  131. {
  132.     register long result asm("x0");
  133.  
  134.         __asm__ __volatile__(
  135.                 "mov x8, #0x39\n\t"
  136.                 "svc #0x0"
  137.                 : "=r" (result)
  138.                 ::"x8"
  139.         );
  140.         return result;
  141. }
  142.  
  143. int ish_fork()
  144. {
  145.         /*
  146.             `fork` doesn't work on aarch64 on Linux. The call should be
  147.             implemented through `clone` with all parameters set to zero and the
  148.             flags parameter set to SIGCHLD (17) to simulate the work of `fork`.
  149.         */
  150. }
  151.  
  152. int ish_execve(
  153.         const char *path,
  154.         char *const arguments[],
  155.         char *const environment[]
  156.     )
  157. {
  158.     register long result asm("x0");
  159.  
  160.         __asm__ __volatile__(
  161.                 "mov x8, #0xDD\n\t"
  162.                 "svc #0x0"
  163.                 : "=r" (result)
  164.                 ::"x1", "x2", "x8"
  165.         );
  166.         return result;
  167. }
  168.  
  169. int ish_waitpid(int pid, int *status, int options)
  170. {
  171.     register int result asm("x0");
  172.  
  173.         __asm__ __volatile__ (
  174.             "mov x3, #0\n\t"
  175.                 "mov x8, #0x104\n\t"
  176.                 "svc #0x0"
  177.                 : "=r" (result)
  178.                 :
  179.                 : "x8","x3"
  180.         );
  181. }
  182.  
  183. long ish_write(
  184.         int file_descriptor,
  185.         const void *buffer,
  186.         unsigned long buffer_size
  187.      )
  188. {
  189.     register long result asm("x0");
  190.  
  191.         __asm__ __volatile__(
  192.                 "mov x8, #0x40\n\t"
  193.                 "svc #0x0"
  194.                 : "=r" (result)
  195.                 ::"x1", "x2", "x8"
  196.         );
  197.         return result;
  198. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement