Skip to content

Commit

Permalink
Merge pull request #1354 from fwsGonzo/dev
Browse files Browse the repository at this point in the history
Temporary fix to chainloader
  • Loading branch information
fwsGonzo authored May 20, 2017
2 parents cdf2c69 + 003c8ad commit 4b57229
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 29 deletions.
2 changes: 1 addition & 1 deletion mod/rapidjson
37 changes: 9 additions & 28 deletions src/chainload/service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@
#include <os>
#include <cstdint>
#include <util/elf_binary.hpp>
#include <util/sha1.hpp>

bool verb = true;

#define MYINFO(X,...) INFO("chainload", X, ##__VA_ARGS__)

extern "C" void hotswap(const char* base, int len, char* dest, void* start,
Expand All @@ -30,50 +28,38 @@ extern "C" void hotswap(const char* base, int len, char* dest, void* start,
extern uintptr_t __multiboot_magic;
extern uintptr_t __multiboot_addr;

constexpr int bits() { return sizeof(void*) * 8; }

/** Modify multiboot data to show first module as the kernel */
void promote_mod_to_kernel(){
static void steal_commandline_from_module()
{
auto* bootinfo = (multiboot_info_t*) __multiboot_addr;

Expects (bootinfo->mods_count);
auto* mod = (multiboot_module_t*)bootinfo->mods_addr;
auto* mod = (multiboot_module_t*) bootinfo->mods_addr;

// Set command line param to mod param
bootinfo->cmdline = mod->cmdline;

// Subtract one module
(bootinfo->mods_count)--;

if (bootinfo->mods_count)
bootinfo->mods_addr = (uintptr_t)((multiboot_module_t*)bootinfo->mods_addr + 1);

}

void Service::start(const std::string&)
{
auto mods = OS::modules();

MYINFO("%i-bit chainloader found %i modules", bits(), mods.size());
MYINFO("%u-bit chainloader found %u modules",
sizeof(void*) * 8, mods.size());

if (mods.size() <= 0) {
MYINFO("Nothing to do. Exiting.");
exit(1);
}
multiboot_module_t binary = mods[0];

//MYINFO("Verifying ELF binary");

Elf_binary<Elf64> elf ({(char*)binary.mod_start,
Elf_binary<Elf64> elf (
{(char*)binary.mod_start,
(int)(binary.mod_end - binary.mod_start)});

void* hotswap_addr = (void*)0x200000;

extern char __hotswap_end;

debug("Moving hotswap function (begin at %p end at %p) of size %i",
&hotswap, &__hotswap_end, &__hotswap_end - (char*)&hotswap);

memcpy(hotswap_addr,(void*)&hotswap, &__hotswap_end - (char*)&hotswap );

extern uintptr_t __multiboot_magic;
Expand All @@ -83,22 +69,17 @@ void Service::start(const std::string&)

char* base = (char*)binary.mod_start;
int len = (int)(binary.mod_end - binary.mod_start);
// FIXME: determine kernel base from ELF program header
char* dest = (char*)0xA00000;
void* start = (void*)elf.entry();

SHA1 sha;
sha.update(base, len);
debug("Sha1 of ELF binary module: %s", sha.as_hex().c_str());


MYINFO("Hotswapping with params: base: %p, len: %i, dest: %p, start: %p",
base, len, dest, start);

promote_mod_to_kernel();
steal_commandline_from_module();

asm("cli");
((decltype(&hotswap))hotswap_addr)(base, len, dest, start, __multiboot_magic, __multiboot_addr);

panic("Should have jumped\n");

}
1 change: 1 addition & 0 deletions test/posix/integration/syslog_plugin/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def tear_down():
UDP_IP = "10.0.0.2"
UDP_PORT = 6514
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.bind((UDP_IP, UDP_PORT))

num_received = 0
Expand Down

0 comments on commit 4b57229

Please sign in to comment.