summaryrefslogtreecommitdiffhomepage
path: root/src/thread/nt32
diff options
context:
space:
mode:
Diffstat (limited to 'src/thread/nt32')
-rw-r--r--src/thread/nt32/__set_thread_area.c13
-rw-r--r--src/thread/nt32/__tls_get_addr.c2
-rw-r--r--src/thread/nt32/clone.c54
-rw-r--r--src/thread/nt32/pthread_detach.c6
-rw-r--r--src/thread/nt32/pthread_equal.c6
-rw-r--r--src/thread/nt32/pthread_self.c10
-rw-r--r--src/thread/nt32/syscall_cp.s15
7 files changed, 106 insertions, 0 deletions
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 <errno.h>
+#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 <syscall.h>
+
+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,
+ &regs);
+}
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 <threads.h>
+#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