Skip to content

Commit a86b225

Browse files
committed
runtime: add a switch to turn handles off
1 parent d6f2a1d commit a86b225

File tree

2 files changed

+50
-4
lines changed

2 files changed

+50
-4
lines changed

runtime/rt/halloc.cpp

+30-3
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,19 @@
99
* and modify it as specified in the file "LICENSE".
1010
*/
1111

12+
// #define MALLOC_BYPASS
13+
14+
#ifdef MALLOC_BYPASS
15+
#include <malloc.h>
16+
#endif
1217

1318
#include <alaska/Runtime.hpp>
1419
#include <alaska/ThreadCache.hpp>
1520
#include <alaska.h>
1621
#include <errno.h>
1722

1823

24+
1925
// TODO: don't have this be global!
2026
static __thread alaska::ThreadCache *g_tc = nullptr;
2127

@@ -38,12 +44,25 @@ static void *_halloc(size_t sz, int zero) {
3844
}
3945

4046

41-
void *halloc(size_t sz) noexcept { return _halloc(sz, 0); }
47+
void *halloc(size_t sz) noexcept {
48+
#ifdef MALLOC_BYPASS
49+
return ::malloc(sz);
50+
#endif
51+
return _halloc(sz, 0);
52+
}
4253

43-
void *hcalloc(size_t nmemb, size_t size) { return _halloc(nmemb * size, 1); }
54+
void *hcalloc(size_t nmemb, size_t size) {
55+
#ifdef MALLOC_BYPASS
56+
return ::calloc(nmemb, size);
57+
#endif
58+
return _halloc(nmemb * size, 1);
59+
}
4460

4561
// Reallocate a handle
4662
void *hrealloc(void *handle, size_t new_size) {
63+
#ifdef MALLOC_BYPASS
64+
return ::realloc(handle, new_size);
65+
#endif
4766
// If the handle is null, then this call is equivalent to malloc(size)
4867
if (handle == NULL) return halloc(new_size);
4968

@@ -71,6 +90,9 @@ void *hrealloc(void *handle, size_t new_size) {
7190

7291

7392
void hfree(void *ptr) {
93+
#ifdef MALLOC_BYPASS
94+
return ::free(ptr);
95+
#endif
7496
// no-op if NULL is passed
7597
if (unlikely(ptr == NULL)) return;
7698

@@ -86,4 +108,9 @@ void hfree(void *ptr) {
86108

87109

88110

89-
size_t alaska_usable_size(void *ptr) { return get_tc()->get_size(ptr); }
111+
size_t alaska_usable_size(void *ptr) {
112+
#ifdef MALLOC_BYPASS
113+
return ::malloc_usable_size(ptr);
114+
#endif
115+
return get_tc()->get_size(ptr);
116+
}

runtime/yukon/yukon.cpp

+20-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ static alaska::ThreadCache *tc = NULL;
3737

3838
static void set_ht_addr(void *addr) {
3939
alaska::printf("set htbase to %p\n", addr);
40+
uint64_t value = (uint64_t)addr;
41+
if (value != 0 and getenv("YUKON_PHYS") != nullptr) {
42+
value |= (1LU << 63);
43+
}
4044
write_csr(0xc2, addr);
4145
}
4246

@@ -107,6 +111,16 @@ static void handle_sig(int sig) {
107111
}
108112

109113

114+
static void segv_handler(int sig, siginfo_t *info, void *ucontext) {
115+
printf("Caught segfault to address %p\n", info->si_addr);
116+
void *buffer[BACKTRACE_SIZE];
117+
// Get the backtrace
118+
int nptrs = backtrace(buffer, BACKTRACE_SIZE);
119+
// Print the backtrace symbols
120+
backtrace_symbols_fd(buffer, nptrs, STDOUT_FILENO);
121+
exit(0);
122+
}
123+
110124

111125
static void init(void) {
112126
setvbuf(stdout, stdout_buf, _IOLBF, BUFSIZ);
@@ -125,9 +139,14 @@ static void init(void) {
125139
asm volatile("fence" ::: "memory");
126140
set_ht_addr(handle_table_base);
127141

142+
struct sigaction act = {0};
143+
act.sa_sigaction = segv_handler;
144+
act.sa_flags = SA_SIGINFO;
145+
sigaction(SIGSEGV, &act, NULL);
146+
128147

129148
signal(SIGABRT, handle_sig);
130-
signal(SIGSEGV, handle_sig);
149+
// signal(SIGSEGV, handle_sig);
131150
signal(SIGBUS, handle_sig);
132151
signal(SIGILL, handle_sig);
133152
}

0 commit comments

Comments
 (0)