Revert "[LV][VPlan] Remove any-of reduction from precomputeCost. NFC" (#117280)
[llvm-project.git] / compiler-rt / test / shadowcallstack / minimal_runtime.h
blobfab4fdf8006f719306fa86000ccdc759000d9e13
1 // A shadow call stack runtime is not yet included with compiler-rt, provide a
2 // minimal runtime to allocate a shadow call stack and assign an
3 // architecture-specific register to point at it.
5 #pragma once
7 #include <stdlib.h>
8 #include <sys/mman.h>
9 #include <sys/prctl.h>
11 #include "libc_support.h"
13 __attribute__((no_sanitize("shadow-call-stack")))
14 static void __shadowcallstack_init() {
15 void *stack = mmap(NULL, 8192, PROT_READ | PROT_WRITE,
16 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
17 if (stack == MAP_FAILED)
18 abort();
20 #if defined(__aarch64__)
21 __asm__ __volatile__("mov x18, %0" ::"r"(stack));
22 #else
23 #error Unsupported platform
24 #endif
27 int scs_main(void);
29 __attribute__((no_sanitize("shadow-call-stack"))) int main(void) {
30 __shadowcallstack_init();
32 // We can't simply return scs_main() because scs_main might have corrupted our
33 // return address for testing purposes (see overflow.c), so we need to exit
34 // ourselves.
35 exit(scs_main());