mirror of
https://github.com/drasko/codezero.git
synced 2026-01-28 18:53:14 +01:00
Added preliminary support for execve(). Updates to clone, fork, exit, task handling.
It turned out we used one version of kmalloc for malloc() and another for kfree()! Now fixed. Added parent-child relationship to tasks. Need to polish handling CLONE_PARENT and THREAD.
This commit is contained in:
42
tasks/mm0/src/lib/elf/elf.c
Normal file
42
tasks/mm0/src/lib/elf/elf.c
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* ELF manipulation routines
|
||||
*
|
||||
* Copyright (C) 2008 Bahadir Balban
|
||||
*/
|
||||
#include <vm_area.h>
|
||||
#include <lib/elf.h>
|
||||
#include <lib/elfprg.h>
|
||||
#include <lib/elfsym.h>
|
||||
#include <lib/elfsect.h>
|
||||
|
||||
|
||||
int elf_probe(struct elf_header *header)
|
||||
{
|
||||
/* Test that it is a 32-bit little-endian ELF file */
|
||||
if (header->e_ident[EI_MAG0] == ELFMAG0 &&
|
||||
header->e_ident[EI_MAG1] == ELFMAG1 &&
|
||||
header->e_ident[EI_MAG2] == ELFMAG2 &&
|
||||
header->e_ident[EI_MAG3] == ELFMAG3 &&
|
||||
header->e_ident[EI_CLASS] == ELFCLASS32 &&
|
||||
header->e_ident[EI_DATA] == ELFDATA2LSB)
|
||||
return 0;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
int elf_parse_executable(struct vm_file *f)
|
||||
{
|
||||
int err;
|
||||
struct elf_header *elf_header = pager_map_page(f, 0);
|
||||
struct elf_program_header *prg_header;
|
||||
struct elf_section_header *sect_header;
|
||||
|
||||
/* Test that it is a valid elf file */
|
||||
if ((err = elf_probe(elf_header)) < 0)
|
||||
return err;
|
||||
|
||||
/* Get the program header table */
|
||||
prg_header = (struct elf_program_header *)((void *)elf_header + elf_header->e_phoff);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,8 @@
|
||||
* Copyright (C) 2007 Bahadir Balban
|
||||
*/
|
||||
#include <lib/idpool.h>
|
||||
#include <kmalloc/kmalloc.h>
|
||||
#include <lib/malloc.h>
|
||||
#include <l4/macros.h>
|
||||
#include INC_GLUE(memory.h)
|
||||
#include <stdio.h>
|
||||
#include <l4/api/errno.h>
|
||||
|
||||
@@ -205,14 +205,6 @@ create a new, free block */
|
||||
return (char *)n + sizeof(malloc_t);
|
||||
}
|
||||
|
||||
static inline void *kzalloc(size_t size)
|
||||
{
|
||||
void *buf = kmalloc(size);
|
||||
|
||||
memset(buf, 0, size);
|
||||
return buf;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
*****************************************************************************/
|
||||
void kfree(void *blk)
|
||||
@@ -254,6 +246,9 @@ void kfree(void *blk)
|
||||
}
|
||||
/* free the block */
|
||||
m->used = 0;
|
||||
/* BB: Addition: put 0xFF to block memory so we know if we use freed memory */
|
||||
memset(blk, 0xFF, m->size);
|
||||
|
||||
/* coalesce adjacent free blocks
|
||||
Hard to spell, hard to do */
|
||||
for(m = (malloc_t *)g_heap_bot; m != NULL; m = m->next)
|
||||
|
||||
Reference in New Issue
Block a user