Add a threading syscall API.
This commit is contained in:
parent
e2aad55a8a
commit
ef8eb5d993
14 changed files with 235 additions and 30 deletions
|
|
@ -136,6 +136,22 @@ 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.vmm().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) {
|
||||
|
|
@ -176,18 +192,13 @@ void EnsureResident(uint64_t addr, uint64_t size) {
|
|||
|
||||
void CopyIntoNonResidentProcess(uint64_t base, uint64_t size,
|
||||
Process& dest_proc, uint64_t dest_virt) {
|
||||
if (size > 0x1000) {
|
||||
panic("Unimplemented NR copy > 1 page");
|
||||
}
|
||||
if (dest_virt & 0xFFF) {
|
||||
panic("Unimplemented NR copy to non page aligned");
|
||||
}
|
||||
uint64_t phys = AllocatePageIfNecessary(dest_virt, dest_proc.vmm().cr3());
|
||||
uint8_t* src = reinterpret_cast<uint8_t*>(base);
|
||||
uint8_t* dest =
|
||||
reinterpret_cast<uint8_t*>(phys + boot::GetHigherHalfDirectMap());
|
||||
while (size > 0) {
|
||||
uint64_t to_copy = size > 0x1000 ? 0x1000 : size;
|
||||
|
||||
for (uint64_t i = 0; i < size; i++) {
|
||||
dest[i] = src[i];
|
||||
CopyPageIntoNonResidentProcess(base, to_copy, dest_proc, dest_virt);
|
||||
|
||||
size -= to_copy;
|
||||
base += 0x1000;
|
||||
dest_virt += 0x1000;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue