1 /* 2 * Copyright 2019 Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #include <commpage.h> 6 7 #include <string.h> 8 9 #include <KernelExport.h> 10 11 #include <cpu.h> 12 #include <elf.h> 13 #include <smp.h> 14 15 16 extern "C" void _thread_exit_syscall(); 17 18 19 static void 20 register_commpage_function(const char* functionName, int32 commpageIndex, 21 const char* commpageSymbolName, addr_t expectedAddress) 22 { 23 // get address and size of function 24 elf_symbol_info symbolInfo; 25 if (elf_lookup_kernel_symbol(functionName, &symbolInfo) != B_OK) { 26 panic("register_commpage_function(): Failed to find signal frame function \"%s\"!", 27 functionName); 28 } 29 30 ASSERT(expectedAddress == symbolInfo.address); 31 32 // fill in the commpage table entry 33 addr_t position = fill_commpage_entry(commpageIndex, (void*)symbolInfo.address, 34 symbolInfo.size); 35 36 // add symbol to the commpage image 37 image_id image = get_commpage_image(); 38 elf_add_memory_image_symbol(image, commpageSymbolName, position, symbolInfo.size, 39 B_SYMBOL_TYPE_TEXT); 40 } 41 42 43 status_t 44 arch_commpage_init(void) 45 { 46 return B_OK; 47 } 48 49 50 status_t 51 arch_commpage_init_post_cpus(void) 52 { 53 register_commpage_function("_thread_exit_syscall", COMMPAGE_ENTRY_ARM64_THREAD_EXIT, 54 "commpage_thread_exit", (addr_t)&_thread_exit_syscall); 55 56 return B_OK; 57 } 58