Skip to content

Commit

Permalink
JKRDisposer, JKRHeap (#37)
Browse files Browse the repository at this point in the history
* JKRDisposer

* JKRHeap
  • Loading branch information
Jcw87 authored Sep 15, 2023
1 parent 2943240 commit 9ff000b
Show file tree
Hide file tree
Showing 6 changed files with 360 additions and 111 deletions.
4 changes: 2 additions & 2 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -755,11 +755,11 @@ def DolphinLib(lib_name, objects):
JSystemLib(
"JKernel",
[
Object(NonMatching, "JSystem/JKernel/JKRHeap.cpp"),
Object(Matching, "JSystem/JKernel/JKRHeap.cpp"),
Object(NonMatching, "JSystem/JKernel/JKRStdHeap.cpp"),
Object(NonMatching, "JSystem/JKernel/JKRExpHeap.cpp"),
Object(NonMatching, "JSystem/JKernel/JKRSolidHeap.cpp"),
Object(NonMatching, "JSystem/JKernel/JKRDisposer.cpp"),
Object(Matching, "JSystem/JKernel/JKRDisposer.cpp"),
Object(NonMatching, "JSystem/JKernel/JKRThread.cpp"),
Object(NonMatching, "JSystem/JKernel/JKRAram.cpp"),
Object(NonMatching, "JSystem/JKernel/JKRAramHeap.cpp"),
Expand Down
32 changes: 11 additions & 21 deletions include/JSystem/JKernel/JKRHeap.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
class JKRHeap;
typedef void (*JKRErrorHandler)(void*, u32, int);

extern bool data_804508B0;

class JKRHeap : public JKRDisposer {
public:
class TState {
Expand Down Expand Up @@ -44,6 +42,7 @@ class JKRHeap : public JKRDisposer {
s32 getFreeSize();
void* getMaxFreeBlock();
s32 getTotalFreeSize();
u8 getCurrentGroupId();
s32 changeGroupID(u8 newGroupId);
u32 getMaxAllocatableSize(int alignment);

Expand Down Expand Up @@ -76,7 +75,7 @@ class JKRHeap : public JKRDisposer {
/* vt[18] */ virtual s32 do_getTotalFreeSize() = 0;
/* vt[19] */ virtual s32 do_changeGroupID(u8 newGroupID);
/* vt[20] */ virtual u8 do_getCurrentGroupId();
/* vt[21] */ virtual u32 state_register(JKRHeap::TState* p, u32 id) const;
/* vt[21] */ virtual void state_register(JKRHeap::TState* p, u32 id) const;
/* vt[22] */ virtual bool state_compare(JKRHeap::TState const& r1, JKRHeap::TState const& r2) const;
/* vt[23] */ virtual void state_dump(JKRHeap::TState const& p) const;

Expand Down Expand Up @@ -135,7 +134,7 @@ class JKRHeap : public JKRDisposer {

static JKRErrorHandler setErrorHandler(JKRErrorHandler errorHandler);

static void setDefaultDebugFill(bool status) { data_804508B0 = status; }
static void setDefaultDebugFill(bool status) { sDefaultFillFlag = status; }
static void* getCodeStart(void) { return mCodeStart; }
static void* getCodeEnd(void) { return mCodeEnd; }
static void* getUserRamStart(void) { return mUserRamStart; }
Expand Down Expand Up @@ -172,32 +171,23 @@ class JKRHeap : public JKRDisposer {

static JKRHeap* sSystemHeap;
static JKRHeap* sCurrentHeap;
static bool sDefaultFillFlag;

static JKRErrorHandler mErrorHandler;
};

// The C++ standard says that the first argument to operator new must be a size_t;
// which on 64-bit systems is unsigned long long; IntelliSense won't recognize the
// override unless we give it that. I don't know of an easy way to convince
// IntelliSense that we're in a 32-bit project, so just give it a different size.
#if defined __INTELLISENSE__
typedef unsigned int NEW_SIZE;
#else
typedef u32 NEW_SIZE;
#endif

void* operator new(NEW_SIZE size);
void* operator new(NEW_SIZE size, int alignment);
void* operator new(NEW_SIZE size, JKRHeap* heap, int alignment);
void* operator new(size_t size);
void* operator new(size_t size, int alignment);
void* operator new(size_t size, JKRHeap* heap, int alignment);

void* operator new[](NEW_SIZE size);
void* operator new[](NEW_SIZE size, int alignment);
void* operator new[](NEW_SIZE size, JKRHeap* heap, int alignment);
void* operator new[](size_t size);
void* operator new[](size_t size, int alignment);
void* operator new[](size_t size, JKRHeap* heap, int alignment);

void operator delete(void* ptr);
void operator delete[](void* ptr);

inline void* operator new(NEW_SIZE size, void* ptr) {
inline void* operator new(size_t size, void* ptr) {
return ptr;
}

Expand Down
4 changes: 4 additions & 0 deletions include/JSystem/JUtility/JUTAssert.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@
#define JUT_WARN(LINE, ...) \
JUTAssertion::setWarningMessage_f(JUTAssertion::getSDevice(), __FILE__, LINE, __VA_ARGS__); \

#define JUT_LOG(LINE, ...) \
JUTAssertion::setLogMessage_f(JUTAssertion::getSDevice(), __FILE__, LINE, __VA_ARGS__)

#define JUT_CONFIRM(LINE, COND) \
JUTAssertion::setConfirmMessage(JUTAssertion::getSDevice(), __FILE__, LINE, COND, #COND)

namespace JUTAssertion {
u32 getSDevice();
void showAssert(u32 device, const char * file, int line, const char * assertion);
void setWarningMessage_f(u32 device, char * file, int line, const char * fmt, ...);
void setLogMessage_f(u32 device, char* file, int line, const char* fmt, ...);
void setConfirmMessage(u32 device, char * file, int line, bool cond, const char * msg);
void create();
u32 flush_subroutine();
Expand Down
5 changes: 5 additions & 0 deletions include/MSL_C/MSL_Common/Src/stddef.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@
extern "C" {
#endif

#if defined __INTELLISENSE__
typedef unsigned int size_t;
typedef int ptrdiff_t;
#else
typedef unsigned long size_t;
typedef long ptrdiff_t;
#endif

#ifndef NULL
#define NULL (0)
Expand Down
14 changes: 10 additions & 4 deletions src/JSystem/JKernel/JKRDisposer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@
//

#include "JSystem/JKernel/JKRDisposer.h"
#include "dolphin/types.h"
#include "JSystem/JKernel/JKRHeap.h"

/* 802B3C30-802B3C98 .text __ct__11JKRDisposerFv */
JKRDisposer::JKRDisposer() {
/* Nonmatching */
JKRDisposer::JKRDisposer() : mLink(this) {
mHeap = JKRHeap::findFromRoot(this);
if (mHeap) {
mHeap->appendDisposer(this);
}
}

/* 802B3C98-802B3D1C .text __dt__11JKRDisposerFv */
JKRDisposer::~JKRDisposer() {
/* Nonmatching */
JKRHeap* heap = mHeap;
if (heap) {
heap->removeDisposer(this);
}
}
Loading

0 comments on commit 9ff000b

Please sign in to comment.