2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
10 #include "sharedmem.h"
12 /* This is not included in my Mingw32 headers */
13 #ifndef FILE_MAP_EXECUTE
14 #define FILE_MAP_EXECUTE 0x0020
20 HANDLE RAM_Handle
= NULL
;
21 void *RAM_Address
= NULL
;
23 void *AllocateRO(size_t len
)
25 return VirtualAlloc(NULL
, len
, MEM_COMMIT
|MEM_RESERVE
, PAGE_EXECUTE_READWRITE
);
29 * Commit executable and read-only state for kickstart's .code
31 int SetRO(void *addr
, size_t len
)
35 return !VirtualProtect(addr
, len
, PAGE_EXECUTE_READ
, &old
);
38 void *AllocateRW(size_t len
)
40 return VirtualAlloc(NULL
, len
, MEM_COMMIT
|MEM_RESERVE
, PAGE_READWRITE
);
43 void *AllocateRAM32(size_t len
)
45 SECURITY_ATTRIBUTES sa
;
47 const char *var
= getenv(SHARED_RAM_VAR
);
51 D(fprintf(stderr
, "[AllocateRAM] Found RAM specification: %s\n", var
));
52 if (sscanf(var
, "%p:%p", &RAM_Handle
, &addr
) != 2) {
53 D(fprintf(stderr
, "[AllocateRAM] Error parsing specification\n"));
58 D(fprintf(stderr
, stderr
, "[AllocateRAM] Inherited memory handle 0x%p address 0x%p\n", RAM_Handle
, addr
));
62 sa
.nLength
= sizeof(sa
);
63 sa
.lpSecurityDescriptor
= NULL
;
64 sa
.bInheritHandle
= TRUE
;
65 RAM_Handle
= CreateFileMapping(INVALID_HANDLE_VALUE
, &sa
, PAGE_EXECUTE_READWRITE
, 0, len
, NULL
);
69 D(fprintf(stderr
, "[AllocateRAM] PAGE_EXECUTE_READWRITE failed, retrying with PAGE_READWRITE\n"));
70 RAM_Handle
= CreateFileMapping(INVALID_HANDLE_VALUE
, &sa
, PAGE_READWRITE
, 0, len
, NULL
);
72 D(fprintf(stderr
, "[AllocateRAM] Shared memory handle 0x%p\n", RAM_Handle
));
76 RAM_Address
= MapViewOfFileEx(RAM_Handle
, FILE_MAP_ALL_ACCESS
|FILE_MAP_EXECUTE
, 0, 0, 0, addr
);
79 D(fprintf(stderr
, "[AllocateRAM] FILE_MAP_EXECUTE failed, retrying without it\n"));
80 RAM_Address
= MapViewOfFileEx(RAM_Handle
, FILE_MAP_ALL_ACCESS
, 0, 0, 0, addr
);
82 D(fprintf(stderr
, "[AllocateRAM] Mapped at 0x%p\n", RAM_Address
));
86 CloseHandle(RAM_Handle
);