mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 18:07:34 +00:00
Kernel: Add ability to load interpreter instead of main program
When the main executable needs an interpreter, we load the requested interpreter program, and pass to it an open file decsriptor to the main executable via the auxiliary vector. Note that we do not allocate a TLS region for the interpreter.
This commit is contained in:
parent
711c42e25e
commit
5b87904ab5
6 changed files with 219 additions and 151 deletions
|
@ -46,7 +46,7 @@ typedef struct
|
|||
#define AT_PAGESZ 6 /* a_val gives system page size in bytes */
|
||||
#define AT_BASE 7 /* a_ptr holds base address that Loader was loaded into memory */
|
||||
#define AT_FLAGS 8 /* a_val holds 1 bit flags. Undefined flags are 0 */
|
||||
#define AT_ENTRY 9 /* a_ptr holds entry point of application for loader */
|
||||
#define AT_ENTRY 9 /* a_ptr holds entry point of the main program */
|
||||
#define AT_NOTELF 10 /* a_val non-zero if the program is not ELF */
|
||||
#define AT_UID 11 /* a_val holds real user id of process */
|
||||
#define AT_EUID 12 /* a_val holds effective user id of process */
|
||||
|
@ -60,6 +60,8 @@ typedef struct
|
|||
#define AT_RANDOM 25 /* a_ptr points to 16 securely generated random bytes */
|
||||
#define AT_HWCAP2 26 /* a_val holds extended hw feature mask. Currently 0 */
|
||||
#define AT_EXECFN 31 /* a_ptr points to file name of executed program */
|
||||
#define AT_EXE_BASE 32 /* a_ptr holds base address where main program was loaded into memory */
|
||||
#define AT_EXE_SIZE 33 /* a_val holds the size of the main program in memory */
|
||||
|
||||
#ifdef __cplusplus
|
||||
# include <AK/String.h>
|
||||
|
@ -89,7 +91,9 @@ struct AuxiliaryValue {
|
|||
BasePlatform = AT_BASE_PLATFORM,
|
||||
Random = AT_RANDOM,
|
||||
HwCap2 = AT_HWCAP2,
|
||||
ExecFilename = AT_EXECFN
|
||||
ExecFilename = AT_EXECFN,
|
||||
ExeBaseAddress = AT_EXE_BASE,
|
||||
ExeSize = AT_EXE_SIZE
|
||||
};
|
||||
|
||||
AuxiliaryValue(Type type, long val)
|
||||
|
|
|
@ -40,8 +40,9 @@
|
|||
|
||||
namespace ELF {
|
||||
|
||||
Loader::Loader(const u8* buffer, size_t size, bool verbose_logging)
|
||||
Loader::Loader(const u8* buffer, size_t size, String&& name, bool verbose_logging)
|
||||
: m_image(buffer, size, verbose_logging)
|
||||
, m_name(move(name))
|
||||
{
|
||||
if (m_image.is_valid())
|
||||
m_symbol_count = m_image.symbol_count();
|
||||
|
@ -101,7 +102,7 @@ bool Loader::layout()
|
|||
program_header.alignment(),
|
||||
program_header.is_readable(),
|
||||
program_header.is_writable(),
|
||||
String::format("elf-alloc-%s%s", program_header.is_readable() ? "r" : "", program_header.is_writable() ? "w" : ""));
|
||||
String::format("%s-alloc-%s%s", m_name.is_empty() ? "elf" : m_name.characters(), program_header.is_readable() ? "r" : "", program_header.is_writable() ? "w" : ""));
|
||||
if (!allocated_section) {
|
||||
failed = true;
|
||||
return;
|
||||
|
@ -133,7 +134,7 @@ bool Loader::layout()
|
|||
program_header.is_readable(),
|
||||
program_header.is_writable(),
|
||||
program_header.is_executable(),
|
||||
String::format("elf-map-%s%s%s", program_header.is_readable() ? "r" : "", program_header.is_writable() ? "w" : "", program_header.is_executable() ? "x" : ""));
|
||||
String::format("%s-map-%s%s%s", m_name.is_empty() ? "elf" : m_name.characters(), program_header.is_readable() ? "r" : "", program_header.is_writable() ? "w" : "", program_header.is_executable() ? "x" : ""));
|
||||
if (!mapped_section) {
|
||||
failed = true;
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ namespace ELF {
|
|||
|
||||
class Loader : public RefCounted<Loader> {
|
||||
public:
|
||||
static NonnullRefPtr<Loader> create(const u8* data, size_t size, bool verbose_logging = true) { return adopt(*new Loader(data, size, verbose_logging)); }
|
||||
static NonnullRefPtr<Loader> create(const u8* data, size_t size, String&& name = String::empty(), bool verbose_logging = true) { return adopt(*new Loader(data, size, move(name), verbose_logging)); }
|
||||
~Loader();
|
||||
|
||||
bool load();
|
||||
|
@ -67,11 +67,12 @@ public:
|
|||
Optional<Image::Symbol> find_symbol(u32 address, u32* offset = nullptr) const;
|
||||
|
||||
private:
|
||||
explicit Loader(const u8*, size_t, bool verbose_logging);
|
||||
explicit Loader(const u8*, size_t, String&& name, bool verbose_logging);
|
||||
|
||||
bool layout();
|
||||
|
||||
Image m_image;
|
||||
String m_name;
|
||||
|
||||
size_t m_symbol_count { 0 };
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue