Skip to content

Commit 46ce47a

Browse files
committed
Use the entry point address from the ELF header instead of looking up _start.
I love these kind of dumb gotcha moments. Turns out you can find the entry address right there in the header. :^)
1 parent ab72666 commit 46ce47a

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

Kernel/ELFImage.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ class ELFImage {
155155
bool is_executable() const { return header().e_type == ET_EXEC; }
156156
bool is_relocatable() const { return header().e_type == ET_REL; }
157157

158+
LinearAddress entry() const { return LinearAddress(header().e_entry); }
159+
158160
private:
159161
bool parseHeader();
160162
const char* raw_data(unsigned offset) const;

Kernel/ELFLoader.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class ELFLoader {
1717
char* symbol_ptr(const char* name);
1818
bool allocate_section(LinearAddress, size_t, size_t alignment, bool is_readable, bool is_writable);
1919
bool map_section(LinearAddress, size_t, size_t alignment, size_t offset_in_image, bool is_readable, bool is_writable);
20+
LinearAddress entry() const { return m_image.entry(); }
2021

2122
private:
2223
bool layout();

Kernel/Process.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ int Process::do_exec(const String& path, Vector<String>&& arguments, Vector<Stri
344344
return -ENOEXEC;
345345
}
346346

347-
entry_eip = (dword)loader.symbol_ptr("_start");
347+
entry_eip = loader.entry().get();
348348
if (!entry_eip) {
349349
m_page_directory = old_page_directory;
350350
MM.enter_process_paging_scope(*this);
@@ -606,7 +606,7 @@ Process::Process(String&& name, uid_t uid, gid_t gid, pid_t ppid, RingLevel ring
606606
if (!fork_parent->m_fds[i].descriptor)
607607
continue;
608608
#ifdef FORK_DEBUG
609-
dbgprintf("fork: cloning fd %u... (%p) istty? %u\n", i, fork_parent->m_fds[i].ptr(), fork_parent->m_fds[i]->isTTY());
609+
dbgprintf("fork: cloning fd %u... (%p) istty? %u\n", i, fork_parent->m_fds[i].descriptor.ptr(), fork_parent->m_fds[i].descriptor->is_tty());
610610
#endif
611611
m_fds[i].descriptor = fork_parent->m_fds[i].descriptor->clone();
612612
m_fds[i].flags = fork_parent->m_fds[i].flags;

0 commit comments

Comments
 (0)