forked from scala-native/scala-native
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Preliminary support for segfault-based safepoints (scala-native#711)
* Add support for volatile loads and stores to NIR * Add support for alignment attribute * Preliminary support for segfault-based safepoints
- Loading branch information
Showing
18 changed files
with
244 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,24 @@ | ||
#include <gc.h> | ||
#include <stdlib.h> | ||
#include <stdio.h> | ||
|
||
// At the moment we rely on the conservative | ||
// mode of Boehm GC as our garbage collector. | ||
|
||
void scalanative_init() { | ||
GC_init(); | ||
} | ||
void scalanative_init() { GC_init(); } | ||
|
||
void* scalanative_alloc(void* info, size_t size) { | ||
void** alloc = (void**) GC_malloc(size); | ||
void *scalanative_alloc(void *info, size_t size) { | ||
void **alloc = (void **)GC_malloc(size); | ||
*alloc = info; | ||
return (void*) alloc; | ||
return (void *)alloc; | ||
} | ||
|
||
void* scalanative_alloc_raw(size_t size) { | ||
return GC_malloc(size); | ||
} | ||
void *scalanative_alloc_raw(size_t size) { return GC_malloc(size); } | ||
|
||
void* scalanative_alloc_raw_atomic(size_t size) { | ||
void *scalanative_alloc_raw_atomic(size_t size) { | ||
return GC_malloc_atomic(size); | ||
} | ||
|
||
void scalanative_collect() { | ||
GC_gcollect(); | ||
} | ||
void scalanative_collect() { GC_gcollect(); } | ||
|
||
void scalanative_safepoint() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include <signal.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <sys/mman.h> | ||
|
||
extern unsigned char scalanative_safepoint_trigger[4096] __attribute__((aligned(4096))); | ||
|
||
void scalanative_safepoint(); | ||
|
||
void scalanative_safepoint_on() { | ||
mprotect((void*) &scalanative_safepoint_trigger, 4096, PROT_NONE); | ||
} | ||
|
||
void scalanative_safepoint_off() { | ||
mprotect((void*) &scalanative_safepoint_trigger, 4096, PROT_READ); | ||
} | ||
|
||
void scalanative_safepoint_handler(int sig, siginfo_t *info, void *ucontext) { | ||
if (info->si_addr == (void*) &scalanative_safepoint_trigger) { | ||
scalanative_safepoint(); | ||
} else { | ||
printf("Segfault %d at %p", sig, info->si_addr); | ||
exit(1); | ||
} | ||
} | ||
|
||
void scalanative_safepoint_init() { | ||
struct sigaction action; | ||
action.sa_sigaction = scalanative_safepoint_handler; | ||
action.sa_flags = SA_RESTART | SA_SIGINFO; | ||
sigemptyset(&action.sa_mask); | ||
sigaction(SIGSEGV, &action, NULL); | ||
sigaction(SIGBUS, &action, NULL); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.