blob: 63cdc795daf2942bf705407248d169c0e9f05a47 (
plain)
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
65
66
|
/* -------------------------------------------
Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
FILE: UserProcessScheduler.inl
PURPOSE: Low level/Ring-3 process scheduler.
------------------------------------------- */
/// @brief USER_PROCESS inline definitions.
/// @author Amlal El Mahrouss (amlal@nekernel.org)
/// @date Tue Apr 22 22:01:07 CEST 2025
namespace Kernel
{
/***********************************************************************************/
/** @brief Free pointer from usage. */
/***********************************************************************************/
template <typename T>
Boolean USER_PROCESS::Delete(ErrorOr<T*> ptr)
{
if (!ptr)
return No;
if (!this->HeapTree)
{
kout << "USER_PROCESS's heap is empty.\r";
return No;
}
USER_HEAP_TREE* entry = this->HeapTree;
while (entry != nullptr)
{
if (entry->MemoryEntry == ptr.Leak().Leak())
{
this->UsedMemory -= entry->MemoryEntrySize;
#ifdef __NE_AMD64__
auto pd = hal_read_cr3();
hal_write_cr3(this->VMRegister);
auto ret = mm_delete_heap(entry->MemoryEntry);
hal_write_cr3(pd);
return ret == kErrorSuccess;
#else
Bool ret = mm_delete_heap(ptr.Leak().Leak());
return ret == kErrorSuccess;
#endif
}
entry = entry->MemoryNext;
}
kout << "USER_PROCESS: Trying to free a pointer which doesn't exist.\r";
this->Crash();
return No;
}
} // namespace Kernel
|