NeKernel dev
Loading...
Searching...
No Matches
UserProcessScheduler.inl
Go to the documentation of this file.
1/* ========================================
2
3 Copyright (C) 2024-2025, Amlal El Mahrouss, licensed under the Apache 2.0 license.
4
5 FILE: UserProcessScheduler.inl
6 PURPOSE: Low level/Ring-3 process scheduler.
7
8======================================== */
9
13
14#ifndef INC_PROCESS_SCHEDULER_H
16#endif // INC_PROCESS_SCHEDULER_H
17
18namespace Kernel {
19/***********************************************************************************/
21/***********************************************************************************/
22
23template <typename T>
24BOOL USER_PROCESS::Delete(ErrorOr<T*> ptr) {
25 if (!ptr) return No;
26
27 if (!this->HeapTree) {
28 kout << "USER_PROCESS: Heap is empty.\r";
29 return No;
30 }
31
32 PROCESS_HEAP_TREE<VoidPtr>* entry = this->HeapTree;
33
34 while (entry != nullptr) {
35 if (entry->Entry == ptr.Leak().Leak()) {
36 this->UsedMemory -= entry->EntrySize;
37
38#ifdef __NE_AMD64__
39 auto page_dir = hal_read_cr3();
40
41 hal_write_cr3(this->VMRegister);
42 auto ret = mm_free_ptr(entry->Entry);
43 hal_write_cr3(page_dir);
44#else
45 auto ret = mm_free_ptr(ptr.Leak().Leak());
46#endif
47
48 return ret == kErrorSuccess;
49 }
50
51 entry = entry->Next;
52 }
53
54 kout << "USER_PROCESS: Trying to free a pointer which doesn't exist.\r";
55
56 this->Crash();
57
58 return No;
59}
60} // namespace Kernel
#define kout
Definition DebugOutput.h:189
#define No
#define BOOL
User Process Scheduler header file.
ErrorOr class for error handling.
Definition ErrorOr.h:22
UPS inline definitions.
Definition Device.h:12
constexpr KPCError kErrorSuccess
Definition KPC.h:32
Int32 mm_free_ptr(VoidPtr heap_ptr)
Declare pointer as free.
Definition HeapMgr.cc:187
Definition CoreProcessScheduler.h:52