@@ -16,7 +16,7 @@ index bab2ca3..5c9608c 100644
16
16
+++ b/rts/linker/Elf.c
17
17
@@ -131,6 +131,56 @@
18
18
https://refspecs.linuxfoundation.org/elf/gabi4+/contents.html
19
-
19
+
20
20
*/
21
21
+ void * memPoolAlloc(SectionKind kind, StgWord size);
22
22
+
@@ -26,21 +26,21 @@ index bab2ca3..5c9608c 100644
26
26
+
27
27
+ void memPoolProtect( void ) {
28
28
+ if(__pool != NULL) {
29
- + mprotect(__pool, 512 *1024*1024, PROT_READ | PROT_WRITE);
30
- + mprotect((void*)((uintptr_t)__pool + 512 *1024*1024), 512 *1024*1024, PROT_READ | PROT_WRITE | PROT_EXEC);
29
+ + mprotect(__pool, 256 *1024*1024, PROT_READ | PROT_WRITE);
30
+ + mprotect((void*)((uintptr_t)__pool + 256 *1024*1024), 256 *1024*1024, PROT_READ | PROT_WRITE | PROT_EXEC);
31
31
+ }
32
32
+ }
33
33
+
34
34
+ void * memPoolAlloc(SectionKind kind, StgWord size) {
35
35
+ if(__pool == NULL) {
36
36
+ // allocate 1 GB of virtual memory.
37
- + __pool = mmapAnonForLinker(1024 *1024*1024);
37
+ + __pool = mmapAnonForLinker(512 *1024*1024);
38
38
+ if(__pool == NULL) {
39
39
+ printf("Failed to allocate memory pool\n");
40
40
+ fflush(stdout);
41
41
+ return NULL;
42
42
+ }
43
- + __pool_rw_offset = (void*)((uintptr_t)__pool + 512 *1024*1024);
43
+ + __pool_rw_offset = (void*)((uintptr_t)__pool + 256 *1024*1024);
44
44
+ __pool_rx_offset = __pool_rw_offset;
45
45
+ }
46
46
+ // align to 64 bytes
@@ -51,7 +51,7 @@ index bab2ca3..5c9608c 100644
51
51
+ ret = __pool_rx_offset;
52
52
+ // printf("Allocated RX %p\n", ret);
53
53
+ __pool_rx_offset = (void*)((uintptr_t)__pool_rx_offset + alignedSize);
54
- + if((uintptr_t)__pool_rx_offset > (uintptr_t)__pool + 1024 *1024*1024) {
54
+ + if((uintptr_t)__pool_rx_offset > (uintptr_t)__pool + 512 *1024*1024) {
55
55
+ printf("Out of memory pool\n");
56
56
+ fflush(stdout);
57
57
+ return NULL;
@@ -68,7 +68,7 @@ index bab2ca3..5c9608c 100644
68
68
+ }
69
69
+ return ret;
70
70
+ }
71
-
71
+
72
72
#if defined(SHN_XINDEX)
73
73
/* global variable which address is used to signal an uninitialised shndx_table */
74
74
@@ -813,7 +863,8 @@ ocGetNames_ELF ( ObjectCode* oc )
@@ -84,11 +84,11 @@ index bab2ca3..5c9608c 100644
84
84
@@ -860,7 +911,8 @@ ocGetNames_ELF ( ObjectCode* oc )
85
85
unsigned nstubs = numberOfStubsForSection(oc, i);
86
86
unsigned stub_space = STUB_SIZE * nstubs;
87
-
87
+
88
88
- void * mem = mmapAnonForLinker(size+stub_space);
89
89
+ void * mem = memPoolAlloc(kind, stub_space + size);
90
90
+ // void * mem = mmapAnonForLinker(size+stub_space);
91
-
91
+
92
92
if( mem == MAP_FAILED ) {
93
93
barf("failed to mmap allocated memory to load section %d. "
94
94
@@ -967,7 +1019,8 @@ ocGetNames_ELF ( ObjectCode* oc )
@@ -104,12 +104,12 @@ index bab2ca3..5c9608c 100644
104
104
@@ -2020,7 +2073,8 @@ ocResolve_ELF ( ObjectCode* oc )
105
105
ocFlushInstructionCache( oc );
106
106
#endif
107
-
107
+
108
108
- return ocMprotect_Elf(oc);
109
109
+ // return ocMprotect_Elf(oc);
110
110
+ return true;
111
111
}
112
-
112
+
113
113
/*
114
114
diff --git a/rts/linker/Elf.h b/rts/linker/Elf.h
115
115
index 2b9ad87..cf7a541 100644
@@ -120,5 +120,5 @@ index 2b9ad87..cf7a541 100644
120
120
void freeNativeCode_ELF ( ObjectCode *nc );
121
121
void *loadNativeObj_ELF ( pathchar *path, char **errmsg );
122
122
+ void memPoolProtect ( void );
123
-
123
+
124
124
#include "EndPrivate.h"
0 commit comments