2 Copyright © 1995-2015, The AROS Development Team. All rights reserved.
10 #include <aros/cpu.h> // for __WORDSIZE
12 #include "bootstrap.h"
18 static void *data
= NULL
;
19 static void *code
= NULL
;
20 static size_t code_len
= 0;
22 static void *RAM32
= NULL
;
23 static size_t RAM32_len
= 0;
25 #if (__WORDSIZE == 64)
26 static void *RAM
= NULL
;
27 static size_t RAM_len
= 0;
31 * Allocate memory for kickstart's .code and .rodata. We allocate it as writable
32 * because we will load the kickstart into it. We will enable execution later in SetRO().
33 * We have to use mmap() and not posix_memalign() here because posix_memalign()
34 * does not pad the allocated memory up to next page boundary. As a result, setting
35 * it read-only will affect the whole page, but the page will still have some unallocated
36 * space which can be reused by malloc().
37 * This causes DisplayError() function to crash on iOS. This also may cause similar effects
41 void *doMMap(void **addr_store
, size_t *size_store
, size_t len
, int prot
, int flags
)
43 /* There's no sense to set MAP_SHARED for ROM */
44 void *ret
= mmap(NULL
, len
, prot
, flags
, -1, 0);
46 if (ret
== MAP_FAILED
)
58 void *AllocateRO(size_t len
)
60 /* There's no sense to set MAP_SHARED for ROM */
61 return doMMap(&code
, &code_len
, len
, PROT_READ
|PROT_WRITE
, MAP_ANON
|MAP_PRIVATE
|MAP_32BIT
);
65 * Disable write and enable execution.
66 * We actually have to do this in two steps because some systems
67 * (Apple iOS) do not allow read-write-execute permissions.
69 int SetRO(void *addr
, size_t len
)
71 return mprotect(addr
, len
, PROT_READ
|PROT_EXEC
);
75 * Allocate kickstart's .data and .bss. Nothing is executed from there, so we
76 * don't have to take some special care about it. Simple malloc() is enough here.
78 void *AllocateRW(size_t len
)
85 * These routines allocate memory usable as AROS RAM. This means they
86 * need to have full permissions.
87 * Yes, iOS will silently mask out PROT_EXEC here. This is bad.
88 * Well, iOS will be a little bit special story in InternalLoadSeg()...
90 void *AllocateRAM32(size_t len
)
92 return doMMap(&RAM32
, &RAM32_len
, len
, PROT_READ
|PROT_WRITE
|PROT_EXEC
, MAP_ANON
|MAP_SHARED
|MAP_32BIT
);
95 #if (__WORDSIZE == 64)
96 void *AllocateRAM(size_t len
)
98 return doMMap(&RAM
, &RAM_len
, len
, PROT_READ
|PROT_WRITE
|PROT_EXEC
, MAP_ANON
|MAP_SHARED
);
102 void Host_FreeMem(void)
104 munmap(code
, code_len
);
106 #if (__WORDSIZE == 64)
108 munmap(RAM
, RAM_len
);
110 munmap(RAM32
, RAM32_len
);