OperatorNewDelete

This commit is contained in:
Charlotte Delenk 2021-10-20 18:41:29 +02:00
parent 9f3eae615a
commit 829ac223d8
Signed by: darkkirb
GPG key ID: 015E3768A70AFBC5
10 changed files with 117 additions and 6 deletions

15
.vscode/settings.json vendored
View file

@ -5,6 +5,19 @@
"string_view": "c", "string_view": "c",
"initializer_list": "c", "initializer_list": "c",
"utility": "c", "utility": "c",
"types.h": "c" "types.h": "c",
"*.tcc": "cpp",
"deque": "cpp",
"list": "cpp",
"string": "cpp",
"unordered_map": "cpp",
"unordered_set": "cpp",
"vector": "cpp",
"memory_resource": "cpp",
"memory": "cpp",
"future": "cpp",
"iosfwd": "cpp",
"sstream": "cpp",
"tuple": "cpp"
}, },
} }

View file

@ -45,7 +45,7 @@ OPTIMIZE_OUTPUT_JAVA = NO
OPTIMIZE_FOR_FORTRAN = NO OPTIMIZE_FOR_FORTRAN = NO
OPTIMIZE_OUTPUT_VHDL = NO OPTIMIZE_OUTPUT_VHDL = NO
OPTIMIZE_OUTPUT_SLICE = NO OPTIMIZE_OUTPUT_SLICE = NO
EXTENSION_MAPPING = EXTENSION_MAPPING = no_extension=C++
MARKDOWN_SUPPORT = YES MARKDOWN_SUPPORT = YES
TOC_INCLUDE_HEADINGS = 5 TOC_INCLUDE_HEADINGS = 5
AUTOLINK_SUPPORT = YES AUTOLINK_SUPPORT = YES
@ -119,7 +119,8 @@ WARN_LOGFILE =
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------
# Configuration options related to the input files # Configuration options related to the input files
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------
INPUT = donut include sdk INPUT = donut include sdk \
include/new
INPUT_ENCODING = UTF-8 INPUT_ENCODING = UTF-8
FILE_PATTERNS = *.c \ FILE_PATTERNS = *.c \
*.cpp \ *.cpp \

View file

@ -20,7 +20,8 @@
,,,,,,80197d50,80197ef4,,,,,,,,,,,,,,,,,,,donut/gfx/XFBManager.o ,,,,,,80197d50,80197ef4,,,,,,,,,,,,,,,,,,,donut/gfx/XFBManager.o
,,,,,,801bd2a4,801bd370,,,,,,,,,,,,,,,,,,,donut/mem/DataBlock.o ,,,,,,801bd2a4,801bd370,,,,,,,,,,,,,,,,,,,donut/mem/DataBlock.o
,,,,,,801bf1b4,801bf1f8,,,,,,,,,,,,,,,,,,,donut/mem/MemBlock.o ,,,,,,801bf1b4,801bf1f8,,,,,,,,,,,,,,,,,,,donut/mem/MemBlock.o
,,,,,,801bf250,801bf2bc,,,,,,,,,80545bf8,80545ed0,,,8055d2a0,8055d2a1,,,,,donut/mem/Memory.o ,,,,,,801bf250,801bf2bc,,,,,,,,,80545bf8,80545ed0,,,8055d2a0,8055d2a8,,,,,donut/mem/Memory.o
,,,,,,801bf618,801bf760,80406338,8040633c,,,,,,,,,,,8055d2a8,8055d2b0,,,,,donut/mem/OperatorNewDelete.o
,,,,,,80405a9c,80405b68,,,,,,,,,,,,,,,,,,,donut/util/Mutex.o ,,,,,,80405a9c,80405b68,,,,,,,,,,,,,,,,,,,donut/util/Mutex.o
80006684,80006728,,,,,,,8040652c,80406530,80406548,8040654c,,,,,,,,,,,,,,, 80006684,80006728,,,,,,,8040652c,80406530,80406548,8040654c,,,,,,,,,,,,,,,
80006728,80006728,800068cc,800068cc,800069e4,800069e4,80406244,80406244,80406530,80406530,8040654c,8040654c,80421030,80421030,804966fc,804966fc,8055640c,8055640c,8055c6d0,8055c6d0,8055df74,8055df74,805643b0,805643b0,805643fc,805643fc, 80006728,80006728,800068cc,800068cc,800069e4,800069e4,80406244,80406244,80406530,80406530,8040654c,8040654c,80421030,80421030,804966fc,804966fc,8055640c,8055640c,8055c6d0,8055c6d0,8055df74,8055df74,805643b0,805643b0,805643fc,805643fc,
1 .init start .init end extab start extab end extabindex start extabindex end .text start .text end .ctors start .ctors end .dtors start .dtors end .rodata start .rodata end .data start .data end .bss start .bss end .sdata start .sdata end .sbss start .sbss end .sdata2 start .sdata2 end .sbss2 start .sbss2 end File
20 80197d50 80197ef4 donut/gfx/XFBManager.o
21 801bd2a4 801bd370 donut/mem/DataBlock.o
22 801bf1b4 801bf1f8 donut/mem/MemBlock.o
23 801bf250 801bf2bc 80545bf8 80545ed0 8055d2a0 8055d2a1 8055d2a8 donut/mem/Memory.o
24 801bf618 801bf760 80406338 8040633c 8055d2a8 8055d2b0 donut/mem/OperatorNewDelete.o
25 80405a9c 80405b68 donut/util/Mutex.o
26 80006684 80006728 8040652c 80406530 80406548 8040654c
27 80006728 80006728 800068cc 800068cc 800069e4 800069e4 80406244 80406244 80406530 80406530 8040654c 8040654c 80421030 80421030 804966fc 804966fc 8055640c 8055640c 8055c6d0 8055c6d0 8055df74 8055df74 805643b0 805643b0 805643fc 805643fc

