diff --git a/programs/develop/libraries/newlib/Makefile b/programs/develop/libraries/newlib/Makefile index 99037a380..566e50dcd 100644 --- a/programs/develop/libraries/newlib/Makefile +++ b/programs/develop/libraries/newlib/Makefile @@ -18,6 +18,7 @@ AMZ_SRCS:= \ crt/chkstk.S \ crt/exit.S \ crt/pseudo-reloc.c \ + crt/dllstart.c \ crt/setjmp.S STATIC_SRCS:= \ @@ -204,6 +205,7 @@ STDIO_SRCS= \ fdopen.c \ fflush.c \ flags.c \ + fileno.c \ findfp.c \ fiprintf.c \ fiscanf.c \ diff --git a/programs/develop/libraries/newlib/crt/chkstk.S b/programs/develop/libraries/newlib/crt/chkstk.S index 1b9cc3387..405dfc6eb 100644 --- a/programs/develop/libraries/newlib/crt/chkstk.S +++ b/programs/develop/libraries/newlib/crt/chkstk.S @@ -4,8 +4,8 @@ .section .text -.def ___chkstk; .scl 2; .type 32; .endef -.def __alloca; .scl 2; .type 32; .endef +#.def ___chkstk; .scl 2; .type 32; .endef +#.def __alloca; .scl 2; .type 32; .endef ___chkstk: __alloca: pushl %ecx /* save temp */ diff --git a/programs/develop/libraries/newlib/crt/crt_amz.S b/programs/develop/libraries/newlib/crt/crt_amz.S index 72bbfb79b..2d317a3ad 100644 --- a/programs/develop/libraries/newlib/crt/crt_amz.S +++ b/programs/develop/libraries/newlib/crt/crt_amz.S @@ -1,11 +1,19 @@ -.section .text .global __start .global ___main +.global _DllMainCRTStartup + + +.section .init + +.def __start; .scl 2; .type 32; .endef +.def _DllMainCRTStartup; .scl 2; .type 32; .endef .align 4 __start: +_DllMainCRTStartup: + call __pei386_runtime_relocator jmp _main diff --git a/programs/develop/libraries/newlib/dll.lds b/programs/develop/libraries/newlib/dll.lds index 1c44270fc..632d03f5a 100644 --- a/programs/develop/libraries/newlib/dll.lds +++ b/programs/develop/libraries/newlib/dll.lds @@ -1,8 +1,6 @@ OUTPUT_FORMAT(pei-i386) -ENTRY("__start") - SECTIONS { . = SIZEOF_HEADERS; diff --git a/programs/develop/libraries/newlib/pe/loader.c b/programs/develop/libraries/newlib/pe/loader.c index cd30cd448..23a0fa9a0 100644 --- a/programs/develop/libraries/newlib/pe/loader.c +++ b/programs/develop/libraries/newlib/pe/loader.c @@ -561,7 +561,75 @@ void* get_entry_point(void *raw) nt = MakePtr( PIMAGE_NT_HEADERS32, dos, dos->e_lfanew); return MakePtr(void*, raw, nt->OptionalHeader.AddressOfEntryPoint); -} +}; + + +void *get_proc_address(module_t *module, char *proc_name) +{ + + PIMAGE_DOS_HEADER expdos; + PIMAGE_NT_HEADERS32 expnt; + PIMAGE_EXPORT_DIRECTORY exp; + + uint32_t *exp_functions; + uint16_t *exp_ordinals; + char **exp_names; + + int minn, maxn; + char *export_name; + uint16_t ordinal; + void *function=NULL; + + exp = module->img_exp; + + exp_functions = MakePtr(uint32_t*,exp->AddressOfFunctions,module->start); + exp_ordinals = MakePtr(uint16_t*, exp->AddressOfNameOrdinals,module->start); + exp_names = MakePtr(char**, exp->AddressOfNames,module->start); + + minn = 0; + maxn = exp->NumberOfNames - 1; + while (minn <= maxn) + { + int mid; + int res; + + mid = (minn + maxn) / 2; + + export_name = MakePtr(char*,exp_names[mid],module->start); + + res = strcmp(export_name, proc_name); + if (res == 0) + { + ordinal = exp_ordinals[mid]; + function = MakePtr(void*,exp_functions[ordinal], module->start); + + if((uint32_t)function >= (uint32_t)exp) + { + printf("forward %s\n", function); + } + else + { + DBG(" \t\tat %x\n", function); + }; + break; + } + else if (minn == maxn) + { + DBG(" unresolved %s\n",proc_name); + break; + } + else if (res > 0) + { + maxn = mid - 1; + } + else + { + minn = mid + 1; + } + }; + + return function; +}; module_t* load_module(const char *name) @@ -642,7 +710,18 @@ module_t* load_module(const char *name) list_add_tail(&module->list, &dll_list); if( link_image(img_base)) + { + int (*dll_startup)(module_t *mod, uint32_t reason); + + dll_startup = get_proc_address(module, "DllStartup"); + if( dll_startup ) + { + if( 0 == dll_startup(module, 1)) + return 0; + } return module; + }; + return NULL; }; diff --git a/programs/develop/libraries/newlib/static.lds b/programs/develop/libraries/newlib/static.lds index 60df13981..b6d4a43e0 100644 --- a/programs/develop/libraries/newlib/static.lds +++ b/programs/develop/libraries/newlib/static.lds @@ -90,7 +90,7 @@ SECTIONS . = . + 256; ___pgmname = .; ___menuet__app_path_area = .; - . = . + 1024 + 16; + . = . + 1024 + __size_of_stack_reserve__; ___stacktop = .; ___memsize = . ; }