initheap.c
1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
=============================================================================
Copyright (C) 1997-1999 NINTENDO Co.,Ltd.
$RCSfile: initheap.c,v $
$Revision: 1.1.1.1 $
$Date: 2002/10/30 02:07:09 $
=============================================================================
関数名:InitHeap
-----------------------------------------------------------------------------
書式: #include <malloc.h>
int InitHeap(void *head, unsigned int size);
引数: head 領域確保の先頭ポインタ
size 領域のサイズ
戻り値:正常に確保出来れば0を、確保に失敗すれば−1を返す。
説明: メモリ割り当て領域確保と初期化を行う。
-----------------------------------------------------------------------------
*/
#include <ultra64.h>
#include "string.h"
#include "malloc.h"
#include "_malloc.h"
char *malloc_ptr = (char *)-1;
void *_InitHeap(void *ptr, unsigned int size)
{
unsigned int p;
struct mallocST *malloc_st_ptr;
if (size < 0x20) return (void *)-1;
p = (unsigned int)ptr;
p += 15;
p &= (~15);
size -= p - (unsigned int)(ptr);
malloc_st_ptr = (struct mallocST *)p;
malloc_st_ptr->next = 0;
malloc_st_ptr->size = size - MALLOC_HEADSIZE;
malloc_st_ptr->flag = 0;
malloc_st_ptr->allsize = size;
return malloc_st_ptr;
}
int InitHeap(void *head, unsigned int size)
{
malloc_ptr = _InitHeap(head, size);
if ((int)malloc_ptr == -1) return -1;
return 0;
}