View file

@ -35,6 +35,7 @@ Address,SymbolName
8004b430,SCInit 8004b430,SCInit
80075730,size__Q23gfx19GXFifoMemoryManagerCFv 80075730,size__Q23gfx19GXFifoMemoryManagerCFv
800dc470,SetTMemLayout__Q34nw4r3g3d4tmemFQ44nw4r3g3d4tmem10TMemLayout 800dc470,SetTMemLayout__Q34nw4r3g3d4tmemFQ44nw4r3g3d4tmem10TMemLayout
800dd3e0,__ct__Q33hel6common34PointerWrapper<Q23mem10IAllocator>Fv
800f16b0,G3dInit__Q24nw4r3g3dFb 800f16b0,G3dInit__Q24nw4r3g3dFb
801007e0,startAddress__Q23mem8MemBlockCFv 801007e0,startAddress__Q23mem8MemBlockCFv
80175b68,__dt__Q33hel6common11NonCopyableFv 80175b68,__dt__Q33hel6common11NonCopyableFv
@ -54,7 +55,6 @@ Address,SymbolName
801bf520,__dt__Q23mem6MemoryFv 801bf520,__dt__Q23mem6MemoryFv
801bf5e8,mem1FixHeap__Q23mem6MemoryFv 801bf5e8,mem1FixHeap__Q23mem6MemoryFv
801bf5f8,mem2FixHeap__Q23mem6MemoryFv 801bf5f8,mem2FixHeap__Q23mem6MemoryFv
801bf714,__dl__FPv
80402ee8,__ct__Q23snd12SoundManagerFv 80402ee8,__ct__Q23snd12SoundManagerFv
80403150,__dt__Q23snd12SoundManagerFv 80403150,__dt__Q23snd12SoundManagerFv
8055c878,Debug_BBA 8055c878,Debug_BBA

1 Address SymbolName
35 8004b430 SCInit
36 80075730 size__Q23gfx19GXFifoMemoryManagerCFv
37 800dc470 SetTMemLayout__Q34nw4r3g3d4tmemFQ44nw4r3g3d4tmem10TMemLayout
38 800dd3e0 __ct__Q33hel6common34PointerWrapper<Q23mem10IAllocator>Fv
39 800f16b0 G3dInit__Q24nw4r3g3dFb
40 801007e0 startAddress__Q23mem8MemBlockCFv
41 80175b68 __dt__Q33hel6common11NonCopyableFv
55 801bf520 __dt__Q23mem6MemoryFv
56 801bf5e8 mem1FixHeap__Q23mem6MemoryFv
57 801bf5f8 mem2FixHeap__Q23mem6MemoryFv
801bf714 __dl__FPv
58 80402ee8 __ct__Q23snd12SoundManagerFv
59 80403150 __dt__Q23snd12SoundManagerFv
60 8055c878 Debug_BBA

