Skip to content

Commit

Permalink
stackTrace: support aarch64/linux
Browse files Browse the repository at this point in the history
stacktrace calls syscall directly via assembler. Create compatible
aarch64 code.
  • Loading branch information
Tsahi Zidenberg committed Feb 16, 2021
1 parent 6ad42d4 commit 442d087
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions pxr/base/arch/stackTrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,6 @@ nonLockingLinux__execve (const char *file,
char *const argv[],
char *const envp[])
{
#if defined(ARCH_BITS_64)
/*
* We make a direct system call here, because we can't find an
* execve which corresponds with the non-locking fork we call
Expand All @@ -594,7 +593,27 @@ nonLockingLinux__execve (const char *file,
* hangs in a threaded app. (We use the non-locking fork to get
* around problems with forking when we have had memory
* corruption.) whew.
*
*/

unsigned long result;

#if defined (__aarch64__)
{
register long __file_result asm ("x0") = (long)file;
register char* const* __argv asm ("x1") = argv;
register char* const* __envp asm ("x2") = envp;
register long __num_execve asm ("x8") = 221;
__asm__ __volatile__ (
"svc 0"
: "=r" (__file_result)
: "r"(__num_execve), "r" (__file_result), "r" (__argv), "r" (__envp)
: "memory"
);
result = __file_result;
}
#elif defined(ARCH_CPU_INTEL) && defined(ARCH_BITS_64)

/*
* %rdi, %rsi, %rdx, %rcx, %r8, %r9 are args 0-5
* syscall clobbers %rcx and %r11
*
Expand All @@ -603,7 +622,6 @@ nonLockingLinux__execve (const char *file,
* constraints to gcc.
*/

unsigned long result;
__asm__ __volatile__ (
"mov %0, %%rdi \n\t"
"mov %%rcx, %%rsi \n\t"
Expand All @@ -614,16 +632,16 @@ nonLockingLinux__execve (const char *file,
: "0" (file), "c" (argv), "d" (envp)
: "memory", "cc", "r11"
);
#else
#error Unknown architecture
#endif

if (result >= 0xfffffffffffff000) {
errno = -result;
result = (unsigned int)-1;
}

return result;
#else
#error Unknown architecture
#endif
}

#endif
Expand Down

0 comments on commit 442d087

Please sign in to comment.