Esempio n. 1
0
int MEM_DynLoad_DefaultAlloc(int size, int alignment, be_val<uint32_t> *outPtr)
{
   auto heap = MEMGetBaseHeapHandle(BaseHeapType::MEM2);
   auto memory = MEMAllocFromExpHeapEx(reinterpret_cast<ExpandedHeap*>(heap), size, alignment);
   *outPtr = gMemory.untranslate(memory);
   return 0;
}
static void *
allocatorExpHeapAlloc(MEMAllocator *allocator,
                      uint32_t size)
{
   return MEMAllocFromExpHeapEx(reinterpret_cast<MEMExpHeap *>(allocator->heap.get()),
                                size,
                                allocator->align);
}
Esempio n. 3
0
void
consoleInit()
{
   MEMHeapHandle mem1;

   OSScreenInit();
   bufferSizeTV = OSScreenGetBufferSizeEx(SCREEN_TV);
   bufferSizeDRC = OSScreenGetBufferSizeEx(SCREEN_DRC);

   mem1 = MEMGetBaseHeapHandle(MEM_BASE_HEAP_MEM2);
   bufferTV = MEMAllocFromExpHeapEx(mem1, bufferSizeTV, 4);
   bufferDRC = MEMAllocFromExpHeapEx(mem1, bufferSizeDRC, 4);

   OSScreenSetBufferEx(SCREEN_TV, bufferTV);
   OSScreenSetBufferEx(SCREEN_DRC, bufferDRC);

   OSScreenEnableEx(SCREEN_TV, 1);
   OSScreenEnableEx(SCREEN_DRC, 1);
}
Esempio n. 4
0
void* _memalign_r(struct _reent *r, size_t alignment, size_t size)
{
   return MEMAllocFromExpHeapEx(MEMGetBaseHeapHandle(MEM_BASE_HEAP_MEM2), size, alignment);
}
Esempio n. 5
0
void * MEMBucket_alloc(unsigned int size, unsigned int align)
{
    if (align < 4)
        align = 4;
    return MEMAllocFromExpHeapEx(bucket_heap, size, align);
}
Esempio n. 6
0
void * MEM1_alloc(unsigned int size, unsigned int align)
{
    if (align < 4)
        align = 4;
    return MEMAllocFromExpHeapEx(mem1_heap, size, align);
}
Esempio n. 7
0
//!-------------------------------------------------------------------------------------------
//! some wrappers
//!-------------------------------------------------------------------------------------------
void * MEM2_alloc(unsigned int size, unsigned int align)
{
    return MEMAllocFromExpHeapEx(MEMGetBaseHeapHandle(MEM_BASE_HEAP_MEM2), size, align);
}
Esempio n. 8
0
File: main.c Progetto: Maschell/wut
static void *
CustomAllocFromDefaultHeapEx(uint32_t size,
                             int32_t alignment)
{
   return MEMAllocFromExpHeapEx(sCustomHeap, size, alignment);
}
Esempio n. 9
0
File: main.c Progetto: Maschell/wut
static void *
CustomAllocFromDefaultHeap(uint32_t size)
{
   return MEMAllocFromExpHeapEx(sCustomHeap, size, 4);
}
Esempio n. 10
0
static void *
sMEMAllocFromDefaultHeapEx(uint32_t size, int alignment)
{
   auto heap = MEMGetBaseHeapHandle(BaseHeapType::MEM2);
   return MEMAllocFromExpHeapEx(reinterpret_cast<ExpandedHeap*>(heap), size, alignment);
}
Esempio n. 11
0
int main(int argc, char **argv)
{
   MEMHeapHandle mem2 = MEMGetBaseHeapHandle(MEM_BASE_HEAP_MEM2);
   test_assert(mem2);

   test_report("Allocating %d bytes from default heap", HeapSize);
   void *heapAddr = MEMAllocFromExpHeapEx(mem2, HeapSize, 4);
   test_assert(heapAddr);

   // Unalign the frame heap base address
   void *frameHeapAddr = heapAddr + 1;
   test_report("Creating frame heap at %p", frameHeapAddr);
   MEMHeapHandle frameHeap = MEMCreateFrmHeapEx(frameHeapAddr, HeapSize, 0);
   test_report("Frame heap created at %p", frameHeap);
   test_assert(frameHeap);
   test_assert((((uint32_t)frameHeap) % 4) == 0);

   uint32_t freeSize1 = MEMGetAllocatableSizeForFrmHeapEx(frameHeap, 4);
   test_report("Free Size before allocation: %d", freeSize1);
   test_assert((freeSize1 % 4) == 0);

   {
      // Allocate an unaligned block from head with an unaligned size
      void *unalignedBlock = MEMAllocFromFrmHeapEx(frameHeap, 5, 1);
      uint32_t unalignedBlockAddress = (uint32_t)unalignedBlock;
      test_report("Unaligned head block allocated at %p", unalignedBlock);
      test_assert(unalignedBlock);

      // Allocate an aligned block from head and ensure it is aligned
      void *alignedBlock = MEMAllocFromFrmHeapEx(frameHeap, 1024, 512);
      uint32_t alignedBlockAddress = (uint32_t)alignedBlock;
      test_report("Aligned head block allocated at %p", alignedBlock);
      test_assert(alignedBlock);
      test_assert((((uint32_t)alignedBlock) % 512) == 0);
      test_assert(alignedBlockAddress - unalignedBlockAddress >= 5);
   }

   {
      // Allocate an unaligned block from tail with an unaligned size
      void *unalignedBlock = MEMAllocFromFrmHeapEx(frameHeap, 5, -1);
      uint32_t unalignedBlockAddress = (uint32_t)unalignedBlock;
      test_report("Unaligned tail block allocated at %p", unalignedBlock);
      test_assert(unalignedBlock);

      // Allocate an aligned block from tail and ensure it is aligned
      void *alignedBlock = MEMAllocFromFrmHeapEx(frameHeap, 1024, -512);
      uint32_t alignedBlockAddress = (uint32_t)alignedBlock;
      test_report("Aligned tail block allocated at %p", alignedBlock);
      test_assert(alignedBlock);
      test_assert((((uint32_t)alignedBlock) % 512) == 0);
      test_assert(unalignedBlockAddress - alignedBlockAddress >= 512);
   }

   // Free all memory
   MEMFreeToFrmHeap(frameHeap, MEM_FRM_HEAP_FREE_ALL);

   uint32_t freeSize3 = MEMGetAllocatableSizeForFrmHeapEx(frameHeap, 4);
   test_report("Free Size after free: %d", freeSize3);
   test_assert(freeSize1 == freeSize3);

   MEMDestroyFrmHeap(frameHeap);
   MEMFreeToExpHeap(mem2, heapAddr);
   return 0;
}
Esempio n. 12
0
/**
 * Allocate memory from an expanded heap with default alignment
 */
void *
MEMAllocFromExpHeap(ExpandedHeap *heap, uint32_t size)
{
   ScopedSpinLock lock(&heap->lock);
   return MEMAllocFromExpHeapEx(heap, size, 4);
}
Esempio n. 13
0
void *
__wrap_memalign(size_t alignment, size_t size) {
   return MEMAllocFromExpHeapEx(MEMGetBaseHeapHandle(MEMORY_ARENA_2), size, alignment);
}