From af36d1bc83d8d4996b1c6042cb172060ad17f931 Mon Sep 17 00:00:00 2001 From: Ilya Berezhniuk Date: Tue, 18 Mar 2008 16:58:41 +0300 Subject: [PATCH] Make Port Crash/Signal Handler shared --- build.xml | 18 ++- make/vm/hythr.xml | 1 + make/vm/port.xml | 43 ++------ make/vm/port_ch.xml | 121 ++++++++++++++++++++ make/vm/vmcore.xml | 3 +- vm/include/open/types.h | 2 +- vm/port/build/ch.exp | 25 ++++ vm/port/include/port_crash_handler.h | 16 ++-- vm/port/include/port_memaccess.h | 5 +- vm/port/include/port_modules.h | 9 +- vm/port/include/port_unwind.h | 7 +- .../src/crash_handler/linux/gdb_crash_handler.cpp | 2 +- vm/port/src/misc/linux/execname.c | 73 ++++++++++++ vm/port/src/misc/linux/sysinfo.c | 46 -------- vm/port/src/misc/win/execname.c | 38 ++++++ vm/port/src/misc/win/sysinfo.c | 15 --- vm/port/src/thread/linux/thread_asm_em64t.s | 10 +- vm/port/src/thread/linux/thread_em64t.c | 8 ++ vm/port/src/thread/win/thread_os.c | 6 +- 19 files changed, 319 insertions(+), 129 deletions(-) create mode 100644 make/vm/port_ch.xml create mode 100644 vm/port/build/ch.exp create mode 100644 vm/port/src/misc/linux/execname.c create mode 100644 vm/port/src/misc/win/execname.c diff --git a/build.xml b/build.xml index 4029694..90a5024 100644 --- a/build.xml +++ b/build.xml @@ -109,22 +109,26 @@ Usage: - + - + - + - + + + + + @@ -137,7 +141,7 @@ Usage: - + @@ -148,7 +152,7 @@ Usage: - + @@ -164,7 +168,7 @@ Usage: - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/make/vm/vmcore.xml b/make/vm/vmcore.xml index 52a33b1..1bb17f8 100644 --- a/make/vm/vmcore.xml +++ b/make/vm/vmcore.xml @@ -217,7 +217,8 @@ - + + diff --git a/vm/include/open/types.h b/vm/include/open/types.h index 63abb85..363d379 100644 --- a/vm/include/open/types.h +++ b/vm/include/open/types.h @@ -18,7 +18,7 @@ #ifndef _VM_TYPES_H_ #define _VM_TYPES_H_ -#include "platform_types.h" +#include "open/platform_types.h" #include diff --git a/vm/port/build/ch.exp b/vm/port/build/ch.exp new file mode 100644 index 0000000..8c4b1b8 --- /dev/null +++ b/vm/port/build/ch.exp @@ -0,0 +1,25 @@ +PORT_0.1 { + global : +# + port_init_crash_handler; + port_shutdown_crash_handler; + port_crash_handler_*; + port_set_breakpoint; + port_clear_breakpoint; + port_is_breakpoint_set; + port_read_memory; + port_write_memory; + port_get_all_modules; + port_dump_modules; + port_clear_modules; + port_find_module; + port_thread_*; + port_transfer_to_regs; + port_set_longjump_regs; + port_transfer_to_function; + port_init_unwind_context; + port_clean_unwind_context; + port_unwind_frame; +# + local : *; +}; diff --git a/vm/port/include/port_crash_handler.h b/vm/port/include/port_crash_handler.h index deca7f1..1692bf9 100644 --- a/vm/port/include/port_crash_handler.h +++ b/vm/port/include/port_crash_handler.h @@ -135,7 +135,7 @@ typedef struct * @return TRUE if initalization is successful. * FALSE if initialization failed. */ -Boolean port_init_crash_handler( +VMEXPORT Boolean port_init_crash_handler( port_signal_handler_registration *registrations, unsigned count, port_unwind_compiled_frame unwind_callback); @@ -201,7 +201,7 @@ typedef enum * * @returns supported crash handler features. */ -unsigned port_crash_handler_get_capabilities(); +VMEXPORT unsigned port_crash_handler_get_capabilities(); /** * Set crash handler output flags. Default mode is @@ -212,7 +212,7 @@ unsigned port_crash_handler_get_capabilities(); * * @param flags - crash handler output flags. */ -void port_crash_handler_set_flags(unsigned flags); +VMEXPORT void port_crash_handler_set_flags(unsigned flags); /** * Callback function that is called at the end of shutdown sequence. @@ -243,7 +243,7 @@ typedef void (*port_crash_handler_action)( * FALSE if action was not added because no memory could * be allocated. */ -Boolean port_crash_handler_add_action(port_crash_handler_action action); +VMEXPORT Boolean port_crash_handler_add_action(port_crash_handler_action action); /** * Shutdown signals and crash handler. All signals are assigned their @@ -255,7 +255,7 @@ Boolean port_crash_handler_add_action(port_crash_handler_action action); * @return TRUE if shutdown is * successful. FALSE if shutdown failed. */ -Boolean port_shutdown_crash_handler(); +VMEXPORT Boolean port_shutdown_crash_handler(); /** @@ -267,7 +267,7 @@ Boolean port_shutdown_crash_handler(); * @note Caller should keep store previous byte to restore * the location in future. */ -int port_set_breakpoint(void* addr, unsigned char* prev); +VMEXPORT int port_set_breakpoint(void* addr, unsigned char* prev); /** * Restores original byte in the location previously instrumented @@ -277,14 +277,14 @@ int port_set_breakpoint(void* addr, unsigned char* prev); * @return 0 if OK; nonzero if the location was not * instrumented yet or if an error occured. */ -int port_clear_breakpoint(void* addr, unsigned char prev); +VMEXPORT int port_clear_breakpoint(void* addr, unsigned char prev); /** * Checks if the location is instrumented. * @param [in] addr - memory location to deinstrument. * @return TRUE if instrumented; FALSE otherwise. */ -Boolean port_is_breakpoint_set(void* addr); +VMEXPORT Boolean port_is_breakpoint_set(void* addr); diff --git a/vm/port/include/port_memaccess.h b/vm/port/include/port_memaccess.h index 3122cae..dfc3577 100644 --- a/vm/port/include/port_memaccess.h +++ b/vm/port/include/port_memaccess.h @@ -20,6 +20,7 @@ #include #include "open/platform_types.h" +#include "port_general.h" #ifdef __cplusplus @@ -34,7 +35,7 @@ extern "C" { * @param buf - buffer to read to. * @return 0 if OK; nonzero if an error occured. */ -int port_read_memory(void* addr, size_t size, void* buf); +VMEXPORT int port_read_memory(void* addr, size_t size, void* buf); /** * Tries to write specified number of bytes from buffer to given address. @@ -43,7 +44,7 @@ int port_read_memory(void* addr, size_t size, void* buf); * @param buf - buffer to write from. * @return 0 if OK; nonzero if an error occured. */ -int port_write_memory(void* addr, size_t size, void* buf); +VMEXPORT int port_write_memory(void* addr, size_t size, void* buf); #ifdef __cplusplus diff --git a/vm/port/include/port_modules.h b/vm/port/include/port_modules.h index 3bd59bd..2abf289 100644 --- a/vm/port/include/port_modules.h +++ b/vm/port/include/port_modules.h @@ -25,6 +25,7 @@ #include #include #include "open/platform_types.h" +#include "port_general.h" typedef enum { @@ -61,20 +62,20 @@ extern "C" { * @param count_ptr - count of modules in the returned list * @return TRUE if OK; FALSE if error occured. */ -Boolean port_get_all_modules(native_module_t** list_ptr, int* count_ptr); +VMEXPORT Boolean port_get_all_modules(native_module_t** list_ptr, int* count_ptr); /** * Dumps the list of modules loaded to the current process.. * @param modules - pointer to the list of modules to dump. * @param out - stream for printing the dump. */ -void port_dump_modules(native_module_t* modules, FILE *out); +VMEXPORT void port_dump_modules(native_module_t* modules, FILE *out); /** * Clears the list of modules passed, writes NULL to the poiner. * @param modules - pointer to the list of modules to clear. */ -void port_clear_modules(native_module_t** list_ptr); +VMEXPORT void port_clear_modules(native_module_t** list_ptr); /** * Searches for the specific address in the list of modules. @@ -82,7 +83,7 @@ void port_clear_modules(native_module_t** list_ptr); * @param code_ptr - the address to look for. * @return native_module_t pointer if OK; otherwise, NULL. */ -native_module_t* port_find_module(native_module_t* modules, void* code_ptr); +VMEXPORT native_module_t* port_find_module(native_module_t* modules, void* code_ptr); #ifdef __cplusplus diff --git a/vm/port/include/port_unwind.h b/vm/port/include/port_unwind.h index 8067073..c7e8bd1 100644 --- a/vm/port/include/port_unwind.h +++ b/vm/port/include/port_unwind.h @@ -18,6 +18,7 @@ #ifndef __PORT_UNWIND_H__ #define __PORT_UNWIND_H__ +#include "port_general.h" #include "port_modules.h" typedef struct UnwindContext { @@ -31,10 +32,10 @@ extern "C" { #endif -bool port_init_unwind_context(UnwindContext* context, native_module_t* modules, Registers* regs); -void port_clean_unwind_context(UnwindContext* context); +VMEXPORT bool port_init_unwind_context(UnwindContext* context, native_module_t* modules, Registers* regs); +VMEXPORT void port_clean_unwind_context(UnwindContext* context); -bool port_unwind_frame(UnwindContext* context, Registers* regs); +VMEXPORT bool port_unwind_frame(UnwindContext* context, Registers* regs); #ifdef __cplusplus diff --git a/vm/port/src/crash_handler/linux/gdb_crash_handler.cpp b/vm/port/src/crash_handler/linux/gdb_crash_handler.cpp index e9b9e58..42a0f39 100644 --- a/vm/port/src/crash_handler/linux/gdb_crash_handler.cpp +++ b/vm/port/src/crash_handler/linux/gdb_crash_handler.cpp @@ -98,6 +98,6 @@ bool init_gdb_crash_handler() void cleanup_gdb_crash_handler() { - STD_FREE(g_executable); +// STD_FREE(g_executable); g_prepared = false; } diff --git a/vm/port/src/misc/linux/execname.c b/vm/port/src/misc/linux/execname.c new file mode 100644 index 0000000..22e6b2d --- /dev/null +++ b/vm/port/src/misc/linux/execname.c @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** +* @author Alexey V. Varlamov +* @version $Revision: 1.1.2.1.4.3 $ +*/ + +#include +#include +#include +#include +#include +#include "port_malloc.h" +#include "port_sysinfo.h" +#if defined(FREEBSD) +#define _GNU_SOURCE +#include +extern int main (int argc, char **argv, char **envp); +#endif + +APR_DECLARE(apr_status_t) port_executable_name(char** self_name) { + + char* buf; + +#if defined(FREEBSD) + Dl_info info; + + if (dladdr( (const void*)&main, &info) == 0) { + return APR_ENOENT; + } + + buf = (char*)STD_MALLOC(strlen(info.dli_fname) + 1); + + if (!buf) + return APR_ENOMEM; + + strcpy(buf, info.dli_fname); +#else + char tmpbuf[PATH_MAX + 1]; + + int n = readlink("/proc/self/exe", tmpbuf, PATH_MAX); + + if (n == -1) { + return apr_get_os_error(); + } + + tmpbuf[n] = '\0'; + + buf = (char*)STD_MALLOC(n + 1); + + if (!buf) + return APR_ENOMEM; + + strcpy(buf, tmpbuf); +#endif + + *self_name = buf; + return APR_SUCCESS; +} diff --git a/vm/port/src/misc/linux/sysinfo.c b/vm/port/src/misc/linux/sysinfo.c index 92f1258..9dade9c 100644 --- a/vm/port/src/misc/linux/sysinfo.c +++ b/vm/port/src/misc/linux/sysinfo.c @@ -24,54 +24,8 @@ #include #include #include -#include "port_malloc.h" #include "port_sysinfo.h" #include -#if defined(FREEBSD) -#define _GNU_SOURCE -#include -extern int main (int argc, char **argv, char **envp); -#endif - -APR_DECLARE(apr_status_t) port_executable_name(char** self_name) { - - char* buf; - -#if defined(FREEBSD) - Dl_info info; - - if (dladdr( (const void*)&main, &info) == 0) { - return APR_ENOENT; - } - - buf = (char*)STD_MALLOC(strlen(info.dli_fname) + 1); - - if (!buf) - return APR_ENOMEM; - - strcpy(buf, info.dli_fname); -#else - char tmpbuf[PATH_MAX + 1]; - - int n = readlink("/proc/self/exe", tmpbuf, PATH_MAX); - - if (n == -1) { - return apr_get_os_error(); - } - - tmpbuf[n] = '\0'; - - buf = (char*)STD_MALLOC(n + 1); - - if (!buf) - return APR_ENOMEM; - - strcpy(buf, tmpbuf); -#endif - - *self_name = buf; - return APR_SUCCESS; -} APR_DECLARE(int) port_CPUs_number(void) { return (int)sysconf(_SC_NPROCESSORS_CONF); diff --git a/vm/port/src/misc/win/execname.c b/vm/port/src/misc/win/execname.c new file mode 100644 index 0000000..fd22978 --- /dev/null +++ b/vm/port/src/misc/win/execname.c @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "port_malloc.h" +#include "port_sysinfo.h" + +#include +#include +#include + +APR_DECLARE(apr_status_t) port_executable_name(char** self_name){ + + char buf[_MAX_PATH*2]; /*XXX result in TCHARs */ + int len = GetModuleFileName(0, buf, _MAX_PATH); + if (0 == len) { + return apr_get_os_error(); + } + + *self_name = STD_MALLOC(strlen(buf) + 1); + if (*self_name) + strcpy(*self_name, buf); + + return APR_SUCCESS; +} diff --git a/vm/port/src/misc/win/sysinfo.c b/vm/port/src/misc/win/sysinfo.c index de98f0d..7d2fdc3 100644 --- a/vm/port/src/misc/win/sysinfo.c +++ b/vm/port/src/misc/win/sysinfo.c @@ -96,21 +96,6 @@ APR_DECLARE(apr_status_t) port_OS_name_version(char** os_name, char** os_ver, return APR_SUCCESS; } -APR_DECLARE(apr_status_t) port_executable_name(char** self_name){ - - char buf[_MAX_PATH*2]; /*XXX result in TCHARs */ - int len = GetModuleFileName(0, buf, _MAX_PATH); - if (0 == len) { - return apr_get_os_error(); - } - - *self_name = STD_MALLOC(strlen(buf) + 1); - if (*self_name) - strcpy(*self_name, buf); - - return APR_SUCCESS; -} - APR_DECLARE(const char *) port_CPU_architecture(void){ #if defined(_IPF_) return "ia64"; diff --git a/vm/port/src/thread/linux/thread_asm_em64t.s b/vm/port/src/thread/linux/thread_asm_em64t.s index 5468020..9a5cd76 100644 --- a/vm/port/src/thread/linux/thread_asm_em64t.s +++ b/vm/port/src/thread/linux/thread_asm_em64t.s @@ -41,11 +41,11 @@ // uint32 eflags;; 88h // }; // -// void port_transfer_to_regs(Registers* regs) +// void port_transfer_to_regs_asm(Registers* regs) -.globl port_transfer_to_regs - .type port_transfer_to_regs, @function -port_transfer_to_regs: +.globl port_transfer_to_regs_asm + .type port_transfer_to_regs_asm, @function +port_transfer_to_regs_asm: movq %rdi, %rdx // regs pointer (1st param - RDI) -> RDX movq 0x08(%rdx), %rbp // RBP field @@ -116,5 +116,5 @@ __skipefl__: port_longjump_stub: // movq 128(%rsp), %rdi // load RDI with the address of saved Registers movq (%rsp), %rdi // load RDI with the address of saved Registers - callq port_transfer_to_regs // restore context + callq port_transfer_to_regs_asm // restore context ret // dummy RET - unreachable diff --git a/vm/port/src/thread/linux/thread_em64t.c b/vm/port/src/thread/linux/thread_em64t.c index a07057d..6bf776f 100644 --- a/vm/port/src/thread/linux/thread_em64t.c +++ b/vm/port/src/thread/linux/thread_em64t.c @@ -185,3 +185,11 @@ void port_transfer_to_function(void* fn, Registers* pregs, int num, ...) port_transfer_to_regs(®s); } + +// Workaround for improper -fPIC processing for assembler files +void port_transfer_to_regs_asm(Registers* regs); + +void port_transfer_to_regs(Registers* regs) +{ + port_transfer_to_regs_asm(regs); +} diff --git a/vm/port/src/thread/win/thread_os.c b/vm/port/src/thread/win/thread_os.c index f59b307..a83c63b 100644 --- a/vm/port/src/thread/win/thread_os.c +++ b/vm/port/src/thread/win/thread_os.c @@ -16,7 +16,7 @@ */ -#include +#include #include "port_thread.h" @@ -297,13 +297,13 @@ int port_thread_set_context(osthread_t thread, thread_context_t *context) static int suspend_init_lock() { - static uint32 initialized = 0; + static uint16 initialized = 0; if (!initialized) { // Critical section should be initialized only once, // do nothing in case someone else already initialized it. - if (apr_atomic_cas32((volatile uint32*)&initialized, 1, 0) == 0) + if (port_atomic_cas16((volatile uint16*)&initialized, 1, 0) == 0) InitializeCriticalSectionAndSpinCount(&g_crit_section, 400); } -- 1.5.4