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 19 extern "C" void x86_64_user_signal_handler(void); 20 extern int x86_64_user_signal_handler_end; 21 22 23 void 24 x86_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 addr_t position = fill_commpage_entry(COMMPAGE_ENTRY_X86_SIGNAL_HANDLER, 32 handlerCode, len); 33 34 // Add symbol to the commpage image. 35 image_id image = get_commpage_image(); 36 elf_add_memory_image_symbol(image, "commpage_signal_handler", position, 37 len, B_SYMBOL_TYPE_TEXT); 38 } 39 40