summaryrefslogtreecommitdiff
path: root/emulators/ppsspp/files/patch-Common_MemoryUtil.cpp
blob: 5bba28f595f1bd2adb231ad6a6b4b9c3d3938a30 (plain) (blame)
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
--- Common/MemoryUtil.cpp.orig	2015-02-26 20:05:06 UTC
+++ Common/MemoryUtil.cpp
@@ -49,6 +49,13 @@ static SYSTEM_INFO sys_info;
 #define round_page(x) ((((uintptr_t)(x)) + PAGE_MASK) & ~(PAGE_MASK))
 #endif
 
+#if defined(__FreeBSD__)
+/* setrlimit(2) */
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/resource.h>
+#endif
+
 #ifdef __SYMBIAN32__
 #include <e32std.h>
 #define CODECHUNK_SIZE 1024*1024*20
@@ -142,6 +149,21 @@ void* AllocateExecutableMemory(size_t si
 			map_hint = (char*)round_page(&hint_location) - 0x20000000; // 0.5gb lower than our approximate location
 		else
 			map_hint = (char*)0x20000000; // 0.5GB mark in memory
+
+#if defined(__FreeBSD__)
+		// XXX Fix maximum data segment size (data + BSS + heap) to 256 MB.
+		// This allows avoiding calling mmap(2) with MAP_FIXED.
+		// On FreeBSD, without lowering this limit, calling mmap(2)
+		// without MAP_FIXED will result in getting an address just
+		// beyond maximum data segment size which will be far beyond
+		// the desired 2 GB.
+		struct rlimit limit;
+		limit.rlim_cur = 0x10000000; // 256 MB
+		limit.rlim_max = 0x10000000;
+		if(setrlimit(RLIMIT_DATA, &limit) != 0) {
+		        PanicAlert("Failed to lower maximum data segment size");
+		}
+#endif
 	}
 	else if (exec && (uintptr_t) map_hint > 0xFFFFFFFFULL)
 	{