Homebrew Official 5.5.X ELF Loader

  • Thread starter Thread starter NWPlayer123
  • Start date Start date
  • Views Views 104,744
  • Replies Replies 427
  • Likes Likes 63
Does anyone know the maximum allocatable size we can get from heap ?
I have to allocate a buffer to copy an unsigned char array of about 990 000 rows . When I use MEMAllocFromHeapEx function it crashes, so i assume it's not possible to allocate a buffer that big...
If it's not possible, how can i allocate directly from the stack (and what is the stack adress range for the elf loader) ?.

I have another question, when i allocate memory for a struct, does it allocate memory for struct pointers placed inside the struct (as in linked list for ex) ?
Probably not unless you use u32 MEMGetBaseHeapHandle(int arena); void* MEMAllocFromExpHeapEx(u32 *handle, u32 size, int alignment); Be sure to check if the alloc value returned is NULL.
EDIT: whoops, changed something, need to pass in the arena, want to do MEMGetBaseHeapHandle(1);
 
Last edited by NWPlayer123,
Probably not unless you use u32 MEMGetBaseHeapHandle(int arena); void* MEMAllocFromExpHeapEx(u32 *handle, u32 size, int alignment); Be sure to check if the alloc value returned is NULL.
EDIT: whoops, changed something, need to pass in the arena, want to do MEMGetBaseHeapHandle(1);
Thanks but it doesn't work...
Must be something wrong with my code :
Code:
    uint32_t coreinit_handle;
    OSDynLoad_Acquire("coreinit.rpl", &coreinit_handle);
    uint32_t (*MEMGetBaseHeapHandle)(int mem_arena);
    OSDynLoad_FindExport(coreinit_handle, 0, "MEMGetBaseHeapHandle", &MEMGetBaseHeapHandle);
    uint32_t *memalign, *freemem;
    OSDynLoad_FindExport(coreinit_handle, 0, "MEMAllocFromExpHeapEx", &memalign); 
    OSDynLoad_FindExport(coreinit_handle, 0, "MEMFreeToDefaultHeap", &freemem); 
    void* (*MEMAllocFromExpHeapEx)(uint32_t heap, uint32_t size, int align) = (void*(*)(uint32_t,uint32_t,int))*memalign;
    void  (*MEMFreeToDefaultHeap)(void *ptr) = (void (*)(void*))*freemem;

    uint32_t heap = MEMGetBaseHeapHandle(1);
    void *buffer = MEMAllocFromExpHeapEx(heap, 0x200, 0x20);
    if(buffer == NULL) OSFatal("Memory allocation failed");
    OSFatal("Buffer allocated");
    MEMFreeToDefaultHeap(buffer);
It crashes before OSFatal... no clue :unsure:
 
Last edited by eliboa,
Thanks but it doesn't work...
Must be something wrong with my code :
Code:
    uint32_t coreinit_handle;
    OSDynLoad_Acquire("coreinit.rpl", &coreinit_handle);
    uint32_t (*MEMGetBaseHeapHandle)(int mem_arena);
    OSDynLoad_FindExport(coreinit_handle, 0, "MEMGetBaseHeapHandle", &MEMGetBaseHeapHandle);
    uint32_t *memalign, *freemem;
    OSDynLoad_FindExport(coreinit_handle, 0, "MEMAllocFromExpHeapEx", &memalign);
    OSDynLoad_FindExport(coreinit_handle, 0, "MEMFreeToDefaultHeap", &freemem);
    void* (*MEMAllocFromExpHeapEx)(uint32_t heap, uint32_t size, int align) = (void*(*)(uint32_t,uint32_t,int))*memalign;
    void  (*MEMFreeToDefaultHeap)(void *ptr) = (void (*)(void*))*freemem;

    uint32_t heap = MEMGetBaseHeapHandle(1);
    void *buffer = MEMAllocFromExpHeapEx(heap, 0x200, 0x20);
    if(buffer == NULL) OSFatal("Memory allocation failed");
    OSFatal("Buffer allocated");
    MEMFreeToDefaultHeap(buffer);
It crashes before OSFatal... no clue :unsure:

What are you trying to do?

I know I'm new, but your IF syntax looks wrong... if () {};
 
Last edited by SonyUSA,
The loader works great. Thanks!

--------------------- MERGED ---------------------------

Thanks but it doesn't work...
Must be something wrong with my code :
Code:
    uint32_t coreinit_handle;
    OSDynLoad_Acquire("coreinit.rpl", &coreinit_handle);
    uint32_t (*MEMGetBaseHeapHandle)(int mem_arena);
    OSDynLoad_FindExport(coreinit_handle, 0, "MEMGetBaseHeapHandle", &MEMGetBaseHeapHandle);
    uint32_t *memalign, *freemem;
    OSDynLoad_FindExport(coreinit_handle, 0, "MEMAllocFromExpHeapEx", &memalign);
    OSDynLoad_FindExport(coreinit_handle, 0, "MEMFreeToDefaultHeap", &freemem);
    void* (*MEMAllocFromExpHeapEx)(uint32_t heap, uint32_t size, int align) = (void*(*)(uint32_t,uint32_t,int))*memalign;
    void  (*MEMFreeToDefaultHeap)(void *ptr) = (void (*)(void*))*freemem;

    uint32_t heap = MEMGetBaseHeapHandle(1);
    void *buffer = MEMAllocFromExpHeapEx(heap, 0x200, 0x20);
    if(buffer == NULL) OSFatal("Memory allocation failed");
    OSFatal("Buffer allocated");
    MEMFreeToDefaultHeap(buffer);
It crashes before OSFatal... no clue :unsure:
Keep in mind that it can never get to MEMFreeToDefaultHeap.
 

Site & Scene News

Popular threads in this forum