SG_BEGIN_DECL()
+/** Cache the size of a memory page for the current system. */
+XBT_PUBLIC_DATA(int) xbt_pagesize;
+
XBT_PUBLIC(const char *) xbt_procname(void);
#define XBT_BACKTRACE_SIZE 10 /* FIXME: better place? Do document */
raw_heap = NULL;
#else
/* Create the second region a page after the first one ends + safety gap */
- raw_heap = xbt_mheap_new(-1, (char*)(std_heap) + STD_HEAP_SIZE + getpagesize());
+ raw_heap = xbt_mheap_new(-1, (char*)(std_heap) + STD_HEAP_SIZE + xbt_pagesize);
xbt_assert(raw_heap != NULL);
#endif
}
heaplimit = ((struct mdesc *)heap1)->heaplimit;
- s_heap = (char *)mmalloc_get_current_heap() - STD_HEAP_SIZE - getpagesize();
+ s_heap = (char *)mmalloc_get_current_heap() - STD_HEAP_SIZE - xbt_pagesize;
heapbase1 = (char *)heap1 + BLOCKSIZE;
heapbase2 = (char *)heap2 + BLOCKSIZE;
/* Heap information */
heaplimit = ((struct mdesc *)heap1)->heaplimit;
- s_heap = (char *)mmalloc_get_current_heap() - STD_HEAP_SIZE - getpagesize();
+ s_heap = (char *)mmalloc_get_current_heap() - STD_HEAP_SIZE - xbt_pagesize;
heapbase1 = (char *)heap1 + BLOCKSIZE;
heapbase2 = (char *)heap2 + BLOCKSIZE;
{
int res;
if (__mmalloc_default_mdp == NULL) {
- unsigned long mask = ~((unsigned long)getpagesize() - 1);
+ unsigned long mask = ~((unsigned long)xbt_pagesize - 1);
void *addr = (void*)(((unsigned long)sbrk(0) + HEAP_OFFSET) & mask);
__mmalloc_default_mdp = xbt_mheap_new(-1, addr);
/* Fixme? only the default mdp in protected against forks */
#include "mmprivate.h"
-/* Cache the pagesize for the current host machine. Note that if the host
- does not readily provide a getpagesize() function, we need to emulate it
- elsewhere, not clutter up this file with lots of kluges to try to figure
- it out. */
-
-static size_t pagesize;
-
-#define PAGE_ALIGN(addr) (void*) (((long)(addr) + pagesize - 1) & \
- ~(pagesize - 1))
+#define PAGE_ALIGN(addr) (void*) (((long)(addr) + xbt_pagesize - 1) & \
+ ~((long)xbt_pagesize - 1))
/* Return MAP_PRIVATE if MDP represents /dev/zero. Otherwise, return
MAP_SHARED. */
char buf = 0; /* Single byte to write to extend mapped file */
// fprintf(stderr,"increase %p by %u\n",mdp,size);
- if (pagesize == 0)
- pagesize = getpagesize();
if (size == 0) {
/* Just return the current "break" value. */
#include "xbt/misc.h"
#include "simgrid_config.h" /* _XBT_WIN32 */
#include "internal_config.h" /* MMALLOC_WANT_OVERRIDE_LEGACY */
-
+#include "portable.h"
#include "xbt/sysdep.h"
#include "xbt/log.h"
#include "xbt/dynar.h"
int xbt_initialized = 0;
int _sg_do_clean_atexit = 1;
+int xbt_pagesize;
+
/* Declare xbt_preinit and xbt_postexit as constructor/destructor of the library.
* This is crude and rather compiler-specific, unfortunately.
*/
static void xbt_preinit(void) {
unsigned int seed = 2147483647;
+ xbt_pagesize = sysconf(_SC_PAGESIZE);
+
#ifdef MMALLOC_WANT_OVERRIDE_LEGACY
mmalloc_preinit();
#endif
xbt_init(&argc,argv);
XBT_INFO("Allocating a new heap");
- unsigned long mask = ~((unsigned long)getpagesize() - 1);
+ unsigned long mask = ~((unsigned long)xbt_pagesize - 1);
void *addr = (void*)(((unsigned long)sbrk(0) + BUFFSIZE) & mask);
heapA = xbt_mheap_new(-1, addr);
if (heapA == NULL) {