38 lines
855 B
C++
38 lines
855 B
C++
|
#include "binfmt/BinaryFormat.h"
|
||
|
#include "binfmt/ELF.h"
|
||
|
|
||
|
struct BinaryFormatDescriptor
|
||
|
{
|
||
|
binfmt_loader_creator_t creator;
|
||
|
void* arg;
|
||
|
};
|
||
|
|
||
|
Vector<BinaryFormatDescriptor> g_binary_formats;
|
||
|
|
||
|
Result<void> BinaryFormat::init()
|
||
|
{
|
||
|
TRY(register_binary_format(ELFLoader::create, nullptr));
|
||
|
|
||
|
return {};
|
||
|
}
|
||
|
|
||
|
Result<void> BinaryFormat::register_binary_format(binfmt_loader_creator_t creator, void* arg)
|
||
|
{
|
||
|
return g_binary_formats.try_append({ creator, arg });
|
||
|
}
|
||
|
|
||
|
Result<SharedPtr<BinaryFormatLoader>> BinaryFormat::create_loader(SharedPtr<VFS::Inode> inode)
|
||
|
{
|
||
|
for (const auto& format : g_binary_formats)
|
||
|
{
|
||
|
auto loader = TRY(format.creator(inode, format.arg));
|
||
|
if (TRY(loader->sniff())) return loader;
|
||
|
}
|
||
|
|
||
|
return err(ENOEXEC);
|
||
|
}
|
||
|
|
||
|
BinaryFormatLoader::BinaryFormatLoader(SharedPtr<VFS::Inode> inode) : m_inode(inode)
|
||
|
{
|
||
|
}
|