Check-in [7413ca5b27]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Remove extra C file.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 7413ca5b277bf8e10b983fbdf2000234a5d59d9c
User & Date: stephanie.gawroriski 2019-06-16 15:27:56
Context
2019-06-16
15:52
Turn MEM_MARK_INVALID into MEM_SET_INT; Add fallback for MEM_SET and MEM_SET_INT check-in: 3437cabeb6 user: stephanie.gawroriski tags: trunk
15:27
Remove extra C file. check-in: 7413ca5b27 user: stephanie.gawroriski tags: trunk
14:23
Correct bug in the allocator where free chunks were only marked used when they had to be split. check-in: b5598278dd user: stephanie.gawroriski tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Deleted ratufacoat/rc_mem.c.

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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/* ---------------------------------------------------------------------------
// Multi-Phasic Applications: SquirrelJME
//     Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
// ---------------------------------------------------------------------------
// SquirrelJME is under the GNU General Public License v3+, or later.
// See license.mkd for licensing and copyright information.
// --------------------------------------------------------------------------*/

/**
 * This file contains the memory management functions.
 *
 * @since 2019/05/31
 */

/** Include check. */
#if !defined(SJME_CHECK_INCLUDE)
	#define SJME_CHECK_INCLUDE
#endif

#include "ratufac.h"

#if defined(RATUFACOAT_ISLINUX)
	// If this is a 64-bit system then use mmap for 32-bit addresses
	#if __WORDSIZE == 64
		#define RATUFACOAT_USELINUXMMAP 1
	#endif
	
	// Header with memory map
	#include <sys/mman.h>
#endif

/** Allocates a pointer in the low 4GiB of memory for 32-bit pointer usage. */
void* ratufacoat_memalloc(size_t len)
{
#if defined(RATUFACOAT_USELINUXMMAP)
	// Use Linux mmap method to allocate in the low address space
	void* sp;
	size_t vlen;
	uintptr_t usp;
	uint32_t vsp;
	
	// Virtual length since the mapping length needs to be included
	vlen = len + 4;
	
	// MMap 32-bit pointer
	sp = mmap(NULL, vlen, PROT_READ | PROT_WRITE,
		MAP_PRIVATE | MAP_ANONYMOUS | MAP_32BIT, -1, 0);
	if (sp == MAP_FAILED)
		return NULL;
	
	// Check to ensure the pointer is in range
	usp = (uintptr_t)sp;
	if (usp > (uintptr_t)UINT32_MAX)
	{
		munmap(sp, vlen);
		return NULL;
	}
	
	// Clear it
	memset(sp, 0, vlen);
	
	// Encode vlen
	*((uint32_t*)sp) = vlen;
	
	// Return mapped pointer
	return (void*)(usp + 4);
#else
	// Use standard C function
	void* p;
	uintptr_t up;
	
	// Allocate memory
	p = calloc(1, len);
	if (p == NULL)
		return NULL;
	
	// Check to ensure the pointer is in range
	up = (uintptr_t)p;
	if (up > (uintptr_t)UINT32_MAX)
	{
		free(p);
		return NULL;
	}
	
	// Use this pointer
	return p;
#endif
}

/** Frees a pointer which was previously allocated with ratufacoat_memalloc. */
void ratufacoat_memfree(void* p)
{
#if defined(RATUFACOAT_USELINUXMMAP)
	void* xp;
#endif
	
	// Do nothing on NULL pointers
	if (p == NULL)
		return;
	
#if defined(RATUFACOAT_USELINUXMMAP)
	// Get the true base pointer
	xp = (void*)(((uintptr_t)p) - 4);
	
	// Unmap, be sure to use the base pointer!
	munmap(xp, *(((uint32_t*)xp)));
#else
	// Use standard C free
	free(p);
#endif
}

/** Reads a Java byte from memory. */
int8_t ratufacoat_memreadjbyte(void* p, int32_t o)
{
	uint8_t* rp;
	
	// Determine real pointer to use
	rp = (uint8_t*)(((uintptr_t)p) + o);
	
	// Read from memory
	return ((int8_t)(rp[0] & 0xFF));
}

/** Reads a Java int from memory. */
int32_t ratufacoat_memreadjint(void* p, int32_t o)
{
	uint8_t* rp;
	
	// Determine real pointer to use
	rp = (uint8_t*)(((uintptr_t)p) + o);
	
	// Read from memory
	return (int32_t)(((((uint32_t)rp[0]) & 0xFF) << 24) |
		((((uint32_t)rp[1]) & 0xFF) << 16) |
		((((uint32_t)rp[2]) & 0xFF) << 8) |
		((((uint32_t)rp[3]) & 0xFF)));
}

/** Reads a Java short from memory. */
int16_t ratufacoat_memreadjshort(void* p, int32_t o)
{
	uint8_t* rp;
	
	// Determine real pointer to use
	rp = (uint8_t*)(((uintptr_t)p) + o);
	
	// Read from memory
	return (int16_t)(((((uint32_t)rp[0]) & 0xFF) << 8) |
		(((uint32_t)rp[1]) & 0xFF));
}
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<