Fix x86 Windows build and testsuite
[ghc.git] / rts / sm / OSMem.h
1 /* -----------------------------------------------------------------------------
2 *
3 * (c) The University of Glasgow 2006-2008
4 *
5 * OS-specific memory management
6 *
7 * ---------------------------------------------------------------------------*/
8
9 #ifndef SM_OSMEM_H
10 #define SM_OSMEM_H
11
12 #include "BeginPrivate.h"
13
14 void osMemInit(void);
15 void *osGetMBlocks(uint32_t n);
16 void osFreeMBlocks(void *addr, uint32_t n);
17 void osReleaseFreeMemory(void);
18 void osFreeAllMBlocks(void);
19 size_t getPageSize (void);
20 StgWord64 getPhysicalMemorySize (void);
21 void setExecutable (void *p, W_ len, bool exec);
22 bool osNumaAvailable(void);
23 uint32_t osNumaNodes(void);
24 uint64_t osNumaMask(void);
25 void osBindMBlocksToNode(void *addr, StgWord size, uint32_t node);
26
27 INLINE_HEADER size_t
28 roundDownToPage (size_t x)
29 {
30 size_t size = getPageSize();
31 return (x & ~(size - 1));
32 }
33
34 INLINE_HEADER size_t
35 roundUpToPage (size_t x)
36 {
37 size_t size = getPageSize();
38 return ((x + size - 1) & ~(size - 1));
39 }
40
41
42 #ifdef USE_LARGE_ADDRESS_SPACE
43
44 /*
45 If "large address space" is enabled, we allocate memory in two
46 steps: first we request some address space, and then we request some
47 memory in it. This allows us to ask for much more address space that
48 we will ever need, which keeps everything nice and consecutive.
49 */
50
51 // Reserve the large address space blob of the given size, and return the
52 // address that the OS has chosen for it. It is not safe to access the memory
53 // pointed to by the return value, until that memory is committed using
54 // osCommitMemory().
55 //
56 // The value pointed to by len will be filled by the caller with an upper
57 // bound on the amount of memory to reserve. On return this will be set
58 // to the amount of memory actually reserved.
59 //
60 // This function is called once when the block allocator is initialized.
61 //
62 // startAddress must be greater or equal than 8 * (1 << 30), and can be
63 // NULL, in which case a default will be picked by the RTS.
64 void *osReserveHeapMemory(void *startAddress, W_ *len);
65
66 // Commit (allocate memory for) a piece of address space, which must
67 // be within the previously reserved space After this call, it is safe
68 // to access @p up to @len bytes.
69 //
70 // There is no guarantee on the contents of the memory pointed to by
71 // @p, in particular it must not be assumed to contain all zeros.
72 void osCommitMemory(void *p, W_ len);
73
74 // Decommit (release backing memory for) a piece of address space,
75 // which must be within the previously reserve space and must have
76 // been previously committed After this call, it is again unsafe to
77 // access @p (up to @len bytes), but there is no guarantee that the
78 // memory will be released to the system (as far as eg. RSS statistics
79 // from top are concerned).
80 void osDecommitMemory(void *p, W_ len);
81
82 // Release the address space previously obtained and undo the effects of
83 // osReserveHeapMemory
84 //
85 // This function is called once, when the block allocator is deinitialized
86 // before the program terminates.
87 void osReleaseHeapMemory(void);
88 #endif
89
90 #include "EndPrivate.h"
91
92 #endif /* SM_OSMEM_H */