26 02 27 pjb dev 2 (#41)

* fix kankyo UB

* Fix TEV Stage DL writing

BE issue

* BE Fixes in materials/shapes

* Move to Aurora GD impl

* JUTDataFileHeader

* j3d: load vertex and texture not through GD

* Endian swap vertex data (mostly)

* Just exit(0) when closing the game

Fix crashes :godo:

* fix fopAcM_ct_placement and remove memcpy

* J3D: track vertex arrays correctly, swap work

* fix visibility, turn off overridden new/delete when we call into aurora

* event: cut name be

* Default window improvements

Double size, allow OS to decide position

* survive TParse::parseHeader_next

* color swap fix

* swap endian/fixes oob function pointer

* Remove GXGetViewportv stub

Aurora has it now

* Set array pointers via GD again

Relies on https://github.com/encounter/aurora/pull/35

* Let Aurora decide graphics backend

* disable procbar drawing

* Fix TColor endianness conversion issues

Fixes the wrong color for the flashing logo

* cam param swap

* simplify vtx loading, mat/amb color fix

* endian swap stb/fvb data

* aurora stat changes

* fix storage buffer crash

dont unnecessarily reassign vertex buffers in a way that forces aurora to recache things

* set bgobj spec fix

* add camera debug, endian swap more stb data, d_a_bg_obj::spec_data_c swapped

* JKRExpHeap: fix bad allocator slowdown

* solid tex

* texture caching

* log level

* fix window aspect ratio, disable bloom, endian swap camera type data

camera is now actually playing opening cutscene!!!!

* add GXDestroyTexObj to a couple stack init'd GXTexObjs, remove some diag printfs

* endian swap joint weight envelope data

* move to dusk config

* verbose arg errors

* better stub logging (for now)

* less logging, more BE

* more stubbing, move logging stuff around

* move all logging to aurora logging

* fix STUB_LOG, __FUNCTION__ isn't a string literal, wasn't building as it
was.

* update aurora

* fix heap alignment mismatch and always head align for now

* prevent them from fucking up my shit

* forward jut warning to DuskLog

* remove report logging

* maybe and i must emphasize maybe fix JMessage parsing

* this was a dumb idea

* preserve negative alignment for JKRHeap

* use normal free on macos and linux

* ^

* fix JMAHermiteInterpolation c impl

* endian swap J2DScreen mColor (oops)

* swap more J3D anim data, remove weird pointer addr check in J3DMaterial getMaterialAnm

* typo fix

* Fix aligned_alloc() size issues on POSIX

aligned_alloc() requires its input size to be a multiple of alignment. This wasn't being upheld so there were allocation failures in init code that made the game fail to start outside Windows.

Also just cleaned up some of this code a bit and removed fallback cases that *shouldn't* get hit.

* _Exit instead of exit()

Seriously I don't want destructors to run. Let the OS reclaim that shit.

* Reapply "Isolate JKRHeap operator overloads" (#39)

This reverts commit 3623b27f37.

* Fix some oopsies

* Fix hardcoded pointer size in JUTCacheFont::allocArray

* More operator overload fixes

Add void template specialization for jkrDelete

Add new[] placement overload. Apparently.

* Fix delete macros on nullptr

TIL C++ allows that.

* fix delete[]

* fix new(std::nothrow) overload

* fix avoid ub

* swap remaining anim data needed for title logo

* get rid of op 7

* move aurora_end_frame to correct spot

* juttexture destroy tex

* j2d animation be

* shutdown crash

* link warp material fix

* mDoExt_3DlineMat1_c fix

* hacky keyboard controls

* endian swap J2DResReference, add kb_pad to files.cmake

* fix some missing endian swaps in J2D, remove addr alignment check

* Remove heap unsetting in aurora calls

Never worked properly and not the right solution even if it did

* Don't print in DC stubs

They're fine to never implement

* Fix alignment stuff again

* Compile GF from dolphin lib

Doesn't seem to break anything and shuts up some stub warnings

* j3dtexture tlut obj fix

* addTexMtxIndexInDL fix

* don't recreate null tex data every frame

* the actual fix i wanted to push

* its kinda fakematch city over here

* insert hte efb copy

* limited window size / viewport support

* IsDelete FIX

---------

Co-authored-by: madeline <qwertytrogi@gmail.com>
Co-authored-by: Jasper St. Pierre <jstpierre@mecheye.net>
Co-authored-by: Jeffrey Crowell <jeff@crowell.biz>
Co-authored-by: TakaRikka <takarikka@outlook.com>
Co-authored-by: CraftyBoss <talibabdulmaalik@gmail.com>
Co-authored-by: Lurs <2795933+Lurs@users.noreply.github.com>
This commit is contained in:
Pieter-Jan Briers
2026-03-08 23:27:15 +01:00
committed by GitHub
parent 820e2e3df6
commit b289dece80
726 changed files with 5289 additions and 4237 deletions
+4 -4
View File
@@ -32,7 +32,7 @@ JKRAram* JKRAram::sAramObject;
JKRAram* JKRAram::create(u32 aram_audio_buffer_size, u32 aram_audio_graph_size, s32 stream_priority,
s32 decomp_priority, s32 piece_priority) {
if (!sAramObject) {
sAramObject = new (JKRGetSystemHeap(), 0)
sAramObject = JKR_NEW_ARGS (JKRGetSystemHeap(), 0)
JKRAram(aram_audio_buffer_size, aram_audio_graph_size, piece_priority);
}
@@ -81,13 +81,13 @@ JKRAram::JKRAram(u32 audio_buffer_size, u32 audio_graph_size, s32 priority)
OS_REPORT("ARAM graph area %08x: %08x\n", mGraphMemoryPtr, mGraphMemorySize);
OS_REPORT("ARAM user area %08x: %08x\n", mAramMemoryPtr, mAramMemorySize);
mAramHeap = new (JKRGetSystemHeap(), 0) JKRAramHeap(mGraphMemoryPtr, mGraphMemorySize);
mAramHeap = JKR_NEW_ARGS (JKRGetSystemHeap(), 0) JKRAramHeap(mGraphMemoryPtr, mGraphMemorySize);
}
JKRAram::~JKRAram() {
sAramObject = NULL;
if (mAramHeap)
delete mAramHeap;
JKR_DELETE(mAramHeap);
}
void* JKRAram::run(void) {
@@ -98,7 +98,7 @@ void* JKRAram::run(void) {
JKRAramCommand* message = (JKRAramCommand*)msg;
int result = message->field_0x00;
JKRAMCommand* command = (JKRAMCommand*)message->command;
delete message;
JKR_DELETE(message);
switch (result) {
case 1:
+4 -4
View File
@@ -48,11 +48,11 @@ JKRAramArchive::~JKRAramArchive() {
}
if (mDvdFile != NULL) {
delete mDvdFile;
JKR_DELETE(mDvdFile);
}
if (mBlock != NULL) {
delete mBlock;
JKR_DELETE(mBlock);
}
JKRFileLoader::sVolumeList.remove(&mFileLoaderLink);
@@ -105,7 +105,7 @@ bool JKRAramArchive::open(s32 entryNum) {
mStringTable = NULL;
mBlock = NULL;
mDvdFile = new (JKRGetSystemHeap(), mMountDirection == MOUNT_DIRECTION_HEAD ? 4 : -4)
mDvdFile = JKR_NEW_ARGS (JKRGetSystemHeap(), mMountDirection == MOUNT_DIRECTION_HEAD ? 4 : -4)
JKRDvdFile(entryNum);
if (mDvdFile == NULL) {
mMountMode = 0;
@@ -187,7 +187,7 @@ cleanup:
if (mMountMode == 0) {
OS_REPORT(":::[%s: %d] Cannot alloc memory\n", __FILE__, 415);
if (mDvdFile != NULL) {
delete mDvdFile;
JKR_DELETE(mDvdFile);
}
return false;
}
+2 -2
View File
@@ -30,7 +30,7 @@ JKRAramBlock* JKRAramBlock::allocHead(u32 size, u8 groupId, JKRAramHeap* aramHea
u32 nextAddress = mAddress + mSize;
u32 nextFreeSize = mFreeSize - size;
JKRAramBlock* block = new (aramHeap->getMgrHeap(), 0)
JKRAramBlock* block = JKR_NEW_ARGS (aramHeap->getMgrHeap(), 0)
JKRAramBlock(nextAddress, size, nextFreeSize, groupId, false);
mFreeSize = 0;
@@ -42,7 +42,7 @@ JKRAramBlock* JKRAramBlock::allocTail(u32 size, u8 groupId, JKRAramHeap* aramHea
u32 tailAddress = mAddress + mSize + mFreeSize - size;
JKRAramBlock* block =
new (aramHeap->getMgrHeap(), 0) JKRAramBlock(tailAddress, size, 0, groupId, true);
JKR_NEW_ARGS (aramHeap->getMgrHeap(), 0) JKRAramBlock(tailAddress, size, 0, groupId, true);
mFreeSize -= size;
mBlockLink.getSupervisor()->insert(mBlockLink.getNext(), &block->mBlockLink);
+2 -2
View File
@@ -17,12 +17,12 @@ JKRAramHeap::JKRAramHeap(u32 startAddress, u32 size) {
mTailAddress = mHeadAddress + mSize;
mGroupId = -1;
JKRAramBlock* block = new (mHeap, 0) JKRAramBlock(mHeadAddress, 0, mSize, -1, false);
JKRAramBlock* block = JKR_NEW_ARGS (mHeap, 0) JKRAramBlock(mHeadAddress, 0, mSize, -1, false);
sAramList.append(&block->mBlockLink);
}
JKRAramHeap::~JKRAramHeap() {
for (JSUListIterator<JKRAramBlock> iterator = sAramList.getFirst(); iterator != sAramList.getEnd(); delete (iterator++).getObject()) {}
for (JSUListIterator<JKRAramBlock> iterator = sAramList.getFirst(); iterator != sAramList.getEnd(); JKR_DELETE((iterator++).getObject())) {}
}
JKRAramBlock* JKRAramHeap::alloc(u32 size, JKRAramHeap::EAllocMode allocationMode) {
+7 -5
View File
@@ -9,7 +9,7 @@
JKRAMCommand* JKRAramPiece::prepareCommand(int direction, uintptr_t src, uintptr_t dst, u32 length,
JKRAramBlock* block,
JKRAMCommand::AsyncCallback callback) {
JKRAMCommand* command = new (JKRGetSystemHeap(), -4) JKRAMCommand();
JKRAMCommand* command = JKR_NEW_ARGS (JKRGetSystemHeap(), -4) JKRAMCommand();
command->mTransferDirection = direction;
command->mSrc = src;
command->mDst = dst;
@@ -30,6 +30,7 @@ OSMutex JKRAramPiece::mMutex;
JKRAMCommand* JKRAramPiece::orderAsync(int direction, uintptr_t source, uintptr_t destination, u32 length,
JKRAramBlock* block, JKRAMCommand::AsyncCallback callback) {
lock();
#if !TARGET_PC
if ((source & 0x1f) != 0 || (destination & 0x1f) != 0) {
OSReport("direction = %x\n", direction);
OSReport("source = %x\n", source);
@@ -37,8 +38,9 @@ JKRAMCommand* JKRAramPiece::orderAsync(int direction, uintptr_t source, uintptr_
OSReport("length = %x\n", length);
JUTException::panic(__FILE__, 108, "illegal address. abort.");
}
#endif
JKRAramCommand* message = new (JKRGetSystemHeap(), -4) JKRAramCommand();
JKRAramCommand* message = JKR_NEW_ARGS (JKRGetSystemHeap(), -4) JKRAramCommand();
JKRAMCommand* command =
JKRAramPiece::prepareCommand(direction, source, destination, length, block, callback);
message->setting(1, command);
@@ -80,7 +82,7 @@ BOOL JKRAramPiece::orderSync(int direction, uintptr_t source, uintptr_t destinat
JKRAMCommand* command =
JKRAramPiece::orderAsync(direction, source, destination, length, block, NULL);
BOOL result = JKRAramPiece::sync(command, 0);
delete command;
JKR_DELETE(command);
unlock();
return result;
@@ -132,9 +134,9 @@ JKRAMCommand::JKRAMCommand() : mPieceLink(this), field_0x30(this) {
JKRAMCommand::~JKRAMCommand() {
if (field_0x8C)
delete field_0x8C;
JKR_DELETE(field_0x8C);
if (field_0x90)
delete field_0x90;
JKR_DELETE(field_0x90);
if (field_0x94)
JKRFree(field_0x94);
+2 -2
View File
@@ -16,7 +16,7 @@ JKRAramStream* JKRAramStream::sAramStreamObject;
JKRAramStream* JKRAramStream::create(s32 priority) {
if (!sAramStreamObject) {
sAramStreamObject = new (JKRGetSystemHeap(), 0) JKRAramStream(priority);
sAramStreamObject = JKR_NEW_ARGS (JKRGetSystemHeap(), 0) JKRAramStream(priority);
JKRResetAramTransferBuffer();
}
@@ -141,7 +141,7 @@ JKRHeap* JKRAramStream::transHeap;
JKRAramStreamCommand* JKRAramStream::write_StreamToAram_Async(JSUFileInputStream* stream, u32 addr,
u32 size, u32 offset,
u32* returnSize) {
JKRAramStreamCommand* command = new (JKRGetSystemHeap(), -4) JKRAramStreamCommand();
JKRAramStreamCommand* command = JKR_NEW_ARGS (JKRGetSystemHeap(), -4) JKRAramStreamCommand();
command->mType = JKRAramStreamCommand::WRITE;
command->mAddress = addr;
command->mSize = size;
+7 -7
View File
@@ -45,7 +45,7 @@ JKRArchive* JKRArchive::mount(void* ptr, JKRHeap* heap,
int alignment = mountDirection == MOUNT_DIRECTION_HEAD ? 4 : -4;
JKRArchive* newArchive = new (heap, alignment) JKRMemArchive(ptr, 0xFFFF, JKRMEMBREAK_FLAG_UNKNOWN0);
JKRArchive* newArchive = JKR_NEW_ARGS (heap, alignment) JKRMemArchive(ptr, 0xFFFF, JKRMEMBREAK_FLAG_UNKNOWN0);
return newArchive;
}
@@ -60,21 +60,21 @@ JKRArchive* JKRArchive::mount(s32 entryNum, JKRArchive::EMountMode mountMode, JK
JKRArchive* newArchive;
switch (mountMode) {
case JKRArchive::MOUNT_MEM:
newArchive = new (heap, alignment) JKRMemArchive(entryNum, mountDirection);
newArchive = JKR_NEW_ARGS (heap, alignment) JKRMemArchive(entryNum, mountDirection);
break;
case JKRArchive::MOUNT_ARAM:
newArchive = new (heap, alignment) JKRAramArchive(entryNum, mountDirection);
newArchive = JKR_NEW_ARGS (heap, alignment) JKRAramArchive(entryNum, mountDirection);
break;
case JKRArchive::MOUNT_DVD:
newArchive = new (heap, alignment) JKRDvdArchive(entryNum, mountDirection);
newArchive = JKR_NEW_ARGS (heap, alignment) JKRDvdArchive(entryNum, mountDirection);
break;
case JKRArchive::MOUNT_COMP:
newArchive = new (heap, alignment) JKRCompArchive(entryNum, mountDirection);
newArchive = JKR_NEW_ARGS (heap, alignment) JKRCompArchive(entryNum, mountDirection);
break;
}
if (newArchive && newArchive->mMountMode == JKRArchive::UNKNOWN_MOUNT_MODE) {
delete newArchive;
JKR_DELETE(newArchive);
newArchive = NULL;
}
@@ -330,7 +330,7 @@ JKRFileFinder* JKRArchive::getFirstFile(const char* path) const {
if (dirEntry) {
// don't know what is correct here... for now we're casting away const
return new (JKRGetSystemHeap(), 0)
return JKR_NEW_ARGS (JKRGetSystemHeap(), 0)
JKRArcFinder((JKRArchive*)this, dirEntry->first_file_index, (u32)dirEntry->num_entries);
}
+1 -1
View File
@@ -23,7 +23,7 @@ JKRAssertHeap* JKRAssertHeap::create(JKRHeap* parent) {
if (!ptr)
return NULL;
JKRAssertHeap* heap = new (ptr) JKRAssertHeap(NULL, 0, parent, false);
JKRAssertHeap* heap = JKR_NEW_ARGS (ptr) JKRAssertHeap(NULL, 0, parent, false);
return heap;
}
+3 -3
View File
@@ -54,7 +54,7 @@ JKRCompArchive::~JKRCompArchive() {
}
if (mDvdFile != NULL) {
delete mDvdFile;
JKR_DELETE(mDvdFile);
}
sVolumeList.remove(&mFileLoaderLink);
@@ -73,7 +73,7 @@ bool JKRCompArchive::open(s32 entryNum) {
mFiles = NULL;
mStringTable = NULL;
mDvdFile = new (JKRGetSystemHeap(), 0) JKRDvdFile(entryNum);
mDvdFile = JKR_NEW_ARGS (JKRGetSystemHeap(), 0) JKRDvdFile(entryNum);
if(mDvdFile == NULL) {
mMountMode = 0;
return 0;
@@ -216,7 +216,7 @@ bool JKRCompArchive::open(s32 entryNum) {
if (mMountMode == 0) {
OS_REPORT(":::[%s: %d] Cannot alloc memory in mounting CompArchive\n", __FILE__, 567);
if(mDvdFile != NULL) {
delete mDvdFile;
JKR_DELETE(mDvdFile);
}
return false;
}
+3 -3
View File
@@ -14,7 +14,7 @@ JKRDecomp* JKRDecomp::sDecompObject;
JKRDecomp* JKRDecomp::create(s32 priority) {
if (!sDecompObject) {
sDecompObject = new (JKRGetSystemHeap(), 0) JKRDecomp(priority);
sDecompObject = JKR_NEW_ARGS (JKRGetSystemHeap(), 0) JKRDecomp(priority);
}
return sDecompObject;
@@ -62,7 +62,7 @@ void* JKRDecomp::run() {
JKRDecompCommand* JKRDecomp::prepareCommand(u8* srcBuffer, u8* dstBuffer, u32 srcLength,
u32 dstLength,
JKRDecompCommand::AsyncCallback callback) {
JKRDecompCommand* command = new (JKRGetSystemHeap(), -4) JKRDecompCommand();
JKRDecompCommand* command = JKR_NEW_ARGS (JKRGetSystemHeap(), -4) JKRDecompCommand();
command->mSrcBuffer = srcBuffer;
command->mDstBuffer = dstBuffer;
command->mSrcLength = srcLength;
@@ -102,7 +102,7 @@ bool JKRDecomp::sync(JKRDecompCommand* command, int isNonBlocking) {
bool JKRDecomp::orderSync(u8* srcBuffer, u8* dstBuffer, u32 srcLength, u32 dstLength) {
JKRDecompCommand* command = orderAsync(srcBuffer, dstBuffer, srcLength, dstLength, NULL);
bool result = sync(command, JKRDECOMP_SYNC_BLOCKING);
delete command;
JKR_DELETE(command);
return result;
}
+10 -10
View File
@@ -38,17 +38,17 @@ JKRAramBlock* JKRDvdAramRipper::loadToAram(JKRDvdFile* dvdFile, u32 address,
syncAram(command, 0);
if (command->field_0x48 < 0) {
delete command;
JKR_DELETE(command);
return NULL;
}
if (address) {
delete command;
JKR_DELETE(command);
return (JKRAramBlock*)-1;
}
JKRAramBlock* result = command->mBlock;
delete command;
JKR_DELETE(command);
return result;
}
@@ -56,7 +56,7 @@ JKRADCommand* JKRDvdAramRipper::loadToAram_Async(JKRDvdFile* dvdFile, u32 addres
JKRExpandSwitch expandSwitch,
void (*callback)(u32), u32 param_4, u32 param_5,
u32* param_6) {
JKRADCommand* command = new (JKRGetSystemHeap(), -4) JKRADCommand();
JKRADCommand* command = JKR_NEW_ARGS (JKRGetSystemHeap(), -4) JKRADCommand();
command->mDvdFile = dvdFile;
command->mAddress = address;
command->mBlock = NULL;
@@ -68,7 +68,7 @@ JKRADCommand* JKRDvdAramRipper::loadToAram_Async(JKRDvdFile* dvdFile, u32 addres
JKRADCommand* cmd2 = callCommand_Async(command);
if (!cmd2) {
delete command;
JKR_DELETE(command);
return NULL;
}
@@ -94,7 +94,7 @@ JKRADCommand* JKRDvdAramRipper::callCommand_Async(JKRADCommand* command) {
bVar1 = false;
} else {
dvdFile->field_0x50 = OSGetCurrentThread();
JSUFileInputStream* stream = new (JKRGetSystemHeap(), -4) JSUFileInputStream(dvdFile);
JSUFileInputStream* stream = JKR_NEW_ARGS (JKRGetSystemHeap(), -4) JSUFileInputStream(dvdFile);
dvdFile->mFileStream = stream;
u32 fileSize = dvdFile->getFileSize();
if (command->field_0x40 && fileSize > command->field_0x40) {
@@ -111,7 +111,7 @@ JKRADCommand* JKRDvdAramRipper::callCommand_Async(JKRADCommand* command) {
}
if (JKRDvdAramRipper::errorRetry == 0) {
delete stream;
JKR_DELETE(stream);
return NULL;
}
@@ -206,10 +206,10 @@ bool JKRDvdAramRipper::syncAram(JKRADCommand* command, int param_1) {
(*((JSUList<JKRADCommand>*)&sDvdAramAsyncList)).remove(&command->mLink);
if (command->mStreamCommand) {
delete command->mStreamCommand;
JKR_DELETE(command->mStreamCommand);
}
delete dvdFile->mFileStream;
JKR_DELETE(dvdFile->mFileStream);
dvdFile->field_0x50 = NULL;
OSUnlockMutex(&dvdFile->mMutex2);
return true;
@@ -222,7 +222,7 @@ JKRADCommand::JKRADCommand() : mLink(this) {
JKRADCommand::~JKRADCommand() {
if (field_0x4c == 1) {
delete mDvdFile;
JKR_DELETE(mDvdFile);
}
}
+3 -3
View File
@@ -46,7 +46,7 @@ JKRDvdArchive::~JKRDvdArchive() {
}
if (mDvdFile) {
delete mDvdFile;
JKR_DELETE(mDvdFile);
}
sVolumeList.remove(&mFileLoaderLink);
@@ -61,7 +61,7 @@ bool JKRDvdArchive::open(s32 entryNum) {
mFiles = NULL;
mStringTable = NULL;
mDvdFile = new (JKRGetSystemHeap(), 0) JKRDvdFile(entryNum);
mDvdFile = JKR_NEW_ARGS (JKRGetSystemHeap(), 0) JKRDvdFile(entryNum);
if (!mDvdFile) {
mMountMode = UNKNOWN_MOUNT_MODE;
return false;
@@ -137,7 +137,7 @@ cleanup:
if (mMountMode == UNKNOWN_MOUNT_MODE) {
OS_REPORT(":::Cannot alloc memory [%s][%d]\n", __FILE__, 397);
if (mDvdFile) {
delete mDvdFile;
JKR_DELETE(mDvdFile);
}
return false;
}
+15 -6
View File
@@ -30,7 +30,7 @@ JKRExpHeap* JKRExpHeap::createRoot(int maxHeaps, bool errorFlag) {
}
}
#endif
JKRExpHeap* heap2 = new (mem2) JKRExpHeap(local_20, local_24, NULL, errorFlag);
JKRExpHeap* heap2 = JKR_NEW_ARGS (mem2) JKRExpHeap(local_20, local_24, NULL, errorFlag);
sRootHeap2 = heap2;
heap2->field_0x6e = true;
#endif
@@ -49,7 +49,7 @@ JKRExpHeap* JKRExpHeap::createRoot(int maxHeaps, bool errorFlag) {
}
}
#endif
heap = new (mem1) JKRExpHeap(start1, alignedSize, NULL, errorFlag);
heap = JKR_NEW_ARGS (mem1) JKRExpHeap(start1, alignedSize, NULL, errorFlag);
sRootHeap = heap;
}
heap->field_0x6e = true;
@@ -79,7 +79,7 @@ JKRExpHeap* JKRExpHeap::create(u32 size, JKRHeap* parent, bool errorFlag) {
return NULL;
}
newHeap = new (memory) JKRExpHeap(dataPtr, alignedSize - expHeapSize, parent, errorFlag);
newHeap = JKR_NEW_ARGS (memory) JKRExpHeap(dataPtr, alignedSize - expHeapSize, parent, errorFlag);
if (newHeap == NULL) {
JKRFree(memory);
@@ -117,7 +117,7 @@ JKRExpHeap* JKRExpHeap::create(void* ptr, u32 size, JKRHeap* parent, bool errorF
u8* dataPtr = r28 + expHeapSize;
u32 alignedSize = ALIGN_PREV((uintptr_t)ptr + size - (uintptr_t)dataPtr, 0x10);
if (r28) {
newHeap = new (r28) JKRExpHeap(dataPtr, alignedSize, parent2, errorFlag);
newHeap = JKR_NEW_ARGS (r28) JKRExpHeap(dataPtr, alignedSize, parent2, errorFlag);
}
#if DEBUG
if (newHeap) {
@@ -212,12 +212,17 @@ void* JKRExpHeap::do_alloc(u32 size, int alignment) {
}
#endif
#if TARGET_PC
JUT_ASSERT_MSG_F(__LINE__, ptr != nullptr, "failed to alloc memory! (0x%x byte).\n", size);
#else
if (ptr == NULL) {
JUTWarningConsole_f(":::cannot alloc memory (0x%x byte).\n", size);
if (getErrorFlag() == true) {
callErrorHandler(this, size, alignment);
}
}
#endif
unlock();
return ptr;
@@ -783,9 +788,9 @@ void JKRExpHeap::recycleFreeBlock(JKRExpHeap::CMemBlock* block) {
}
void JKRExpHeap::joinTwoBlocks(CMemBlock* block) {
u32 endAddr = (uintptr_t)(block + 1) + block->size;
uintptr_t endAddr = (uintptr_t)(block + 1) + block->size;
CMemBlock* next = block->mNext;
u32 nextAddr = (uintptr_t)next - (next->mFlags & 0x7f);
uintptr_t nextAddr = (uintptr_t)next - (next->mFlags & 0x7f);
if (endAddr > nextAddr) {
JUTWarningConsole_f(":::Heap may be broken. (block = %x)", block);
OS_REPORT(":::block = %x\n", block);
@@ -1005,6 +1010,10 @@ JKRExpHeap::CMemBlock* JKRExpHeap::CMemBlock::allocFore(u32 size1, u8 groupId1,
mGroupId = groupId1;
mFlags = alignment1;
if (size >= size1 + sizeof(CMemBlock)) {
#if TARGET_PC
if ((size - size1) <= sizeof(CMemBlock))
return NULL;
#endif
block = (CMemBlock*)(size1 + (uintptr_t)this);
block[1].mGroupId = groupId2;
block[1].mFlags = alignment2;
+7 -7
View File
@@ -33,7 +33,7 @@ JKRFileCache* JKRFileCache::mount(const char* path, JKRHeap* heap, const char* p
}
JKRFileCache* fileCache = new (heap, 0) JKRFileCache(path, param_3);
JKRFileCache* fileCache = JKR_NEW_ARGS (heap, 0) JKRFileCache(path, param_3);
return fileCache;
}
@@ -123,7 +123,7 @@ void* JKRFileCache::getResource(const char* path) {
if (buffer) {
dvdFile.read(buffer, alignedSize, 0);
cacheBlock = new (JKRGetSystemHeap(), 0)
cacheBlock = JKR_NEW_ARGS (JKRGetSystemHeap(), 0)
CCacheBlock(dvdFile.getFileID(), dvdFile.getFileInfo()->length, buffer);
mCacheBlockList.append(&cacheBlock->mCacheBlockLink);
}
@@ -202,7 +202,7 @@ void JKRFileCache::removeResourceAll(void) {
while (iterator != mCacheBlockList.getEnd()) {
JKRFreeToHeap(mParentHeap, iterator->mMemoryPtr);
mCacheBlockList.remove(&iterator.getObject()->mCacheBlockLink);
delete (iterator++).getObject();
JKR_DELETE((iterator++).getObject());
}
}
@@ -216,7 +216,7 @@ bool JKRFileCache::removeResource(void* resource) {
if (--cacheBlock->mReferenceCount == 0) {
JKRFreeToHeap(mParentHeap, resource);
mCacheBlockList.remove(&cacheBlock->mCacheBlockLink);
delete cacheBlock;
JKR_DELETE(cacheBlock);
}
return true;
@@ -230,7 +230,7 @@ bool JKRFileCache::detachResource(void* resource) {
return false;
mCacheBlockList.remove(&cacheBlock->mCacheBlockLink);
delete cacheBlock;
JKR_DELETE(cacheBlock);
return true;
}
@@ -262,11 +262,11 @@ u32 JKRFileCache::countFile(const char* path) const {
JKRFileFinder* JKRFileCache::getFirstFile(const char* path) const {
char* name = getDvdPathName(path);
JKRDvdFinder* finder = new (JKRGetSystemHeap(), 0) JKRDvdFinder(name);
JKRDvdFinder* finder = JKR_NEW_ARGS (JKRGetSystemHeap(), 0) JKRDvdFinder(name);
JKRFreeToSysHeap(name);
if (finder->isAvailable() != true) {
delete finder;
JKR_DELETE(finder);
return NULL;
}
+3 -1
View File
@@ -6,6 +6,8 @@
#include <cstring>
#include <cctype>
#include <string>
#include "JSystem/JKernel/JKRHeap.h"
#include "global.h"
JKRFileLoader* JKRFileLoader::sCurrentVolume;
@@ -23,7 +25,7 @@ JKRFileLoader::~JKRFileLoader() {
void JKRFileLoader::unmount(void) {
if (mMountCount != 0) {
if (--mMountCount == 0) {
delete this;
JKR_DELETE(this);
}
}
}
+72 -40
View File
@@ -11,6 +11,8 @@
#include <algorithm>
#endif
#include <cassert>
#include "JSystem/JUtility/JUTAssert.h"
#include "JSystem/JUtility/JUTException.h"
#ifdef __MWERKS__
@@ -515,19 +517,54 @@ bool JKRHeap::isSubHeap(JKRHeap* heap) const {
return false;
}
#if TARGET_PC
[[nodiscard]]
static void* fallback_alloc(size_t size, size_t align, bool log=true) {
if (log) {
auto curHeap = JKRHeap::getCurrentHeap();
const char* name = "<null>";
if (curHeap != nullptr) {
name = curHeap->getName();
}
OSReport(
"[NEW] JKRHeap (%s) FULL! Fallback to malloc for size %u\n",
name, (unsigned)size);
}
if (align == 0) {
align = alignof(max_align_t);
}
assert((align & (align - 1)) == 0 && "Alignment must be a power of two");
#if _WIN32
// aligned_alloc() is not available on Windows.
// NOTE: We always use _aligned_malloc(), even for allocs <= max_align_t,
// because otherwise we can't tell in operator delete() whether a pointer needs to be freed with
// _aligned_free() or regular free().
return _aligned_malloc(size, align);
#else
// aligned_alloc() requires size be a multiple of align. So ensure it is.
size = ALIGN_NEXT(size, align);
return aligned_alloc(align, size);
#endif
}
#endif
#if !TARGET_PC
void* operator new(size_t size) {
return JKRHeap::alloc(size, 4, NULL);
}
#else
void* operator new(size_t size) {
void* operator new(size_t size JKR_HEAP_TOKEN_PARAM) {
if (sCurrentHeap == NULL) {
return malloc(size);
return fallback_alloc(size, 0, false);
}
void* mem = JKRHeap::alloc(size, alignof(max_align_t), NULL);
if (mem == NULL) {
OSReport("[NEW] JKRHeap FULL! Fallback to malloc for size %u\n", (unsigned)size);
mem = malloc(size);
if (mem == nullptr) {
return fallback_alloc(size, 0, true);
}
return mem;
}
@@ -538,27 +575,16 @@ void* operator new(size_t size, int alignment) {
return JKRHeap::alloc(size, alignment, NULL);
}
#else
void* operator new(size_t size, int alignment) {
if (sCurrentHeap == nullptr)
#if !_WIN32
return aligned_alloc(alignment, size);
#else
return _aligned_malloc(size, alignment);
#endif
void* operator new(size_t size JKR_HEAP_TOKEN_PARAM, int alignment) {
void* mem = JKRHeap::alloc(size, alignment, nullptr);
if (mem == nullptr) {
OSReport("[NEW] JKRHeap FULL! Fallback to aligned_malloc size %u\n", (unsigned)size);
#if !_WIN32
return aligned_alloc(alignment, size);
#else
return _aligned_malloc(size, alignment);
#endif
return fallback_alloc(size, abs(alignment), true);
}
return mem;
}
#endif
void* operator new(size_t size, JKRHeap* heap, int alignment) {
void* operator new(size_t size JKR_HEAP_TOKEN_PARAM, JKRHeap* heap, int alignment) {
return JKRHeap::alloc(size, alignment, heap);
}
@@ -568,11 +594,17 @@ void* operator new[](size_t size) {
}
#else
void* operator new[](size_t size) {
if (sCurrentHeap == NULL)
return malloc(size);
return fallback_alloc(size, 0, false);
}
void* operator new[](std::size_t size, const std::nothrow_t&) noexcept {
return fallback_alloc(size, 0, false);
}
void* operator new[](size_t size JKR_HEAP_TOKEN_PARAM) {
void* mem = JKRHeap::alloc(size, alignof(max_align_t), NULL);
if (mem == NULL) {
mem = malloc(size);
return fallback_alloc(size, 0, true);
}
return mem;
}
@@ -583,25 +615,16 @@ void* operator new[](size_t size, int alignment) {
return JKRHeap::alloc(size, alignment, NULL);
}
#else
void* operator new[](size_t size, int alignment) {
if (sCurrentHeap == nullptr)
#if !_WIN32
return aligned_alloc(alignment, size);
#else
return _aligned_malloc(size, alignment);
#endif
void* operator new[](size_t size JKR_HEAP_TOKEN_PARAM, int alignment) {
void* mem = JKRHeap::alloc(size, alignment, nullptr);
if (mem == nullptr)
#if !_WIN32
return aligned_alloc(alignment, size);
#else
return _aligned_malloc(size, alignment);
#endif
if (mem == nullptr) {
return fallback_alloc(size, 0, true);
}
return mem;
}
#endif
void* operator new[](size_t size, JKRHeap* heap, int alignment) {
void* operator new[](size_t size JKR_HEAP_TOKEN_PARAM, JKRHeap* heap, int alignment) {
return JKRHeap::alloc(size, alignment, heap);
}
@@ -610,15 +633,19 @@ void operator delete(void* ptr) {
JKRHeap::free(ptr, NULL);
}
#else
void operator delete(void* ptr) {
void operator delete(void* ptr JKR_HEAP_TOKEN_PARAM) {
if (ptr == NULL)
return;
JKRHeap* heap = JKRHeap::findFromRoot(ptr);
if (heap == NULL) {
#if !_WIN32
free(ptr);
#else
_aligned_free(ptr);
#endif
return;
}
JKRHeap::free(ptr, NULL);
JKRHeap::free(ptr, heap);
}
#endif
@@ -632,10 +659,14 @@ void operator delete[](void* ptr) {
return;
JKRHeap* heap = JKRHeap::findFromRoot(ptr);
if (heap == NULL) {
#if !_WIN32
free(ptr);
#else
_aligned_free(ptr);
#endif
return;
}
JKRHeap::free(ptr, NULL);
JKRHeap::free(ptr, heap);
}
#endif
@@ -681,7 +712,8 @@ JKRHeap* JKRHeap::getCurrentHeap() {
void JKRHeap::setName(const char* name) {
size_t len = strlen(name);
memcpy(mName, name, std::max(len, sizeof(mName)-1));
strncpy(mName, name, sizeof(mName) - 1);
mName[sizeof(mName) - 1] = '\0';
}
const char* JKRHeap::getName() const {
return mName;
+1 -1
View File
@@ -27,7 +27,7 @@ JKRSolidHeap* JKRSolidHeap::create(u32 size, JKRHeap* heap, bool useErrorHandler
if (!mem)
return NULL;
return new (mem) JKRSolidHeap(dataPtr, alignedSize - solidHeapSize, heap, useErrorHandler);
return JKR_NEW_ARGS (mem) JKRSolidHeap(dataPtr, alignedSize - solidHeapSize, heap, useErrorHandler);
}
void JKRSolidHeap::do_destroy(void) {
+3 -3
View File
@@ -127,7 +127,7 @@ JKRThreadSwitch* JKRThreadSwitch::createManager(JKRHeap* heap) {
heap = JKRGetCurrentHeap();
}
sManager = new (heap, 0) JKRThreadSwitch(heap);
sManager = JKR_NEW_ARGS (heap, 0) JKRThreadSwitch(heap);
return sManager;
}
@@ -282,7 +282,7 @@ void JKRThreadSwitch::draw(JKRThreadName_* thread_name_list, JUTConsole* console
static void dummy4(JKRTask* thread, JSULink<JKRTask>* link) {
thread->getStack();
delete link;
JKR_DELETE(link);
}
JKRTask::~JKRTask() {
@@ -322,7 +322,7 @@ int JKRTask::check() {
#if !PLATFORM_GCN
static void dummy(JKRIdleThread* thread) {
thread->run();
delete thread;
JKR_DELETE(thread);
thread->destroy();
}
#endif