Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Refactor const methods
  • Loading branch information
djphoenix committed May 28, 2019
1 parent 1a76fb5 commit 6365427
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 30 deletions.
4 changes: 3 additions & 1 deletion src/kernlib/include/list.hpp
Expand Up @@ -10,6 +10,7 @@ class List {
Item *items = nullptr;
size_t count = 0;
size_t capacity = 0;

public:
~List() { Heap::free(items); }

Expand All @@ -26,7 +27,8 @@ class List {

void add(const Item &item) { insert() = item; }

size_t getCount() { return count; }
size_t getCount() const { return count; }

Item& operator[] (const size_t index) { return items[index]; }
const Item& operator[] (const size_t index) const { return items[index]; }
};
2 changes: 1 addition & 1 deletion src/process/include/modules.hpp
Expand Up @@ -16,7 +16,7 @@ class ModuleManager {
void parseInternal();
void parseInitRD();
void loadStream(Stream *stream);
bool parseModuleInfo(ModuleInfo *info, Process *process);
bool parseModuleInfo(ModuleInfo *info, const Process *process);
bool bindRequirement(const char *req, Process *process);
bool bindRequirements(const char *reqs, Process *process);
static void init();
Expand Down
4 changes: 2 additions & 2 deletions src/process/include/process.hpp
Expand Up @@ -40,14 +40,14 @@ class Process {
void exit(int code);
void addThread(Thread *thread, bool suspended);

uint64_t getId() { return id; }
uint64_t getId() const { return id; }

Pagetable::Entry *pagetable;
uintptr_t addSection(SectionType type, size_t size);
void addSymbol(const char *name, uintptr_t ptr);
void setEntryAddress(uintptr_t ptr);

uintptr_t getSymbolByName(const char* name) PURE;
uintptr_t getSymbolByName(const char* name) const PURE;
uintptr_t linkLibrary(const char* funcname);
void allowIOPorts(uint16_t min, uint16_t max);

Expand Down
5 changes: 2 additions & 3 deletions src/process/include/thread.hpp
Expand Up @@ -4,9 +4,7 @@
#pragma once
#include "kernlib.hpp"

class Thread {
public:
Thread();
struct Thread {
struct {
uint64_t rip, rflags;
uint64_t rsi, rdi, rbp, rsp;
Expand All @@ -16,4 +14,5 @@ class Thread {
} regs;
uint64_t suspend_ticks;
uint64_t stack_top;
Thread() : regs(), suspend_ticks(0), stack_top(0) {}
};
9 changes: 3 additions & 6 deletions src/process/modules.cpp
Expand Up @@ -9,11 +9,10 @@
volatile ModuleManager* ModuleManager::manager = nullptr;
Mutex ModuleManager::managerMutex;

bool ModuleManager::parseModuleInfo(ModuleInfo *info, Process *process) {
bool ModuleManager::parseModuleInfo(ModuleInfo *info, const Process *process) {
struct {
uintptr_t entry, name, version, desc, reqs, dev;
uintptr_t name, version, desc, reqs, dev;
} symbols = {
process->getSymbolByName("module"),
process->getSymbolByName("module_name"),
process->getSymbolByName("module_version"),
process->getSymbolByName("module_description"),
Expand All @@ -22,12 +21,10 @@ bool ModuleManager::parseModuleInfo(ModuleInfo *info, Process *process) {
};
ModuleInfo mod = { nullptr, nullptr, nullptr, nullptr, nullptr };

if ((symbols.entry == 0) || (symbols.name == 0) || (symbols.version == 0)
if ((symbols.name == 0) || (symbols.version == 0)
|| (symbols.desc == 0) || (symbols.reqs == 0) || (symbols.dev == 0))
return false;

process->setEntryAddress(symbols.entry);

mod.name = process->readString(symbols.name);
mod.version = process->readString(symbols.version);
mod.description = process->readString(symbols.desc);
Expand Down
2 changes: 1 addition & 1 deletion src/process/process.cpp
Expand Up @@ -137,7 +137,7 @@ void Process::addSymbol(const char *name, uintptr_t ptr) {
void Process::setEntryAddress(uintptr_t ptr) {
entry = ptr;
}
uintptr_t Process::getSymbolByName(const char* name) {
uintptr_t Process::getSymbolByName(const char* name) const {
for (size_t i = 0; i < symbols.getCount(); i++) {
if (klib::strcmp(symbols[i].name, name) == 0)
return symbols[i].ptr;
Expand Down
16 changes: 0 additions & 16 deletions src/process/thread.cpp

This file was deleted.

0 comments on commit 6365427

Please sign in to comment.