4 void set_thread_stack(void *address
) {
5 /* KLUDGE: There is no interface to change the stack location of
6 the initial thread, and without that backtrace(3) returns zero
7 frames, which breaks some graphical applications on High Sierra
9 pthread_t thread
= pthread_self();
10 void *stackaddr
= pthread_get_stackaddr_np(thread
);
11 size_t stacksize
= pthread_get_stacksize_np(thread
);
13 if (__PTHREAD_SIZE__
>= 22*8 &&
14 ((void **)thread
->__opaque
)[20] == stackaddr
&&
15 ((size_t *)thread
->__opaque
)[21] == stacksize
) {
16 ((void **)thread
->__opaque
)[20] = address
;
17 ((size_t *)thread
->__opaque
)[21] = thread_control_stack_size
;
18 ((size_t *)thread
->__opaque
)[23] = (thread_control_stack_size
+ vm_page_size
);
22 void jit_patch(lispobj
* address
, lispobj value
) {
28 void jit_copy_code_insts(lispobj dst
, lispobj
* src
)
30 lispobj
* aligned_src
= (lispobj
*)(src
+ ((uword_t
)src
& N_WORD_BYTES
)); // align up
31 struct code
* code
= (struct code
*)(dst
-OTHER_POINTER_LOWTAG
);
32 int nwords
= code_total_nwords(code
);
33 gc_assert(code_total_nwords((struct code
*)aligned_src
));
35 // Leave the header word alone
36 memcpy(&code
->boxed_size
, aligned_src
+ 1, (nwords
-1)<<WORD_SHIFT
);
37 for_each_simple_fun(i
, fun
, code
, 1, { fun
->self
= fun_self_from_baseptr(fun
); })
40 // FINISH-FIXUPS didn't call SB-VM:SANCTIFY-FOR-EXECUTION
41 // because the copy of the code on which it operates was only temporary.
42 __clear_cache(code
, (lispobj
*)code
+ nwords
);
45 void jit_copy_code_constants(lispobj lispcode
, lispobj constants
)
47 struct code
* code
= (void*)(lispcode
- OTHER_POINTER_LOWTAG
);
48 gc_assert(header_widetag(code
->header
) == CODE_HEADER_WIDETAG
);
49 struct vector
* v
= VECTOR(constants
);
50 gc_assert(header_widetag(v
->header
) == SIMPLE_VECTOR_WIDETAG
);
51 gc_assert(find_page_index((void*)code
) >= 0);
54 block_blockable_signals(&mask
);
56 gc_card_mark
[addr_to_card_index(code
)] = CARD_MARKED
;
57 SET_WRITTEN_FLAG((lispobj
*)code
);
58 memcpy(&code
->constants
, v
->data
, vector_len(v
) * N_WORD_BYTES
);
60 thread_sigmask(SIG_SETMASK
, &mask
, 0);
63 void jit_memcpy(void* dst
, void* src
, size_t n
) {
69 void jit_patch_code(lispobj code
, lispobj value
, unsigned long index
) {
70 /* It is better not to the touch a card mark if the object is off-heap,
71 * though it's not terribly important any more */
72 if (find_page_index((void*)code
) >= 0) {
74 // Disallow GC in between setting the WRITTEN flag and doing the assigmment
75 block_blockable_signals(&mask
);
78 gc_card_mark
[addr_to_card_index(code
)] = CARD_MARKED
;
79 SET_WRITTEN_FLAG(native_pointer(code
));
80 native_pointer(code
)[index
] = value
;
83 thread_sigmask(SIG_SETMASK
, &mask
, 0);
84 } else { // Off-heap code objects can't be executed (or GC'd)
85 // umm, so why do they exist? I wish I could remember...
86 SET_WRITTEN_FLAG(native_pointer(code
));
87 native_pointer(code
)[index
] = value
;
93 os_flush_icache(os_vm_address_t address
, os_vm_size_t length
)
95 os_vm_address_t end_address
96 = (os_vm_address_t
)(((uintptr_t) address
) + length
);
97 __clear_cache(address
, end_address
);
101 sigill_handler(int signal
, siginfo_t
*siginfo
, os_context_t
*context
) {
103 if (siginfo
->si_code
== ILL_ILLTRP
&&
104 ((esr
= context
->uc_mcontext
->__es
.__esr
)>>26 & 0x3f) == 0x2C) {
109 else if (esr
& 1 << 3) {
111 } else if (esr
& 1 << 2) {
113 } else if (esr
& 1 << 1) {
115 } else if (esr
& 1) {
118 /* if (esr & 1 << 7) {
119 Input Denormal Floating-point exception trapped bit.
120 No FPE_ constant for it.
123 siginfo
->si_code
= code
;
124 return interrupt_handle_now(SIGFPE
, siginfo
, context
);
127 fake_foreign_function_call(context
);
128 lose("Unhandled SIGILL at %p.", (void*)OS_CONTEXT_PC(context
));