Skip to content

Commit

Permalink
some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
cuckydev committed Jan 26, 2024
1 parent 638ab4b commit 47527cb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions include/CKSDK/CKSDK.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,8 @@
// Keep section
/// @brief Keep section
/// @details This is used to keep a function in the final binary. You should use this for any functions that are called from DLLs.
#ifdef __INTELLISENSE__
#define KEEP
#else
#define KEEP __attribute__((used))
#endif
13 changes: 13 additions & 0 deletions src/OS/Mem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ namespace CKSDK

KEEP void *Alloc(size_t size)
{
OS::DisableIRQ();

// Align size
size = Align(size) + Align(sizeof(Block));

Expand All @@ -118,11 +120,13 @@ namespace CKSDK
prev->next = head;

// Return pointer
OS::EnableIRQ();
return (void*)((char*)head + Align(sizeof(Block)));
}

KEEP void *Realloc(void *ptr, size_t size)
{
OS::DisableIRQ();

// Get block
if (ptr == nullptr)
Expand Down Expand Up @@ -155,11 +159,14 @@ namespace CKSDK
head->next->prev = head;
newprev->next = head;

OS::EnableIRQ();
return (void*)((char*)head + Align(sizeof(Block)));
}

KEEP void Free(void *ptr)
{
OS::DisableIRQ();

// Get block
if (ptr == nullptr)
return;
Expand All @@ -168,10 +175,14 @@ namespace CKSDK
// Unlink block
if ((head->prev->next = head->next) != nullptr)
head->next->prev = head->prev;

OS::EnableIRQ();
}

KEEP void Profile(size_t *used, size_t *total, size_t *blocks)
{
OS::DisableIRQ();

if (used != nullptr)
{
size_t u = 0;
Expand All @@ -188,6 +199,8 @@ namespace CKSDK
b++;
*blocks = b;
}

OS::EnableIRQ();
}
}
}

0 comments on commit 47527cb

Please sign in to comment.