mmap #8
@ -5,6 +5,7 @@
|
|||||||
#include "paging.h"
|
#include "paging.h"
|
||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
#include "zero.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make sure the program is in a valid ELF format, map it into memory,
|
* Make sure the program is in a valid ELF format, map it into memory,
|
||||||
@ -17,6 +18,7 @@ uaddr_t loadElfProg(const char *prog, struct process *proc)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
uaddr_t lastUserAddr = 0;
|
uaddr_t lastUserAddr = 0;
|
||||||
|
struct uAddrSpace *as = processGetAddrSpace(proc);
|
||||||
|
|
||||||
/* e_ident value */
|
/* e_ident value */
|
||||||
#define ELFMAG0 0x7f
|
#define ELFMAG0 0x7f
|
||||||
@ -136,6 +138,11 @@ uaddr_t loadElfProg(const char *prog, struct process *proc)
|
|||||||
unrefPhyPage(ppage);
|
unrefPhyPage(ppage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Hack: Even if already allocated mark the adresse space as managed by a ressource
|
||||||
|
// So this address space is not used by another ressource.
|
||||||
|
uaddr = elf_phdrs[i].p_vaddr;
|
||||||
|
zeroMmap(as, &uaddr, elf_phdrs[i].p_memsz, PAGING_MEM_USER | PAGING_MEM_WRITE | PAGING_MEM_READ, 0);
|
||||||
|
|
||||||
/* Copy segment into memory */
|
/* Copy segment into memory */
|
||||||
memcpy((void *)elf_phdrs[i].p_vaddr, (void *)(prog + elf_phdrs[i].p_offset),
|
memcpy((void *)elf_phdrs[i].p_vaddr, (void *)(prog + elf_phdrs[i].p_offset),
|
||||||
elf_phdrs[i].p_filesz);
|
elf_phdrs[i].p_filesz);
|
||||||
|
@ -57,6 +57,7 @@ int zeroOnMapped(struct uAddrVirtualReg *vreg)
|
|||||||
int zeroMmap(struct uAddrSpace *as, uaddr_t *uaddr, size_t size, uint32_t rights,
|
int zeroMmap(struct uAddrSpace *as, uaddr_t *uaddr, size_t size, uint32_t rights,
|
||||||
uint32_t flags)
|
uint32_t flags)
|
||||||
{
|
{
|
||||||
|
int ret = 0;
|
||||||
struct mappedRessource *res =
|
struct mappedRessource *res =
|
||||||
(struct mappedRessource *)zalloc(sizeof(struct mappedRessource));
|
(struct mappedRessource *)zalloc(sizeof(struct mappedRessource));
|
||||||
struct zeroMappedEntry *cust =
|
struct zeroMappedEntry *cust =
|
||||||
@ -67,5 +68,12 @@ int zeroMmap(struct uAddrSpace *as, uaddr_t *uaddr, size_t size, uint32_t rights
|
|||||||
res->customData = cust;
|
res->customData = cust;
|
||||||
res->onResMapped = zeroOnMapped;
|
res->onResMapped = zeroOnMapped;
|
||||||
|
|
||||||
return uAddrSpaceMmap(as, uaddr, size, rights, flags, res, 0);
|
ret = uAddrSpaceMmap(as, uaddr, size, rights, flags, res, 0);
|
||||||
|
|
||||||
|
if (ret) {
|
||||||
|
free(res);
|
||||||
|
free(cust);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user