OperatorNewDelete
This commit is contained in:
parent
9f3eae615a
commit
829ac223d8
10 changed files with 117 additions and 6 deletions
15
.vscode/settings.json
vendored
15
.vscode/settings.json
vendored
|
@ -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"
|
||||||
},
|
},
|
||||||
}
|
}
|
5
Doxyfile
5
Doxyfile
|
@ -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 \
|
||||||
|
|
|
@ -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,
|
|
|
@ -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
|
||||||
|
|
|
68
donut/mem/OperatorNewDelete.cpp
Normal file
68
donut/mem/OperatorNewDelete.cpp
Normal 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
|
10
include/hel/common/PointerWrapper.hpp
Normal file
10
include/hel/common/PointerWrapper.hpp
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace hel {
|
||||||
|
namespace common {
|
||||||
|
template <class T> struct PointerWrapper {
|
||||||
|
T *ptr_;
|
||||||
|
PointerWrapper();
|
||||||
|
};
|
||||||
|
} // namespace common
|
||||||
|
} // namespace hel
|
11
include/mem/OperatorNewDelete.hpp
Normal file
11
include/mem/OperatorNewDelete.hpp
Normal 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
6
include/new
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
// vim: set ft=cpp
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace std {
|
||||||
|
struct nothrow_t {};
|
||||||
|
} // namespace std
|
|
@ -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"),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
@ -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())?
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue