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