git://scm.lunaixsky.com
/
lunaix-os.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Decoupling Architectural-specific Code (#35)
[lunaix-os.git]
/
lunaix-os
/
kernel
/
exe
/
elf32
/
elf32bfmt.c
diff --git
a/lunaix-os/kernel/exe/elf32/elf32bfmt.c
b/lunaix-os/kernel/exe/elf32/elf32bfmt.c
index 451c3946bd915dd23b5d0eaa631c092901f50a92..da94735fe99216fec9b2bbd9ac178b838d438ad5 100644
(file)
--- a/
lunaix-os/kernel/exe/elf32/elf32bfmt.c
+++ b/
lunaix-os/kernel/exe/elf32/elf32bfmt.c
@@
-1,4
+1,3
@@
-#include <lunaix/common.h>
#include <lunaix/exebi/elf32.h>
#include <lunaix/fs.h>
#include <lunaix/mm/valloc.h>
#include <lunaix/exebi/elf32.h>
#include <lunaix/fs.h>
#include <lunaix/mm/valloc.h>
@@
-13,6
+12,26
@@
elf32_read(struct v_file* elf, void* data, size_t off, size_t len)
return pcache_read(elf->inode, data, len, off);
}
return pcache_read(elf->inode, data, len, off);
}
+static int
+elf32_do_open(struct elf32* elf, struct v_file* elf_file)
+{
+ int status = 0;
+ elf->pheaders = NULL;
+ elf->elf_file = elf_file;
+
+ if ((status = elf32_read_ehdr(elf)) < 0) {
+ elf32_close(elf);
+ return status;
+ }
+
+ if ((status = elf32_read_phdr(elf)) < 0) {
+ elf32_close(elf);
+ return status;
+ }
+
+ return 0;
+}
+
int
elf32_open(struct elf32* elf, const char* path)
{
int
elf32_open(struct elf32* elf, const char* path)
{
@@
-28,27
+47,15
@@
elf32_open(struct elf32* elf, const char* path)
return error;
}
return error;
}
- return elf32_
openat
(elf, elffile);
+ return elf32_
do_open
(elf, elffile);
}
int
}
int
-elf32_openat(struct elf32* elf,
const
void* elf_vfile)
+elf32_openat(struct elf32* elf, void* elf_vfile)
{
{
- int status = 0;
- elf->pheaders = NULL;
- elf->elf_file = elf_vfile;
-
- if ((status = elf32_read_ehdr(elf)) < 0) {
- elf32_close(elf);
- return status;
- }
-
- if ((status = elf32_read_phdr(elf)) < 0) {
- elf32_close(elf);
- return status;
- }
-
- return 0;
+ // so the ref count kept in sync
+ vfs_ref_file(elf_vfile);
+ return elf32_do_open(elf, elf_vfile);
}
int
}
int
@@
-164,12
+171,19
@@
elf32_read_phdr(struct elf32* elf)
}
int
}
int
-elf32_check_exec(const struct elf32* elf)
+elf32_check_exec(const struct elf32* elf, int type)
+{
+ const struct elf32_ehdr* ehdr = &elf->eheader;
+
+ return (ehdr->e_entry) && ehdr->e_type == type;
+}
+
+int
+elf32_check_arch(const struct elf32* elf)
{
const struct elf32_ehdr* ehdr = &elf->eheader;
return *(u32_t*)(ehdr->e_ident) == ELFMAGIC &&
ehdr->e_ident[EI_CLASS] == ELFCLASS32 &&
{
const struct elf32_ehdr* ehdr = &elf->eheader;
return *(u32_t*)(ehdr->e_ident) == ELFMAGIC &&
ehdr->e_ident[EI_CLASS] == ELFCLASS32 &&
- ehdr->e_ident[EI_DATA] == ELFDATA2LSB && ehdr->e_
type == ET_EXEC &&
- ehdr->e_machine == EM_386;
-}
+ ehdr->e_ident[EI_DATA] == ELFDATA2LSB && ehdr->e_
machine == EM_386;
+}
\ No newline at end of file