1/*
2 * Copyright 2012, Alex Smith, alex@alex-smith.me.uk.
3 * Distributed under the terms of the MIT License.
4 */
5
6
7#include "x86_signals.h"
8
9#include <string.h>
10
11#include <KernelExport.h>
12
13#include <commpage.h>
14#include <cpu.h>
15#include <elf.h>
16#include <smp.h>
17
18
19extern "C" void x86_64_user_signal_handler(void);
20extern int x86_64_user_signal_handler_end;
21
22
23void
24x86_initialize_commpage_signal_handler()
25{
26	void* handlerCode = (void*)&x86_64_user_signal_handler;
27	void* handlerCodeEnd = &x86_64_user_signal_handler_end;
28
29	// Copy the signal handler code to the commpage.
30	size_t len = (size_t)((addr_t)handlerCodeEnd - (addr_t)handlerCode);
31	fill_commpage_entry(COMMPAGE_ENTRY_X86_SIGNAL_HANDLER, handlerCode, len);
32
33	// Add symbol to the commpage image.
34	image_id image = get_commpage_image();
35	elf_add_memory_image_symbol(image, "commpage_signal_handler",
36		((addr_t*)USER_COMMPAGE_ADDR)[COMMPAGE_ENTRY_X86_SIGNAL_HANDLER],
37		len, B_SYMBOL_TYPE_TEXT);
38}
39
40