ELFLoader: Make check_elf_image return how much memory the executable will use on success
This commit is contained in:
parent
4091799701
commit
9cddf9485d
@ -8,6 +8,6 @@ namespace ELFLoader
|
||||
ELFImage* load_elf_from_vfs(VFS::Node* node); // This function assumes check_elf_image has been called first.
|
||||
ELFImage* load_elf_from_filesystem(const char* filename);
|
||||
void release_elf_image(ELFImage* image);
|
||||
int check_elf_image(VFS::Node* node);
|
||||
int check_elf_image_from_filesystem(const char* filename);
|
||||
long check_elf_image(VFS::Node* node);
|
||||
long check_elf_image_from_filesystem(const char* filename);
|
||||
}
|
@ -43,7 +43,7 @@ ELFImage* ELFLoader::load_elf_from_filesystem(const char* filename)
|
||||
return result;
|
||||
}
|
||||
|
||||
int ELFLoader::check_elf_image_from_filesystem(const char* filename)
|
||||
long ELFLoader::check_elf_image_from_filesystem(const char* filename)
|
||||
{
|
||||
VFS::Node* node = VFS::resolve_path(filename);
|
||||
|
||||
@ -105,7 +105,7 @@ ELFImage* ELFLoader::load_elf_from_vfs(VFS::Node* node)
|
||||
return image;
|
||||
}
|
||||
|
||||
int ELFLoader::check_elf_image(VFS::Node* node)
|
||||
long ELFLoader::check_elf_image(VFS::Node* node)
|
||||
{
|
||||
Elf64_Ehdr elf_ehdr;
|
||||
if (VFS::read(node, 0, sizeof(elf_ehdr), (char*)&elf_ehdr) < 0)
|
||||
@ -145,6 +145,7 @@ int ELFLoader::check_elf_image(VFS::Node* node)
|
||||
}
|
||||
int i;
|
||||
int loadable_sections = 0;
|
||||
long memusage = 0;
|
||||
Elf64_Phdr phdr;
|
||||
for (VFS::read(node, elf_ehdr.e_phoff, sizeof(Elf64_Phdr), (char*)&phdr), i = 0; i < elf_ehdr.e_phnum;
|
||||
i++, VFS::read(node, elf_ehdr.e_phoff + (i * elf_ehdr.e_phentsize), sizeof(Elf64_Phdr), (char*)&phdr))
|
||||
@ -162,6 +163,7 @@ int ELFLoader::check_elf_image(VFS::Node* node)
|
||||
return -1;
|
||||
}
|
||||
loadable_sections++;
|
||||
memusage += Utilities::get_blocks_from_size(PAGE_SIZE, phdr.p_memsz) * PAGE_SIZE;
|
||||
}
|
||||
}
|
||||
if (!loadable_sections)
|
||||
@ -169,7 +171,7 @@ int ELFLoader::check_elf_image(VFS::Node* node)
|
||||
kwarnln("No loadable sections");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
return memusage;
|
||||
}
|
||||
|
||||
void ELFLoader::release_elf_image(ELFImage* image)
|
||||
|
Loading…
Reference in New Issue
Block a user