newlib: fix stack allocation

git-svn-id: svn://kolibrios.org@2040 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Sergey Semyonov (Serge) 2011-08-07 13:02:30 +00:00
parent e95850da21
commit 3b27f053ae
6 changed files with 94 additions and 7 deletions

View File

@ -18,6 +18,7 @@ AMZ_SRCS:= \
crt/chkstk.S \ crt/chkstk.S \
crt/exit.S \ crt/exit.S \
crt/pseudo-reloc.c \ crt/pseudo-reloc.c \
crt/dllstart.c \
crt/setjmp.S crt/setjmp.S
STATIC_SRCS:= \ STATIC_SRCS:= \
@ -204,6 +205,7 @@ STDIO_SRCS= \
fdopen.c \ fdopen.c \
fflush.c \ fflush.c \
flags.c \ flags.c \
fileno.c \
findfp.c \ findfp.c \
fiprintf.c \ fiprintf.c \
fiscanf.c \ fiscanf.c \

View File

@ -4,8 +4,8 @@
.section .text .section .text
.def ___chkstk; .scl 2; .type 32; .endef #.def ___chkstk; .scl 2; .type 32; .endef
.def __alloca; .scl 2; .type 32; .endef #.def __alloca; .scl 2; .type 32; .endef
___chkstk: ___chkstk:
__alloca: __alloca:
pushl %ecx /* save temp */ pushl %ecx /* save temp */

View File

@ -1,11 +1,19 @@
.section .text
.global __start .global __start
.global ___main .global ___main
.global _DllMainCRTStartup
.section .init
.def __start; .scl 2; .type 32; .endef
.def _DllMainCRTStartup; .scl 2; .type 32; .endef
.align 4 .align 4
__start: __start:
_DllMainCRTStartup:
call __pei386_runtime_relocator call __pei386_runtime_relocator
jmp _main jmp _main

View File

@ -1,8 +1,6 @@
OUTPUT_FORMAT(pei-i386) OUTPUT_FORMAT(pei-i386)
ENTRY("__start")
SECTIONS SECTIONS
{ {
. = SIZEOF_HEADERS; . = SIZEOF_HEADERS;

View File

@ -561,7 +561,75 @@ void* get_entry_point(void *raw)
nt = MakePtr( PIMAGE_NT_HEADERS32, dos, dos->e_lfanew); nt = MakePtr( PIMAGE_NT_HEADERS32, dos, dos->e_lfanew);
return MakePtr(void*, raw, nt->OptionalHeader.AddressOfEntryPoint); 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) 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); list_add_tail(&module->list, &dll_list);
if( link_image(img_base)) 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 module;
};
return NULL; return NULL;
}; };

View File

@ -90,7 +90,7 @@ SECTIONS
. = . + 256; . = . + 256;
___pgmname = .; ___pgmname = .;
___menuet__app_path_area = .; ___menuet__app_path_area = .;
. = . + 1024 + 16; . = . + 1024 + __size_of_stack_reserve__;
___stacktop = .; ___stacktop = .;
___memsize = . ; ___memsize = . ;
} }