X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/7c7b5f05d39b7739d990f71256a2267ec67a6913..69777bdcab284335651a8002e2896f3862fa423d:/lunaix-os/kernel/exe/elf32/ldelf32.c diff --git a/lunaix-os/kernel/exe/elf32/ldelf32.c b/lunaix-os/kernel/exe/elf32/ldelf32.c index 3dff1a8..64e0eba 100644 --- a/lunaix-os/kernel/exe/elf32/ldelf32.c +++ b/lunaix-os/kernel/exe/elf32/ldelf32.c @@ -1,7 +1,6 @@ #include #include #include -#include #include #include @@ -15,7 +14,7 @@ elf32_smap(struct load_context* ldctx, { struct v_file* elfile = (struct v_file*)elf->elf_file; - assert(PG_ALIGNED(phdre->p_offset)); + assert(!va_offset(phdre->p_offset)); int proct = 0; if ((phdre->p_flags & PF_R)) { @@ -31,24 +30,23 @@ elf32_smap(struct load_context* ldctx, uintptr_t va = phdre->p_va + base_va; struct exec_container* container = ldctx->container; struct mmap_param param = { .vms_mnt = container->vms_mnt, - .pvms = &container->proc->mm, + .pvms = vmspace(container->proc), .proct = proct, - .offset = PG_ALIGN(phdre->p_offset), - .mlen = ROUNDUP(phdre->p_memsz, PG_SIZE), - .flen = phdre->p_filesz, + .offset = va_align(phdre->p_offset), + .mlen = va_alignup(phdre->p_memsz), .flags = MAP_FIXED | MAP_PRIVATE, .type = REGION_TYPE_CODE }; struct mm_region* seg_reg; - int status = mem_map(NULL, &seg_reg, PG_ALIGN(va), elfile, ¶m); + int status = mmap_user(NULL, &seg_reg, va_align(va), elfile, ¶m); if (!status) { size_t next_addr = phdre->p_memsz + va; - ldctx->end = MAX(ldctx->end, ROUNDUP(next_addr, PG_SIZE)); + ldctx->end = MAX(ldctx->end, va_alignup(next_addr)); ldctx->mem_sz += phdre->p_memsz; } else { // we probably fucked up our process - terminate_proc(-1); + terminate_current(-1); } return status; @@ -77,8 +75,8 @@ load_executable(struct load_context* context, const struct v_file* exefile) goto done; } - ldpath = valloc(512); - errno = elf32_find_loader(&elf, ldpath, 512); + ldpath = valloc(256); + errno = elf32_find_loader(&elf, ldpath, 256); uintptr_t load_base = 0; if (errno < 0) { @@ -118,7 +116,7 @@ load_executable(struct load_context* context, const struct v_file* exefile) continue; } - if (phdr->p_align != PG_SIZE) { + if (phdr->p_align != PAGE_SIZE) { // surprising alignment! errno = ENOEXEC; break; @@ -131,6 +129,8 @@ done_close_elf32: elf32_close(&elf); done: - vfree_safe(ldpath); + if (!container->argv_pp[1]) { + vfree_safe(ldpath); + } return errno; }