Vlad Tsyrklevich 1781d105ed Add simple runtime tests for shadowcallstack
Summary:
ShadowCallStack does not yet have a runtime provided by compiler-rt, but
this change includes simple tests that make use of a very minimal
runtime in test/shadowcallstack/minimal_runtime.h

Reviewers: pcc, kcc, delcypher, eugenis, filcab

Reviewed By: pcc

Subscribers: kubamracek, mgorny, delcypher, llvm-commits, #sanitizers, kcc

Differential Revision: https://reviews.llvm.org/D44803

llvm-svn: 329210
2018-04-04 17:53:33 +00:00

27 lines
725 B
C

// A shadow call stack runtime is not yet included with compiler-rt, provide a
// minimal runtime to allocate a shadow call stack and assign %gs to point at
// it.
#pragma once
#include <asm/prctl.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <sys/prctl.h>
int arch_prctl(int code, void *addr);
__attribute__((no_sanitize("shadow-call-stack")))
static void __shadowcallstack_init() {
void *stack = mmap(NULL, 8192, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (stack == MAP_FAILED)
abort();
if (arch_prctl(ARCH_SET_GS, stack))
abort();
}
__attribute__((section(".preinit_array"), used))
void (*__shadowcallstack_preinit)(void) = __shadowcallstack_init;