elf.c~

来自「The main purpose of this project is to a」· C~ 代码 · 共 52 行

C~
52
字号
/* * ELF executable loading * Copyright (c) 2003, Jeffrey K. Hollingsworth <hollings@cs.umd.edu> * Copyright (c) 2003, David H. Hovemeyer <daveho@cs.umd.edu> * $Revision: 1.29 $ *  * This is free software.  You are permitted to use, * redistribute, and modify it as specified in the file "COPYING". */#include <geekos/errno.h>#include <geekos/kassert.h>#include <geekos/ktypes.h>#include <geekos/screen.h>  /* for debug Print() statements */#include <geekos/pfat.h>#include <geekos/malloc.h>#include <geekos/string.h>#include <geekos/user.h>#include <geekos/elf.h>/** * From the data of an ELF executable, determine how its segments * need to be loaded into memory. * @param exeFileData buffer containing the executable file * @param exeFileLength length of the executable file in bytes * @param exeFormat structure describing the executable's segments *   and entry address; to be filled in * @return 0 if successful, < 0 on error */int Parse_ELF_Executable(char *exeFileData, ulong_t exeFileLength,    struct Exe_Format *exeFormat){    //TODO("Parse an ELF executable image");    int k;    elfHeader* head = (elfHeader*)exeFileData;    programHeader* proHeader = (programHeader*)(exeFileData + head->phoff);    for(k = 0; k < head->phnum; k++)    {    	exeFormat->segmentList[k].offsetInFile = proHeader->offset;    	exeFormat->segmentList[k].lengthInFile = proHeader->fileSize;    	exeFormat->segmentList[k].startAddress = proHeader->vaddr;    	exeFormat->segmentList[k].sizeInMemory = proHeader->memSize;    	exeFormat->segmentList[k].protFlags = proHeader->flags;    	proHeader++;    }    exeFormat->numSegments = head->phnum;    exeFormat->entryAddr = head->entry;    return 0;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?