diff --git a/lib/ubix/Makefile b/lib/ubix/Makefile index f2bf4da..45c5b95 100644 --- a/lib/ubix/Makefile +++ b/lib/ubix/Makefile @@ -9,7 +9,7 @@ BINARY = none #Objects -OBJS = sstart.o #startup.o +OBJS = _start.o sstart.o #startup.o CFLAGS = -m32 -fno-builtin -Wno-uninitialized -O2 -fno-strict-aliasing -pipe -Wsystem-headers -Werror -Wall -Wno-format-y2k -W -Wno-unused-parameter -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch -Wshadow -Wcast-align -Wunused-parameter -Wchar-subscripts -Winline -Wnested-externs -Wredundant-decls diff --git a/lib/ubix/sstart.c b/lib/ubix/sstart.c index ecb0045..df1582e 100644 --- a/lib/ubix/sstart.c +++ b/lib/ubix/sstart.c @@ -6,7 +6,34 @@ int a_val; } Elf32_Auxinfo; -void _start(unsigned int *ap, ...) { +typedef void (*fptr)(void); + +void _start1(fptr cleanup, int argc, char *argv[]) +{ + char **env; + + env = argv + argc + 1; +/* + handle_argv(argc, argv, env); + if (&_DYNAMIC != NULL) + atexit(cleanup); + else + _init_tls(); + +#ifdef GCRT + atexit(_mcleanup); + monstartup(&eprol, &etext); +__asm__("eprol:"); +#endif + + handle_static_init(argc, argv, env); +*/ + exit(main(argc, argv, env)); +} + + +#ifdef _BALLS +void _start1(unsigned int *ap, ...) { Elf32_Auxinfo *aux, *auxp; unsigned int *argcp; int argc; @@ -52,3 +79,4 @@ exit(main(argc, argv, env)); } +#endif diff --git a/sys/i386/i386_exec.c b/sys/i386/i386_exec.c index 19ef2b7..ae70b23 100644 --- a/sys/i386/i386_exec.c +++ b/sys/i386/i386_exec.c @@ -224,18 +224,18 @@ return; } - _current->td.abi = binaryHeader->eIdent[EI_OSABI]; + _current->td.abi = binaryHeader->e_ident[EI_OSABI]; /* Load The Program Header(s) */ - programHeader = (elfProgramHeader *) kmalloc( sizeof(elfProgramHeader) * binaryHeader->ePhnum ); - fseek( tmpFd, binaryHeader->ePhoff, 0 ); + programHeader = (elfProgramHeader *) kmalloc( sizeof(elfProgramHeader) * binaryHeader->e_phnum ); + fseek( tmpFd, binaryHeader->e_phoff, 0 ); - //kprintf(">c:%i:0x%X:0x%X<",sizeof(elfProgramHeader)*binaryHeader->ePhnum,programHeader,tmpFd); - fread( programHeader, (sizeof(elfProgramHeader) * binaryHeader->ePhnum), 1, tmpFd ); + //kprintf(">c:%i:0x%X:0x%X<",sizeof(elfProgramHeader)*binaryHeader->e_phnum,programHeader,tmpFd); + fread( programHeader, (sizeof(elfProgramHeader) * binaryHeader->e_phnum), 1, tmpFd ); //kprintf(">d<"); /* Loop Through The Header And Load Sections Which Need To Be Loaded */ - for ( i = 0; i < binaryHeader->ePhnum; i++ ) { + for ( i = 0; i < binaryHeader->e_phnum; i++ ) { if ( programHeader[i].phType == 1 ) { /* Allocate Memory Im Going To Have To Make This Load Memory With Correct @@ -286,7 +286,7 @@ _current->tss.ss1 = 0x0; _current->tss.esp2 = 0x0; _current->tss.ss2 = 0x0; - _current->tss.eip = (long) binaryHeader->eEntry; + _current->tss.eip = (long) binaryHeader->e_entry; _current->tss.eflags = 0x206; _current->tss.esp = STACK_ADDR - 16; _current->tss.ebp = STACK_ADDR; @@ -312,14 +312,14 @@ fclose( tmpFd ); tmp = (uInt32 *) _current->tss.esp0 - 5; - tmp[0] = binaryHeader->eEntry; + tmp[0] = binaryHeader->e_entry; tmp[3] = STACK_ADDR - 12; tmp = (uint32_t *) _current->tss.esp; kprintf( "argv: [0x%X]\n", argv ); - *tmp++ = 0x0; // Stack EIP Return Addr - *tmp++ = tmp + 1; // Pointer To AP + //*tmp++ = 0x0; // Stack EIP Return Addr + //*tmp++ = tmp + 1; // Pointer To AP *tmp++ = 0x1; // ARGC *tmp++ = 0x0; // ARGV *tmp++ = 0x0; // ARGV TERM @@ -611,18 +611,23 @@ //kprintf( "EBP-1(%i): EBP: [0x%X], EIP: [0x%X], ESP: [0x%X]\n", _current->id, iFrame->ebp, iFrame->eip, iFrame->user_esp ); - argc = 1; + argc = 2; iFrame->ebp = STACK_ADDR; - iFrame->eip = binaryHeader->eEntry; - iFrame->user_esp = ((uint32_t) STACK_ADDR) - ((sizeof(uint32_t) * (argc + 8 + 1)) + (sizeof(Elf32_Auxinfo) * 2)); + iFrame->eip = binaryHeader->e_entry; + //iFrame->user_ebp = 0x0; + iFrame->edx = 0x0; + //iFrame->user_esp = ((uint32_t) STACK_ADDR) - ((sizeof(uint32_t) * (argc + 8 + 1)) + (sizeof(Elf32_Auxinfo) * 2)); + iFrame->user_esp = ((uint32_t) STACK_ADDR) - (128);//(sizeof(uint32_t) * (argc + 8 + 1)) + (sizeof(Elf32_Auxinfo) * 2)); tmp = (void *) iFrame->user_esp; //MrOlsen 2017-11-14 iFrame->user_ebp; - *tmp++ = 0x0; // Stack EIP Return Addr - *tmp++ = tmp + 1; // Pointer To AP + + //memset(tmp,0x0,((sizeof(uint32_t) * (argc + 8 + 1)) + (sizeof(Elf32_Auxinfo) * 2))); + memset((char *)(STACK_ADDR - 128),0x0,128); *tmp++ = argc; // ARGC + /* if ( argc == 1 ) { *tmp++ = 0x0; //ARGV Pointers } @@ -631,6 +636,7 @@ *tmp++ = (u_int) argv[i]; } } + */ *tmp++ = 0x0; // ARGV Terminator *tmp++ = 0x0; // ENV @@ -644,47 +650,12 @@ *tmp++ = 0x0; // End Marker - tmp = (void *)STACK_ADDR; - tmp[0] = (void *)iFrame->user_esp; //0x10; -/* -*/ - - /* - * App Entry Stack - argc - argv[0] - argv[1] - argv[2] .. - argv[argc - 1] = null - END OF ARGV - env[0] - env[1] - NULL end of env - */ - - //} - //else { - //tmp = (uint32_t *)STACK_ADDR - 2; - //tmp[0] = 0x1; - //tmp[1] = 0x0; - //tmp[1] = (uint32_t)argv; - //} kfree( argvNew ); + /* Now That We Relocated The Binary We Can Unmap And Free Header Info */ kfree( binaryHeader ); kfree( programHeader ); - //kprintf( "EBP-3(%i): [0x%X], EIP: [0x%X], ESP: [0x%X]\n", _current->id, iFrame->ebp, iFrame->eip, iFrame->user_esp ); - //kprintf( "Done EXEC\n" ); - - /* - asm("cli"); - _current->tss.eip = (long) iFrameNew->eip; - _current->tss.eflags = 0x206; - _current->tss.esp = iFrameNew->user_esp; - _current->tss.ebp = iFrameNew->ebp; - */ - /* Set these up to be ring 3 tasks */ - /* _current->tss.es = 0x30 + 3; _current->tss.cs = 0x28 + 3; @@ -713,15 +684,5 @@ */ -/* - asm( - "sti\n" - "ljmp $0x20,$0\n" - ); -*/ - //tmp = (char *)iFrame->eip; - - //kprintf("N:[0x%X]\n", tmp[0]); - //kprintf( "EBP-4(%i): [0x%X], EBP: [0x%X], EIP: [0x%X], ESP: [0x%X], CR3: [0x%X-0x%X]\n", _current->id, _current->oInfo.vmStart, iFrame->ebp, iFrame->eip, iFrame->user_esp, cr3, kernelPageDirectory ); return (0x0); } diff --git a/sys/include/i386/elf.h b/sys/include/i386/elf.h index 18cd593..d482f84 100644 --- a/sys/include/i386/elf.h +++ b/sys/include/i386/elf.h @@ -1,93 +1,74 @@ -#ifndef _I386_ELF_H_ -#define _i386_ELF_H_ 1 - -#define elfExecutable 0x002 -#define elfLibrary 0x003 - -typedef struct { - uInt8 eIdent[16]; /* File identification. */ - uInt16 eType; /* File type. */ - uInt16 eMachine; /* Machine architecture. */ - uInt32 eVersion; /* ELF format version. */ - uInt32 eEntry; /* Entry point. */ - uInt32 ePhoff; /* Program header file offset. */ - uInt32 eShoff; /* Section header file offset. */ - uInt32 eFlags; /* Architecture-specific flags. */ - uInt16 eEhsize; /* Size of ELF header in bytes. */ - uInt16 ePhentsize; /* Size of program header entry. */ - uInt16 ePhnum; /* Number of program header entries. */ - uInt16 eShentsize; /* Size of section header entry. */ - uInt16 eShnum; /* Number of section header entries. */ - uInt16 eShstrndx; /* Section name strings section. */ -} elfHeader; - -typedef struct { - uInt32 phType; /* Entry type. */ - uInt32 phOffset; /* File offset of contents. */ - uInt32 phVaddr; /* Virtual address in memory image. */ - uInt32 phPaddr; /* Physical address (not used). */ - uInt32 phFilesz; /* Size of contents in file. */ - uInt32 phMemsz; /* Size of contents in memory. */ - uInt32 phFlags; /* Access permission flags. */ - uInt32 phAlign; /* Alignment in memory and file. */ -} elfProgramHeader; - -typedef struct { - uInt32 shName; /* Section name (index into the section header string table). */ - uInt32 shType; /* Section type. */ - uInt32 shFlags; /* Section flags. */ - uInt32 shAddr; /* Address in memory image. */ - uInt32 shOffset; /* Offset in file. */ - uInt32 shSize; /* Size in bytes. */ - uInt32 shLink; /* Index of a related section. */ - uInt32 shInfo; /* Depends on section type. */ - uInt32 shAddralign; /* Alignment in bytes. */ - uInt32 shEntsize; /* Size of each entry in section. */ -} elfSectionHeader; - -typedef struct { - uInt32 pltOffset; - uInt32 pltInfo; -} elfPltInfo; - -typedef struct { - uInt32 dynName; - uInt32 dynValue; - uInt32 dynSize; - uInt32 dynInfo; -} elfDynSym; - -typedef struct { - uInt32 dynVal; - uInt32 dynPtr; -} elfDynamic; - -typedef struct { - int32_t execfd; - uint32_t phdr; - uint32_t phent; - uint32_t phnum; - uint32_t pagesz; - uint32_t base; - uint32_t flags; - uint32_t entry; - uint32_t trace; -} Elf_Auxargs; - -typedef struct { /* Auxiliary vector entry on initial stack */ - int a_type; /* Entry type. */ - union { - int a_val; /* Integer value. */ - } a_un; -} Elf32_Auxinfo; - -char *elfGetShType( int ); -char *elfGetPhType( int ); -char *elfGetRelType( int ); -int elf_loadfile( kTask_t *p, const char *file, uint32_t *addr, uint32_t *entry ); - -#define ELF32_R_SYM(i) ((i)>>8) -#define ELF32_R_TYPE(i) ((unsigned char)(i)) -#define ELF32_R_INFO(s, t) ((s)<<8+(unsigned char)(t)) - -#endif +#ifndef _I386_ELF_H_ +#define _i386_ELF_H_ 1 + +#include + +#define elfExecutable 0x002 +#define elfLibrary 0x003 + +typedef struct { + uInt32 phType; /* Entry type. */ + uInt32 phOffset; /* File offset of contents. */ + uInt32 phVaddr; /* Virtual address in memory image. */ + uInt32 phPaddr; /* Physical address (not used). */ + uInt32 phFilesz; /* Size of contents in file. */ + uInt32 phMemsz; /* Size of contents in memory. */ + uInt32 phFlags; /* Access permission flags. */ + uInt32 phAlign; /* Alignment in memory and file. */ +} elfProgramHeader; + +typedef struct { + uInt32 shName; /* Section name (index into the section header string table). */ + uInt32 shType; /* Section type. */ + uInt32 shFlags; /* Section flags. */ + uInt32 shAddr; /* Address in memory image. */ + uInt32 shOffset; /* Offset in file. */ + uInt32 shSize; /* Size in bytes. */ + uInt32 shLink; /* Index of a related section. */ + uInt32 shInfo; /* Depends on section type. */ + uInt32 shAddralign; /* Alignment in bytes. */ + uInt32 shEntsize; /* Size of each entry in section. */ +} elfSectionHeader; + +typedef struct { + uInt32 pltOffset; + uInt32 pltInfo; +} elfPltInfo; + +typedef struct { + uInt32 dynName; + uInt32 dynValue; + uInt32 dynSize; + uInt32 dynInfo; +} elfDynSym; + +typedef struct { + uInt32 dynVal; + uInt32 dynPtr; +} elfDynamic; + +typedef struct { + int32_t execfd; + uint32_t phdr; + uint32_t phent; + uint32_t phnum; + uint32_t pagesz; + uint32_t base; + uint32_t flags; + uint32_t entry; + uint32_t trace; +} Elf_Auxargs; + +typedef struct { /* Auxiliary vector entry on initial stack */ + int a_type; /* Entry type. */ + union { + int a_val; /* Integer value. */ + } a_un; +} Elf32_Auxinfo; + +char *elfGetShType( int ); +char *elfGetPhType( int ); +char *elfGetRelType( int ); +int elf_loadfile( kTask_t *p, const char *file, uint32_t *addr, uint32_t *entry ); + +#endif diff --git a/sys/kernel/execve.c b/sys/kernel/execve.c index a7dd8e9..f560a64 100644 --- a/sys/kernel/execve.c +++ b/sys/kernel/execve.c @@ -1,9 +1,9 @@ -#include -#include -#include - -int sys_execve( struct thread *td, struct sys_execve_args *args ) { - int ret = sys_exec( td, args->fname, args->argv, args->envp ); - kprintf("RETURNING: [%i]\n", ret); - return (ret); -} +#include +#include +#include + +int sys_execve( struct thread *td, struct sys_execve_args *args ) { + int ret = sys_exec( td, args->fname, args->argv, args->envp ); + kprintf("RETURNING: [%i]\n", ret); + return (ret); +} diff --git a/sys/kernel/ld.c b/sys/kernel/ld.c index 0600e7a..f0871f7 100644 --- a/sys/kernel/ld.c +++ b/sys/kernel/ld.c @@ -108,9 +108,6 @@ /* Tells us if the stack should be executable. Failsafe to executable until we add checking */ break; - case PT_PAX_FLAGS: - /* Not sure... */ - break; default: kprintf("Unhandled Header (kernel) : %08x\n", programHeader[i].phType); break;