diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-09-01 09:23:10 +0200 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-09-01 09:23:10 +0200 |
| commit | e757bb6a90c98f53995e4828d68eba26a2327540 (patch) | |
| tree | feabdd3047b67f21ee0e6f76ccd89f8458493e77 /dev/ZKA | |
| parent | 21a0081ac9d9a8abe66cc6a248b5363768de1dc9 (diff) | |
[ IMP ] Found out the issue of ring 3 switch.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'dev/ZKA')
| -rw-r--r-- | dev/ZKA/HALKit/AMD64/HalInterruptAPI.asm | 9 | ||||
| -rw-r--r-- | dev/ZKA/HALKit/AMD64/HalMPContextSwitch.asm | 2 | ||||
| -rw-r--r-- | dev/ZKA/HALKit/AMD64/HalPageAlloc.cxx | 18 | ||||
| -rw-r--r-- | dev/ZKA/HALKit/AMD64/HalPageAlloc.hxx | 3 | ||||
| -rw-r--r-- | dev/ZKA/NetworkKit/IPC.hxx | 10 | ||||
| -rw-r--r-- | dev/ZKA/Sources/Heap.cxx | 9 | ||||
| -rw-r--r-- | dev/ZKA/Sources/Network/IPC.cxx | 6 | ||||
| -rw-r--r-- | dev/ZKA/Sources/PageManager.cxx | 3 |
8 files changed, 46 insertions, 14 deletions
diff --git a/dev/ZKA/HALKit/AMD64/HalInterruptAPI.asm b/dev/ZKA/HALKit/AMD64/HalInterruptAPI.asm index 847c609e..89cb4078 100644 --- a/dev/ZKA/HALKit/AMD64/HalInterruptAPI.asm +++ b/dev/ZKA/HALKit/AMD64/HalInterruptAPI.asm @@ -267,7 +267,7 @@ hal_switch_to_user_code: mov rbx, 0x28 mov es, rbx - mov rsp, [hal_user_code_stack_end] + mov rsp, hal_user_code_stack_end mov rcx, hal_user_code_start mov r11, 0x0202 @@ -275,9 +275,14 @@ hal_switch_to_user_code: o64 sysret hal_user_code_start: -L0: + hlt nop jmp $ +hal_user_code_end: + +section .data + +hal_user_code_sz: dq hal_user_code_end - hal_user_code_start section .bss diff --git a/dev/ZKA/HALKit/AMD64/HalMPContextSwitch.asm b/dev/ZKA/HALKit/AMD64/HalMPContextSwitch.asm index f20ffcee..f5f36b27 100644 --- a/dev/ZKA/HALKit/AMD64/HalMPContextSwitch.asm +++ b/dev/ZKA/HALKit/AMD64/HalMPContextSwitch.asm @@ -50,7 +50,7 @@ mp_do_context_switch: ;; Swap registers, since it's the other way around. mov rcx, r12 ;; code ptr - mov rsp, [r11] ;; stack ptr + mov rsp, r11 ;; stack ptr mov r11, 0x0202 ;; rcx and rdx already set. diff --git a/dev/ZKA/HALKit/AMD64/HalPageAlloc.cxx b/dev/ZKA/HALKit/AMD64/HalPageAlloc.cxx index 4e1b500c..82eea45e 100644 --- a/dev/ZKA/HALKit/AMD64/HalPageAlloc.cxx +++ b/dev/ZKA/HALKit/AMD64/HalPageAlloc.cxx @@ -135,5 +135,23 @@ namespace Kernel // Now allocate the page. return hal_try_alloc_new_page(rw, user, size); } + + auto hal_free_page(VoidPtr page_ptr) -> Bool + { + if (!page_ptr) + return false; + + Detail::VIRTUAL_MEMORY_HEADER* result = reinterpret_cast<Detail::VIRTUAL_MEMORY_HEADER*>((UIntPtr)page_ptr - sizeof(Detail::VIRTUAL_MEMORY_HEADER)); + + if (result->Magic != cVMHMagic) + return false; + + if (result->Present != true) + return true; + + result->Present = false; + + return true; + } } // namespace HAL } // namespace Kernel diff --git a/dev/ZKA/HALKit/AMD64/HalPageAlloc.hxx b/dev/ZKA/HALKit/AMD64/HalPageAlloc.hxx index 30cb7911..38666e7e 100644 --- a/dev/ZKA/HALKit/AMD64/HalPageAlloc.hxx +++ b/dev/ZKA/HALKit/AMD64/HalPageAlloc.hxx @@ -82,7 +82,8 @@ namespace Kernel::HAL PageTable64 ALIGN(kPTEAlign) Pte[kPTEMax]; }; - VoidPtr hal_alloc_page(Boolean rw, Boolean user, SizeT size); + auto hal_alloc_page(Boolean rw, Boolean user, SizeT size) -> VoidPtr; + auto hal_free_page(VoidPtr page_ptr) -> Bool; } // namespace Kernel::HAL namespace Kernel diff --git a/dev/ZKA/NetworkKit/IPC.hxx b/dev/ZKA/NetworkKit/IPC.hxx index 069a2c66..d71248cf 100644 --- a/dev/ZKA/NetworkKit/IPC.hxx +++ b/dev/ZKA/NetworkKit/IPC.hxx @@ -19,12 +19,12 @@ /// @brief IPC EP protocol. /// IA separator. -#define cIPCEPRemoteSeparator ":" +#define cXPCOMRemoteSeparator ":" /// Interchange address, consists of PID:TEAM. -#define cIPCEPRemoteInvalid "00:00" +#define cXPCOMRemoteInvalid "00:00" -#define cIPCEPHeaderMagic (0x4950434) +#define cXPCOMHeaderMagic (0x4950434) namespace Kernel { @@ -61,7 +61,7 @@ namespace Kernel eIPCEPMixedEndian = 2, }; - constexpr auto cIPCEPMsgSize = 6094U; + constexpr auto cXPCOMMsgSize = 6094U; /// @brief IPC connection header, message cannot be greater than 6K. typedef struct IPC_MESSAGE_STRUCT final @@ -74,7 +74,7 @@ namespace Kernel UInt32 IpcCRC32; UInt32 IpcMsg; UInt32 IpcMsgSz; - UInt8 IpcData[cIPCEPMsgSize]; + UInt8 IpcData[cXPCOMMsgSize]; } PACKED IPC_MESSAGE_STRUCT; /// @brief Sanitize packet function diff --git a/dev/ZKA/Sources/Heap.cxx b/dev/ZKA/Sources/Heap.cxx index a89ed584..0146bd55 100644 --- a/dev/ZKA/Sources/Heap.cxx +++ b/dev/ZKA/Sources/Heap.cxx @@ -34,6 +34,8 @@ namespace Kernel UInt32 fMagic; ///! @brief Boolean value which tells if the heap is allocated. Boolean fPresent; + /// @brief Is this valued owned by the user? + Boolean fUserOwned; ///! @brief 32-bit CRC checksum. UInt32 fCRC32; /// @brief 64-bit pointer size. @@ -108,6 +110,8 @@ namespace Kernel heap_info_ptr->fCRC32 = 0U; // dont fill it for now. heap_info_ptr->fTargetPtr = wrapper.VirtualAddress() + sizeof(Detail::HEAP_INFORMATION_BLOCK); heap_info_ptr->fPagePtr = 0UL; + heap_info_ptr->fUserOwned = user; + heap_info_ptr->fPresent = true; ++kHeapCount; @@ -176,7 +180,10 @@ namespace Kernel ke_calculate_crc32((Char*)heapInfoBlk->fTargetPtr, heapInfoBlk->fTargetPtrSize)) { - ke_stop(RUNTIME_CHECK_POINTER); + if (!heapInfoBlk->fUserOwned) + { + ke_stop(RUNTIME_CHECK_POINTER); + } } } diff --git a/dev/ZKA/Sources/Network/IPC.cxx b/dev/ZKA/Sources/Network/IPC.cxx index e5926c7f..e60742ca 100644 --- a/dev/ZKA/Sources/Network/IPC.cxx +++ b/dev/ZKA/Sources/Network/IPC.cxx @@ -41,12 +41,12 @@ Bool ipc_int_sanitize_packet(IPC_MESSAGE_STRUCT* pckt) } if (pckt->IpcFrom == pckt->IpcTo || - pckt->IpcPacketSize > cIPCEPMsgSize) + pckt->IpcPacketSize > cXPCOMMsgSize) { goto ipc_check_failed; } - return pckt->IpcPacketSize > 1 && pckt->IpcHeaderMagic == cIPCEPHeaderMagic; + return pckt->IpcPacketSize > 1 && pckt->IpcHeaderMagic == cXPCOMHeaderMagic; ipc_check_failed: ErrLocal() = kErrorIPC; @@ -92,7 +92,7 @@ namespace Kernel if (*pckt_in) { - (*pckt_in)->IpcHeaderMagic = cIPCEPHeaderMagic; + (*pckt_in)->IpcHeaderMagic = cXPCOMHeaderMagic; auto endian = DEDUCE_ENDIAN((*pckt_in), ((Char*)(*pckt_in))[0]); diff --git a/dev/ZKA/Sources/PageManager.cxx b/dev/ZKA/Sources/PageManager.cxx index 549415f3..d14130ff 100644 --- a/dev/ZKA/Sources/PageManager.cxx +++ b/dev/ZKA/Sources/PageManager.cxx @@ -82,8 +82,9 @@ namespace Kernel { if (wrapper) { - if (!Detail::page_disable(wrapper->VirtualAddress())) + if (!Kernel::HAL::hal_free_page((VoidPtr)wrapper->VirtualAddress())) return false; + return true; } |
