summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2017-01-16 02:32:54 +0000
committermidipix <writeonce@midipix.org>2017-01-16 01:52:23 -0500
commitcd4191db5ebcb3ca96c5d5eb4336eddd895445bf (patch)
treec4dd168fbb5ef6536671a6ff9c65599b925449a0
parentdf4a224d9c3615b3b160432855b5862d2dc69157 (diff)
downloadntapi-cd4191db5ebcb3ca96c5d5eb4336eddd895445bf.tar.bz2
ntapi-cd4191db5ebcb3ca96c5d5eb4336eddd895445bf.tar.xz
daemon initialization: establish SEH frames for the daemon and internal thread.
-rw-r--r--project/arch.mk9
-rw-r--r--project/common.mk1
-rw-r--r--project/tree.mk1
-rw-r--r--src/daemon/ntapi_dsr_init.c12
-rw-r--r--src/daemon/ntapi_dsr_internal_connection.c11
-rw-r--r--src/seh/nt32/ntapi_tt_seh_frame.s21
-rw-r--r--src/seh/nt64/ntapi_tt_seh_frame.s43
-rw-r--r--src/seh/ntapi_tt_seh_frame.c0
8 files changed, 95 insertions, 3 deletions
diff --git a/project/arch.mk b/project/arch.mk
index 458db3e..7040e88 100644
--- a/project/arch.mk
+++ b/project/arch.mk
@@ -12,6 +12,15 @@ src/process/%.lo: $(SOURCE_DIR)/src/process/$(ARCH)/%.s $(ALL_HEADERS) host.tag
src/process/%.o: $(SOURCE_DIR)/src/process/$(ARCH)/%.s $(ALL_HEADERS) host.tag tree.tag
$(CC) -c -o $@ $<
+# seh
+src/seh/%.lo: $(SOURCE_DIR)/src/seh/$(ARCH)/%.s $(ALL_HEADERS) host.tag tree.tag
+ $(CC) -c -o $@ $< $(CFLAGS_SHARED)
+
+src/seh/%.o: $(SOURCE_DIR)/src/seh/$(ARCH)/%.s $(ALL_HEADERS) host.tag tree.tag
+ $(CC) -c -o $@ $< $(CFLAGS_STATIC)
+
shared-objs-asm: src/process/tt_fork_v1.lo
+shared-objs-asm: src/seh/ntapi_tt_seh_frame.lo
static-objs-asm: src/process/tt_fork_v1.o
+static-objs-asm: src/seh/ntapi_tt_seh_frame.o
diff --git a/project/common.mk b/project/common.mk
index c0e9070..ef8b350 100644
--- a/project/common.mk
+++ b/project/common.mk
@@ -47,6 +47,7 @@ COMMON_SRCS = \
src/pty/ntapi_pty_ioctl.c \
src/pty/ntapi_pty_query.c \
src/pty/ntapi_pty_set.c \
+ src/seh/ntapi_tt_seh_frame.c \
src/section/ntapi_tt_get_section_name.c \
src/socket/ntapi_sc_accept.c \
src/socket/ntapi_sc_bind_v1.c \
diff --git a/project/tree.mk b/project/tree.mk
index baabe2d..9d44b3e 100644
--- a/project/tree.mk
+++ b/project/tree.mk
@@ -14,6 +14,7 @@ tree.tag:
mkdir -p src/process
mkdir -p src/pty
mkdir -p src/section
+ mkdir -p src/seh
mkdir -p src/socket
mkdir -p src/string
mkdir -p src/sync
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 <ntapi/ntapi.h>
#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(
&params->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 <ntapi/ntapi.h>
#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
--- /dev/null
+++ b/src/seh/ntapi_tt_seh_frame.c