From 296178913c5dfbc2b35842fc16ed680ef51fd402 Mon Sep 17 00:00:00 2001 From: midipix Date: Sun, 5 Apr 2015 17:05:57 -0400 Subject: nt32: initial commit of core port files. signed-off by Z. Gilboa; see copying.midipix (9cd0746c) for additional information. --- src/thread/nt32/__set_thread_area.c | 13 +++++++++ src/thread/nt32/__tls_get_addr.c | 2 ++ src/thread/nt32/clone.c | 54 +++++++++++++++++++++++++++++++++++++ src/thread/nt32/pthread_detach.c | 6 +++++ src/thread/nt32/pthread_equal.c | 6 +++++ src/thread/nt32/pthread_self.c | 10 +++++++ src/thread/nt32/syscall_cp.s | 15 +++++++++++ 7 files changed, 106 insertions(+) create mode 100644 src/thread/nt32/__set_thread_area.c create mode 100644 src/thread/nt32/__tls_get_addr.c create mode 100644 src/thread/nt32/clone.c create mode 100644 src/thread/nt32/pthread_detach.c create mode 100644 src/thread/nt32/pthread_equal.c create mode 100644 src/thread/nt32/pthread_self.c create mode 100644 src/thread/nt32/syscall_cp.s (limited to 'src/thread/nt32') diff --git a/src/thread/nt32/__set_thread_area.c b/src/thread/nt32/__set_thread_area.c new file mode 100644 index 0000000..c50f6c6 --- /dev/null +++ b/src/thread/nt32/__set_thread_area.c @@ -0,0 +1,13 @@ +#include +#include "pthread_impl.h" + +int __set_thread_area(void * p) +{ + struct pthread ** ptlca; + + ptlca = __psx_tlca(); + if (!ptlca) return -ESRCH; + + *ptlca = p; + return 0; +} diff --git a/src/thread/nt32/__tls_get_addr.c b/src/thread/nt32/__tls_get_addr.c new file mode 100644 index 0000000..ad8d845 --- /dev/null +++ b/src/thread/nt32/__tls_get_addr.c @@ -0,0 +1,2 @@ +/* using a custom, register-based __emutls_get_address */ +typedef int dummy; diff --git a/src/thread/nt32/clone.c b/src/thread/nt32/clone.c new file mode 100644 index 0000000..fb53501 --- /dev/null +++ b/src/thread/nt32/clone.c @@ -0,0 +1,54 @@ +#include + +struct pt_regs { + unsigned long ebp; + unsigned long ebx; + unsigned long eax; + unsigned long ecx; + unsigned long edx; + unsigned long esi; + unsigned long edi; + unsigned long orig_eax; + unsigned long eip; + unsigned long cs; + unsigned long eflags; + unsigned long esp; + unsigned long ss; +}; + +typedef long __sys_clone( + unsigned long flags, + void * child_stack, + void * ptid, + void * ctid, + struct pt_regs *regs); + +typedef int __entry_point(void *); + +extern unsigned long ** __syscall_vtbl; + +int __clone( + __entry_point * fn, + void * child_stack, + int flags, + void * arg, + int * ptid, + void * pthread_self_addr, + int * ctid) +{ + struct pt_regs regs; + __sys_clone * pfn_clone; + + regs.eip = (unsigned long)fn; + regs.ecx = (unsigned long)arg; + regs.edx = (unsigned long)pthread_self_addr; + + pfn_clone = (__sys_clone *)(__syscall_vtbl[SYS_clone]); + + return (int)pfn_clone( + flags, + child_stack, + ptid, + ctid, + ®s); +} diff --git a/src/thread/nt32/pthread_detach.c b/src/thread/nt32/pthread_detach.c new file mode 100644 index 0000000..85db4cb --- /dev/null +++ b/src/thread/nt32/pthread_detach.c @@ -0,0 +1,6 @@ +#include "../pthread_detach.c" + +int __pthread_detach_impl(pthread_t t) +{ + return thrd_detach(t); +} diff --git a/src/thread/nt32/pthread_equal.c b/src/thread/nt32/pthread_equal.c new file mode 100644 index 0000000..a8fcd79 --- /dev/null +++ b/src/thread/nt32/pthread_equal.c @@ -0,0 +1,6 @@ +#include "../pthread_equal.c" + +int __pthread_equal_impl(pthread_t a, pthread_t b) +{ + return thrd_equal(a,b); +} diff --git a/src/thread/nt32/pthread_self.c b/src/thread/nt32/pthread_self.c new file mode 100644 index 0000000..23fbc53 --- /dev/null +++ b/src/thread/nt32/pthread_self.c @@ -0,0 +1,10 @@ +#include "pthread_impl.h" +#include +#include "libc.h" + +pthread_t pthread_self() +{ + return __pthread_self(); +} + +weak_alias(pthread_self, thrd_current); diff --git a/src/thread/nt32/syscall_cp.s b/src/thread/nt32/syscall_cp.s new file mode 100644 index 0000000..c52731f --- /dev/null +++ b/src/thread/nt32/syscall_cp.s @@ -0,0 +1,15 @@ +.text +.globl ___syscall_cp_asm +.globl ___cp_begin +.globl ___cp_end + +___syscall_cp_asm: +___cp_begin: + mov (%ecx), %ecx /* check content of ptr */ + test %ecx, %ecx + jnz ___cancel /* thread is pending cancellation */ + + jmp ___syscall + +___cp_end: + ret -- cgit v1.2.3