diff --git a/conts/posix/mm0/mm/execve.c b/conts/posix/mm0/mm/execve.c index cdb621e..49f33b5 100644 --- a/conts/posix/mm0/mm/execve.c +++ b/conts/posix/mm0/mm/execve.c @@ -181,14 +181,17 @@ int do_execve(struct tcb *sender, char *filename, struct args_struct *args, } /* Map task's new segment markers as virtual memory regions */ - if ((err = task_mmap_segments(new_task, vmfile, &efd, args, env)) < 0) { + if ((err = task_mmap_segments(new_task, vmfile, + &efd, args, env)) < 0) { vm_file_put(vmfile); kfree(new_task); return err; } /* Set up task registers via exchange_registers() */ - task_setup_registers(new_task, 0, new_task->args_start, new_task->pagerid); + task_setup_registers(new_task, 0, + new_task->args_start, + new_task->pagerid); /* Add new task to global list */ global_add_task(new_task); diff --git a/conts/posix/mm0/mm/exit.c b/conts/posix/mm0/mm/exit.c index a06394a..1593c4f 100644 --- a/conts/posix/mm0/mm/exit.c +++ b/conts/posix/mm0/mm/exit.c @@ -106,7 +106,6 @@ void do_exit(struct tcb *task, int status) task_destroy_utcb(task); /* Remove default shared page shm areas from vfs */ - BUG(); // printf("Unmapping 0x%p from vfs as shared-page of %d\n", task->shared_page, task->tid); //shpage_unmap_from_task(task, find_task(VFS_TID)); diff --git a/conts/posix/mm0/mm/file.c b/conts/posix/mm0/mm/file.c index 15bdd50..499c297 100644 --- a/conts/posix/mm0/mm/file.c +++ b/conts/posix/mm0/mm/file.c @@ -663,8 +663,8 @@ int do_close(struct tcb *task, int fd) { int err; - printf("%s: Closing fd: %d on task %d\n", __FUNCTION__, - fd, task->tid); + //printf("%s: Closing fd: %d on task %d\n", __FUNCTION__, + // fd, task->tid); if ((err = id_del(task->files->fdpool, fd)) < 0) { printf("%s: Error releasing fd identifier.\n", diff --git a/conts/posix/test0/SConscript b/conts/posix/test0/SConscript index 4797bf1..fc8b13c 100644 --- a/conts/posix/test0/SConscript +++ b/conts/posix/test0/SConscript @@ -42,6 +42,7 @@ test_exec_objs = test_exec_env.Object(test_exec_src) test_exec = test_exec_env.Program('src/test_exec/test_exec', test_exec_objs) test_exec_asm = Command('test_exec.S', test_exec, generate_incbin_asm) Depends(test_exec, test_exec_objs) +Depends(test_exec, 'include/test_exec_linker.lds') env.Append(LIBS = ['posix', 'c-userspace']) env.Append(LINKFLAGS = '-T' + lma_lds[0].path) diff --git a/conts/posix/test0/include/test_exec_linker.lds b/conts/posix/test0/include/test_exec_linker.lds index 0725dcf..f858b07 100644 --- a/conts/posix/test0/include/test_exec_linker.lds +++ b/conts/posix/test0/include/test_exec_linker.lds @@ -5,7 +5,8 @@ */ virtual_base = 0x10000000; -__stack = (0x20000000 - 0x1000 - 8); /* First page before the env/args */ +/* __stack = (0x20000000 - 0x1000 - 8); */ +/* First page before the env/args */ ENTRY(_start) @@ -16,6 +17,7 @@ SECTIONS .text : { *(.text.head) *(.text) } .rodata : { *(.rodata) } .rodata1 : { *(.rodata1) } + . = ALIGN(4K); .data : { *(.data) } .bss : { *(.bss) } } diff --git a/conts/posix/test0/include/tests.h b/conts/posix/test0/include/tests.h index 4e46a81..d24b7e5 100644 --- a/conts/posix/test0/include/tests.h +++ b/conts/posix/test0/include/tests.h @@ -3,7 +3,7 @@ #define __TASKNAME__ "test0" -#define TEST_VERBOSE_PRINT +//#define TEST_VERBOSE_PRINT #if defined (TEST_VERBOSE_PRINT) #define test_printf(...) printf(__VA_ARGS__) #else @@ -22,7 +22,7 @@ int mmaptest(void); int dirtest(void); int fileio(void); int clonetest(void); -int exectest(void); +int exectest(pid_t); int user_mutex_test(void); #endif /* __TEST0_TESTS_H__ */ diff --git a/conts/posix/test0/main.c b/conts/posix/test0/main.c index af6d7c2..4632d30 100644 --- a/conts/posix/test0/main.c +++ b/conts/posix/test0/main.c @@ -34,7 +34,6 @@ int main(int argc, char *argv[]) wait_pager(0); - printf("\n%s: Running POSIX API tests.\n", __TASKNAME__); dirtest(); @@ -56,7 +55,8 @@ int main(int argc, char *argv[]) if (parent_of_all == getpid()) { user_mutex_test(); } - exectest(); + + exectest(parent_of_all); while (1) wait_pager(0); diff --git a/conts/posix/test0/src/exectest.c b/conts/posix/test0/src/exectest.c index 9b9d945..9adbe8e 100644 --- a/conts/posix/test0/src/exectest.c +++ b/conts/posix/test0/src/exectest.c @@ -14,7 +14,7 @@ extern char _start_test_exec[]; extern char _end_test_exec[]; -int exectest(void) +int exectest(pid_t parent_of_all) { int fd, err; void *exec_start = (void *)_start_test_exec; @@ -22,6 +22,8 @@ int exectest(void) int left, cnt; char *argv[5]; char filename[128]; + char *envp[2]; + char env_string[30]; memset(filename, 0, 128); sprintf(filename, "/home/bahadir/execfile%d", getpid()); @@ -65,8 +67,13 @@ int exectest(void) argv[3] = "FOURTH ARG"; argv[4] = 0; + memset(env_string, 0, 30); + sprintf(env_string, "parent_of_all=%d", parent_of_all); + envp[0] = env_string; + envp[1] = 0; /* This is important as the array needs to end with a null */ + /* Execute the file */ - err = execve(filename, argv, 0); + err = execve(filename, argv, envp); out_err: printf("EXECVE failed with %d\n", err); diff --git a/conts/posix/test0/src/forktest.c b/conts/posix/test0/src/forktest.c index 9780685..bb68203 100644 --- a/conts/posix/test0/src/forktest.c +++ b/conts/posix/test0/src/forktest.c @@ -17,7 +17,7 @@ int forktest(void) /* 16 forks */ - for (int i = 0; i < 1; i++) { + for (int i = 0; i < 3; i++) { test_printf("%d: Forking...\n", getpid()); if (fork() < 0) goto out_err; diff --git a/conts/posix/test0/src/mutextest.c b/conts/posix/test0/src/mutextest.c index d920c6e..e1d346b 100644 --- a/conts/posix/test0/src/mutextest.c +++ b/conts/posix/test0/src/mutextest.c @@ -80,11 +80,11 @@ int user_mutex_test(void) int temp; /* Lock page */ - test_printf("Child locking page.\n"); + // test_printf("Child locking page.\n"); l4_mutex_lock(&shared_page->mutex); /* Read variable */ - test_printf("Child locked page.\n"); + // test_printf("Child locked page.\n"); temp = shared_page->shared_var; /* Update local copy */ @@ -96,11 +96,11 @@ int user_mutex_test(void) /* Write back the result */ shared_page->shared_var = temp; - test_printf("Child modified. Unlocking...\n"); + // test_printf("Child modified. Unlocking...\n"); /* Unlock */ l4_mutex_unlock(&shared_page->mutex); - test_printf("Child unlocked page.\n"); + // test_printf("Child unlocked page.\n"); /* Thread switch */ l4_thread_switch(0); @@ -115,11 +115,11 @@ int user_mutex_test(void) int temp; /* Lock page */ - test_printf("Parent locking page.\n"); + // test_printf("Parent locking page.\n"); l4_mutex_lock(&shared_page->mutex); /* Read variable */ - test_printf("Parent locked page.\n"); + // test_printf("Parent locked page.\n"); temp = shared_page->shared_var; /* Update local copy */ @@ -131,11 +131,11 @@ int user_mutex_test(void) /* Write back the result */ shared_page->shared_var = temp; - test_printf("Parent modified. Unlocking...\n"); + // test_printf("Parent modified. Unlocking...\n"); /* Unlock */ l4_mutex_unlock(&shared_page->mutex); - test_printf("Parent unlocked page.\n"); + // test_printf("Parent unlocked page.\n"); /* Thread switch */ l4_thread_switch(0); @@ -143,7 +143,7 @@ int user_mutex_test(void) /* Sync with the child */ l4_receive(child); - test_printf("Parent checking validity of value.\n"); + // test_printf("Parent checking validity of value.\n"); if (shared_page->shared_var != 0) goto out_err; diff --git a/conts/posix/test0/src/test_exec/container.c b/conts/posix/test0/src/test_exec/container.c index e6ab94b..e7be904 100644 --- a/conts/posix/test0/src/test_exec/container.c +++ b/conts/posix/test0/src/test_exec/container.c @@ -8,15 +8,23 @@ #include #include #include /* Initialisers for posix library */ +#include -void main(void); +int main(int argc, char *argv[]); -void __container_init(void) +int __container_init(int argc, char **argv) { + void *envp = &argv[argc + 1]; + + if ((char *)envp == *argv) + envp = &argv[argc]; + + __libposix_init(envp); + /* Generic L4 thread initialisation */ __l4_init(); /* Entry to main */ - main(); + return main(argc, argv); } diff --git a/conts/posix/test0/src/test_exec/crt0.S b/conts/posix/test0/src/test_exec/crt0.S index d28b311..b9aabb0 100644 --- a/conts/posix/test0/src/test_exec/crt0.S +++ b/conts/posix/test0/src/test_exec/crt0.S @@ -1,93 +1,23 @@ /* - * Australian Public Licence B (OZPLB) - * - * Version 1-0 - * - * Copyright (c) 2004 National ICT Australia - * - * All rights reserved. - * - * Developed by: Embedded, Real-time and Operating Systems Program (ERTOS) - * National ICT Australia - * http://www.ertos.nicta.com.au - * - * Permission is granted by National ICT Australia, free of charge, to - * any person obtaining a copy of this software and any associated - * documentation files (the "Software") to deal with the Software without - * restriction, including (without limitation) the rights to use, copy, - * modify, adapt, merge, publish, distribute, communicate to the public, - * sublicense, and/or sell, lend or rent out copies of the Software, and - * to permit persons to whom the Software is furnished to do so, subject - * to the following conditions: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimers. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimers in the documentation and/or other materials provided - * with the distribution. - * - * * Neither the name of National ICT Australia, nor the names of its - * contributors, may be used to endorse or promote products derived - * from this Software without specific prior written permission. - * - * EXCEPT AS EXPRESSLY STATED IN THIS LICENCE AND TO THE FULL EXTENT - * PERMITTED BY APPLICABLE LAW, THE SOFTWARE IS PROVIDED "AS-IS", AND - * NATIONAL ICT AUSTRALIA AND ITS CONTRIBUTORS MAKE NO REPRESENTATIONS, - * WARRANTIES OR CONDITIONS OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING - * BUT NOT LIMITED TO ANY REPRESENTATIONS, WARRANTIES OR CONDITIONS - * REGARDING THE CONTENTS OR ACCURACY OF THE SOFTWARE, OR OF TITLE, - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, - * THE ABSENCE OF LATENT OR OTHER DEFECTS, OR THE PRESENCE OR ABSENCE OF - * ERRORS, WHETHER OR NOT DISCOVERABLE. - * - * TO THE FULL EXTENT PERMITTED BY APPLICABLE LAW, IN NO EVENT SHALL - * NATIONAL ICT AUSTRALIA OR ITS CONTRIBUTORS BE LIABLE ON ANY LEGAL - * THEORY (INCLUDING, WITHOUT LIMITATION, IN AN ACTION OF CONTRACT, - * NEGLIGENCE OR OTHERWISE) FOR ANY CLAIM, LOSS, DAMAGES OR OTHER - * LIABILITY, INCLUDING (WITHOUT LIMITATION) LOSS OF PRODUCTION OR - * OPERATION TIME, LOSS, DAMAGE OR CORRUPTION OF DATA OR RECORDS; OR LOSS - * OF ANTICIPATED SAVINGS, OPPORTUNITY, REVENUE, PROFIT OR GOODWILL, OR - * OTHER ECONOMIC LOSS; OR ANY SPECIAL, INCIDENTAL, INDIRECT, - * CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES, ARISING OUT OF OR IN - * CONNECTION WITH THIS LICENCE, THE SOFTWARE OR THE USE OF OR OTHER - * DEALINGS WITH THE SOFTWARE, EVEN IF NATIONAL ICT AUSTRALIA OR ITS - * CONTRIBUTORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH CLAIM, LOSS, - * DAMAGES OR OTHER LIABILITY. - * - * If applicable legislation implies representations, warranties, or - * conditions, or imposes obligations or liability on National ICT - * Australia or one of its contributors in respect of the Software that - * cannot be wholly or partly excluded, restricted or modified, the - * liability of National ICT Australia or the contributor is limited, to - * the full extent permitted by the applicable legislation, at its - * option, to: - * a. in the case of goods, any one or more of the following: - * i. the replacement of the goods or the supply of equivalent goods; - * ii. the repair of the goods; - * iii. the payment of the cost of replacing the goods or of acquiring - * equivalent goods; - * iv. the payment of the cost of having the goods repaired; or - * b. in the case of services: - * i. the supplying of the services again; or - * ii. the payment of the cost of having the services supplied again. - * - * The construction, validity and performance of this licence is governed - * by the laws in force in New South Wales, Australia. + * Copyright (C) 2009 Bahadir Balban */ -#ifdef __thumb__ -#define bl blx -#endif +/* + * We expect initial stack state: + * + * (low) |->argc|argv[0]|argv[1]|...|argv[argc] = 0|envp[0]|...|NULL| (high) + * + */ .section .text.head - .code 32 .global _start; .align; _start: - ldr sp, =__stack - bl platform_init + mov fp, #0 @ Clear frame pointer + mov lr, #0 @ Clear link register + ldmfd sp!, {r0} @ Argc value in r0 + mov r1, sp @ Ptr to argv in r1 + bl __container_init 1: b 1b diff --git a/conts/posix/test0/src/test_exec/test_exec.c b/conts/posix/test0/src/test_exec/test_exec.c index 5e40cb5..9faccc6 100644 --- a/conts/posix/test0/src/test_exec/test_exec.c +++ b/conts/posix/test0/src/test_exec/test_exec.c @@ -12,6 +12,7 @@ #include #include #include +#include void wait_pager(l4id_t partner) { @@ -22,15 +23,35 @@ void wait_pager(l4id_t partner) // printf("Pager synced with us.\n"); } -void main(void) +int main(int argc, char *argv[]) { wait_pager(0); - if (getpid() == 2) { + char *parent_of_all; + char pidbuf[10]; + + + /* Convert current pid to string */ + sprintf(pidbuf, "%d", getpid()); + + if (strcmp(argv[0], "FIRST ARG") || + strcmp(argv[1], "SECOND ARG") || + strcmp(argv[2], "THIRD ARG") || + strcmp(argv[3], "FOURTH ARG")) { + printf("EXECVE TEST -- FAILED --\n"); + goto out; + } + + /* Get parent of all pid as a string from environment */ + parent_of_all = getenv("parent_of_all"); + + /* Compare two pid strings. We use strings because we dont have atoi() */ + if (!strcmp(pidbuf, parent_of_all)) { printf("EXECVE TEST -- PASSED --\n"); printf("\nThread (%d): Continues to sync with the pager...\n\n", getpid()); while (1) wait_pager(0); } +out: _exit(0); } diff --git a/loader/SConscript b/loader/SConscript index 5474097..738e8f5 100644 --- a/loader/SConscript +++ b/loader/SConscript @@ -9,7 +9,9 @@ from os.path import join Import('env') - +### +### FIXME: We are missing the dependency on containers.elf +### PROJRELROOT = '../../' from config.projpaths import * diff --git a/loader/libs/elf/src/elf.c b/loader/libs/elf/src/elf.c index 73aa5e6..d4a7839 100644 --- a/loader/libs/elf/src/elf.c +++ b/loader/libs/elf/src/elf.c @@ -375,8 +375,8 @@ elf_loadFile(void *elfFile, bool phys) // printf("Elf program header offset: %p\n", src); pheader_type = elf_getProgramHeaderType(elfFile, i); // printf("Elf program header type: %p\n", pheader_type); - - printf("Copying to range from 0x%x to 0x%x of size: 0x%x\n", (unsigned int)dest, (unsigned int)dest + (unsigned int)len, (unsigned int)len); +// Comment +//printf("Copying to range from 0x%x to 0x%x of size: 0x%x\n", (unsigned int)dest, (unsigned int)dest + (unsigned int)len, (unsigned int)len); memcpy((void*) (uintptr_t) dest, (void*) (uintptr_t) src, len); dest += len; clrsize = elf_getProgramHeaderMemorySize(elfFile, i) - len; @@ -385,7 +385,7 @@ elf_loadFile(void *elfFile, bool phys) // printf("Memory cleared.\n"); } // And this one - printf("\n"); + //printf("\n"); return true; }