View file

@ -0,0 +1,68 @@
#include <hel/common/PointerWrapper.hpp>
#include <mem/Memory.hpp>
#include <mem/OperatorNewDelete.hpp>
#include <new>
#ifdef __CWCC__
#pragma dont_inline on
#endif
using namespace mem;
using namespace hel::common;
namespace {
PointerWrapper<IAllocator> t_allocator;
PointerWrapper<IAllocator> t_globalNewDeleteAllocator;
IAllocator &t_allocatorRef(void) {
Memory::SetupIfNotSetup();
IAllocator *allocatorRef = t_globalNewDeleteAllocator.ptr_;
if (allocatorRef)
return *allocatorRef;
allocatorRef = t_allocator.ptr_;
if (allocatorRef)
return *allocatorRef;
allocatorRef = &MEMORY_OBJ->mem1FixHeap();
return *allocatorRef;
}
void *t_operatorNew(u32 size) {
return t_allocatorRef().allocatorAlloc(size, 4);
}
void *t_operatorNew(u32 size, IAllocator &alloc) {
return alloc.allocatorAlloc(size, 4);
}
void t_operatorDelete(void *ptr) {
if (ptr != 0) {
t_allocatorRef().allocatorFree(ptr);
}
}
} // namespace
void *operator new(u32 size, IAllocator &alloc) {
return t_operatorNew(size, alloc);
}
void *operator new(u32 size) { return t_operatorNew(size); }
void operator delete(void *ptr) { t_operatorDelete(ptr); }
namespace mem {
void OperatorNewDelete::SetDefaultAllocator(IAllocator &alloc) {
t_allocator.ptr_ = &alloc;
}
void OperatorNewDelete::SetGlobalNewDeleteAllocator(IAllocator &alloc) {
t_globalNewDeleteAllocator.ptr_ = &alloc;
}
void OperatorNewDelete::UnsetGlobalNewDeleteAllocator(IAllocator &alloc) {
// extraneous argument is not a copy-paste error
t_globalNewDeleteAllocator.ptr_ = 0;
}
} // namespace mem

View file

@ -0,0 +1,10 @@
#pragma once
namespace hel {
namespace common {
template <class T> struct PointerWrapper {
T *ptr_;
PointerWrapper();
};
} // namespace common
} // namespace hel

View file

@ -0,0 +1,11 @@
#pragma once
#include <mem/IAllocator.hpp>
namespace mem {
struct OperatorNewDelete {
static void SetDefaultAllocator(IAllocator &alloc);
static void SetGlobalNewDeleteAllocator(IAllocator &alloc);
static void UnsetGlobalNewDeleteAllocator(IAllocator &alloc);
};
} // namespace mem

6
include/new Normal file
View file

@ -0,0 +1,6 @@
// vim: set ft=cpp
#pragma once
namespace std {
struct nothrow_t {};
} // namespace std

View file

@ -32,6 +32,7 @@ const SOURCES: &[(&str, &str)] = &[
("donut/mem/DataBlock.cpp", "donut"), ("donut/mem/DataBlock.cpp", "donut"),
("donut/mem/MemBlock.cpp", "donut"), ("donut/mem/MemBlock.cpp", "donut"),
("donut/mem/Memory.cpp", "donut"), ("donut/mem/Memory.cpp", "donut"),
("donut/mem/OperatorNewDelete.cpp", "donut"),
("donut/util/Mutex.cpp", "donut"), ("donut/util/Mutex.cpp", "donut"),
]; ];

View file

@ -66,7 +66,7 @@ MEMORY {
let result = result?; let result = result?;
out.write_all( out.write_all(
format!( format!(
" {} = 0x{:08x};\n", " \"{}\" = 0x{:08x};\n",
result.get(1).unwrap(), result.get(1).unwrap(),
parse_hex(result.get(0).unwrap())? parse_hex(result.get(0).unwrap())?
) )