X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/4386010688d60bea7f54c2383aa9c923f2980948..b9625f82f86db0674e911887addce45dca31b57f:/src/xbt/mmalloc/mmorecore.c diff --git a/src/xbt/mmalloc/mmorecore.c b/src/xbt/mmalloc/mmorecore.c index 354e40b405..d59a2a3c75 100644 --- a/src/xbt/mmalloc/mmorecore.c +++ b/src/xbt/mmalloc/mmorecore.c @@ -1,6 +1,6 @@ /* Support for an sbrk-like function that uses mmap. */ -/* Copyright (c) 2010-2014. The SimGrid Team. +/* Copyright (c) 2010-2020. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -50,7 +50,7 @@ ? 0 \ : off) -/** @brief Add memoty to this heap +/** @brief Add memory to this heap * * Get core for the memory region specified by MDP, using SIZE as the * amount to either add to or subtract from the existing region. Works @@ -63,7 +63,6 @@ */ void *mmorecore(struct mdesc *mdp, ssize_t size) { - ssize_t test = 0; void* result; // please keep it uninitialized to track issues off_t foffset; /* File offset at which new mapping will start */ size_t mapbytes; /* Number of bytes to map */ @@ -80,7 +79,7 @@ void *mmorecore(struct mdesc *mdp, ssize_t size) /* We are deallocating memory. If the amount requested would cause us to try to deallocate back past the base of * the mmap'd region then die verbosely. Otherwise, deallocate the memory and return the old break value. */ if (((char*)mdp->breakval) + size >= (char*)mdp->base) { - result = (void*)mdp->breakval; + result = mdp->breakval; mdp->breakval = (char*)mdp->breakval + size; moveto = PAGE_ALIGN(mdp->breakval); munmap(moveto, (size_t)(((char*)mdp->top) - ((char*)moveto)) - 1); @@ -103,10 +102,11 @@ void *mmorecore(struct mdesc *mdp, ssize_t size) foffset = (char*)mdp->top - (char*)mdp->base; if (mdp->fd > 0) { - /* FIXME: Test results of lseek() */ - lseek(mdp->fd, foffset + mapbytes - 1, SEEK_SET); - test = write(mdp->fd, &buf, 1); - if (test == -1) { + if (lseek(mdp->fd, foffset + mapbytes - 1, SEEK_SET) == -1) { + fprintf(stderr, "Internal error: lseek into mmap'ed fd failed! error: %s", strerror(errno)); + abort(); + } + if (write(mdp->fd, &buf, 1) == -1) { fprintf(stderr,"Internal error: write to mmap'ed fd failed! error: %s", strerror(errno)); abort(); } @@ -134,18 +134,18 @@ void *mmorecore(struct mdesc *mdp, ssize_t size) mdp->base = mdp->breakval = mapto; mdp->top = PAGE_ALIGN((char*)mdp->breakval + size); - result = (void *) mdp->breakval; + result = mdp->breakval; mdp->breakval = (char*)mdp->breakval + size; } else { /* Memory is already mapped, we only need to increase the breakval: */ - result = (void *) mdp->breakval; + result = mdp->breakval; mdp->breakval = (char*)mdp->breakval + size; } } return (result); } -void *__mmalloc_remap_core(xbt_mheap_t mdp) +void* __mmalloc_remap_core(const s_xbt_mheap_t* mdp) { /* FIXME: Quick hack, needs error checking and other attention. */