int i = 1;
while (argv[i] != nullptr && argv[i][0] == '-')
i++;
+ if (env.find("LD_PRELOAD") == env.end())
+ setenv("LD_PRELOAD", "libsgmalloc.so", 1);
+
for (auto const& [key, val] : env) {
- XBT_INFO("setenv '%s'='%s'", key.c_str(), val.c_str());
- setenv(key.c_str(), val.c_str(), 1);
+ if (key == "LD_PRELOAD") {
+ auto v2 = std::string("libsgmalloc.so:") + val;
+ XBT_INFO("setenv '%s'='%s'", key.c_str(), v2.c_str());
+ setenv(key.c_str(), v2.c_str(), 1);
+ } else {
+ XBT_INFO("setenv '%s'='%s'", key.c_str(), val.c_str());
+ setenv(key.c_str(), val.c_str(), 1);
+ }
}
xbt_assert(argv[i] != nullptr,
"Unable to find a binary to exec on the command line. Did you only pass config flags?");
--- /dev/null
+/* External interface to a mmap'd malloc managed region. */
+
+/* Copyright (c) 2012-2022. The SimGrid Team. All rights reserved. */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
+/* Copyright 1992, 2000 Free Software Foundation, Inc.
+
+ Contributed by Fred Fish at Cygnus Support. fnf@cygnus.com
+
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If
+ not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include "mmprivate.h"
+#include <fcntl.h> /* After sys/types.h, at least for dpx/2. */
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+// This is the underlying implementation of mmalloc_get_bytes_used_remote.
+// Is it used directly to evaluate the bytes used from a different process.
+size_t mmalloc_get_bytes_used_remote(size_t heaplimit, const malloc_info* heapinfo)
+{
+ int bytes = 0;
+ for (size_t i = 0; i < heaplimit; ++i) {
+ if (heapinfo[i].type == MMALLOC_TYPE_UNFRAGMENTED) {
+ if (heapinfo[i].busy_block.busy_size > 0)
+ bytes += heapinfo[i].busy_block.busy_size;
+ } else if (heapinfo[i].type > 0) {
+ for (size_t j = 0; j < (size_t)(BLOCKSIZE >> heapinfo[i].type); j++) {
+ if (heapinfo[i].busy_frag.frag_size[j] > 0)
+ bytes += heapinfo[i].busy_frag.frag_size[j];
+ }
+ }
+ }
+ return bytes;
+}
+
+__attribute__((weak)) xbt_mheap_t mmalloc_get_current_heap(void)
+{
+ fprintf(stderr, "Fake mmalloc_get_current_heap()\n");
+ return NULL;
+}
\ No newline at end of file
return __mmalloc_default_mdp;
}
-
-// This is the underlying implementation of mmalloc_get_bytes_used_remote.
-// Is it used directly in order to evaluate the bytes used from a different
-// process.
-size_t mmalloc_get_bytes_used_remote(size_t heaplimit, const malloc_info* heapinfo)
-{
- int bytes = 0;
- for (size_t i=0; i < heaplimit; ++i){
- if (heapinfo[i].type == MMALLOC_TYPE_UNFRAGMENTED){
- if (heapinfo[i].busy_block.busy_size > 0)
- bytes += heapinfo[i].busy_block.busy_size;
- } else if (heapinfo[i].type > 0) {
- for (size_t j=0; j < (size_t) (BLOCKSIZE >> heapinfo[i].type); j++){
- if(heapinfo[i].busy_frag.frag_size[j] > 0)
- bytes += heapinfo[i].busy_frag.frag_size[j];
- }
- }
- }
- return bytes;
-}
if(HAVE_MMALLOC)
add_executable (mmalloc_test EXCLUDE_FROM_ALL ${CMAKE_CURRENT_SOURCE_DIR}/mmalloc/mmalloc_test.cpp)
- target_link_libraries(mmalloc_test simgrid)
+ target_link_libraries(mmalloc_test simgrid sgmalloc)
set_target_properties(mmalloc_test PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/mmalloc)
set_property(TARGET mmalloc_test APPEND PROPERTY INCLUDE_DIRECTORIES "${INTERNAL_INCLUDES}")
add_dependencies(tests mmalloc_test)
)
if(HAVE_MMALLOC)
- set(XBT_SRC ${XBT_SRC} src/xbt/mmalloc/mm.c )
+ set(SGMALLOC_SRC src/xbt/mmalloc/mm.c)
else()
set(EXTRA_DIST ${EXTRA_DIST} src/xbt/mmalloc/mm.c)
endif()
src/mc/mc_smx.cpp
src/mc/udpor_global.cpp
src/mc/udpor_global.hpp
+
+ src/xbt/mmalloc/mm_interface.c
)
set(MC_SIMGRID_MC_SRC src/mc/explo/simgrid_mc.cpp)
set(EXTRA_DIST ${EXTRA_DIST} ${STHREAD_SRC})
endif()
+if(HAVE_MMALLOC)
+ add_library(sgmalloc SHARED ${SGMALLOC_SRC})
+ set_property(TARGET sgmalloc
+ APPEND PROPERTY INCLUDE_DIRECTORIES "${INTERNAL_INCLUDES}")
+endif()
+
if(enable_model-checking)
add_executable(simgrid-mc ${MC_SIMGRID_MC_SRC})
target_link_libraries(simgrid-mc simgrid)