mirror of
https://github.com/justinian/jsix.git
synced 2025-12-10 00:14:32 -08:00
Change initrd 'executable' bool to type enum.
This commit is contained in:
@@ -11,6 +11,7 @@
|
|||||||
[[files]]
|
[[files]]
|
||||||
dest = "vdso.so"
|
dest = "vdso.so"
|
||||||
source = "host/libvdso.so"
|
source = "host/libvdso.so"
|
||||||
|
type = "vdso"
|
||||||
|
|
||||||
[[files]]
|
[[files]]
|
||||||
dest = "screenfont.psf"
|
dest = "screenfont.psf"
|
||||||
@@ -19,9 +20,9 @@ source = "../assets/fonts/tamsyn8x16r.psf"
|
|||||||
[[files]]
|
[[files]]
|
||||||
dest = "nulldrv1"
|
dest = "nulldrv1"
|
||||||
source = "user/nulldrv"
|
source = "user/nulldrv"
|
||||||
executable = true
|
type = "executable"
|
||||||
|
|
||||||
[[files]]
|
[[files]]
|
||||||
dest = "nulldrv2"
|
dest = "nulldrv2"
|
||||||
source = "user/nulldrv"
|
source = "user/nulldrv"
|
||||||
executable = true
|
type = "executable"
|
||||||
|
|||||||
@@ -108,7 +108,11 @@ kernel_main(kernel_args *header)
|
|||||||
initrd::disk ird(header->initrd, heap);
|
initrd::disk ird(header->initrd, heap);
|
||||||
log::info(logs::boot, "initrd loaded with %d files.", ird.files().count());
|
log::info(logs::boot, "initrd loaded with %d files.", ird.files().count());
|
||||||
for (auto &f : ird.files())
|
for (auto &f : ird.files())
|
||||||
log::info(logs::boot, " %s%s (%d bytes).", f.executable() ? "*" : "", f.name(), f.size());
|
log::info(logs::boot, " %s%s (%d bytes).",
|
||||||
|
f.type() == initrd::file_type::executable ? "*" :
|
||||||
|
f.type() == initrd::file_type::vdso ? "^" : "",
|
||||||
|
f.name(),
|
||||||
|
f.size());
|
||||||
|
|
||||||
/*
|
/*
|
||||||
page_manager::get()->dump_pml4(nullptr, 0);
|
page_manager::get()->dump_pml4(nullptr, 0);
|
||||||
@@ -163,7 +167,7 @@ kernel_main(kernel_args *header)
|
|||||||
sched->create_kernel_task(-1, logger_task);
|
sched->create_kernel_task(-1, logger_task);
|
||||||
|
|
||||||
for (auto &f : ird.files()) {
|
for (auto &f : ird.files()) {
|
||||||
if (f.executable())
|
if (f.type() == initrd::file_type::executable)
|
||||||
sched->load_process(f.name(), f.data(), f.size());
|
sched->load_process(f.name(), f.data(), f.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
13
src/libraries/initrd/include/initrd/file_type.h
Normal file
13
src/libraries/initrd/include/initrd/file_type.h
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
namespace initrd {
|
||||||
|
|
||||||
|
enum class file_type : uint8_t
|
||||||
|
{
|
||||||
|
unknown,
|
||||||
|
executable,
|
||||||
|
vdso
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace initrd
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "kutil/enum_bitfields.h"
|
#include "kutil/enum_bitfields.h"
|
||||||
|
#include "initrd/file_type.h"
|
||||||
|
|
||||||
namespace initrd {
|
namespace initrd {
|
||||||
|
|
||||||
@@ -18,10 +19,8 @@ struct disk_header
|
|||||||
uint8_t reserved[3];
|
uint8_t reserved[3];
|
||||||
} __attribute__ ((packed));
|
} __attribute__ ((packed));
|
||||||
|
|
||||||
|
enum class file_flags : uint8_t
|
||||||
enum class file_flags : uint16_t
|
|
||||||
{
|
{
|
||||||
executable = 0x01
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct file_header
|
struct file_header
|
||||||
@@ -29,10 +28,10 @@ struct file_header
|
|||||||
uint32_t offset;
|
uint32_t offset;
|
||||||
uint32_t length;
|
uint32_t length;
|
||||||
uint16_t name_offset;
|
uint16_t name_offset;
|
||||||
|
file_type type;
|
||||||
file_flags flags;
|
file_flags flags;
|
||||||
} __attribute__ ((packed));
|
} __attribute__ ((packed));
|
||||||
|
|
||||||
} // namepsace initrd
|
} // namepsace initrd
|
||||||
|
|
||||||
IS_BITFIELD(initrd::disk_flags);
|
IS_BITFIELD(initrd::disk_flags);
|
||||||
IS_BITFIELD(initrd::file_flags);
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "kutil/vector.h"
|
#include "kutil/vector.h"
|
||||||
|
#include "initrd/file_type.h"
|
||||||
|
|
||||||
// File format:
|
// File format:
|
||||||
// 1x disk_header
|
// 1x disk_header
|
||||||
@@ -33,8 +34,8 @@ public:
|
|||||||
/// Get a pointer to the file data
|
/// Get a pointer to the file data
|
||||||
const void * data() const;
|
const void * data() const;
|
||||||
|
|
||||||
/// Whether this file is an executable
|
/// Type of file
|
||||||
bool executable() const;
|
file_type type() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const file_header *m_header;
|
const file_header *m_header;
|
||||||
|
|||||||
@@ -16,11 +16,7 @@ file::file(const file_header *header, const void *start) :
|
|||||||
const char * file::name() const { return m_name; }
|
const char * file::name() const { return m_name; }
|
||||||
const size_t file::size() const { return m_header->length; }
|
const size_t file::size() const { return m_header->length; }
|
||||||
const void * file::data() const { return m_data; }
|
const void * file::data() const { return m_data; }
|
||||||
|
file_type file::type() const { return m_header->type; }
|
||||||
bool
|
|
||||||
file::executable() const {
|
|
||||||
return bitfield_has(m_header->flags, file_flags::executable);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
disk::disk(const void *start, kutil::allocator &alloc) :
|
disk::disk(const void *start, kutil::allocator &alloc) :
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
#include "entry.h"
|
#include "entry.h"
|
||||||
|
|
||||||
entry::entry(const std::string &in, const std::string &out, bool executable) :
|
entry::entry(const std::string &in, const std::string &out, initrd::file_type type) :
|
||||||
m_in(in),
|
m_in(in),
|
||||||
m_out(out),
|
m_out(out),
|
||||||
m_file(in, std::ios_base::binary),
|
m_file(in, std::ios_base::binary),
|
||||||
m_exec(executable)
|
m_type(type)
|
||||||
{
|
{
|
||||||
m_file.seekg(0, std::ios_base::end);
|
m_file.seekg(0, std::ios_base::end);
|
||||||
m_size = m_file.tellg();
|
m_size = m_file.tellg();
|
||||||
|
|||||||
@@ -1,17 +1,18 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include "initrd/headers.h"
|
||||||
|
|
||||||
class entry
|
class entry
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
entry(const std::string &in, const std::string &out, bool executable = false);
|
entry(const std::string &in, const std::string &out, initrd::file_type type);
|
||||||
|
|
||||||
inline const std::string & in() const { return m_in; }
|
inline const std::string & in() const { return m_in; }
|
||||||
inline const std::string & out() const { return m_out; }
|
inline const std::string & out() const { return m_out; }
|
||||||
inline const std::ifstream & file() const { return m_file; }
|
inline const std::ifstream & file() const { return m_file; }
|
||||||
|
|
||||||
inline bool executable() const { return m_exec; }
|
inline initrd::file_type type() const { return m_type; }
|
||||||
inline size_t size() const { return m_size; }
|
inline size_t size() const { return m_size; }
|
||||||
inline bool good() const { return m_file.good(); }
|
inline bool good() const { return m_file.good(); }
|
||||||
|
|
||||||
@@ -20,6 +21,6 @@ private:
|
|||||||
std::string m_out;
|
std::string m_out;
|
||||||
std::ifstream m_file;
|
std::ifstream m_file;
|
||||||
size_t m_size;
|
size_t m_size;
|
||||||
bool m_exec;
|
initrd::file_type m_type;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -43,9 +43,15 @@ int main(int argc, char **argv)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto exec = file->get_as<bool>("executable").value_or(false);
|
auto type_name = file->get_as<std::string>("type").value_or("unknown");
|
||||||
|
initrd::file_type type = initrd::file_type::unknown;
|
||||||
|
if (type_name == "executable") {
|
||||||
|
type = initrd::file_type::executable;
|
||||||
|
} else if (type_name == "vdso") {
|
||||||
|
type = initrd::file_type::vdso;
|
||||||
|
}
|
||||||
|
|
||||||
entries.emplace_back(*source, *dest, exec);
|
entries.emplace_back(*source, *dest, type);
|
||||||
const entry &e = entries.back();
|
const entry &e = entries.back();
|
||||||
|
|
||||||
if (!e.good()) {
|
if (!e.good()) {
|
||||||
@@ -92,9 +98,7 @@ int main(int argc, char **argv)
|
|||||||
fheader.offset = file_offset;
|
fheader.offset = file_offset;
|
||||||
fheader.length = e.size();
|
fheader.length = e.size();
|
||||||
fheader.name_offset = name_offset;
|
fheader.name_offset = name_offset;
|
||||||
|
fheader.type = e.type();
|
||||||
if (e.executable())
|
|
||||||
fheader.flags |= initrd::file_flags::executable;
|
|
||||||
|
|
||||||
out.write(
|
out.write(
|
||||||
reinterpret_cast<const char *>(&fheader),
|
reinterpret_cast<const char *>(&fheader),
|
||||||
|
|||||||
Reference in New Issue
Block a user