diff --git a/config.project b/config.project index f5ea936..14c748b 100644 --- a/config.project +++ b/config.project @@ -56,7 +56,7 @@ mb_default_elf_config_defs= # config -mb_all_static=yes +mb_all_static= mb_all_shared= mb_disable_frontend= mb_disable_static=yes diff --git a/project/common.mk b/project/common.mk index c3dde46..f847b6c 100644 --- a/project/common.mk +++ b/project/common.mk @@ -1,3 +1,8 @@ +INIT_SRCS = \ + src/init/ntux_init_ldso.c \ + src/init/ntux_init_static.c \ + src/init/ntux_init_vrfs.c \ + DRIVER_SRCS = \ src/driver/ntux_amain.c \ src/driver/ntux_driver_ctx.c \ @@ -24,6 +29,7 @@ APP_SRCS = \ src/ntux.c COMMON_SRCS = \ + $(INIT_SRCS) \ $(DRIVER_SRCS) \ $(INTERNAL_SRCS) \ $(CMD_SRCS) \ diff --git a/project/extras.mk b/project/extras.mk index ee0026e..6ecb2a1 100644 --- a/project/extras.mk +++ b/project/extras.mk @@ -7,6 +7,10 @@ CFLAGS_CONFIG += -D_MIDIPIX_FREESTANDING -D__NT$(HOST_BITS) CFLAGS_CONFIG += -UWIN32 -U_WIN32 -U__WIN32 -U__WIN32__ CFLAGS_CONFIG += -UWIN64 -U_WIN64 -U__WIN64 -U__WIN64__ +ifeq ($(ALL_STATIC),yes) +CFLAGS_CONFIG += -DNTUX_ALL_STATIC +endif + src/driver/ntux_driver_ctx.o: version.tag src/driver/ntux_driver_ctx.lo: version.tag diff --git a/project/tree.mk b/project/tree.mk index 9f0d99e..9ac1469 100644 --- a/project/tree.mk +++ b/project/tree.mk @@ -1,10 +1,10 @@ tree.tag: mkdir -p src mkdir -p src/cmds + mkdir -p src/init mkdir -p src/driver mkdir -p src/internal mkdir -p src/internal/nolibc - mkdir -p src/logic mkdir -p src/output mkdir -p src/skin touch tree.tag diff --git a/src/init/ntux_init_ldso.c b/src/init/ntux_init_ldso.c new file mode 100644 index 0000000..11b0fce --- /dev/null +++ b/src/init/ntux_init_ldso.c @@ -0,0 +1,71 @@ +/***********************************************************/ +/* ntux: native translation und extension */ +/* Copyright (C) 2016--2018 Z. Gilboa */ +/* Released under GPLv2 and GPLv3; see COPYING.NTUX. */ +/***********************************************************/ + +#include +#include +#include +#include +#include + +#ifndef NTUX_ALL_STATIC +#ifndef NTUX_STANDALONE + +/* framework (rtdata) abi */ +static const struct pe_guid __ldsoabi = NT_PROCESS_GUID_RTDATA; + +/* loader root-relative name */ +static const unsigned short __rrldso[] = {'l','i','b','\\', + 'l','i','b','p','s','x','s','c','l', + '.','s','o',0}; + +/* pty server root-relative name */ +static const unsigned short __rrctty[] = {'b','i','n','\\', + 'n','t','c','t','t','y', + '.','e','x','e',0}; + +/* system call layer init context */ +static struct __psx_context ctx = {sizeof(ctx),0,0,0,0,0,0,0,0,0,0,0}; + +/* ldso buffer */ +static uintptr_t __attribute__((section(".dsodata"))) + __dsodata[65536/sizeof(unsigned long)]; + +int ntux_entry_routine( + int(*__psx_init_routine)(int *,char ***,char ***,void *), + struct __psx_context * ctx); + +void ntux_entry_point(void) +{ + int status; + void * hroot; + void * hdsodir; + void * ldsobase; + int (*__psx_init)( + int *,char ***,char ***, + void *); + + if ((status = __ldso_load_framework_loader_ex( + &ldsobase,&hroot,&hdsodir, + &__ldsoabi, + 0,__rrldso,ntux_main, + __dsodata,sizeof(__dsodata), + PE_LDSO_DEFAULT_EXECUTABLE, + &(unsigned int){0}))) + __ldso_terminate_current_process(status); + + if (!(__psx_init = __ldso_get_procedure_address( + ldsobase,"__psx_init"))) + __ldso_terminate_current_process(NT_STATUS_NOINTERFACE); + + ctx.options = __PSXOPT_LDSO; + ctx.ctty = __rrctty; + ctx.refaddr = ntux_entry_point; + + ntux_entry_routine(__psx_init,&ctx); +} + +#endif +#endif diff --git a/src/init/ntux_init_static.c b/src/init/ntux_init_static.c new file mode 100644 index 0000000..8d7f8bb --- /dev/null +++ b/src/init/ntux_init_static.c @@ -0,0 +1,28 @@ +/***********************************************************/ +/* ntux: native translation und extension */ +/* Copyright (C) 2016--2018 Z. Gilboa */ +/* Released under GPLv2 and GPLv3; see COPYING.NTUX. */ +/***********************************************************/ + +#include +#include +#include +#include +#include + +#ifdef NTUX_ALL_STATIC + +int __psx_init(int *,char ***,char ***,void *); + +int ntux_entry_routine( + int(*__psx_init_routine)(int *,char ***,char ***,void *), + struct __psx_context * ctx); + +static struct __psx_context ctx = {sizeof(ctx),0,0,0,0,0,0,0,0,0,0,0}; + +void ntux_entry_point(void) +{ + ntux_entry_routine(__psx_init,&ctx); +} + +#endif diff --git a/src/init/ntux_init_vrfs.c b/src/init/ntux_init_vrfs.c new file mode 100644 index 0000000..08c1fef --- /dev/null +++ b/src/init/ntux_init_vrfs.c @@ -0,0 +1,67 @@ +/***********************************************************/ +/* ntux: native translation und extension */ +/* Copyright (C) 2016--2018 Z. Gilboa */ +/* Released under GPLv2 and GPLv3; see COPYING.NTUX. */ +/***********************************************************/ + +#include +#include +#include +#include +#include + +#ifdef NTUX_STANDALONE + +/* framework (rtdata) abi */ +static const struct pe_guid __ldsoabi = NT_PROCESS_GUID_RTDATA; + +/* loader standalone (single directory) name */ +static const unsigned short __sdldso[] = {'l','i','b','p','s','x','s','c','l', + '.','s','o',0}; + +/* pty server standalone name */ +static const unsigned short __sdctty[] = {'n','t','c','t','t','y', + '.','e','x','e',0}; + +/* system call layer init context */ +static struct __psx_context ctx = {sizeof(ctx),0,0,0,0,0,0,0,0,0,0,0}; + +/* ldso buffer */ +static uintptr_t __attribute__((section(".dsodata"))) + __dsodata[65536/sizeof(unsigned long)]; + +int ntux_entry_routine( + int(*__psx_init_routine)(int *,char ***,char ***,void *), + struct __psx_context * ctx); + +void ntux_entry_point(void) +{ + int status; + void * hroot; + void * hdsodir; + void * ldsobase; + int (*__psx_init)( + int *,char ***,char ***, + void *); + + if ((status = __ldso_load_framework_loader_ex( + &ldsobase,&hroot,&hdsodir, + &__ldsoabi, + __sdldso,0,ntux_main, + __dsodata,sizeof(__dsodata), + PE_LDSO_STANDALONE_EXECUTABLE, + &(unsigned int){0}))) + __ldso_terminate_current_process(status); + + if (!(__psx_init = __ldso_get_procedure_address( + ldsobase,"__psx_init"))) + __ldso_terminate_current_process(NT_STATUS_NOINTERFACE); + + ctx.options = __PSXOPT_VRFS; + ctx.ctty = __sdctty; + ctx.refaddr = ntux_entry_point; + + ntux_entry_routine(__psx_init,&ctx); +} + +#endif diff --git a/src/ntux.c b/src/ntux.c index 41cc4d3..890fbc0 100644 --- a/src/ntux.c +++ b/src/ntux.c @@ -8,18 +8,16 @@ #include #include "ntux_driver_impl.h" -int ntux_entry_point(void) +int ntux_entry_routine( + int(*__psx_init_routine)(int *,char ***,char ***,void *), + struct __psx_context * ctx) { int argc; char ** argv; char ** envp; - struct __psx_context ctx = {0,0,0,0,0,0,0,0,0,0,0,0}; - - /* ctx */ - ctx.size = sizeof(ctx); /* __psx_init must succeed... */ - if (__psx_init(&argc,&argv,&envp,&ctx)) + if (__psx_init_routine(&argc,&argv,&envp,ctx)) return -1; /* ...and conform */