1 /*---------------------------------------------------------------------------*
2
3 Copyright (C) Nintendo. All rights reserved.
4
5 These coded instructions, statements, and computer programs contain
6 proprietary information of Nintendo of America Inc. and/or Nintendo
7 Company Ltd., and are protected by Federal copyright law. They may
8 not be disclosed to third parties or copied or duplicated in any form,
9 in whole or in part, without the prior written consent of Nintendo.
10
11 *---------------------------------------------------------------------------*/
12 #include <errno.h>
13 #include <string.h>
14 #include <cafe/mem.h>
15
16 void __gh_set_errno(int err);
17
18 /******************************************************************************/
19 /* void *sbrk (size_t size); */
20 /* Return a pointer to at least size bytes of contiguous read/write memory. */
21 /* The memory returned by sbrk on different calls need not be contiguous */
22 /* with each other (although they should be for compatibility with unix). */
23 /* */
24 /* Return -1 on an error and set errno = ENOMEM. */
25 /* */
26 /* sbrk is normally only called by malloc. */
27 /* */
28 /* WARNING: __ghs_alloc() relies on our contiguous algorithm and our */
29 /* behavior for size==0, which returns the next-available pointer. */
30 /******************************************************************************/
31
sbrk(size_t size)32 void *sbrk (size_t size)
33 {
34 /* don't need a lock as MEMAllocFromDefaultHeapEx() has it's own lock */
35 void *ret = NULL;
36 if (size != 0) {
37 ret = MEMAllocFromDefaultHeapEx(size,PPC_IO_BUFFER_ALIGN);
38 }
39 if (ret == NULL) {
40 ret = (void *)-1;
41 __gh_set_errno(ENOMEM);
42 }
43 return ret;
44 }
45
__ghs_alloc(int size,int align)46 void *__ghs_alloc (int size, int align)
47 {
48 /* MEMAllocFromDefaultHeapEx() has it's own lock __ghsLock() not needed here */
49 return MEMAllocFromDefaultHeapEx(size, align);
50 }
51