13 st_mmap_anon (st_pointer address
, st_uint length
,
14 int protect
, int flags
)
16 /* Wrapper for mmap(), with the default flags as MAP_PRIVATE | MAP_ANONYMOUS.
17 * Returns NULL on failure.
21 result
= mmap (address
, length
, protect
,
22 flags
| MAP_PRIVATE
| MAP_ANONYMOUS
,
25 if (result
== (st_pointer
) -1) {
26 fprintf (stderr
, "panda: error: %s\n", strerror (errno
));
34 st_system_reserve_memory (st_pointer addr
, st_uint size
)
36 /* Reserves a virtual memory region without actually allocating any
37 * storage in physical memory or swap space.
41 flags
= MAP_NORESERVE
;
45 return st_mmap_anon (addr
, size
, PROT_NONE
, flags
);
49 st_system_commit_memory (st_pointer addr
, st_uint size
)
51 /* Allocates storage in physical memory or swap space.
55 if (munmap (addr
, size
) < 0) {
56 fprintf (stderr
, "panda: error: %s\n", strerror (errno
));
63 return st_mmap_anon (addr
, size
, PROT_READ
| PROT_WRITE
, flags
);
67 st_system_decommit_memory (st_pointer addr
, st_uint size
)
69 /* Deallocates any storage but ensures that the given region is still reserved
73 st_assert (addr
!= NULL
);
74 if (munmap (addr
, size
) < 0) {
75 fprintf (stderr
, "panda: error: %s\n", strerror (errno
));
79 flags
= MAP_NORESERVE
;
83 return st_mmap_anon (addr
, size
, PROT_NONE
, flags
);
87 st_system_release_memory (st_pointer addr
, st_uint size
)
89 /* destroys any virtual memory mappings within the given region
91 st_assert (addr
!= NULL
);
92 if (munmap (addr
, size
) < 0) {
93 fprintf (stderr
, "panda: error: %s\n", strerror (errno
));
94 st_assert_not_reached ();
99 st_system_pagesize (void)
101 return getpagesize ();