/
process.hpp
64 lines (51 loc) · 1.51 KB
/
process.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// PhoeniX OS Process subsystem
// Copyright © 2017 Yury Popov a.k.a. PhoeniX
#pragma once
#include "kernlib.hpp"
#include "thread.hpp"
#include "pagetable.hpp"
#include "list.hpp"
struct ProcessSymbol {
uintptr_t ptr;
char* name;
};
enum SectionType: uint8_t {
SectionTypeCode,
SectionTypeData,
SectionTypeROData,
SectionTypeBSS,
SectionTypeStack
};
class Process {
private:
uint64_t id;
List<Thread*> threads;
List<ProcessSymbol> symbols;
uintptr_t entry;
Pagetable::Entry* addPage(uintptr_t vaddr, void* paddr, uint8_t flags);
uintptr_t _aslrCode, _aslrStack, _syscallPage;
size_t _syscallNum;
void *iomap[2];
char *name;
public:
Process();
~Process();
void startup();
void exit(int code);
void addThread(Thread *thread, bool suspended);
uint64_t getId() { 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 linkLibrary(const char* funcname);
void allowIOPorts(uint16_t min, uint16_t max);
void writeData(uintptr_t address, const void* src, size_t size);
void readData(void* dst, uintptr_t address, size_t size) const;
char* readString(uintptr_t address) const;
const char *getName() const;
void setName(const char *name);
void* getPhysicalAddress(uintptr_t ptr) const PURE;
static void print_stacktrace(uintptr_t base = 0, const Process *process = nullptr);
};