1*95ed3b44SJérôme Duval /*
2*95ed3b44SJérôme Duval * Copyright 2018, Jérôme Duval, jerome.duval@gmail.com.
3*95ed3b44SJérôme Duval * Copyright 2012, Alex Smith, alex@alex-smith.me.uk.
4*95ed3b44SJérôme Duval * Distributed under the terms of the MIT License.
5*95ed3b44SJérôme Duval */
6*95ed3b44SJérôme Duval
7*95ed3b44SJérôme Duval
8*95ed3b44SJérôme Duval #include "x86_signals.h"
9*95ed3b44SJérôme Duval
10*95ed3b44SJérôme Duval #include <string.h>
11*95ed3b44SJérôme Duval
12*95ed3b44SJérôme Duval #include <KernelExport.h>
13*95ed3b44SJérôme Duval
14*95ed3b44SJérôme Duval #include <commpage_compat.h>
15*95ed3b44SJérôme Duval #include <cpu.h>
16*95ed3b44SJérôme Duval #include <elf.h>
17*95ed3b44SJérôme Duval #include <smp.h>
18*95ed3b44SJérôme Duval
19*95ed3b44SJérôme Duval
20*95ed3b44SJérôme Duval extern "C" void x86_64_signal_handler_compat(void);
21*95ed3b44SJérôme Duval extern int x86_64_signal_handler_compat_end;
22*95ed3b44SJérôme Duval
23*95ed3b44SJérôme Duval
24*95ed3b44SJérôme Duval void
x86_compat_initialize_commpage_signal_handler()25*95ed3b44SJérôme Duval x86_compat_initialize_commpage_signal_handler()
26*95ed3b44SJérôme Duval {
27*95ed3b44SJérôme Duval void* handlerCode = (void*)&x86_64_signal_handler_compat;
28*95ed3b44SJérôme Duval void* handlerCodeEnd = &x86_64_signal_handler_compat_end;
29*95ed3b44SJérôme Duval
30*95ed3b44SJérôme Duval // Copy the signal handler code to the commpage.
31*95ed3b44SJérôme Duval size_t len = (size_t)((addr_t)handlerCodeEnd - (addr_t)handlerCode);
32*95ed3b44SJérôme Duval addr_t position = fill_commpage_compat_entry(
33*95ed3b44SJérôme Duval COMMPAGE_ENTRY_X86_SIGNAL_HANDLER, handlerCode, len);
34*95ed3b44SJérôme Duval
35*95ed3b44SJérôme Duval // Add symbol to the commpage image.
36*95ed3b44SJérôme Duval image_id image = get_commpage_compat_image();
37*95ed3b44SJérôme Duval elf_add_memory_image_symbol(image, "commpage_compat_signal_handler",
38*95ed3b44SJérôme Duval position, len, B_SYMBOL_TYPE_TEXT);
39*95ed3b44SJérôme Duval }
40*95ed3b44SJérôme Duval
41