将common文件夹下的c文件移动到lib文件夹下

This commit is contained in:
fslongjin
2022-09-28 21:45:38 +08:00
parent be9ac3d58b
commit 1872d9bd4a
18 changed files with 34 additions and 50 deletions

View File

@ -0,0 +1,8 @@
all: elf.o
CFLAGS += -I .
elf.o: elf.c
gcc $(CFLAGS) -c elf.c -o elf.o

33
kernel/lib/libELF/elf.c Normal file
View File

@ -0,0 +1,33 @@
#include "elf.h"
#include <common/unistd.h>
#include <common/glib.h>
/**
* @brief 校验是否为ELF文件
*
* @param ehdr
*/
bool elf_check(void *ehdr)
{
Elf32_Ehdr *ptr = (Elf32_Ehdr *)ehdr;
bool flag = ptr->e_ident[EI_MAG0] == ELFMAG0 && ptr->e_ident[EI_MAG1] == ELFMAG1 && ptr->e_ident[EI_MAG2] == ELFMAG2 && ptr->e_ident[EI_MAG3] == ELFMAG3;
// 标头已经不符合要求
if (!flag)
return false;
// 检验EI_CLASS是否合法
if (ptr->e_ident[EI_CLASS] == 0 || ptr->e_ident[EI_CLASS] > 2)
return false;
// 检验EI_DATA是否合法
if (ptr->e_ident[EI_DATA] == 0 || ptr->e_ident[EI_DATA] > 2)
return false;
// 检验EI_VERSION是否合法
if(ptr->e_ident[EI_VERSION]==EV_NONE)
return false;
// 是elf文件
return true;
}