title: Android Studio 64 bit inline ARM assembly
body: <p>I am trying to run some inline assembly code for aarch64 from Android Studio 3.4.2 and I got a compilation error <code>error: Don't know how to handle indirect register inputs yet for constraint 'r'</code>.</p>
  
  <p>My code snippet as follows</p>
  
  <pre><code>std::string system_file = "/system/bin/sh";
  std::int64_t file_descriptor = -1;
  
  #ifdef __aarch64__
      __asm__ volatile("mov x8, #180\n\t"
                       "mov x0, %1\n\t"
                       "mov x1, #0\n\t"
                       "svc #1\n\t"
                       "mov %0, x0\n\t"
                      :"=r"(file_descriptor)
                      :"r"(system_file)
                      :"x0","x1","x8"
                      );
  #endif
  </code></pre>
  
  <p>ARM64 syscalls based on this article</p>
  
  <p><a href="https://reverseengineering.stackexchange.com/questions/16917/arm64-syscalls-table">https://reverseengineering.stackexchange.com/questions/16917/arm64-syscalls-table</a></p>
  
  <p>and taken from</p>
  
  <p><a href="https://github.com/torvalds/linux/blob/v4.17/include/uapi/asm-generic/unistd.h" rel="nofollow noreferrer">https://github.com/torvalds/linux/blob/v4.17/include/uapi/asm-generic/unistd.h</a></p>
  
  <p>I am not sure if the error is due to Android Studio or am I doing something wrong here? Any advice is appreciated.</p>
  
  <p>**** EDIT ****</p>
  
  <p>I think I may have been looking at the wrong syscall number. Instead, I should be looking at</p>
  
  <pre><code>#define __NR_openat 56
  __SC_COMP(__NR_openat, sys_openat, compat_sys_openat)
  </code></pre>
  
  <p>Now I am trying to do this and it seems to be wrong.</p>
  
  <pre><code>    std::string system_file = "/system/bin/sh";
      const char *ptr  = system_file.c_str();
      std::int64_t file_descriptor = 0;
      register std::int64_t x8 asm("x8") = 56;
      register std::int64_t x0 asm("x0") = 0;
      register std::int64_t x2 asm("x2") = 0;
  
      __asm__ volatile("svc #1"
      :"=r"(file_descriptor)
      :"r"(x0),"r"(ptr),"r"(x2),"r"(x8)
      :"memory"
      );
  
      __android_log_print(ANDROID_LOG_DEBUG,"native_code","file_descriptor: %i",file_descriptor);
  </code></pre>
  
  <p>I can see a number "56" returned in logcat but it is the same number regardless the file exists or not. Is it a coincidence that it is the same as the syscall number?</p>