summaryrefslogtreecommitdiffhomepage
path: root/dev/Boot/src/New+Delete.cc
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-12-26 21:19:14 +0100
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-12-26 21:19:14 +0100
commit486425ed00acec134f8799bdde64bfd093c5fb55 (patch)
tree5104af49b56f39d0b14941d76f9d6d746cd1677b /dev/Boot/src/New+Delete.cc
parentc0f7f3f300d603d355fc7ec5be317afe1f0ee1b6 (diff)
IMPL: A lot of new changes, see details.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'dev/Boot/src/New+Delete.cc')
-rw-r--r--dev/Boot/src/New+Delete.cc60
1 files changed, 60 insertions, 0 deletions
diff --git a/dev/Boot/src/New+Delete.cc b/dev/Boot/src/New+Delete.cc
new file mode 100644
index 00000000..3abf0ef3
--- /dev/null
+++ b/dev/Boot/src/New+Delete.cc
@@ -0,0 +1,60 @@
+/* -------------------------------------------
+
+ Copyright (C) 2024, Theater Quality Inc, all rights reserved.
+
+------------------------------------------- */
+
+#include <BootKit/Platform.h>
+#include <BootKit/Protocol.h>
+#include <BootKit/BootKit.h>
+
+#ifdef __BOOTLDR_STANDALONE__
+EXTERN EfiBootServices* BS;
+
+/// @brief Allocates a new object.
+/// @param sz the size.
+/// @return
+void* operator new(size_t sz)
+{
+ void* buf = nullptr;
+
+ while (BS->AllocatePool(EfiMemoryType::EfiLoaderData, sz, &buf) == kBufferTooSmall)
+ BS->FreePool(buf);
+
+ return buf;
+}
+
+/// @brief Allocates a new object.
+/// @param sz the size.
+/// @return
+void* operator new[](size_t sz)
+{
+ void* buf = nullptr;
+ BS->AllocatePool(EfiMemoryType::EfiLoaderData, sz, &buf);
+
+ return buf;
+}
+
+/// @brief Deletes the object.
+/// @param buf the object.
+void operator delete(void* buf)
+{
+ BS->FreePool(buf);
+}
+
+/// @brief Deletes the object.
+/// @param buf the object.
+void operator delete[](void* buf)
+{
+ BS->FreePool(buf);
+}
+
+/// @brief Deletes the object (array specific).
+/// @param buf the object.
+/// @param size it's size.
+void operator delete(void* buf, size_t size)
+{
+ BS->FreePool(buf);
+}
+
+#endif // __BOOTLDR_STANDALONE__