diff options
Diffstat (limited to 'arch/nt64/src')
-rw-r--r-- | arch/nt64/src/crt_glue.c | 87 | ||||
-rw-r--r-- | arch/nt64/src/crt_pe.c | 7 | ||||
-rw-r--r-- | arch/nt64/src/crt_tls.c | 27 | ||||
-rw-r--r-- | arch/nt64/src/libc_entry_point.c | 10 | ||||
-rw-r--r-- | arch/nt64/src/syscall_disp.c | 22 | ||||
-rw-r--r-- | arch/nt64/src/vtbl.c | 12 |
6 files changed, 165 insertions, 0 deletions
diff --git a/arch/nt64/src/crt_glue.c b/arch/nt64/src/crt_glue.c new file mode 100644 index 0000000..e8a07de --- /dev/null +++ b/arch/nt64/src/crt_glue.c @@ -0,0 +1,87 @@ +#include <unistd.h> +#include <pthread.h> +#include "atomic.h" +#include "syscall.h" +#include "psxglue.h" +#include "pthread_impl.h" + +extern struct __ldso_vtbl * __ldso_vtbl; +extern struct __psx_vtbl * __psx_vtbl; + +typedef int __app_main(); +typedef int __pthread_surrogate_routine(struct pthread *); + +extern int _init(void); +static int __pthread_surrogate_init(struct pthread * self); + +extern int __libc_start_main( + void * main, + int argc, + char ** argv); + +void __libc_entry_routine( + __app_main * __main, + __psx_init_routine * __psx_init_routine, + int options) +{ + int argc; + char ** argv; + char ** envp; + struct __psx_context ctx; + + /* ctx init */ + ctx.size = sizeof(ctx); + ctx.options = options; + ctx.pthread_create_fn = pthread_create; + ctx.pthread_surrogate_fn= __pthread_surrogate_init; + + /* __psx_init must succeed... */ + if (__psx_init_routine(&argc,&argv,&envp,&ctx)) + a_crash(); + + /* ...and conform */ + else if (envp != argv + (argc + 1)) + a_crash(); + + /* dso init routines */ + _init(); + + /* write once */ + __syscall_vtbl = (unsigned long **)ctx.sys_vtbl; + __ldso_vtbl = ctx.ldso_vtbl; + __psx_vtbl = ctx.psx_vtbl; + __teb_sys_idx = ctx.teb_sys_idx; + __teb_libc_idx = ctx.teb_libc_idx; + + /* enter libc */ + __libc_start_main(__main,argc,argv); + + /* guard */ + a_crash(); +} + +static int __pthread_surrogate_init(struct pthread * self) +{ + /** + * invoked by psxscl upon creation of a surrogate libc + * thread, which in turn may only call pthread_create(); + * + * the purpose of this mecahnism is to support a scenario + * where a third-party library creates a non-posix thread + * which then calls, be it directly or via a callback + * function, a libc api that depends on a valid + * pthread_self. + * + * self: a pointer to an already zero'ed memory page + * + * struct pthread relevant members: + * -------------------------------- + * cancel (already zero) + * canary (already zero) + * + * pthread_create() reference: + * 1a47ed15eebf96d0c8d5de4aea54108bc8cc3f53 + **/ + + return 0; +} diff --git a/arch/nt64/src/crt_pe.c b/arch/nt64/src/crt_pe.c new file mode 100644 index 0000000..0dc75a4 --- /dev/null +++ b/arch/nt64/src/crt_pe.c @@ -0,0 +1,7 @@ +#include "pthread_impl.h" +#include <threads.h> + +void * __pthread_getspecific_impl(pthread_key_t k) +{ + return (__pthread_self())->tsd[k]; +} diff --git a/arch/nt64/src/crt_tls.c b/arch/nt64/src/crt_tls.c new file mode 100644 index 0000000..15183d3 --- /dev/null +++ b/arch/nt64/src/crt_tls.c @@ -0,0 +1,27 @@ +#include <stdint.h> +#include <stddef.h> +#include "psxglue.h" +#include "pthread_arch.h" + +typedef unsigned int __tls_word __attribute__((mode(word))); +typedef unsigned int __tls_ptr __attribute__((mode(pointer))); + +struct __emutls_object +{ + __tls_word size; + __tls_word align; + ptrdiff_t offset; + void * defval; +}; + +void * __emutls_get_address (struct __emutls_object * obj) +{ + int dsoidx = obj->align & 0xFFFF0000; + struct __tlca * tlca = (struct __tlca *)__psx_tlca(); + + if (dsoidx) + return (*tlca->pthread_dtls)[dsoidx >> 16] + obj->offset; + else + return tlca->pthread_tls + obj->offset; +} + diff --git a/arch/nt64/src/libc_entry_point.c b/arch/nt64/src/libc_entry_point.c new file mode 100644 index 0000000..0929cc4 --- /dev/null +++ b/arch/nt64/src/libc_entry_point.c @@ -0,0 +1,10 @@ +typedef unsigned int uint32_t; + +int __libc_entry_point( + void * hinstance, + uint32_t reason, + void * reserved) +{ + return 1; +} + diff --git a/arch/nt64/src/syscall_disp.c b/arch/nt64/src/syscall_disp.c new file mode 100644 index 0000000..cb9655d --- /dev/null +++ b/arch/nt64/src/syscall_disp.c @@ -0,0 +1,22 @@ +#include <stdint.h> +#include <stddef.h> +#include "syscall.h" +#include "psxglue.h" + +extern struct __psx_vtbl * __psx_vtbl; + +void __unmapself(void * base, size_t size) +{ + __psx_vtbl->unmapself(base,size); +} + +uintptr_t __syscall_disp(long n, + uintptr_t a1, + uintptr_t a2, + uintptr_t a3, + uintptr_t a4, + uintptr_t a5, + uintptr_t a6) +{ + return __syscall(n,a1,a2,a3,a4,a5,a6); +} diff --git a/arch/nt64/src/vtbl.c b/arch/nt64/src/vtbl.c new file mode 100644 index 0000000..028f153 --- /dev/null +++ b/arch/nt64/src/vtbl.c @@ -0,0 +1,12 @@ +#include "psxglue.h" + +unsigned long ** __syscall_vtbl = 0; +struct __ldso_vtbl * __ldso_vtbl = 0; +struct __psx_vtbl * __psx_vtbl = 0; +unsigned long __teb_sys_idx = 0; +unsigned long __teb_libc_idx = 0; + +void ___chkstk_ms(void) +{ +} + |