From cd4191db5ebcb3ca96c5d5eb4336eddd895445bf Mon Sep 17 00:00:00 2001 From: midipix Date: Mon, 16 Jan 2017 02:32:54 +0000 Subject: daemon initialization: establish SEH frames for the daemon and internal thread. --- src/daemon/ntapi_dsr_init.c | 12 +++++++-- src/daemon/ntapi_dsr_internal_connection.c | 11 +++++++- src/seh/nt32/ntapi_tt_seh_frame.s | 21 +++++++++++++++ src/seh/nt64/ntapi_tt_seh_frame.s | 43 ++++++++++++++++++++++++++++++ src/seh/ntapi_tt_seh_frame.c | 0 5 files changed, 84 insertions(+), 3 deletions(-) create mode 100644 src/seh/nt32/ntapi_tt_seh_frame.s create mode 100644 src/seh/nt64/ntapi_tt_seh_frame.s create mode 100644 src/seh/ntapi_tt_seh_frame.c (limited to 'src') diff --git a/src/daemon/ntapi_dsr_init.c b/src/daemon/ntapi_dsr_init.c index 317a421..b54131e 100644 --- a/src/daemon/ntapi_dsr_init.c +++ b/src/daemon/ntapi_dsr_init.c @@ -12,6 +12,8 @@ #include #include "ntapi_impl.h" +int32_t __ntapi_tt_seh_frame(void *, void *, void *, int32_t (*)(nt_daemon_params *)); + static int32_t __stdcall __ntapi_dsr_once(nt_daemon_params * params); int32_t __stdcall __ntapi_dsr_init(nt_daemon_params * params) @@ -139,7 +141,7 @@ int32_t __stdcall __ntapi_dsr_init(nt_daemon_params * params) /* __ntapi_dsr_start executes in the daemon's dedicated thread */ -int32_t __stdcall __ntapi_dsr_start_impl(nt_daemon_params * params) +static int32_t __ntapi_dsr_start_impl(nt_daemon_params * params) { int32_t status; void * ctx; @@ -161,7 +163,7 @@ int32_t __stdcall __ntapi_dsr_start_impl(nt_daemon_params * params) return NT_STATUS_SUCCESS; } -int32_t __stdcall __ntapi_dsr_start(nt_daemon_params * params) +static int32_t __ntapi_dsr_start_routine(nt_daemon_params * params) { at_store_32( ¶ms->exit_code_daemon_loop, @@ -172,6 +174,12 @@ int32_t __stdcall __ntapi_dsr_start(nt_daemon_params * params) __ntapi_dsr_start_impl(params)); } +int32_t __stdcall __ntapi_dsr_start(nt_daemon_params * params) +{ + return __ntapi_tt_seh_frame( + params,0,0, + __ntapi_dsr_start_routine); +} /* __ntapi_dsr_once executes in the daemon's dedicated thread */ static int32_t __stdcall __ntapi_dsr_once(nt_daemon_params * params) diff --git a/src/daemon/ntapi_dsr_internal_connection.c b/src/daemon/ntapi_dsr_internal_connection.c index 2d6e39f..109ea43 100644 --- a/src/daemon/ntapi_dsr_internal_connection.c +++ b/src/daemon/ntapi_dsr_internal_connection.c @@ -12,6 +12,8 @@ #include #include "ntapi_impl.h" +int32_t __ntapi_tt_seh_frame(void *, void *, void *, int32_t (*)(nt_daemon_params *)); + static int32_t __stdcall __ntapi_dsr_internal_client_connect_fail( nt_daemon_params * params, int32_t status) @@ -82,7 +84,7 @@ int32_t __stdcall __ntapi_dsr_connect_internal_client(nt_daemon_params * params) /* __ntapi_dsr_internal_client_connect executes in its own temporary thread */ -int32_t __stdcall __ntapi_dsr_internal_client_connect(nt_daemon_params * params) +static int32_t __ntapi_dsr_internal_client_connect_impl(nt_daemon_params * params) { int32_t status; nt_unicode_string server_name; @@ -143,3 +145,10 @@ int32_t __stdcall __ntapi_dsr_internal_client_connect(nt_daemon_params * params) NT_CURRENT_THREAD_HANDLE, status); } + +int32_t __stdcall __ntapi_dsr_internal_client_connect(nt_daemon_params * params) +{ + return __ntapi_tt_seh_frame( + params,0,0, + __ntapi_dsr_internal_client_connect_impl); +} \ No newline at end of file diff --git a/src/seh/nt32/ntapi_tt_seh_frame.s b/src/seh/nt32/ntapi_tt_seh_frame.s new file mode 100644 index 0000000..d301217 --- /dev/null +++ b/src/seh/nt32/ntapi_tt_seh_frame.s @@ -0,0 +1,21 @@ +########################################################## +## ntapi: Native API core library ## +## Copyright (C) 2013--2017 Z. Gilboa ## +## Released under GPLv2 and GPLv3; see COPYING.NTAPI. ## +########################################################## + +.section .text + +.global ___ntapi_tt_seh_frame + + .def ___ntapi_tt_seh_frame; .scl 3; .type 32; .endef + +___ntapi_tt_seh_frame: + movl 16(%esp),%eax + jmp *%eax + + .section .got$___ntapi_tt_seh_frame,"r" + .global __imp____ntapi_tt_seh_frame +__imp____ntapi_tt_seh_frame: + .long ___ntapi_tt_seh_frame + .linkonce discard diff --git a/src/seh/nt64/ntapi_tt_seh_frame.s b/src/seh/nt64/ntapi_tt_seh_frame.s new file mode 100644 index 0000000..cd4a681 --- /dev/null +++ b/src/seh/nt64/ntapi_tt_seh_frame.s @@ -0,0 +1,43 @@ +########################################################## +## ntapi: Native API core library ## +## Copyright (C) 2013--2017 Z. Gilboa ## +## Released under GPLv2 and GPLv3; see COPYING.NTAPI. ## +########################################################## + +.section .text + +.global __ntapi_tt_seh_frame + + .def __ntapi_tt_seh_frame; .scl 3; .type 32; .endef + .def __seh_trap; .scl 3; .type 32; .endef + +__seh_trap: + nop + jmp __seh_trap + + .seh_proc __ntapi_tt_seh_frame +__ntapi_tt_seh_frame: + .seh_endprologue + +.__init_frame_begin: + .seh_handler __seh_trap, @except + .seh_handlerdata + .long 1 + .long .__init_frame_begin,.__init_frame_end,__seh_trap,.__init_frame_end + .text + + subq $40, %rsp + call *%r9 + addq $40, %rsp + + nop +.__init_frame_end: + ret + + .seh_endproc + + .section .got$__ntapi_tt_seh_frame,"r" + .global __imp___ntapi_tt_seh_frame +__imp___ntapi_tt_seh_frame: + .quad __ntapi_tt_seh_frame + .linkonce discard diff --git a/src/seh/ntapi_tt_seh_frame.c b/src/seh/ntapi_tt_seh_frame.c new file mode 100644 index 0000000..e69de29 -- cgit v1.2.3