aboutsummaryrefslogtreecommitdiff
path: root/common/elf.c
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2022-04-10 15:39:41 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2022-04-10 15:42:04 +0300
commit8aa17b12f29536ea9c8b6ca22c7f153e8d90fa3b (patch)
treee7dba9b6b9cdcd1d04cba639c8f76e9685ac549f /common/elf.c
parent4760462d9b3bf2aba8664c57be85f4adbfa164a2 (diff)
downloadkmi-8aa17b12f29536ea9c8b6ca22c7f153e8d90fa3b.tar.gz
kmi-8aa17b12f29536ea9c8b6ca22c7f153e8d90fa3b.zip
add clang format and run it
Diffstat (limited to 'common/elf.c')
-rw-r--r--common/elf.c33
1 files changed, 18 insertions, 15 deletions
diff --git a/common/elf.c b/common/elf.c
index 9ce357d..ddf61c9 100644
--- a/common/elf.c
+++ b/common/elf.c
@@ -6,20 +6,21 @@
static uint8_t __elf_to_uvflags(uint8_t elf_flags)
{
uint8_t uvflags = VM_V | VM_U;
- if(elf_flags & PF_X)
+ if (elf_flags & PF_X)
uvflags |= VM_X;
- if(elf_flags & PF_W)
+ if (elf_flags & PF_W)
uvflags |= VM_W;
- if(elf_flags & PF_R)
+ if (elf_flags & PF_R)
uvflags |= VM_R;
return uvflags;
}
/* useful bit of info: all segments are sorted in ascending order of p_vaddr */
-static void __map_exec(struct tcb *t, vm_t bin, uint8_t ei_c, vm_t phstart, size_t phnum, size_t phsize)
+static void __map_exec(struct tcb *t, vm_t bin, uint8_t ei_c, vm_t phstart,
+ size_t phnum, size_t phsize)
{
/* TODO: take alignment into consideration? */
/* TODO: take overlapping memory regions into account, probably mostly
@@ -29,21 +30,22 @@ static void __map_exec(struct tcb *t, vm_t bin, uint8_t ei_c, vm_t phstart, size
* filled with zeroes. */
/* TODO: in general, make this a low more clean. */
vm_t runner = phstart;
- for(size_t i = 0; i < phnum; ++i, runner += phsize){
- if(program_header_prop(ei_c, runner, p_type) != PT_LOAD)
+ for (size_t i = 0; i < phnum; ++i, runner += phsize) {
+ if (program_header_prop(ei_c, runner, p_type) != PT_LOAD)
continue;
vm_t va = program_header_prop(ei_c, runner, p_vaddr);
size_t vsz = program_header_prop(ei_c, runner, p_memsz);
vm_t start = alloc_fixed_region(&t->sp_r, va, vsz, &vsz);
- if(!start)
- return; /* out of memory or something */
+ if (!start)
+ return; /* out of memory or something */
uint8_t elf_flags = program_header_prop(ei_c, runner, p_flags);
uint8_t uvflags = __elf_to_uvflags(elf_flags);
- map_allocd_region(t->b_r, start, vsz, VM_V | VM_X | VM_R | VM_W | VM_U);
+ map_allocd_region(t->b_r, start, vsz,
+ VM_V | VM_X | VM_R | VM_W | VM_U);
vm_t vo = bin + program_header_prop(ei_c, runner, p_offset);
vm_t vfz = program_header_prop(ei_c, runner, p_filesz);
@@ -60,7 +62,8 @@ static void __map_exec(struct tcb *t, vm_t bin, uint8_t ei_c, vm_t phstart, size
}
}
-static vm_t __map_dyn(struct tcb *t, vm_t bin, uint8_t ei_c, vm_t phstart, size_t phnum, size_t phsize)
+static vm_t __map_dyn(struct tcb *t, vm_t bin, uint8_t ei_c, vm_t phstart,
+ size_t phnum, size_t phsize)
{
/* TODO: this path should only be taken when no PT_INTERP is defined, as
* making sure ld is loaded should be done in userspace. Maybe a bit
@@ -70,7 +73,7 @@ static vm_t __map_dyn(struct tcb *t, vm_t bin, uint8_t ei_c, vm_t phstart, size_
static vm_t __prepare_proc(struct tcb *t, uint8_t ei_c, vm_t elf)
{
short e_type = elf_header_prop(ei_c, elf, e_type);
- if(e_type != ET_DYN && e_type != ET_EXEC)
+ if (e_type != ET_DYN && e_type != ET_EXEC)
return 0;
vm_t phstart = ptradd(elf, elf_header_prop(ei_c, elf, e_phoff));
@@ -78,7 +81,7 @@ static vm_t __prepare_proc(struct tcb *t, uint8_t ei_c, vm_t elf)
size_t phsize = elf_header_prop(ei_c, elf, e_phentsize);
vm_t entry = elf_header_prop(ei_c, elf, e_entry);
- if(e_type == ET_EXEC){
+ if (e_type == ET_EXEC) {
__map_exec(t, elf, ei_c, phstart, phnum, phsize);
return entry;
} else {
@@ -91,11 +94,11 @@ static vm_t __prepare_proc(struct tcb *t, uint8_t ei_c, vm_t elf)
vm_t load_elf(struct tcb *t, vm_t b)
{
struct elf_ident *i = (struct elf_ident *)b;
- if(i->ei_magic != cpu_to_be32(EI_MAGIC))
+ if (i->ei_magic != cpu_to_be32(EI_MAGIC))
return 0;
- if(i->ei_class != ELFCLASS32 && i->ei_class != ELFCLASS64)
- return 0;
+ if (i->ei_class != ELFCLASS32 && i->ei_class != ELFCLASS64)
+ return 0;
/* more sanity checks? */
return __prepare_proc(t, i->ei_class, b);