Get the second process elf from a MemoryObject instead of hardcoding.
Allows us to delete the CopyIntoNonResidentProcess function and simply rely on the MemoryObject copy functions.
This commit is contained in:
parent
eb454300e6
commit
e246f28d9c
|
@ -1,11 +1,12 @@
|
|||
#include <mammoth/debug.h>
|
||||
#include <mammoth/process.h>
|
||||
|
||||
constexpr uint64_t prog2 = 0x00000020'00000000;
|
||||
#include <zcall.h>
|
||||
|
||||
int main() {
|
||||
dbgln("Testing");
|
||||
check(SpawnProcessFromElfRegion(prog2));
|
||||
uint64_t vaddr;
|
||||
check(ZAddressSpaceMap(Z_INIT_AS_SELF, 0, Z_INIT_BOOT_VMMO, &vaddr));
|
||||
check(SpawnProcessFromElfRegion(vaddr));
|
||||
dbgln("Return");
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
#define ZC_PROC_SPAWN_THREAD 0x101
|
||||
|
||||
#define Z_INIT_PROC_SELF 0x1
|
||||
#define Z_INIT_AS_SELF 0x2
|
||||
|
||||
// Thread Calls.
|
||||
#define Z_THREAD_CREATE 0x10
|
||||
|
@ -27,8 +26,12 @@
|
|||
#define Z_ADDRESS_SPACE_MAP 0x21
|
||||
#define Z_ADDRESS_SPACE_UNMAP 0x22
|
||||
|
||||
#define Z_INIT_AS_SELF 0x20
|
||||
|
||||
#define Z_MEMORY_OBJECT_CREATE 0x30
|
||||
|
||||
#define Z_INIT_BOOT_VMMO 0x31
|
||||
|
||||
// Debugging Calls.
|
||||
#define Z_DEBUG_PRINT 0x10000000
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include "boot/boot_info.h"
|
||||
#include "debug/debug.h"
|
||||
#include "include/zcall.h"
|
||||
#include "lib/ref_ptr.h"
|
||||
#include "memory/paging_util.h"
|
||||
#include "object/process.h"
|
||||
|
@ -107,7 +108,6 @@ const limine_file& GetInitProgram(const char* path) {
|
|||
void LoadInitProgram() {
|
||||
DumpModules();
|
||||
const limine_file& init_prog = GetInitProgram("/sys/test");
|
||||
const limine_file& prog2 = GetInitProgram("/sys/test2");
|
||||
|
||||
RefPtr<Process> proc = Process::Create();
|
||||
gProcMan->InsertProcess(proc);
|
||||
|
@ -115,9 +115,11 @@ void LoadInitProgram() {
|
|||
uint64_t entry = LoadElfProgram(
|
||||
*proc, reinterpret_cast<uint64_t>(init_prog.address), init_prog.size);
|
||||
|
||||
CopyIntoNonResidentProcess(reinterpret_cast<uint64_t>(prog2.address),
|
||||
prog2.size, *proc,
|
||||
proc->vmas()->GetNextMemMapAddr(prog2.size));
|
||||
const limine_file& prog2 = GetInitProgram("/sys/test2");
|
||||
RefPtr<MemoryObject> prog2_vmmo = MakeRefCounted<MemoryObject>(prog2.size);
|
||||
prog2_vmmo->CopyBytesToObject(reinterpret_cast<uint64_t>(prog2.address),
|
||||
prog2.size);
|
||||
proc->AddCapability(Z_INIT_BOOT_VMMO, prog2_vmmo);
|
||||
|
||||
proc->CreateThread()->Start(entry, 0, 0);
|
||||
}
|
||||
|
|
|
@ -97,22 +97,6 @@ uint64_t CurrCr3() {
|
|||
return pml4_addr;
|
||||
}
|
||||
|
||||
void CopyPageIntoNonResidentProcess(uint64_t base, uint64_t size,
|
||||
Process& dest_proc, uint64_t dest_virt) {
|
||||
if (size > 0x1000) {
|
||||
panic("NR copy > 1 page");
|
||||
}
|
||||
if (dest_virt & 0xFFF) {
|
||||
panic("NR copy to non page aligned");
|
||||
}
|
||||
uint64_t phys = AllocatePageIfNecessary(dest_virt, dest_proc.vmas()->cr3());
|
||||
uint8_t* src = reinterpret_cast<uint8_t*>(base);
|
||||
uint8_t* dest =
|
||||
reinterpret_cast<uint8_t*>(phys + boot::GetHigherHalfDirectMap());
|
||||
for (uint64_t i = 0; i < size; i++) {
|
||||
dest[i] = src[i];
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void InitializePml4(uint64_t pml4_physical_addr) {
|
||||
|
@ -167,10 +151,8 @@ void MapPage(uint64_t cr3, uint64_t vaddr, uint64_t paddr) {
|
|||
}
|
||||
}
|
||||
|
||||
uint64_t AllocatePageIfNecessary(uint64_t addr, uint64_t cr3) {
|
||||
if (cr3 == 0) {
|
||||
cr3 = CurrCr3();
|
||||
}
|
||||
uint64_t AllocatePageIfNecessary(uint64_t addr) {
|
||||
uint64_t cr3 = CurrCr3();
|
||||
uint64_t phys = PagePhysIfResident(cr3, addr);
|
||||
if (phys) {
|
||||
return phys;
|
||||
|
@ -191,16 +173,3 @@ void EnsureResident(uint64_t addr, uint64_t size) {
|
|||
addr += 0x1000;
|
||||
}
|
||||
}
|
||||
|
||||
void CopyIntoNonResidentProcess(uint64_t base, uint64_t size,
|
||||
Process& dest_proc, uint64_t dest_virt) {
|
||||
while (size > 0) {
|
||||
uint64_t to_copy = size > 0x1000 ? 0x1000 : size;
|
||||
|
||||
CopyPageIntoNonResidentProcess(base, to_copy, dest_proc, dest_virt);
|
||||
|
||||
size -= to_copy;
|
||||
base += 0x1000;
|
||||
dest_virt += 0x1000;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,8 +8,5 @@ void InitializePml4(uint64_t pml4_physical_addr);
|
|||
|
||||
void MapPage(uint64_t cr3, uint64_t vaddr, uint64_t paddr);
|
||||
|
||||
uint64_t AllocatePageIfNecessary(uint64_t addr, uint64_t cr3 = 0);
|
||||
uint64_t AllocatePageIfNecessary(uint64_t addr);
|
||||
void EnsureResident(uint64_t addr, uint64_t size);
|
||||
|
||||
void CopyIntoNonResidentProcess(uint64_t base, uint64_t size,
|
||||
Process& dest_proc, uint64_t dest_virt);
|
||||
|
|
|
@ -99,3 +99,8 @@ uint64_t Process::AddCapability(const RefPtr<MemoryObject>& mo) {
|
|||
new Capability(mo, Capability::MEMORY_OBJECT, cap_id, ZC_WRITE));
|
||||
return cap_id;
|
||||
}
|
||||
|
||||
void Process::AddCapability(uint64_t cap_id, const RefPtr<MemoryObject>& mo) {
|
||||
caps_.PushBack(
|
||||
new Capability(mo, Capability::MEMORY_OBJECT, cap_id, ZC_WRITE));
|
||||
}
|
||||
|
|
|
@ -33,6 +33,8 @@ class Process : public KernelObject {
|
|||
uint64_t AddCapability(const RefPtr<Process>& p);
|
||||
uint64_t AddCapability(const RefPtr<AddressSpace>& as);
|
||||
uint64_t AddCapability(const RefPtr<MemoryObject>& mo);
|
||||
|
||||
void AddCapability(uint64_t cap_id, const RefPtr<MemoryObject>& mo);
|
||||
// Checks the state of all child threads and transitions to
|
||||
// finished if all have finished.
|
||||
void CheckState();
|
||||
|
|
Loading…
Reference in New Issue