From ea9cce21b6d3f37823143217f1ca183bb2f0c9ac Mon Sep 17 00:00:00 2001 From: Gabriel Corona Date: Tue, 14 Apr 2015 15:48:06 +0200 Subject: [PATCH] [mc] Switch to C++ The code in just renamed in .cpp files and some adaptation are made (this is still C style code). --- buildtools/Cmake/DefinePackages.cmake | 66 +++++++-------- buildtools/Cmake/Flags.cmake | 2 +- buildtools/Cmake/UnitTesting.cmake | 4 +- include/xbt/dynar.h | 8 +- include/xbt/swag.h | 8 +- ...c_address_space.c => mc_address_space.cpp} | 0 src/mc/mc_address_space.h | 41 ++++++---- src/mc/{mc_base.c => mc_base.cpp} | 40 ++++++++-- src/mc/mc_base.h | 1 + src/mc/{mc_checkpoint.c => mc_checkpoint.cpp} | 46 ++++++----- src/mc/{mc_client.c => mc_client.cpp} | 12 ++- src/mc/mc_client.h | 3 +- src/mc/{mc_client_api.c => mc_client_api.cpp} | 4 + ..._determinism.c => mc_comm_determinism.cpp} | 12 ++- ...{mc_comm_pattern.c => mc_comm_pattern.cpp} | 9 ++- src/mc/mc_compare.cpp | 8 +- src/mc/{mc_config.c => mc_config.cpp} | 4 + src/mc/{mc_diff.c => mc_diff.cpp} | 71 +++++++++------- src/mc/{mc_dwarf.c => mc_dwarf.cpp} | 80 ++++++++++--------- ...f_expression.c => mc_dwarf_expression.cpp} | 11 ++- src/mc/mc_forward.h | 5 ++ src/mc/{mc_global.c => mc_global.cpp} | 24 ++++-- src/mc/{mc_hash.c => mc_hash.cpp} | 11 ++- src/mc/{mc_ignore.c => mc_ignore.cpp} | 4 + src/mc/{mc_liveness.c => mc_liveness.cpp} | 6 +- src/mc/{mc_member.c => mc_member.cpp} | 6 ++ src/mc/{mc_memory.c => mc_memory.cpp} | 4 + src/mc/mc_mmalloc.h | 7 +- ...c_model_checker.c => mc_model_checker.cpp} | 4 + .../{mc_object_info.c => mc_object_info.cpp} | 4 + src/mc/mc_object_info.h | 10 +-- src/mc/mc_page_store.cpp | 4 + src/mc/{mc_pair.c => mc_pair.cpp} | 4 + src/mc/{mc_process.c => mc_process.cpp} | 53 +++++------- src/mc/mc_process.h | 23 +++--- src/mc/{mc_protocol.c => mc_protocol.cpp} | 10 ++- src/mc/mc_protocol.h | 2 +- src/mc/{mc_record.c => mc_record.cpp} | 6 +- src/mc/{mc_request.c => mc_request.cpp} | 10 ++- src/mc/{mc_safety.c => mc_safety.cpp} | 6 +- src/mc/mc_server.cpp | 8 +- src/mc/mc_server.h | 2 + src/mc/{mc_smx.c => mc_smx.cpp} | 8 +- src/mc/{mc_snapshot.c => mc_snapshot.cpp} | 14 +++- src/mc/mc_snapshot.h | 2 +- src/mc/{mc_state.c => mc_state.cpp} | 7 +- src/mc/{mc_unw.c => mc_unw.cpp} | 12 ++- src/mc/{mc_unw_vmread.c => mc_unw_vmread.cpp} | 10 ++- src/mc/{mc_visited.c => mc_visited.cpp} | 14 ++-- src/mc/{memory_map.c => memory_map.cpp} | 6 +- src/simix/smx_context_sysv.c | 2 + src/xbt/mmalloc/mmprivate.h | 6 ++ 52 files changed, 463 insertions(+), 261 deletions(-) rename src/mc/{mc_address_space.c => mc_address_space.cpp} (100%) rename src/mc/{mc_base.c => mc_base.cpp} (85%) rename src/mc/{mc_checkpoint.c => mc_checkpoint.cpp} (96%) rename src/mc/{mc_client.c => mc_client.cpp} (95%) rename src/mc/{mc_client_api.c => mc_client_api.cpp} (99%) rename src/mc/{mc_comm_determinism.c => mc_comm_determinism.cpp} (99%) rename src/mc/{mc_comm_pattern.c => mc_comm_pattern.cpp} (97%) rename src/mc/{mc_config.c => mc_config.cpp} (99%) rename src/mc/{mc_diff.c => mc_diff.cpp} (95%) rename src/mc/{mc_dwarf.c => mc_dwarf.cpp} (94%) rename src/mc/{mc_dwarf_expression.c => mc_dwarf_expression.cpp} (99%) rename src/mc/{mc_global.c => mc_global.cpp} (99%) rename src/mc/{mc_hash.c => mc_hash.cpp} (98%) rename src/mc/{mc_ignore.c => mc_ignore.cpp} (99%) rename src/mc/{mc_liveness.c => mc_liveness.cpp} (99%) rename src/mc/{mc_member.c => mc_member.cpp} (97%) rename src/mc/{mc_memory.c => mc_memory.cpp} (99%) rename src/mc/{mc_model_checker.c => mc_model_checker.cpp} (98%) rename src/mc/{mc_object_info.c => mc_object_info.cpp} (98%) rename src/mc/{mc_pair.c => mc_pair.cpp} (98%) rename src/mc/{mc_process.c => mc_process.cpp} (93%) rename src/mc/{mc_protocol.c => mc_protocol.cpp} (94%) rename src/mc/{mc_record.c => mc_record.cpp} (98%) rename src/mc/{mc_request.c => mc_request.cpp} (99%) rename src/mc/{mc_safety.c => mc_safety.cpp} (99%) rename src/mc/{mc_smx.c => mc_smx.cpp} (98%) rename src/mc/{mc_snapshot.c => mc_snapshot.cpp} (98%) rename src/mc/{mc_state.c => mc_state.cpp} (99%) rename src/mc/{mc_unw.c => mc_unw.cpp} (96%) rename src/mc/{mc_unw_vmread.c => mc_unw_vmread.cpp} (96%) rename src/mc/{mc_visited.c => mc_visited.cpp} (98%) rename src/mc/{memory_map.c => memory_map.cpp} (98%) diff --git a/buildtools/Cmake/DefinePackages.cmake b/buildtools/Cmake/DefinePackages.cmake index 15a6ec5c8f..5ab062a559 100644 --- a/buildtools/Cmake/DefinePackages.cmake +++ b/buildtools/Cmake/DefinePackages.cmake @@ -579,73 +579,73 @@ set(JEDULE_SRC ) set(MC_SRC_BASE - src/mc/mc_base.c + src/mc/mc_base.cpp src/mc/mc_base.h src/mc/mc_record.h - src/mc/mc_record.c - src/mc/mc_config.c - src/mc/mc_global.c + src/mc/mc_record.cpp + src/mc/mc_config.cpp + src/mc/mc_global.cpp ) set(MC_SRC src/mc/mc_address_space.h - src/mc/mc_address_space.c + src/mc/mc_address_space.cpp src/mc/mc_forward.h src/mc/mc_process.h - src/mc/mc_process.c + src/mc/mc_process.cpp src/mc/mc_unw.h - src/mc/mc_unw.c - src/mc/mc_unw_vmread.c + src/mc/mc_unw.cpp + src/mc/mc_unw_vmread.cpp src/mc/mc_mmalloc.h src/mc/mc_model_checker.h - src/mc/mc_model_checker.c + src/mc/mc_model_checker.cpp src/mc/mc_object_info.h - src/mc/mc_object_info.c - src/mc/mc_checkpoint.c + src/mc/mc_object_info.cpp + src/mc/mc_checkpoint.cpp src/mc/mc_snapshot.h - src/mc/mc_snapshot.c + src/mc/mc_snapshot.cpp src/mc/mc_page_store.h src/mc/mc_page_store.cpp src/mc/mc_page_snapshot.cpp src/mc/mc_comm_pattern.h - src/mc/mc_comm_pattern.c - src/mc/mc_comm_determinism.c + src/mc/mc_comm_pattern.cpp + src/mc/mc_comm_determinism.cpp src/mc/mc_compare.cpp - src/mc/mc_diff.c - src/mc/mc_dwarf.c + src/mc/mc_diff.cpp + src/mc/mc_dwarf.cpp src/mc/mc_dwarf_attrnames.h - src/mc/mc_dwarf_expression.c + src/mc/mc_dwarf_expression.cpp src/mc/mc_dwarf_tagnames.h - src/mc/mc_hash.c - src/mc/mc_ignore.c + src/mc/mc_hash.cpp + src/mc/mc_ignore.cpp src/mc/mc_interface.h src/mc/mc_liveness.h src/mc/mc_location.h - src/mc/mc_liveness.c - src/mc/mc_record.c - src/mc/mc_member.c - src/mc/mc_memory.c - src/mc/mc_pair.c + src/mc/mc_liveness.cpp + src/mc/mc_record.cpp + src/mc/mc_member.cpp + src/mc/mc_memory.cpp + src/mc/mc_pair.cpp src/mc/mc_private.h src/mc/mc_request.h - src/mc/mc_request.c + src/mc/mc_request.cpp src/mc/mc_safety.h - src/mc/mc_safety.c + src/mc/mc_safety.cpp src/mc/mc_set.cpp src/mc/mc_state.h - src/mc/mc_state.c - src/mc/mc_visited.c + src/mc/mc_state.cpp + src/mc/mc_visited.cpp src/mc/mc_memory_map.h - src/mc/memory_map.c - src/mc/mc_client.c - src/mc/mc_client_api.c + src/mc/memory_map.cpp + src/mc/mc_client.cpp + src/mc/mc_client_api.cpp src/mc/mc_client.h src/mc/mc_protocol.h - src/mc/mc_protocol.c + src/mc/mc_protocol.cpp src/mc/mc_server.cpp src/mc/mc_server.h src/mc/mc_smx.h - src/mc/mc_smx.c + src/mc/mc_smx.cpp ) set(MC_SIMGRID_MC_SRC diff --git a/buildtools/Cmake/Flags.cmake b/buildtools/Cmake/Flags.cmake index 27aa988d29..ec05853d50 100644 --- a/buildtools/Cmake/Flags.cmake +++ b/buildtools/Cmake/Flags.cmake @@ -37,7 +37,7 @@ if(enable_compile_warnings) endif() endif() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wunused -Wpointer-arith -Wchar-subscripts -Wcomment -Wno-unknown-warning-option -Wformat -Wwrite-strings -Wno-unused-function -Wno-unused-parameter -Wno-strict-aliasing -Wclobbered -Wno-error=clobbered -Wno-format-nonliteral -Werror") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wunused -Wpointer-arith -Wchar-subscripts -Wcomment -Wformat -Wwrite-strings -Wno-unused-function -Wno-unused-parameter -Wno-strict-aliasing -Wclobbered -Wno-error=clobbered -Wno-format-nonliteral -Werror") set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -Wall") # FIXME: Q&D hack diff --git a/buildtools/Cmake/UnitTesting.cmake b/buildtools/Cmake/UnitTesting.cmake index 4cfedb0538..411ff08131 100644 --- a/buildtools/Cmake/UnitTesting.cmake +++ b/buildtools/Cmake/UnitTesting.cmake @@ -31,11 +31,11 @@ set(TEST_UNITS if(HAVE_MC) set(TEST_CFILES ${TEST_CFILES} src/mc/mc_page_store.cpp - src/mc/mc_snapshot.c + src/mc/mc_snapshot.cpp ) set(TEST_UNITS ${TEST_UNITS} ${CMAKE_CURRENT_BINARY_DIR}/src/mc_page_store_unit.cpp - ${CMAKE_CURRENT_BINARY_DIR}/src/mc_snapshot_unit.c + ${CMAKE_CURRENT_BINARY_DIR}/src/mc_snapshot_unit.cpp ) endif() diff --git a/include/xbt/dynar.h b/include/xbt/dynar.h index 31b5adbaf7..1b345149ca 100644 --- a/include/xbt/dynar.h +++ b/include/xbt/dynar.h @@ -284,11 +284,17 @@ xbt_dynar_foreach (dyn,cpt,str) { _xbt_dynar_cursor_get(_dynar,_cursor,&_data) ; \ (_cursor)++ ) +#ifndef __cplusplus #define xbt_dynar_foreach_ptr(_dynar,_cursor,_ptr) \ for (_xbt_dynar_cursor_first(_dynar,&(_cursor)) ; \ (_ptr = _cursor < _dynar->used ? xbt_dynar_get_ptr(_dynar,_cursor) : NULL) ; \ (_cursor)++ ) - +#else +#define xbt_dynar_foreach_ptr(_dynar,_cursor,_ptr) \ + for (_xbt_dynar_cursor_first(_dynar,&(_cursor)) ; \ + (_ptr = _cursor < _dynar->used ? (decltype(_ptr)) xbt_dynar_get_ptr(_dynar,_cursor) : NULL) ; \ + (_cursor)++ ) +#endif /** @} */ SG_END_DECL() diff --git a/include/xbt/swag.h b/include/xbt/swag.h index df2bdfde4d..0017a38415 100644 --- a/include/xbt/swag.h +++ b/include/xbt/swag.h @@ -149,11 +149,17 @@ static XBT_INLINE void *xbt_swag_getFirst(xbt_swag_t swag) * @param swag what to iterate over * @warning you cannot modify the \a swag while using this loop * @hideinitializer */ +#ifndef __cplusplus #define xbt_swag_foreach(obj,swag) \ for((obj)=xbt_swag_getFirst((swag)); \ (obj)!=NULL; \ (obj)=xbt_swag_getNext((obj),(swag)->offset)) - +#else +#define xbt_swag_foreach(obj,swag) \ + for((obj)=(decltype(obj)) xbt_swag_getFirst((swag)); \ + (obj)!=NULL; \ + (obj)=(decltype(obj)) xbt_swag_getNext((obj),(swag)->offset)) +#endif /** * @brief A safe swag iterator * @param obj the indice of the loop diff --git a/src/mc/mc_address_space.c b/src/mc/mc_address_space.cpp similarity index 100% rename from src/mc/mc_address_space.c rename to src/mc/mc_address_space.cpp diff --git a/src/mc/mc_address_space.h b/src/mc/mc_address_space.h index a8724bc35a..a64b07c888 100644 --- a/src/mc/mc_address_space.h +++ b/src/mc/mc_address_space.h @@ -7,22 +7,25 @@ #ifndef MC_ADDRESS_SPACE_H #define MC_ADDRESS_SPACE_H +#include + #include #include "mc_forward.h" -// ***** Data types +SG_BEGIN_DECL() -typedef enum e_adress_space_read_flags { - MC_ADDRESS_SPACE_READ_FLAGS_NONE = 0, +// ***** Data types - /** Avoid a copy for when the data is available in the current process. - * - * In this case, the return value of a MC_address_space_read might - * be different from the provided buffer. - */ - MC_ADDRESS_SPACE_READ_FLAGS_LAZY = 1 -} e_adress_space_read_flags_t; +/** Options for the read() operation + * + * - MC_ADDRESS_SPACE_READ_FLAGS_LAZY, avoid a copy when the data is + * available in the current process. In this case, the return value + * of MC_address_space_read might be different from the provided one. + */ +typedef int adress_space_read_flags_t; +#define MC_ADDRESS_SPACE_READ_FLAGS_NONE 0 +#define MC_ADDRESS_SPACE_READ_FLAGS_LAZY 1 /** Process index used when no process is available * @@ -56,21 +59,27 @@ struct s_mc_address_space { */ struct s_mc_address_space_class { const void* (*read)( - mc_address_space_t address_space, e_adress_space_read_flags_t flags, + mc_address_space_t address_space, adress_space_read_flags_t flags, void* target, const void* addr, size_t size, int process_index); mc_process_t (*get_process)(mc_address_space_t address_space); }; +typedef const void* (*mc_address_space_class_read_callback_t)( + mc_address_space_t address_space, adress_space_read_flags_t flags, + void* target, const void* addr, size_t size, + int process_index); +typedef mc_process_t (*mc_address_space_class_get_process_callback_t)(mc_address_space_t address_space); + // ***** Virtual/non-final methods /** Read data from the given address space * - * Dynamic dispatch. + * Dysnamic dispatch. */ static inline __attribute__((always_inline)) const void* MC_address_space_read( - mc_address_space_t address_space, e_adress_space_read_flags_t flags, + mc_address_space_t address_space, adress_space_read_flags_t flags, void* target, const void* addr, size_t size, int process_index) { @@ -82,8 +91,12 @@ const void* MC_address_space_read( static inline __attribute__((always_inline)) const void* MC_address_space_get_process(mc_address_space_t address_space) { - return address_space->address_space_class->get_process(address_space); + if (address_space->address_space_class->get_process) + return address_space->address_space_class->get_process(address_space); + else + return NULL; } +SG_END_DECL() #endif diff --git a/src/mc/mc_base.c b/src/mc/mc_base.cpp similarity index 85% rename from src/mc/mc_base.c rename to src/mc/mc_base.cpp index 65052ef791..fd67dae861 100644 --- a/src/mc/mc_base.c +++ b/src/mc/mc_base.cpp @@ -20,6 +20,8 @@ #include "mc_server.h" #endif +extern "C" { + XBT_LOG_NEW_CATEGORY(mc, "All MC categories"); void MC_wait_for_requests(void) @@ -64,7 +66,7 @@ int MC_request_is_enabled(smx_simcall_t req) #ifdef HAVE_MC // Fetch from MCed memory: if (!MC_process_is_self(&mc_model_checker->process)) { - MC_process_read(&mc_model_checker->process, MC_PROCESS_NO_FLAG, + MC_process_read(&mc_model_checker->process, MC_ADDRESS_SPACE_READ_FLAGS_NONE, &temp_synchro, act, sizeof(temp_synchro), MC_PROCESS_INDEX_ANY); act = &temp_synchro; @@ -108,7 +110,7 @@ int MC_request_is_enabled(smx_simcall_t req) #ifdef HAVE_MC // Fetch from MCed memory: if (!MC_process_is_self(&mc_model_checker->process)) { - MC_process_read(&mc_model_checker->process, MC_PROCESS_NO_FLAG, + MC_process_read(&mc_model_checker->process, MC_ADDRESS_SPACE_READ_FLAGS_NONE, &temp_synchro, act, sizeof(temp_synchro), MC_PROCESS_INDEX_ANY); act = &temp_synchro; @@ -126,7 +128,7 @@ int MC_request_is_enabled(smx_simcall_t req) #ifdef HAVE_MC s_smx_mutex_t temp_mutex; if (!MC_process_is_self(&mc_model_checker->process)) { - MC_process_read(&mc_model_checker->process, MC_PROCESS_NO_FLAG, + MC_process_read(&mc_model_checker->process, MC_ADDRESS_SPACE_READ_FLAGS_NONE, &temp_mutex, mutex, sizeof(temp_mutex), MC_PROCESS_INDEX_ANY); mutex = &temp_mutex; @@ -181,12 +183,12 @@ static int prng_random(int min, int max) unsigned long accept_size = input_size - reject_size; // module*accept_size // Use rejection in order to avoid skew - long x; + unsigned long x; do { #ifndef _XBT_WIN32 - x = random(); + x = (unsigned long) random(); #else - x = rand(); + x = (unsigned long) rand(); #endif } while( x >= accept_size ); return min + (x % output_size); @@ -200,3 +202,29 @@ int simcall_HANDLER_mc_random(smx_simcall_t simcall, int min, int max) return simcall->mc_value; } + +void MC_simcall_handle(smx_simcall_t req, int value) +{ +#ifndef HAVE_MC + SIMIX_simcall_handle(req, value); +#else + if (MC_process_is_self(&mc_model_checker->process)) { + SIMIX_simcall_handle(req, value); + return; + } + + unsigned i; + mc_smx_process_info_t pi = NULL; + + xbt_dynar_foreach_ptr(mc_model_checker->process.smx_process_infos, i, pi) { + if (req == &pi->copy.simcall) { + MC_server_simcall_handle(&mc_model_checker->process, pi->copy.pid, value); + return; + } + } + + xbt_die("Could not find the request"); +#endif +} + +} diff --git a/src/mc/mc_base.h b/src/mc/mc_base.h index c21a00bc26..d972c52b40 100644 --- a/src/mc/mc_base.h +++ b/src/mc/mc_base.h @@ -7,6 +7,7 @@ #ifndef MC_BASE_H #define MC_BASE_H +#include #include #include "simgrid_config.h" #include "internal_config.h" diff --git a/src/mc/mc_checkpoint.c b/src/mc/mc_checkpoint.cpp similarity index 96% rename from src/mc/mc_checkpoint.c rename to src/mc/mc_checkpoint.cpp index b2a0538787..1db06bc863 100644 --- a/src/mc/mc_checkpoint.c +++ b/src/mc/mc_checkpoint.cpp @@ -4,8 +4,6 @@ /* 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. */ -#define _GNU_SOURCE - #include #include @@ -37,6 +35,8 @@ #include "mc_protocol.h" #include "mc_smx.h" +extern "C" { + XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_checkpoint, mc, "Logging specific to mc_checkpoint"); @@ -295,7 +295,7 @@ static void MC_get_memory_regions(mc_process_t process, mc_snapshot_t snapshot) * */ void MC_find_object_address(memory_map_t maps, mc_object_info_t result) { - unsigned int i = 0; + ssize_t i = 0; s_map_region_t reg; const char *name = basename(result->file_name); while (i < maps->mapsize) { @@ -307,26 +307,26 @@ void MC_find_object_address(memory_map_t maps, mc_object_info_t result) xbt_assert(!result->start_rw, "Multiple read-write segments for %s, not supported", maps->regions[i].pathname); - result->start_rw = reg.start_addr; - result->end_rw = reg.end_addr; + result->start_rw = (char*) reg.start_addr; + result->end_rw = (char*) reg.end_addr; // .bss is usually after the .data: s_map_region_t *next = &(maps->regions[i + 1]); if (next->pathname == NULL && (next->prot & PROT_WRITE) && next->start_addr == reg.end_addr) { - result->end_rw = maps->regions[i + 1].end_addr; + result->end_rw = (char*) maps->regions[i + 1].end_addr; } } else if ((reg.prot & PROT_READ) && (reg.prot & PROT_EXEC)) { xbt_assert(!result->start_exec, "Multiple executable segments for %s, not supported", maps->regions[i].pathname); - result->start_exec = reg.start_addr; - result->end_exec = reg.end_addr; + result->start_exec = (char*) reg.start_addr; + result->end_exec = (char*) reg.end_addr; } else if ((reg.prot & PROT_READ) && !(reg.prot & PROT_EXEC)) { xbt_assert(!result->start_ro, "Multiple read only segments for %s, not supported", maps->regions[i].pathname); - result->start_ro = reg.start_addr; - result->end_ro = reg.end_addr; + result->start_ro = (char*) reg.start_addr; + result->end_ro = (char*) reg.end_addr; } i++; } @@ -554,7 +554,7 @@ static xbt_dynar_t MC_take_snapshot_stacks(mc_snapshot_t * snapshot) unw_word_t sp = xbt_dynar_get_as(st->stack_frames, 0, mc_stack_frame_t)->sp; xbt_dynar_push(res, &st); - (*snapshot)->stack_sizes = + (*snapshot)->stack_sizes = (size_t*) xbt_realloc((*snapshot)->stack_sizes, (cursor + 1) * sizeof(size_t)); (*snapshot)->stack_sizes[cursor] = (char*) current_stack->address + current_stack->size - (char*) sp; @@ -659,8 +659,10 @@ static void MC_get_current_fd(mc_snapshot_t snapshot) const size_t fd_dir_path_size = 20; char fd_dir_path[fd_dir_path_size]; - if (snprintf(fd_dir_path, fd_dir_path_size, - "/proc/%lli/fd", (long long int) snapshot->process->pid) > fd_dir_path_size) + int res = snprintf(fd_dir_path, fd_dir_path_size, + "/proc/%lli/fd", (long long int) snapshot->process->pid); + xbt_assert(res >= 0); + if ((size_t) res > fd_dir_path_size) xbt_die("Unexpected buffer is too small for fd_dir_path"); DIR* fd_dir = opendir(fd_dir_path); @@ -678,13 +680,15 @@ static void MC_get_current_fd(mc_snapshot_t snapshot) const size_t source_size = 25; char source[25]; - if (snprintf(source, source_size, "/proc/%lli/fd/%s", - (long long int) snapshot->process->pid, fd_number->d_name) > source_size) + int res = snprintf(source, source_size, "/proc/%lli/fd/%s", + (long long int) snapshot->process->pid, fd_number->d_name); + xbt_assert(res >= 0); + if ((size_t) res > source_size) xbt_die("Unexpected buffer is too small for fd %s", fd_number->d_name); const size_t link_size = 200; char link[200]; - int res = readlink(source, link, link_size); + res = readlink(source, link, link_size); if (res<0) { xbt_die("Could not read link for %s", source); } @@ -720,7 +724,7 @@ static void MC_get_current_fd(mc_snapshot_t snapshot) fd->number = fd_value; fd->flags = fcntl(fd_value, F_GETFL) | fcntl(fd_value, F_GETFD) ; fd->current_position = lseek(fd_value, 0, SEEK_CUR); - snapshot->current_fd = xbt_realloc(snapshot->current_fd, (total_fd + 1) * sizeof(fd_infos_t)); + snapshot->current_fd = (fd_infos_t*) xbt_realloc(snapshot->current_fd, (total_fd + 1) * sizeof(fd_infos_t)); snapshot->current_fd[total_fd] = fd; total_fd++; } @@ -730,7 +734,8 @@ static void MC_get_current_fd(mc_snapshot_t snapshot) } static s_mc_address_space_class_t mc_snapshot_class = { - .read = (void*) &MC_snapshot_read + .read = (mc_address_space_class_read_callback_t) &MC_snapshot_read, + .get_process = NULL }; mc_snapshot_t MC_take_snapshot(int num_state) @@ -817,8 +822,7 @@ void MC_restore_snapshot_fds(mc_snapshot_t snapshot) xbt_die("FD snapshot not implemented in client/server mode."); int new_fd; - size_t i; - for(i=0; i < snapshot->total_fd; i++){ + for (int i=0; i < snapshot->total_fd; i++) { new_fd = open(snapshot->current_fd[i]->filename, snapshot->current_fd[i]->flags); if (new_fd <0) { @@ -860,3 +864,5 @@ mc_snapshot_t simcall_HANDLER_mc_snapshot(smx_simcall_t simcall) { return MC_take_snapshot(1); } + +} diff --git a/src/mc/mc_client.c b/src/mc/mc_client.cpp similarity index 95% rename from src/mc/mc_client.c rename to src/mc/mc_client.cpp index 7403eb244c..984a221ac0 100644 --- a/src/mc/mc_client.c +++ b/src/mc/mc_client.cpp @@ -25,6 +25,8 @@ #include "mc_private.h" // MC_deadlock_check() #include "mc_smx.h" +extern "C" { + XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_client, mc, "MC client logic"); mc_client_t mc_client; @@ -68,7 +70,7 @@ void MC_client_send_message(void* message, size_t size) xbt_die("Could not send message %i", (int) ((mc_message_t)message)->type); } -void MC_client_send_simple_message(int type) +void MC_client_send_simple_message(e_mc_message_type type) { if (MC_protocol_send_simple_message(mc_client->fd, type)) xbt_die("Could not send message %i", type); @@ -80,12 +82,12 @@ void MC_client_handle_messages(void) XBT_DEBUG("Waiting messages from model-checker"); char message_buffer[MC_MESSAGE_LENGTH]; - size_t s; - if ((s = MC_receive_message(mc_client->fd, &message_buffer, sizeof(message_buffer), 0)) == -1) + ssize_t s; + if ((s = MC_receive_message(mc_client->fd, &message_buffer, sizeof(message_buffer), 0)) < 0) xbt_die("Could not receive commands from the model-checker"); s_mc_message_t message; - if (s < sizeof(message)) + if ((size_t) s < sizeof(message)) xbt_die("Received message is too small"); memcpy(&message, message_buffer, sizeof(message)); switch (message.type) { @@ -136,3 +138,5 @@ void MC_client_main_loop(void) MC_wait_for_requests(); } } + +} diff --git a/src/mc/mc_client.h b/src/mc/mc_client.h index 7f82c11769..6e1bdb5f02 100644 --- a/src/mc/mc_client.h +++ b/src/mc/mc_client.h @@ -8,6 +8,7 @@ #define MC_CLIENT_H #include +#include "mc_protocol.h" SG_BEGIN_DECL() @@ -22,7 +23,7 @@ void MC_client_init(void); void MC_client_hello(void); void MC_client_handle_messages(void); void MC_client_send_message(void* message, size_t size); -void MC_client_send_simple_message(int type); +void MC_client_send_simple_message(e_mc_message_type type); #ifdef HAVE_MC void MC_ignore(void* addr, size_t size); diff --git a/src/mc/mc_client_api.c b/src/mc/mc_client_api.cpp similarity index 99% rename from src/mc/mc_client_api.c rename to src/mc/mc_client_api.cpp index f9d58db27c..e180720787 100644 --- a/src/mc/mc_client_api.c +++ b/src/mc/mc_client_api.cpp @@ -17,6 +17,8 @@ #include "mc_protocol.h" #include "mc_client.h" +extern "C" { + XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_client_api, mc, "Public API for the model-checked application"); @@ -70,3 +72,5 @@ void MC_ignore(void* addr, size_t size) MC_process_ignore_memory(&mc_model_checker->process, addr, size); mmalloc_set_current_heap(heap); } + +} diff --git a/src/mc/mc_comm_determinism.c b/src/mc/mc_comm_determinism.cpp similarity index 99% rename from src/mc/mc_comm_determinism.c rename to src/mc/mc_comm_determinism.cpp index 2ae9d1c9d1..ab30d5c14d 100644 --- a/src/mc/mc_comm_determinism.c +++ b/src/mc/mc_comm_determinism.cpp @@ -13,6 +13,8 @@ #include "mc_smx.h" #include "mc_client.h" +extern "C" { + XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_comm_determinism, mc, "Logging specific to MC communication determinism detection"); @@ -37,15 +39,15 @@ static e_mc_comm_pattern_difference_t compare_comm_pattern(mc_comm_pattern_t com if (comm1->data_size != comm2->data_size) return DATA_SIZE_DIFF; if(comm1->data == NULL && comm2->data == NULL) - return 0; + return NONE_DIFF; if(comm1->data != NULL && comm2->data !=NULL) { if (!memcmp(comm1->data, comm2->data, comm1->data_size)) - return 0; + return NONE_DIFF; return DATA_DIFF; }else{ return DATA_DIFF; } - return 0; + return NONE_DIFF; } static char* print_determinism_result(e_mc_comm_pattern_difference_t diff, int process, mc_comm_pattern_t comm, unsigned int cursor) { @@ -469,7 +471,7 @@ static void MC_modelcheck_comm_determinism_main(void) MC_SET_MC_HEAP; - while ((state = xbt_fifo_shift(mc_stack)) != NULL) { + while ((state = (mc_state_t) xbt_fifo_shift(mc_stack)) != NULL) { if (MC_state_interleave_size(state) && xbt_fifo_size(mc_stack) < _sg_mc_max_depth) { /* We found a back-tracking point, let's loop */ XBT_DEBUG("Back-tracking to state %d at depth %d", state->num, xbt_fifo_size(mc_stack) + 1); @@ -528,3 +530,5 @@ void MC_modelcheck_comm_determinism(void) mmalloc_set_current_heap(heap); } + +} diff --git a/src/mc/mc_comm_pattern.c b/src/mc/mc_comm_pattern.cpp similarity index 97% rename from src/mc/mc_comm_pattern.c rename to src/mc/mc_comm_pattern.cpp index 37a90b3d69..0141625341 100644 --- a/src/mc/mc_comm_pattern.c +++ b/src/mc/mc_comm_pattern.cpp @@ -12,6 +12,8 @@ #include "mc_comm_pattern.h" #include "mc_smx.h" +extern "C" { + XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_comm_pattern, mc, "Logging specific to MC communication patterns"); @@ -74,7 +76,7 @@ void MC_restore_communications_pattern(mc_state_t state) list_process_comm->index_comm = (int)xbt_dynar_get_as(state->index_comm, cursor, int); } - for (int i = 0; i < MC_smx_get_maxpid(); i++) { + for (unsigned i = 0; i < MC_smx_get_maxpid(); i++) { MC_patterns_copy( xbt_dynar_get_as(incomplete_communications_pattern, i, xbt_dynar_t), xbt_dynar_get_as(state->incomplete_comm_pattern, i, xbt_dynar_t) @@ -86,8 +88,7 @@ void MC_state_copy_incomplete_communications_pattern(mc_state_t state) { state->incomplete_comm_pattern = xbt_dynar_new(sizeof(xbt_dynar_t), xbt_dynar_free_voidp); - int i; - for (i=0; i < MC_smx_get_maxpid(); i++) { + for (unsigned i=0; i < MC_smx_get_maxpid(); i++) { xbt_dynar_t comms = xbt_dynar_get_as(incomplete_communications_pattern, i, xbt_dynar_t); xbt_dynar_t copy = MC_comm_patterns_dup(comms); xbt_dynar_insert_at(state->incomplete_comm_pattern, i, ©); @@ -160,3 +161,5 @@ void MC_list_comm_pattern_free_voidp(void *p) { MC_list_comm_pattern_free((mc_list_comm_pattern_t) * (void **) p); } + +} diff --git a/src/mc/mc_compare.cpp b/src/mc/mc_compare.cpp index 3420b02989..2d66dbaf61 100644 --- a/src/mc/mc_compare.cpp +++ b/src/mc/mc_compare.cpp @@ -8,6 +8,8 @@ #include #include +#include + #include "internal_config.h" #include "mc_object_info.h" #include "mc_safety.h" @@ -24,9 +26,6 @@ #include -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_compare, mc, - "Logging specific to mc_compare"); - typedef struct s_pointers_pair { void *p1; void *p2; @@ -55,6 +54,9 @@ struct mc_compare_state { extern "C" { +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_compare, xbt, + "Logging specific to mc_compare in mc"); + /************************** Free functions ****************************/ /********************************************************************/ diff --git a/src/mc/mc_config.c b/src/mc/mc_config.cpp similarity index 99% rename from src/mc/mc_config.c rename to src/mc/mc_config.cpp index 79e2be36a0..9239ba8774 100644 --- a/src/mc/mc_config.c +++ b/src/mc/mc_config.cpp @@ -20,6 +20,8 @@ #include "mc_record.h" +extern "C" { + XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_config, mc, "Configuration of MC"); @@ -183,3 +185,5 @@ void _mc_cfg_cb_termination(const char *name, int pos) } #endif + +} diff --git a/src/mc/mc_diff.c b/src/mc/mc_diff.cpp similarity index 95% rename from src/mc/mc_diff.c rename to src/mc/mc_diff.cpp index c526fe9d64..5b692dcb0a 100644 --- a/src/mc/mc_diff.c +++ b/src/mc/mc_diff.cpp @@ -15,6 +15,8 @@ #include "mc/mc_private.h" #include "mc/mc_snapshot.h" +extern "C" { + XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_diff, xbt, "Logging specific to mc_diff in mc"); @@ -375,19 +377,19 @@ int init_heap_information(xbt_mheap_t heap1, xbt_mheap_t heap2, xbt_dynar_t i1, state->to_ignore2 = i2; if (state->heaplimit > state->available) { - state->equals_to1 = + state->equals_to1 = (s_heap_area_t*) realloc(state->equals_to1, state->heaplimit * MAX_FRAGMENT_PER_BLOCK * sizeof(s_heap_area_t)); - state->types1 = + state->types1 = (s_dw_type**) realloc(state->types1, state->heaplimit * MAX_FRAGMENT_PER_BLOCK * sizeof(type_name *)); - state->equals_to2 = + state->equals_to2 = (s_heap_area_t*) realloc(state->equals_to2, state->heaplimit * MAX_FRAGMENT_PER_BLOCK * sizeof(s_heap_area_t)); - state->types2 = + state->types2 = (s_dw_type**) realloc(state->types2, state->heaplimit * MAX_FRAGMENT_PER_BLOCK * sizeof(type_name *)); @@ -451,13 +453,13 @@ int mmalloc_compare_heap(mc_snapshot_t snapshot1, mc_snapshot_t snapshot2) void* heapinfo_address = &((xbt_mheap_t) process->heap_address)->heapinfo; // This is in snapshot do not use them directly: - const malloc_info* heapinfos1 = MC_snapshot_read_pointer(snapshot1, heapinfo_address, MC_PROCESS_INDEX_MISSING); - const malloc_info* heapinfos2 = MC_snapshot_read_pointer(snapshot2, heapinfo_address, MC_PROCESS_INDEX_MISSING); + const malloc_info* heapinfos1 = (const malloc_info*) MC_snapshot_read_pointer(snapshot1, heapinfo_address, MC_PROCESS_INDEX_MISSING); + const malloc_info* heapinfos2 = (const malloc_info*) MC_snapshot_read_pointer(snapshot2, heapinfo_address, MC_PROCESS_INDEX_MISSING); while (i1 <= state->heaplimit) { - const malloc_info* heapinfo1 = MC_region_read(heap_region1, &heapinfo_temp1, &heapinfos1[i1], sizeof(malloc_info)); - const malloc_info* heapinfo2 = MC_region_read(heap_region2, &heapinfo_temp2, &heapinfos2[i1], sizeof(malloc_info)); + const malloc_info* heapinfo1 = (const malloc_info*) MC_region_read(heap_region1, &heapinfo_temp1, &heapinfos1[i1], sizeof(malloc_info)); + const malloc_info* heapinfo2 = (const malloc_info*) MC_region_read(heap_region2, &heapinfo_temp2, &heapinfos2[i1], sizeof(malloc_info)); if (heapinfo1->type == MMALLOC_TYPE_FREE || heapinfo1->type == MMALLOC_TYPE_HEAPINFO) { /* Free block */ i1 ++; @@ -528,7 +530,7 @@ int mmalloc_compare_heap(mc_snapshot_t snapshot1, mc_snapshot_t snapshot2) continue; } - const malloc_info* heapinfo2b = MC_region_read(heap_region2, &heapinfo_temp2b, &heapinfos2[i2], sizeof(malloc_info)); + const malloc_info* heapinfo2b = (const malloc_info*) MC_region_read(heap_region2, &heapinfo_temp2b, &heapinfos2[i2], sizeof(malloc_info)); if (heapinfo2b->type != MMALLOC_TYPE_UNFRAGMENTED) { i2++; @@ -605,7 +607,9 @@ int mmalloc_compare_heap(mc_snapshot_t snapshot1, mc_snapshot_t snapshot2) while (i2 <= state->heaplimit && !equal) { - const malloc_info* heapinfo2b = MC_region_read(heap_region2, &heapinfo_temp2b, &heapinfos2[i2], sizeof(malloc_info)); + const malloc_info* heapinfo2b = (const malloc_info*) MC_region_read( + heap_region2, &heapinfo_temp2b, &heapinfos2[i2], + sizeof(malloc_info)); if (heapinfo2b->type == MMALLOC_TYPE_FREE || heapinfo2b->type == MMALLOC_TYPE_HEAPINFO) { i2 ++; @@ -676,7 +680,8 @@ int mmalloc_compare_heap(mc_snapshot_t snapshot1, mc_snapshot_t snapshot2) size_t i = 1, j = 0; for(i = 1; i <= state->heaplimit; i++) { - const malloc_info* heapinfo1 = MC_region_read(heap_region1, &heapinfo_temp1, &heapinfos1[i], sizeof(malloc_info)); + const malloc_info* heapinfo1 = (const malloc_info*) MC_region_read( + heap_region1, &heapinfo_temp1, &heapinfos1[i], sizeof(malloc_info)); if (heapinfo1->type == MMALLOC_TYPE_UNFRAGMENTED) { if (i1 == state->heaplimit) { if (heapinfo1->busy_block.busy_size > 0) { @@ -717,7 +722,8 @@ int mmalloc_compare_heap(mc_snapshot_t snapshot1, mc_snapshot_t snapshot2) XBT_DEBUG("Number of blocks/fragments not found in heap1 : %d", nb_diff1); for (i=1; i <= state->heaplimit; i++) { - const malloc_info* heapinfo2 = MC_region_read(heap_region2, &heapinfo_temp2, &heapinfos2[i], sizeof(malloc_info)); + const malloc_info* heapinfo2 = (const malloc_info*) MC_region_read( + heap_region2, &heapinfo_temp2, &heapinfos2[i], sizeof(malloc_info)); if (heapinfo2->type == MMALLOC_TYPE_UNFRAGMENTED) { if (i1 == state->heaplimit) { if (heapinfo2->busy_block.busy_size > 0) { @@ -885,7 +891,7 @@ top: } dw_type_t subtype, subsubtype; - int res, elm_size, i; + int res, elm_size; unsigned int cursor = 0; dw_type_t member; const void *addr_pointed1, *addr_pointed2;; @@ -955,7 +961,7 @@ top: return 0; break; } - for (i = 0; i < type->element_count; i++) { + for (int i = 0; i < type->element_count; i++) { // TODO, add support for variable stride (DW_AT_byte_stride) res = compare_heap_area_with_type(state, process_index, @@ -978,7 +984,7 @@ top: } else { pointer_level++; if (pointer_level > 1) { /* Array of pointers */ - for (i = 0; i < (area_size / sizeof(void *)); i++) { + for (size_t i = 0; i < (area_size / sizeof(void *)); i++) { addr_pointed1 = MC_snapshot_read_pointer(snapshot1, (char*) real_area1 + i * sizeof(void *), process_index); addr_pointed2 = MC_snapshot_read_pointer(snapshot2, (char*) real_area2 + i * sizeof(void *), process_index); if (addr_pointed1 > state->std_heap_copy.heapbase @@ -1015,7 +1021,7 @@ top: type = type->full_type; if (area_size != -1 && type->byte_size != area_size) { if (area_size > type->byte_size && area_size % type->byte_size == 0) { - for (i = 0; i < (area_size / type->byte_size); i++) { + for (size_t i = 0; i < (size_t)(area_size / type->byte_size); i++) { res = compare_heap_area_with_type(state, process_index, (char *) real_area1 + i * type->byte_size, @@ -1032,9 +1038,9 @@ top: cursor = 0; xbt_dynar_foreach(type->members, cursor, member) { // TODO, optimize this? (for the offset case) - char *real_member1 = + void *real_member1 = mc_member_resolve(real_area1, type, member, (mc_address_space_t) snapshot1, process_index); - char *real_member2 = + void *real_member2 = mc_member_resolve(real_area2, type, member, (mc_address_space_t) snapshot2, process_index); res = compare_heap_area_with_type(state, process_index, real_member1, real_member2, @@ -1100,9 +1106,10 @@ static dw_type_t get_offset_type(void *real_base_address, dw_type_t type, if (member->offset == offset) return member->subtype; } else { - char *real_member = - mc_member_resolve(real_base_address, type, member, (mc_address_space_t) snapshot, process_index); - if (real_member - (char *) real_base_address == offset) + void *real_member = + mc_member_resolve(real_base_address, type, member, + (mc_address_space_t) snapshot, process_index); + if ((char*) real_member - (char *) real_base_address == offset) return member->subtype; } @@ -1152,8 +1159,10 @@ int compare_heap_area(int process_index, const void *area1, const void *area2, m // This is the address of std_heap->heapinfo in the application process: void* heapinfo_address = &((xbt_mheap_t) process->heap_address)->heapinfo; - const malloc_info* heapinfos1 = MC_snapshot_read_pointer(snapshot1, heapinfo_address, process_index); - const malloc_info* heapinfos2 = MC_snapshot_read_pointer(snapshot2, heapinfo_address, process_index); + const malloc_info* heapinfos1 = (const malloc_info*) MC_snapshot_read_pointer( + snapshot1, heapinfo_address, process_index); + const malloc_info* heapinfos2 = (const malloc_info*) MC_snapshot_read_pointer( + snapshot2, heapinfo_address, process_index); malloc_info heapinfo_temp1, heapinfo_temp2; @@ -1181,9 +1190,9 @@ int compare_heap_area(int process_index, const void *area1, const void *area2, m } // If either block is not in the expected area of memory: if (((char *) area1 < (char *) state->std_heap_copy.heapbase) - || (block1 > state->heapsize1) || (block1 < 1) + || (block1 > (ssize_t) state->heapsize1) || (block1 < 1) || ((char *) area2 < (char *) state->std_heap_copy.heapbase) - || (block2 > state->heapsize2) || (block2 < 1)) { + || (block2 > (ssize_t) state->heapsize2) || (block2 < 1)) { if (match_pairs) { xbt_dynar_free(&previous); } @@ -1218,8 +1227,10 @@ int compare_heap_area(int process_index, const void *area1, const void *area2, m mc_mem_region_t heap_region1 = MC_get_heap_region(snapshot1); mc_mem_region_t heap_region2 = MC_get_heap_region(snapshot2); - const malloc_info* heapinfo1 = MC_region_read(heap_region1, &heapinfo_temp1, &heapinfos1[block1], sizeof(malloc_info)); - const malloc_info* heapinfo2 = MC_region_read(heap_region2, &heapinfo_temp2, &heapinfos2[block2], sizeof(malloc_info)); + const malloc_info* heapinfo1 = (const malloc_info*) MC_region_read( + heap_region1, &heapinfo_temp1, &heapinfos1[block1], sizeof(malloc_info)); + const malloc_info* heapinfo2 = (const malloc_info*) MC_region_read( + heap_region2, &heapinfo_temp2, &heapinfos2[block2], sizeof(malloc_info)); if ((heapinfo1->type == MMALLOC_TYPE_FREE || heapinfo1->type==MMALLOC_TYPE_HEAPINFO) && (heapinfo2->type == MMALLOC_TYPE_FREE || heapinfo2->type ==MMALLOC_TYPE_HEAPINFO)) { @@ -1252,8 +1263,8 @@ int compare_heap_area(int process_index, const void *area1, const void *area2, m } if (type_size != -1) { - if (type_size != heapinfo1->busy_block.busy_size - && type_size != heapinfo2->busy_block.busy_size + if (type_size != (ssize_t) heapinfo1->busy_block.busy_size + && type_size != (ssize_t) heapinfo2->busy_block.busy_size && (type->name == NULL || !strcmp(type->name, "struct s_smx_context"))) { if (match_pairs) { match_equals(state, previous); @@ -1732,3 +1743,5 @@ int mmalloc_linear_compare_heap(xbt_mheap_t heap1, xbt_mheap_t heap2) } #endif + +} diff --git a/src/mc/mc_dwarf.c b/src/mc/mc_dwarf.cpp similarity index 94% rename from src/mc/mc_dwarf.c rename to src/mc/mc_dwarf.cpp index 55de42ecb9..1fb7db17b8 100644 --- a/src/mc/mc_dwarf.c +++ b/src/mc/mc_dwarf.cpp @@ -17,6 +17,8 @@ #include "mc_object_info.h" #include "mc_private.h" +extern "C" { + static void MC_dwarf_register_global_variable(mc_object_info_t info, dw_variable_t variable); static void MC_register_variable(mc_object_info_t info, dw_frame_t frame, dw_variable_t variable); static void MC_dwarf_register_non_global_variable(mc_object_info_t info, dw_frame_t frame, dw_variable_t variable); @@ -61,13 +63,13 @@ static uint64_t MC_dwarf_array_element_count(Dwarf_Die * die, Dwarf_Die * unit); */ static void MC_dwarf_handle_die(mc_object_info_t info, Dwarf_Die * die, Dwarf_Die * unit, dw_frame_t frame, - const char *namespace); + const char *ns); /** \brief Process a type DIE */ static void MC_dwarf_handle_type_die(mc_object_info_t info, Dwarf_Die * die, Dwarf_Die * unit, dw_frame_t frame, - const char *namespace); + const char *ns); /** \brief Calls MC_dwarf_handle_die on all childrend of the given die * @@ -78,7 +80,7 @@ static void MC_dwarf_handle_type_die(mc_object_info_t info, Dwarf_Die * die, */ static void MC_dwarf_handle_children(mc_object_info_t info, Dwarf_Die * die, Dwarf_Die * unit, dw_frame_t frame, - const char *namespace); + const char *ns); /** \brief Handle a variable (DW_TAG_variable or other) * @@ -89,7 +91,7 @@ static void MC_dwarf_handle_children(mc_object_info_t info, Dwarf_Die * die, */ static void MC_dwarf_handle_variable_die(mc_object_info_t info, Dwarf_Die * die, Dwarf_Die * unit, dw_frame_t frame, - const char *namespace); + const char *ns); /** \brief Get the DW_TAG_type of the DIE * @@ -632,7 +634,7 @@ static void MC_dwarf_add_members(mc_object_info_t info, Dwarf_Die * die, */ static dw_type_t MC_dwarf_die_to_type(mc_object_info_t info, Dwarf_Die * die, Dwarf_Die * unit, dw_frame_t frame, - const char *namespace) + const char *ns) { dw_type_t type = xbt_new0(s_dw_type_t, 1); @@ -669,7 +671,7 @@ static dw_type_t MC_dwarf_die_to_type(mc_object_info_t info, Dwarf_Die * die, const char *name = MC_dwarf_attr_integrate_string(die, DW_AT_name); if (name != NULL) { type->name = - namespace ? bprintf("%s%s::%s", prefix, namespace, + ns ? bprintf("%s%s::%s", prefix, ns, name) : bprintf("%s%s", prefix, name); } @@ -703,10 +705,10 @@ static dw_type_t MC_dwarf_die_to_type(mc_object_info_t info, Dwarf_Die * die, case DW_TAG_union_type: case DW_TAG_class_type: MC_dwarf_add_members(info, die, unit, type); - char *new_namespace = namespace == NULL ? xbt_strdup(type->name) - : bprintf("%s::%s", namespace, name); - MC_dwarf_handle_children(info, die, unit, frame, new_namespace); - free(new_namespace); + char *new_ns = ns == NULL ? xbt_strdup(type->name) + : bprintf("%s::%s", ns, name); + MC_dwarf_handle_children(info, die, unit, frame, new_ns); + free(new_ns); break; } @@ -715,9 +717,9 @@ static dw_type_t MC_dwarf_die_to_type(mc_object_info_t info, Dwarf_Die * die, static void MC_dwarf_handle_type_die(mc_object_info_t info, Dwarf_Die * die, Dwarf_Die * unit, dw_frame_t frame, - const char *namespace) + const char *ns) { - dw_type_t type = MC_dwarf_die_to_type(info, die, unit, frame, namespace); + dw_type_t type = MC_dwarf_die_to_type(info, die, unit, frame, ns); char *key = bprintf("%" PRIx64, (uint64_t) type->id); xbt_dict_set(info->types, key, type, NULL); @@ -732,7 +734,7 @@ static int mc_anonymous_variable_index = 0; static dw_variable_t MC_die_to_variable(mc_object_info_t info, Dwarf_Die * die, Dwarf_Die * unit, dw_frame_t frame, - const char *namespace) + const char *ns) { // Skip declarations: if (MC_dwarf_attr_flag(die, DW_AT_declaration, false)) @@ -821,9 +823,9 @@ static dw_variable_t MC_die_to_variable(mc_object_info_t info, Dwarf_Die * die, } } - if (namespace && variable->global) { + if (ns && variable->global) { char *old_name = variable->name; - variable->name = bprintf("%s::%s", namespace, old_name); + variable->name = bprintf("%s::%s", ns, old_name); free(old_name); } // The current code needs a variable name, @@ -837,10 +839,10 @@ static dw_variable_t MC_die_to_variable(mc_object_info_t info, Dwarf_Die * die, static void MC_dwarf_handle_variable_die(mc_object_info_t info, Dwarf_Die * die, Dwarf_Die * unit, dw_frame_t frame, - const char *namespace) + const char *ns) { dw_variable_t variable = - MC_die_to_variable(info, die, unit, frame, namespace); + MC_die_to_variable(info, die, unit, frame, ns); if (variable == NULL) return; MC_dwarf_register_variable(info, frame, variable); @@ -854,7 +856,7 @@ static void mc_frame_free_voipd(dw_frame_t * p) static void MC_dwarf_handle_scope_die(mc_object_info_t info, Dwarf_Die * die, Dwarf_Die * unit, dw_frame_t parent_frame, - const char *namespace) + const char *ns) { // TODO, handle DW_TAG_type/DW_TAG_location for DW_TAG_with_stmt int tag = dwarf_tag(die); @@ -877,7 +879,7 @@ static void MC_dwarf_handle_scope_die(mc_object_info_t info, Dwarf_Die * die, if (klass == mc_tag_subprogram) { const char *name = MC_dwarf_attr_integrate_string(die, DW_AT_name); frame->name = - namespace ? bprintf("%s::%s", namespace, name) : xbt_strdup(name); + ns ? bprintf("%s::%s", ns, name) : xbt_strdup(name); } frame->abstract_origin_id = @@ -947,39 +949,39 @@ static void MC_dwarf_handle_scope_die(mc_object_info_t info, Dwarf_Die * die, xbt_dynar_push(parent_frame->scopes, &frame); } // Handle children: - MC_dwarf_handle_children(info, die, unit, frame, namespace); + MC_dwarf_handle_children(info, die, unit, frame, ns); } static void mc_dwarf_handle_namespace_die(mc_object_info_t info, Dwarf_Die * die, Dwarf_Die * unit, dw_frame_t frame, - const char *namespace) + const char *ns) { const char *name = MC_dwarf_attr_integrate_string(die, DW_AT_name); if (frame) xbt_die("Unexpected namespace in a subprogram"); - char *new_namespace = namespace == NULL ? xbt_strdup(name) - : bprintf("%s::%s", namespace, name); - MC_dwarf_handle_children(info, die, unit, frame, new_namespace); - xbt_free(new_namespace); + char *new_ns = ns == NULL ? xbt_strdup(name) + : bprintf("%s::%s", ns, name); + MC_dwarf_handle_children(info, die, unit, frame, new_ns); + xbt_free(new_ns); } static void MC_dwarf_handle_children(mc_object_info_t info, Dwarf_Die * die, Dwarf_Die * unit, dw_frame_t frame, - const char *namespace) + const char *ns) { // For each child DIE: Dwarf_Die child; int res; for (res = dwarf_child(die, &child); res == 0; res = dwarf_siblingof(&child, &child)) { - MC_dwarf_handle_die(info, &child, unit, frame, namespace); + MC_dwarf_handle_die(info, &child, unit, frame, ns); } } static void MC_dwarf_handle_die(mc_object_info_t info, Dwarf_Die * die, Dwarf_Die * unit, dw_frame_t frame, - const char *namespace) + const char *ns) { int tag = dwarf_tag(die); mc_tag_class klass = MC_dwarf_tag_classify(tag); @@ -987,22 +989,22 @@ static void MC_dwarf_handle_die(mc_object_info_t info, Dwarf_Die * die, // Type: case mc_tag_type: - MC_dwarf_handle_type_die(info, die, unit, frame, namespace); + MC_dwarf_handle_type_die(info, die, unit, frame, ns); break; // Subprogram or scope: case mc_tag_subprogram: case mc_tag_scope: - MC_dwarf_handle_scope_die(info, die, unit, frame, namespace); + MC_dwarf_handle_scope_die(info, die, unit, frame, ns); return; // Variable: case mc_tag_variable: - MC_dwarf_handle_variable_die(info, die, unit, frame, namespace); + MC_dwarf_handle_variable_die(info, die, unit, frame, ns); break; case mc_tag_namespace: - mc_dwarf_handle_namespace_die(info, die, unit, frame, namespace); + mc_dwarf_handle_namespace_die(info, die, unit, frame, ns); break; default: @@ -1178,7 +1180,7 @@ static void MC_post_process_variables(mc_object_info_t info) dw_variable_t variable = NULL; xbt_dynar_foreach(info->global_variables, cursor, variable) { if (variable->type_origin) { - variable->type = xbt_dict_get_or_null(info->types, variable->type_origin); + variable->type = (dw_type_t) xbt_dict_get_or_null(info->types, variable->type_origin); } } } @@ -1190,7 +1192,7 @@ static void mc_post_process_scope(mc_object_info_t info, dw_frame_t scope) // Attach correct namespaced name in inlined subroutine: char *key = bprintf("%" PRIx64, (uint64_t) scope->abstract_origin_id); - dw_frame_t abstract_origin = xbt_dict_get_or_null(info->subprograms, key); + dw_frame_t abstract_origin = (dw_frame_t) xbt_dict_get_or_null(info->subprograms, key); xbt_assert(abstract_origin, "Could not lookup abstract origin %s", key); xbt_free(key); scope->name = xbt_strdup(abstract_origin->name); @@ -1201,7 +1203,7 @@ static void mc_post_process_scope(mc_object_info_t info, dw_frame_t scope) dw_variable_t variable = NULL; xbt_dynar_foreach(scope->variables, cursor, variable) { if (variable->type_origin) { - variable->type = xbt_dict_get_or_null(info->types, variable->type_origin); + variable->type = (dw_type_t) xbt_dict_get_or_null(info->types, variable->type_origin); } } @@ -1230,7 +1232,7 @@ static void MC_resolve_subtype(mc_object_info_t info, dw_type_t type) if (type->dw_type_id == NULL) return; - type->subtype = xbt_dict_get_or_null(info->types, type->dw_type_id); + type->subtype = (dw_type_t) xbt_dict_get_or_null(info->types, type->dw_type_id); if (type->subtype == NULL) return; if (type->subtype->byte_size != 0) @@ -1241,7 +1243,7 @@ static void MC_resolve_subtype(mc_object_info_t info, dw_type_t type) // We need to fix in order to support C++. dw_type_t subtype = - xbt_dict_get_or_null(info->full_types_by_name, type->subtype->name); + (dw_type_t) xbt_dict_get_or_null(info->full_types_by_name, type->subtype->name); if (subtype != NULL) { type->subtype = subtype; } @@ -1385,7 +1387,7 @@ void MC_post_process_object_info(mc_process_t process, mc_object_info_t info) // Resolve full_type: if (subtype->name && subtype->byte_size == 0) { for (size_t i = 0; i != process->object_infos_size; ++i) { - dw_type_t same_type = + dw_type_t same_type = (dw_type_t) xbt_dict_get_or_null(process->object_infos[i]->full_types_by_name, subtype->name); if (same_type && same_type->name && same_type->byte_size) { @@ -1397,3 +1399,5 @@ void MC_post_process_object_info(mc_process_t process, mc_object_info_t info) } } + +} diff --git a/src/mc/mc_dwarf_expression.c b/src/mc/mc_dwarf_expression.cpp similarity index 99% rename from src/mc/mc_dwarf_expression.c rename to src/mc/mc_dwarf_expression.cpp index adcf360b80..3d2bc3639d 100644 --- a/src/mc/mc_dwarf_expression.c +++ b/src/mc/mc_dwarf_expression.cpp @@ -13,6 +13,8 @@ #include "mc_object_info.h" #include "mc_private.h" +extern "C" { + static int mc_dwarf_push_value(mc_expression_state_t state, Dwarf_Off value) { if (state->stack_size >= MC_EXPRESSION_STACK_SIZE) @@ -96,7 +98,7 @@ static int mc_dwarf_register_to_libunwind(int dwarf_register) int mc_dwarf_execute_expression(size_t n, const Dwarf_Op * ops, mc_expression_state_t state) { - for (int i = 0; i != n; ++i) { + for (size_t i = 0; i != n; ++i) { int error = 0; const Dwarf_Op *op = ops + i; uint8_t atom = op->atom; @@ -220,7 +222,7 @@ int mc_dwarf_execute_expression(size_t n, const Dwarf_Op * ops, // Address from the base address of this ELF object. // Push the address on the stack (base_address + argument). - case DW_OP_addr: + case DW_OP_addr: { if (!state->object_info) return MC_EXPRESSION_E_NO_BASE_ADDRESS; if (state->stack_size == MC_EXPRESSION_STACK_SIZE) @@ -229,6 +231,7 @@ int mc_dwarf_execute_expression(size_t n, const Dwarf_Op * ops, MC_object_base_address(state->object_info) + op->number; error = mc_dwarf_push_value(state, addr); break; + } // General constants: // Push the constant argument on the stack. @@ -555,7 +558,7 @@ void mc_dwarf_expression_init(mc_expression_t expression, size_t len, expression->lowpc = NULL; expression->highpc = NULL; expression->size = len; - expression->ops = xbt_malloc(len * sizeof(Dwarf_Op)); + expression->ops = (Dwarf_Op*) xbt_malloc(len * sizeof(Dwarf_Op)); memcpy(expression->ops, ops, len * sizeof(Dwarf_Op)); } @@ -606,3 +609,5 @@ void mc_dwarf_location_list_init(mc_location_list_t list, mc_object_info_t info, } } + +} diff --git a/src/mc/mc_forward.h b/src/mc/mc_forward.h index bd78e99299..3ba15f6e7b 100644 --- a/src/mc/mc_forward.h +++ b/src/mc/mc_forward.h @@ -7,9 +7,12 @@ #ifndef MC_FORWARD_H #define MC_FORWARD_H +#include #include #include "mc_interface.h" +SG_BEGIN_DECL() + typedef struct s_mc_object_info s_mc_object_info_t, *mc_object_info_t; typedef struct s_dw_type s_dw_type_t, *dw_type_t; typedef struct s_memory_map s_memory_map_t, *memory_map_t; @@ -23,4 +26,6 @@ typedef struct s_mc_process s_mc_process_t, * mc_process_t; typedef struct s_mc_model_checker s_mc_model_checker_t, *mc_model_checker_t; extern mc_model_checker_t mc_model_checker; +SG_END_DECL() + #endif diff --git a/src/mc/mc_global.c b/src/mc/mc_global.cpp similarity index 99% rename from src/mc/mc_global.c rename to src/mc/mc_global.cpp index faf1eaf685..28cbc9d3c2 100644 --- a/src/mc/mc_global.c +++ b/src/mc/mc_global.cpp @@ -44,6 +44,8 @@ #include "mc_protocol.h" #include "mc_client.h" +extern "C" { + XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_global, mc, "Logging specific to MC (global)"); @@ -104,11 +106,6 @@ static void MC_init_dot_output() } -void MC_init() -{ - MC_init_pid(getpid(), -1); -} - static void MC_init_mode(void) { if (mc_mode == MC_MODE_NONE) { @@ -120,6 +117,12 @@ static void MC_init_mode(void) } } +#ifdef HAVE_MC +void MC_init() +{ + MC_init_pid(getpid(), -1); +} + void MC_init_pid(pid_t pid, int socket) { /* Initialize the data structures that must be persistent across every @@ -209,6 +212,7 @@ void MC_init_pid(pid_t pid, int socket) mmalloc_set_current_heap(heap); } +#endif /******************************* Core of MC *******************************/ /**************************************************************************/ @@ -273,6 +277,7 @@ void MC_exit(void) //xbt_abort(); } +#ifdef HAVE_MC int MC_deadlock_check() { if (mc_mode == MC_MODE_SERVER) { @@ -309,6 +314,7 @@ int MC_deadlock_check() } return deadlock; } +#endif /** * \brief Re-executes from the state at position start all the transitions indicated by @@ -320,7 +326,7 @@ void MC_replay(xbt_fifo_t stack) { xbt_mheap_t heap = mmalloc_set_current_heap(mc_heap); - int value, count = 1, j; + int value, count = 1; char *req_str; smx_simcall_t req = NULL, saved_req = NULL; xbt_fifo_item_t item, start_item; @@ -354,10 +360,10 @@ void MC_replay(xbt_fifo_t stack) if (_sg_mc_comms_determinism || _sg_mc_send_determinism) { // int n = xbt_dynar_length(incomplete_communications_pattern); - int n = MC_smx_get_maxpid(); + unsigned n = MC_smx_get_maxpid(); assert(n == xbt_dynar_length(incomplete_communications_pattern)); assert(n == xbt_dynar_length(initial_communications_pattern)); - for (j=0; j < n ; j++) { + for (unsigned j=0; j < n ; j++) { xbt_dynar_reset((xbt_dynar_t)xbt_dynar_get_as(incomplete_communications_pattern, j, xbt_dynar_t)); xbt_dynar_get_as(initial_communications_pattern, j, mc_list_comm_pattern_t)->index_comm = 0; } @@ -760,3 +766,5 @@ void MC_report_assertion_error(void) MC_print_statistics(mc_stats); } #endif + +} diff --git a/src/mc/mc_hash.c b/src/mc/mc_hash.cpp similarity index 98% rename from src/mc/mc_hash.c rename to src/mc/mc_hash.cpp index b83bc83be8..834308e75b 100644 --- a/src/mc/mc_hash.c +++ b/src/mc/mc_hash.cpp @@ -11,6 +11,8 @@ #include "mc/datatypes.h" #include +extern "C" { + XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_hash, mc, "Logging specific to mc_hash"); // This is djb2: @@ -20,7 +22,7 @@ typedef uint64_t mc_hash_t; // #define MC_HASH(hash, value) hash = (((hash << 5) + hash) + (uint64_t) value) #define MC_HASH(hash, value) \ { hash = (((hash << 5) + hash) + (uint64_t) value);\ - XBT_DEBUG("%s:%i: %"PRIx64" -> %"PRIx64, __FILE__, __LINE__, (uint64_t) value, hash); } + XBT_DEBUG("%s:%i: %" PRIx64 " -> %" PRIx64, __FILE__, __LINE__, (uint64_t) value, hash); } // ***** Hash state @@ -62,9 +64,8 @@ static bool mc_ignored(const void *address, size_t size) static void mc_hash_binary(mc_hash_t * hash, const void *s, size_t len) { - const char *p = (const void *) s; - int i; - for (i = 0; i != len; ++i) { + const char *p = (const char*) s; + for (size_t i = 0; i != len; ++i) { MC_HASH(*hash, p[i]); } } @@ -338,3 +339,5 @@ uint64_t mc_hash_processes_state(int num_state, xbt_dynar_t stacks) XBT_DEBUG("END hash %i", num_state); return hash; } + +} diff --git a/src/mc/mc_ignore.c b/src/mc/mc_ignore.cpp similarity index 99% rename from src/mc/mc_ignore.c rename to src/mc/mc_ignore.cpp index 051a1f40c1..677fb3354e 100644 --- a/src/mc/mc_ignore.c +++ b/src/mc/mc_ignore.cpp @@ -13,6 +13,8 @@ #include "mc_protocol.h" #include "mc_client.h" +extern "C" { + XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_ignore, mc, "Logging specific to MC ignore mechanism"); @@ -427,3 +429,5 @@ void MC_process_ignore_memory(mc_process_t process, void *addr, size_t size) } } } + +} diff --git a/src/mc/mc_liveness.c b/src/mc/mc_liveness.cpp similarity index 99% rename from src/mc/mc_liveness.c rename to src/mc/mc_liveness.cpp index 8505daf83a..293eebd007 100644 --- a/src/mc/mc_liveness.c +++ b/src/mc/mc_liveness.cpp @@ -17,6 +17,8 @@ #include "mc_smx.h" #include "mc_client.h" +extern "C" { + XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_liveness, mc, "Logging specific to algorithms for liveness properties verification"); @@ -376,7 +378,7 @@ static void MC_modelcheck_liveness_main(void) /* Traverse the stack backwards until a pair with a non empty interleave set is found, deleting all the pairs that have it empty in the way. */ - while ((current_pair = xbt_fifo_shift(mc_stack)) != NULL) { + while ((current_pair = (mc_pair_t) xbt_fifo_shift(mc_stack)) != NULL) { if (current_pair->requests > 0) { /* We found a backtracking point */ XBT_DEBUG("Backtracking to depth %d", current_pair->depth); @@ -425,3 +427,5 @@ void MC_modelcheck_liveness(void) mmalloc_set_current_heap(heap); } + +} diff --git a/src/mc/mc_member.c b/src/mc/mc_member.cpp similarity index 97% rename from src/mc/mc_member.c rename to src/mc/mc_member.cpp index 666a2463a7..a75a9afdb5 100644 --- a/src/mc/mc_member.c +++ b/src/mc/mc_member.cpp @@ -4,9 +4,13 @@ /* 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. */ +#include + #include "mc_object_info.h" #include "mc_private.h" +extern "C" { + /** Resolve snapshot in the process address space * * @param object Process address of the struct/class @@ -39,3 +43,5 @@ void *mc_member_resolve(const void *base, dw_type_t type, dw_type_t member, else return (void *) state.stack[state.stack_size - 1]; } + +} diff --git a/src/mc/mc_memory.c b/src/mc/mc_memory.cpp similarity index 99% rename from src/mc/mc_memory.c rename to src/mc/mc_memory.cpp index 72f51a9159..6f8398307b 100644 --- a/src/mc/mc_memory.c +++ b/src/mc/mc_memory.cpp @@ -15,6 +15,8 @@ #include "mc_object_info.h" #include "mc_private.h" +extern "C" { + XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_memory, mc, "Logging specific to MC (memory)"); @@ -49,3 +51,5 @@ void MC_memory_exit(void) if (mc_heap && mc_heap != std_heap) xbt_mheap_destroy(mc_heap); } + +} diff --git a/src/mc/mc_mmalloc.h b/src/mc/mc_mmalloc.h index 4ceecbd9df..b59d7d7f31 100644 --- a/src/mc/mc_mmalloc.h +++ b/src/mc/mc_mmalloc.h @@ -7,6 +7,7 @@ #ifndef MC_MMALLOC_H #define MC_MMALLOC_H +#include #include /** file @@ -16,7 +17,9 @@ * Normally the system should operate in std, for switching to raw mode * you must wrap the code between MC_SET_RAW_MODE and MC_UNSET_RAW_MODE. */ - + +SG_BEGIN_DECL() + extern xbt_mheap_t std_heap; extern xbt_mheap_t mc_heap; @@ -35,4 +38,6 @@ extern xbt_mheap_t mc_heap; #define MC_SET_MC_HEAP mmalloc_set_current_heap(mc_heap) #define MC_SET_STD_HEAP mmalloc_set_current_heap(std_heap) +SG_END_DECL() + #endif diff --git a/src/mc/mc_model_checker.c b/src/mc/mc_model_checker.cpp similarity index 98% rename from src/mc/mc_model_checker.c rename to src/mc/mc_model_checker.cpp index 98aa299117..45b13b266e 100644 --- a/src/mc/mc_model_checker.c +++ b/src/mc/mc_model_checker.cpp @@ -7,6 +7,8 @@ #include "mc_model_checker.h" #include "mc_page_store.h" +extern "C" { + mc_model_checker_t mc_model_checker = NULL; mc_model_checker_t MC_model_checker_new(pid_t pid, int socket) @@ -39,3 +41,5 @@ unsigned long MC_smx_get_maxpid(void) &maxpid, sizeof(maxpid)); return maxpid; } + +} diff --git a/src/mc/mc_object_info.c b/src/mc/mc_object_info.cpp similarity index 98% rename from src/mc/mc_object_info.c rename to src/mc/mc_object_info.cpp index 874235c7ed..679c0b4ae7 100644 --- a/src/mc/mc_object_info.c +++ b/src/mc/mc_object_info.cpp @@ -5,6 +5,8 @@ #include "mc_object_info.h" #include "mc_private.h" +extern "C" { + dw_frame_t MC_file_object_info_find_function(mc_object_info_t info, const void *ip) { xbt_dynar_t dynar = info->functions_index; @@ -36,3 +38,5 @@ dw_variable_t MC_file_object_info_find_variable_by_name(mc_object_info_t info, c return NULL; } + +} diff --git a/src/mc/mc_object_info.h b/src/mc/mc_object_info.h index 9914c56dbc..bb5814b375 100644 --- a/src/mc/mc_object_info.h +++ b/src/mc/mc_object_info.h @@ -53,13 +53,13 @@ void dw_variable_free_voidp(void *t); // ***** Object info -enum mc_object_info_flags { - MC_OBJECT_INFO_NONE = 0, - MC_OBJECT_INFO_EXECUTABLE = 1 -}; +/** Bit field of options */ +typedef int mc_object_info_flags; +#define MC_OBJECT_INFO_NONE 0 +#define MC_OBJECT_INFO_EXECUTABLE 1 struct s_mc_object_info { - enum mc_object_info_flags flags; + mc_object_info_flags flags; char* file_name; const void* start, *end; char *start_exec, *end_exec; // Executable segment diff --git a/src/mc/mc_page_store.cpp b/src/mc/mc_page_store.cpp index 222f3a7eff..db4bc051b6 100644 --- a/src/mc/mc_page_store.cpp +++ b/src/mc/mc_page_store.cpp @@ -21,6 +21,8 @@ #include "mc_mmu.h" +extern "C" { + XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_page_snapshot, mc, "Logging specific to mc_page_snapshot"); @@ -280,3 +282,5 @@ XBT_TEST_UNIT("base", test_mc_page_store, "Test adding/removing pages in the sto } #endif /* SIMGRID_TEST */ + +} diff --git a/src/mc/mc_pair.c b/src/mc/mc_pair.cpp similarity index 98% rename from src/mc/mc_pair.c rename to src/mc/mc_pair.cpp index ee3ad5d3e5..7f754cd35e 100644 --- a/src/mc/mc_pair.c +++ b/src/mc/mc_pair.cpp @@ -8,6 +8,8 @@ #include "mc_liveness.h" #include "mc_private.h" +extern "C" { + mc_pair_t MC_pair_new() { mc_pair_t p = NULL; @@ -33,3 +35,5 @@ void mc_pair_free_voidp(void *p) { MC_pair_delete((mc_pair_t) * (void **) p); } + +} diff --git a/src/mc/mc_process.c b/src/mc/mc_process.cpp similarity index 93% rename from src/mc/mc_process.c rename to src/mc/mc_process.cpp index e49a7e23dc..86ccf94fd3 100644 --- a/src/mc/mc_process.c +++ b/src/mc/mc_process.cpp @@ -28,6 +28,8 @@ #include "mc_smx.h" #include "mc_server.h" +extern "C" { + XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_process, mc, "MC process information"); @@ -43,8 +45,8 @@ static mc_process_t MC_process_get_process(mc_process_t p) { } static const s_mc_address_space_class_t mc_process_class = { - .read = (void*) &MC_process_read, - .get_process = (void*) MC_process_get_process + .read = (mc_address_space_class_read_callback_t) &MC_process_read, + .get_process = (mc_address_space_class_get_process_callback_t) MC_process_get_process }; bool MC_is_process(mc_address_space_t p) @@ -66,7 +68,7 @@ void MC_process_init(mc_process_t process, pid_t pid, int sockfd) process->status = 0; process->memory_map = MC_get_memory_map(pid); process->memory_file = -1; - process->cache_flags = 0; + process->cache_flags = MC_PROCESS_CACHE_FLAG_NONE; process->heap = NULL; process->heap_info = NULL; MC_process_init_memory_map_info(process); @@ -135,7 +137,7 @@ void MC_process_clear(mc_process_t process) unw_destroy_addr_space(process->unw_addr_space); process->unw_addr_space = NULL; - process->cache_flags = 0; + process->cache_flags = MC_PROCESS_CACHE_FLAG_NONE; free(process->heap); process->heap = NULL; @@ -150,7 +152,7 @@ void MC_process_refresh_heap(mc_process_t process) // Read/dereference/refresh the std_heap pointer: if (!process->heap) { xbt_mheap_t oldheap = mmalloc_set_current_heap(mc_heap); - process->heap = malloc(sizeof(struct mdesc)); + process->heap = (struct mdesc*) malloc(sizeof(struct mdesc)); mmalloc_set_current_heap(oldheap); } MC_process_read(process, MC_ADDRESS_SPACE_READ_FLAGS_NONE, @@ -169,7 +171,7 @@ void MC_process_refresh_malloc_info(mc_process_t process) (process->heap->heaplimit + 1) * sizeof(malloc_info); xbt_mheap_t heap = mmalloc_set_current_heap(mc_heap); - process->heap_info = realloc(process->heap_info, malloc_info_bytesize); + process->heap_info = (malloc_info*) realloc(process->heap_info, malloc_info_bytesize); mmalloc_set_current_heap(heap); MC_process_read(process, MC_ADDRESS_SPACE_READ_FLAGS_NONE, @@ -262,8 +264,7 @@ static void MC_process_init_memory_map_info(mc_process_t process) const char* current_name = NULL; - size_t i = 0; - for (i=0; i < maps->mapsize; i++) { + for (ssize_t i=0; i < maps->mapsize; i++) { map_region_t reg = &(maps->regions[i]); const char* pathname = maps->regions[i].pathname; @@ -319,7 +320,7 @@ static void MC_process_init_memory_map_info(mc_process_t process) regfree(&res.version_re); // Resolve time (including accress differents objects): - for (i=0; i!=process->object_infos_size; ++i) + for (size_t i=0; i!=process->object_infos_size; ++i) MC_post_process_object_info(process, process->object_infos[i]); xbt_assert(process->maestro_stack_start, "Did not find maestro_stack_start"); @@ -408,10 +409,10 @@ void MC_process_read_variable(mc_process_t process, const char* name, void* targ xbt_die("No simple location for this variable"); if (!var->type->full_type) xbt_die("Partial type for %s, cannot check size", name); - if (var->type->full_type->byte_size != size) + if ((size_t) var->type->full_type->byte_size != size) xbt_die("Unexpected size for %s (expected %zi, was %zi)", name, size, (size_t) var->type->full_type->byte_size); - MC_process_read(process, MC_PROCESS_NO_FLAG, target, var->address, size, + MC_process_read(process, MC_ADDRESS_SPACE_READ_FLAGS_NONE, target, var->address, size, MC_PROCESS_INDEX_ANY); } @@ -422,8 +423,8 @@ char* MC_process_read_string(mc_process_t process, void* address) if (MC_process_is_self(process)) return strdup((char*) address); - size_t len = 128; - char* res = malloc(len); + off_t len = 128; + char* res = (char*) malloc(len); off_t off = 0; while (1) { @@ -444,7 +445,7 @@ char* MC_process_read_string(mc_process_t process, void* address) off += c; if (off == len) { len *= 2; - res = realloc(res, len); + res = (char*) realloc(res, len); } } } @@ -456,7 +457,7 @@ int MC_process_vm_open(pid_t pid, int flags) const size_t buffer_size = 30; char buffer[buffer_size]; int res = snprintf(buffer, buffer_size, "/proc/%lli/mem", (long long) pid); - if (res < 0 || res >= buffer_size) { + if (res < 0 || (size_t) res >= buffer_size) { errno = ENAMETOOLONG; return -1; } @@ -512,7 +513,7 @@ static ssize_t pwrite_whole(int fd, const void *buf, size_t count, off_t offset) return real_count; } -const void* MC_process_read(mc_process_t process, e_adress_space_read_flags_t flags, +const void* MC_process_read(mc_process_t process, adress_space_read_flags_t flags, void* local, const void* remote, size_t len, int process_index) { @@ -545,7 +546,7 @@ const void* MC_process_read(mc_process_t process, e_adress_space_read_flags_t fl const void* MC_process_read_simple(mc_process_t process, void* local, const void* remote, size_t len) { - e_adress_space_read_flags_t flags = MC_PROCESS_NO_FLAG; + adress_space_read_flags_t flags = MC_ADDRESS_SPACE_READ_FLAGS_NONE; int index = MC_PROCESS_INDEX_ANY; MC_process_read(process, flags, local, remote, len, index); return local; @@ -614,22 +615,4 @@ void MC_process_clear_memory(mc_process_t process, void* remote, size_t len) } } -void MC_simcall_handle(smx_simcall_t req, int value) -{ - if (MC_process_is_self(&mc_model_checker->process)) { - SIMIX_simcall_handle(req, value); - return; - } - - unsigned i; - mc_smx_process_info_t pi = NULL; - - xbt_dynar_foreach_ptr(mc_model_checker->process.smx_process_infos, i, pi) { - if (req == &pi->copy.simcall) { - MC_server_simcall_handle(&mc_model_checker->process, pi->copy.pid, value); - return; - } - } - - xbt_die("Could not find the request"); } diff --git a/src/mc/mc_process.h b/src/mc/mc_process.h index 5e2175c716..cf5aefbffd 100644 --- a/src/mc/mc_process.h +++ b/src/mc/mc_process.h @@ -33,18 +33,17 @@ SG_BEGIN_DECL() int MC_process_vm_open(pid_t pid, int flags); -typedef enum { - MC_PROCESS_NO_FLAG = 0, - MC_PROCESS_SELF_FLAG = 1, -} e_mc_process_flags_t; +typedef int mc_process_flags_t; +#define MC_PROCESS_NO_FLAG 0 +#define MC_PROCESS_SELF_FLAG 1 // Those flags are used to track down which cached information // is still up to date and which information needs to be updated. -typedef enum { - MC_PROCESS_CACHE_FLAG_HEAP = 1, - MC_PROCESS_CACHE_FLAG_MALLOC_INFO = 2, - MC_PROCESS_CACHE_FLAG_SIMIX_PROCESSES = 4, -} e_mc_process_cache_flags_t ; +typedef int mc_process_cache_flags_t; +#define MC_PROCESS_CACHE_FLAG_NONE 0 +#define MC_PROCESS_CACHE_FLAG_HEAP 1 +#define MC_PROCESS_CACHE_FLAG_MALLOC_INFO 2 +#define MC_PROCESS_CACHE_FLAG_SIMIX_PROCESSES 4 typedef struct s_mc_smx_process_info s_mc_smx_process_info_t, *mc_smx_process_info_t; @@ -52,7 +51,7 @@ typedef struct s_mc_smx_process_info s_mc_smx_process_info_t, *mc_smx_process_in */ struct s_mc_process { s_mc_address_space_t address_space; - e_mc_process_flags_t process_flags; + mc_process_flags_t process_flags; pid_t pid; int socket; int status; @@ -78,7 +77,7 @@ struct s_mc_process { xbt_dynar_t smx_old_process_infos; /** State of the cache (which variables are up to date) */ - e_mc_process_cache_flags_t cache_flags; + mc_process_cache_flags_t cache_flags; /** Address of the heap structure in the MCed process. */ void* heap_address; @@ -158,7 +157,7 @@ bool MC_process_is_self(mc_process_t process) * @param len data size */ const void* MC_process_read(mc_process_t process, - e_adress_space_read_flags_t flags, + adress_space_read_flags_t flags, void* local, const void* remote, size_t len, int process_index); diff --git a/src/mc/mc_protocol.c b/src/mc/mc_protocol.cpp similarity index 94% rename from src/mc/mc_protocol.c rename to src/mc/mc_protocol.cpp index c51979787b..2e5ffd3eb6 100644 --- a/src/mc/mc_protocol.c +++ b/src/mc/mc_protocol.cpp @@ -15,6 +15,8 @@ #include "mc_protocol.h" #include "mc_client.h" +extern "C" { + XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_protocol, mc, "Generic MC protocol logic"); int MC_protocol_send(int socket, void* message, size_t size) @@ -32,7 +34,7 @@ int MC_protocol_send(int socket, void* message, size_t size) return 0; } -int MC_protocol_send_simple_message(int socket, int type) +int MC_protocol_send_simple_message(int socket, e_mc_message_type type) { s_mc_message_t message; message.type = type; @@ -50,7 +52,7 @@ int MC_protocol_hello(int socket) s_mc_message_t message; message.type = MC_MESSAGE_NONE; - size_t s; + ssize_t s; while ((s = MC_receive_message(socket, &message, sizeof(message), 0)) == -1) { if (errno == EINTR) continue; @@ -59,7 +61,7 @@ int MC_protocol_hello(int socket) return 2; } } - if (s < sizeof(message) || message.type != MC_MESSAGE_HELLO) { + if ((size_t) s < sizeof(message) || message.type != MC_MESSAGE_HELLO) { XBT_ERROR("Did not receive suitable HELLO message. Who are you?"); return 3; } @@ -127,3 +129,5 @@ const char* MC_mode_name(e_mc_mode_t mode) return "?"; } } + +} diff --git a/src/mc/mc_protocol.h b/src/mc/mc_protocol.h index b6507f4c57..6ad420b715 100644 --- a/src/mc/mc_protocol.h +++ b/src/mc/mc_protocol.h @@ -105,7 +105,7 @@ typedef struct s_mc_register_symbol_message { } s_mc_register_symbol_message_t, * mc_register_symbol_message_t; int MC_protocol_send(int socket, void* message, size_t size); -int MC_protocol_send_simple_message(int socket, int type); +int MC_protocol_send_simple_message(int socket, e_mc_message_type type); int MC_protocol_hello(int socket); ssize_t MC_receive_message(int socket, void* message, size_t size, int options); diff --git a/src/mc/mc_record.c b/src/mc/mc_record.cpp similarity index 98% rename from src/mc/mc_record.c rename to src/mc/mc_record.cpp index d57816899c..cfe0cbdd4f 100644 --- a/src/mc/mc_record.c +++ b/src/mc/mc_record.cpp @@ -20,6 +20,8 @@ #include "mc_smx.h" #endif +extern "C" { + XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_record, mc, " Logging specific to MC record/replay facility"); @@ -73,7 +75,7 @@ xbt_dynar_t MC_record_from_string(const char* data) xbt_dynar_push(dynar, &item); // Find next chunk: - char* end = strchr(current, ';'); + const char* end = strchr(current, ';'); if(end==NULL) break; else @@ -146,3 +148,5 @@ void MC_record_replay_init() { mc_time = xbt_new0(double, simix_process_maxpid); } + +} diff --git a/src/mc/mc_request.c b/src/mc/mc_request.cpp similarity index 99% rename from src/mc/mc_request.c rename to src/mc/mc_request.cpp index 8b79524bd5..0209effe3b 100644 --- a/src/mc/mc_request.c +++ b/src/mc/mc_request.cpp @@ -11,6 +11,8 @@ #include "mc_private.h" #include "mc_smx.h" +extern "C" { + XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_request, mc, "Logging specific to MC (request)"); @@ -40,7 +42,7 @@ int MC_request_depend(smx_simcall_t r1, smx_simcall_t r2) // Those are internal requests, we do not need indirection // because those objects are copies: - smx_synchro_t synchro1, synchro2; + smx_synchro_t synchro1 = NULL, synchro2 = NULL; if (r1->call == SIMCALL_COMM_WAIT) { synchro1 = simcall_comm_wait__get__comm(r1); } @@ -230,7 +232,7 @@ static char *buff_size_to_string(size_t buff_size) char *MC_request_to_string(smx_simcall_t req, int value, e_mc_request_type_t request_type) { - bool use_remote_comm; + bool use_remote_comm = false; switch(request_type) { case MC_REQUEST_SIMIX: use_remote_comm = true; @@ -472,7 +474,7 @@ unsigned int MC_request_testany_fail(smx_simcall_t req) // Get the element: smx_synchro_t remote_action; - memcpy(buffer + comms.elmsize * cursor, &remote_action, sizeof(remote_action)); + memcpy(&remote_action, buffer + comms.elmsize * cursor, sizeof(remote_action)); // Dereference the pointer: s_smx_synchro_t action; @@ -684,3 +686,5 @@ char *MC_request_get_dot_output(smx_simcall_t req, int value) return str; } + +} diff --git a/src/mc/mc_safety.c b/src/mc/mc_safety.cpp similarity index 99% rename from src/mc/mc_safety.c rename to src/mc/mc_safety.cpp index 2efe90a2e2..4717ab9390 100644 --- a/src/mc/mc_safety.c +++ b/src/mc/mc_safety.cpp @@ -16,6 +16,8 @@ #include "xbt/mmalloc/mmprivate.h" +extern "C" { + XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_safety, mc, "Logging specific to MC safety verification "); @@ -204,7 +206,7 @@ static void MC_modelcheck_safety_main(void) executed before it. If it does then add it to the interleave set of the state that executed that previous request. */ - while ((state = xbt_fifo_shift(mc_stack)) != NULL) { + while ((state = (mc_state_t) xbt_fifo_shift(mc_stack))) { if (mc_reduce_kind == e_mc_reduce_dpor) { req = MC_state_get_internal_request(state); const smx_process_t issuer = MC_smx_simcall_get_issuer(req); @@ -296,3 +298,5 @@ void MC_modelcheck_safety(void) xbt_abort(); //MC_exit(); } + +} diff --git a/src/mc/mc_server.cpp b/src/mc/mc_server.cpp index 4b8da8b53a..6cde38d8cb 100644 --- a/src/mc/mc_server.cpp +++ b/src/mc/mc_server.cpp @@ -21,6 +21,8 @@ #include "mc_private.h" #include "mc_ignore.h" +extern "C" { + XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_server, mc, "MC server logic"); // HArdcoded index for now: @@ -124,7 +126,7 @@ void s_mc_server::resume(mc_process_t process) int res = MC_protocol_send_simple_message(socket, MC_MESSAGE_CONTINUE); if (res) throw std::system_error(res, std::system_category()); - process->cache_flags = (e_mc_process_cache_flags_t) 0; + process->cache_flags = (mc_process_cache_flags_t) 0; } static @@ -349,7 +351,7 @@ void MC_server_simcall_handle(mc_process_t process, unsigned long pid, int value m.pid = pid; m.value = value; MC_protocol_send(mc_model_checker->process.socket, &m, sizeof(m)); - process->cache_flags = (e_mc_process_cache_flags_t) 0; + process->cache_flags = (mc_process_cache_flags_t) 0; while (mc_model_checker->process.running) { if (!mc_server->handle_events()) return; @@ -360,3 +362,5 @@ void MC_server_loop(mc_server_t server) { server->loop(); } + +} diff --git a/src/mc/mc_server.h b/src/mc/mc_server.h index 860cfac3f9..e07d6e6230 100644 --- a/src/mc/mc_server.h +++ b/src/mc/mc_server.h @@ -7,6 +7,8 @@ #ifndef MC_SERVER_H #define MC_SERVER_H +#include + #include #include diff --git a/src/mc/mc_smx.c b/src/mc/mc_smx.cpp similarity index 98% rename from src/mc/mc_smx.c rename to src/mc/mc_smx.cpp index 358e21be5f..a10abd588d 100644 --- a/src/mc/mc_smx.c +++ b/src/mc/mc_smx.cpp @@ -13,6 +13,8 @@ #include "mc_smx.h" #include "mc_model_checker.h" +extern "C" { + static void MC_smx_process_info_clear(mc_smx_process_info_t p) { @@ -70,7 +72,7 @@ static void MC_process_refresh_simix_process_list( // Load each element of the dynar from the MCed process: int i = 0; - for (p = swag.head; p; ++i) { + for (p = (smx_process_t) swag.head; p; ++i) { s_mc_smx_process_info_t info; info.address = p; @@ -81,7 +83,7 @@ static void MC_process_refresh_simix_process_list( xbt_dynar_push(target, &info); // Lookup next process address: - p = xbt_swag_getNext(&info.copy, swag.offset); + p = (smx_process_t) xbt_swag_getNext(&info.copy, swag.offset); } assert(i == swag.count); } @@ -239,3 +241,5 @@ int MC_smpi_process_count(void) return res; } } + +} diff --git a/src/mc/mc_snapshot.c b/src/mc/mc_snapshot.cpp similarity index 98% rename from src/mc/mc_snapshot.c rename to src/mc/mc_snapshot.cpp index 0a4f4f564d..327376640d 100644 --- a/src/mc/mc_snapshot.c +++ b/src/mc/mc_snapshot.cpp @@ -14,6 +14,8 @@ #include "mc_mmu.h" #include "mc_page_store.h" +extern "C" { + /** @brief Find the snapshoted region from a pointer * * @param addr Pointer @@ -38,7 +40,7 @@ mc_mem_region_t mc_get_snapshot_region(const void* addr, mc_snapshot_t snapshot, if (process_index < 0) { xbt_die("Missing process index"); } - if (process_index >= region->privatized.regions_count) { + if (process_index >= (int) region->privatized.regions_count) { xbt_die("Invalid process index"); } mc_mem_region_t priv_region = region->privatized.regions[process_index]; @@ -104,7 +106,7 @@ const void* MC_region_read_fragmented(mc_mem_region_t region, void* target, cons * @return Pointer where the data is located (target buffer or original location) */ const void* MC_snapshot_read( - mc_snapshot_t snapshot, e_adress_space_read_flags_t flags, + mc_snapshot_t snapshot, adress_space_read_flags_t flags, void* target, const void* addr, size_t size, int process_index) { mc_mem_region_t region = mc_get_snapshot_region(addr, snapshot, process_index); @@ -177,12 +179,14 @@ int MC_snapshot_memcmp( #include "mc/mc_snapshot.h" #include "mc/mc_mmu.h" +extern "C" { + XBT_TEST_SUITE("mc_snapshot", "Snapshots"); static inline void init_memory(void* mem, size_t size) { char* dest = (char*) mem; - for (int i=0; i!=size; ++i) { + for (size_t i = 0; i < size; ++i) { dest[i] = rand() & 255; } } @@ -284,4 +288,8 @@ static void test_snapshot(bool sparse_checkpoint) { mc_model_checker = NULL; } +} + #endif /* SIMGRID_TEST */ + +} diff --git a/src/mc/mc_snapshot.h b/src/mc/mc_snapshot.h index 7591a310cb..82406b4ea3 100644 --- a/src/mc/mc_snapshot.h +++ b/src/mc/mc_snapshot.h @@ -281,7 +281,7 @@ void mc_restore_page_snapshot_region( const void* MC_region_read_fragmented(mc_mem_region_t region, void* target, const void* addr, size_t size); -const void* MC_snapshot_read(mc_snapshot_t snapshot, e_adress_space_read_flags_t flags, +const void* MC_snapshot_read(mc_snapshot_t snapshot, adress_space_read_flags_t flags, void* target, const void* addr, size_t size, int process_index); int MC_snapshot_region_memcmp( const void* addr1, mc_mem_region_t region1, diff --git a/src/mc/mc_state.c b/src/mc/mc_state.cpp similarity index 99% rename from src/mc/mc_state.c rename to src/mc/mc_state.cpp index 8e707b2f9d..a3f20eee13 100644 --- a/src/mc/mc_state.c +++ b/src/mc/mc_state.cpp @@ -14,6 +14,8 @@ #include "mc_comm_pattern.h" #include "mc_smx.h" +extern "C" { + XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_state, mc, "Logging specific to MC (state)"); @@ -139,7 +141,7 @@ void MC_state_set_executed_request(mc_state_t state, smx_simcall_t req, simcall_comm_test__set__comm(&state->internal_req, &state->internal_comm); break; - case SIMCALL_MC_RANDOM: + case SIMCALL_MC_RANDOM: { state->internal_req = *req; int random_max = simcall_mc_random__get__max(req); if (value != random_max) { @@ -153,6 +155,7 @@ void MC_state_set_executed_request(mc_state_t state, smx_simcall_t req, ); } break; + } default: state->internal_req = *req; @@ -277,3 +280,5 @@ smx_simcall_t MC_state_get_request(mc_state_t state, int *value) return NULL; } + +} diff --git a/src/mc/mc_unw.c b/src/mc/mc_unw.cpp similarity index 96% rename from src/mc/mc_unw.c rename to src/mc/mc_unw.cpp index ee671769fb..a141f09739 100644 --- a/src/mc/mc_unw.c +++ b/src/mc/mc_unw.cpp @@ -9,7 +9,7 @@ */ // We need this for the register indices: -#define _GNU_SOURCE +// #define _GNU_SOURCE #include @@ -22,6 +22,8 @@ #include "mc_process.h" #include "mc_unw.h" +extern "C" { + // ***** Implementation /** Get frame unwind information (libunwind method) @@ -78,9 +80,9 @@ static int access_mem(unw_addr_space_t as, { mc_unw_context_t context = (mc_unw_context_t) arg; if (write) - return -UNW_EREADONLYREG; + return - UNW_EREADONLYREG; MC_address_space_read(context->address_space, - 0, valp, (void*) addr, sizeof(unw_word_t), MC_PROCESS_INDEX_ANY); + MC_ADDRESS_SPACE_READ_FLAGS_NONE, valp, (void*) addr, sizeof(unw_word_t), MC_PROCESS_INDEX_ANY); // We don't handle failure gracefully. return 0; } @@ -124,7 +126,7 @@ static int access_reg(unw_addr_space_t as, unw_context_t* context = &as_context->context; if (write) return -UNW_EREADONLYREG; - greg_t* preg = get_reg(context, regnum); + greg_t* preg = (greg_t*) get_reg(context, regnum); if (!preg) return -UNW_EBADREG; *valp = *preg; @@ -236,3 +238,5 @@ int mc_unw_init_cursor(unw_cursor_t *cursor, mc_unw_context_t context) return unw_init_remote(cursor, context->process->unw_addr_space, context); } + +} diff --git a/src/mc/mc_unw_vmread.c b/src/mc/mc_unw_vmread.cpp similarity index 96% rename from src/mc/mc_unw_vmread.c rename to src/mc/mc_unw_vmread.cpp index 742359ef3a..3893ec9a1c 100644 --- a/src/mc/mc_unw_vmread.c +++ b/src/mc/mc_unw_vmread.cpp @@ -1,5 +1,3 @@ -#define _GNU_SOURCE - #include #include @@ -8,6 +6,8 @@ #include "mc_unw.h" +extern "C" { + /** \file * Libunwind namespace implementation using process_vm_readv. *. @@ -30,7 +30,7 @@ struct _UPT_info { static inline pid_t _UPT_getpid(void* arg) { - struct _UPT_info* info = arg; + struct _UPT_info* info = (_UPT_info*) arg; return info->pid; } @@ -54,7 +54,7 @@ static int access_mem(const unw_addr_space_t as, struct iovec remote = { (void*) addr, size }; s = process_vm_readv(pid, &local, 1, &remote, 1, 0); if (s >= 0) { - if (s != size) + if ((size_t) s != size) return - UNW_EINVAL; else return 0; @@ -106,3 +106,5 @@ unw_accessors_t mc_unw_vmread_accessors = .resume = &_UPT_resume, .get_proc_name = &_UPT_get_proc_name }; + +} diff --git a/src/mc/mc_visited.c b/src/mc/mc_visited.cpp similarity index 98% rename from src/mc/mc_visited.c rename to src/mc/mc_visited.cpp index c644abf4b4..3fd5249198 100644 --- a/src/mc/mc_visited.c +++ b/src/mc/mc_visited.cpp @@ -14,6 +14,8 @@ #include "mc_process.h" #include "mc_smx.h" +extern "C" { + XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_visited, mc, "Logging specific to state equaity detection mechanisms"); @@ -148,7 +150,7 @@ int get_search_interval(xbt_dynar_t list, void *ref, int *min, int *max) xbt_mheap_t heap = mmalloc_set_current_heap(mc_heap); - int cursor = 0, previous_cursor, next_cursor; + int cursor = 0, previous_cursor; int nb_processes, heap_bytes_used, nb_processes_test, heap_bytes_used_test; void *ref_test; @@ -201,7 +203,7 @@ int get_search_interval(xbt_dynar_t list, void *ref, int *min, int *max) *min = previous_cursor; previous_cursor--; } - next_cursor = cursor + 1; + size_t next_cursor = cursor + 1; while (next_cursor < xbt_dynar_length(list)) { if (_sg_mc_liveness) { ref_test = (mc_visited_pair_t) xbt_dynar_get_as(list, next_cursor, mc_visited_pair_t); @@ -244,7 +246,7 @@ mc_visited_state_t is_visited_state(mc_state_t graph_state) communications are not finished (at least, data are transfered). These communications are incomplete and they cannot be analyzed and compared with the initial pattern. */ if (_sg_mc_comms_determinism || _sg_mc_send_determinism) { - int current_process = 1; + size_t current_process = 1; while (current_process < MC_smx_get_maxpid()) { if (!xbt_dynar_is_empty((xbt_dynar_t)xbt_dynar_get_as(incomplete_communications_pattern, current_process, xbt_dynar_t))){ XBT_DEBUG("Some communications are not finished, cannot stop the exploration ! State not visited."); @@ -351,7 +353,7 @@ mc_visited_state_t is_visited_state(mc_state_t graph_state) } // We have reached the maximum number of stored states; - if (xbt_dynar_length(visited_states) > _sg_mc_visited) { + if ((ssize_t) xbt_dynar_length(visited_states) > _sg_mc_visited) { XBT_DEBUG("Try to remove visited state (maximum number of stored states reached)"); @@ -478,7 +480,7 @@ int is_visited_pair(mc_visited_pair_t visited_pair, mc_pair_t pair) { } } - if (xbt_dynar_length(visited_pairs) > _sg_mc_visited) { + if ((ssize_t) xbt_dynar_length(visited_pairs) > _sg_mc_visited) { int min2 = mc_stats->expanded_pairs; unsigned int cursor2 = 0; unsigned int index2 = 0; @@ -503,3 +505,5 @@ int is_visited_pair(mc_visited_pair_t visited_pair, mc_pair_t pair) { mmalloc_set_current_heap(heap); return -1; } + +} diff --git a/src/mc/memory_map.c b/src/mc/memory_map.cpp similarity index 98% rename from src/mc/memory_map.c rename to src/mc/memory_map.cpp index 337ed9da2c..db0fcce64e 100644 --- a/src/mc/memory_map.c +++ b/src/mc/memory_map.cpp @@ -11,6 +11,8 @@ #include "mc_memory_map.h" #include "mc_private.h" +extern "C" { + XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_memory_map, mc, "Logging specific to algorithms for memory_map"); @@ -143,7 +145,7 @@ memory_map_t MC_get_memory_map(pid_t pid) /* parsed stuff from the temporal memreg variable */ XBT_DEBUG("Found region for %s", memreg.pathname ? memreg.pathname : "(null)"); - ret->regions = + ret->regions = (map_region_t) xbt_realloc(ret->regions, sizeof(memreg) * (ret->mapsize + 1)); memcpy(ret->regions + ret->mapsize, &memreg, sizeof(memreg)); ret->mapsize++; @@ -164,3 +166,5 @@ void MC_free_memory_map(memory_map_t map){ xbt_free(map->regions); xbt_free(map); } + +} diff --git a/src/simix/smx_context_sysv.c b/src/simix/smx_context_sysv.c index e074c52731..61445553b9 100644 --- a/src/simix/smx_context_sysv.c +++ b/src/simix/smx_context_sysv.c @@ -152,10 +152,12 @@ smx_ctx_sysv_create_context(xbt_main_func_t code, int argc, char **argv, sysv_maestro_context = context; } +#ifdef HAVE_MC if (MC_is_active() && code) { MC_new_stack_area(context->stack, ((smx_context_t)context)->process, &(context->uc), smx_context_usable_stack_size); } +#endif return (smx_context_t) context; } diff --git a/src/xbt/mmalloc/mmprivate.h b/src/xbt/mmalloc/mmprivate.h index 8a40c4891d..07ef47d242 100644 --- a/src/xbt/mmalloc/mmprivate.h +++ b/src/xbt/mmalloc/mmprivate.h @@ -14,6 +14,8 @@ #ifndef __MMPRIVATE_H #define __MMPRIVATE_H 1 +#include + #include "portable.h" #include "xbt/xbt_os_thread.h" #include "xbt/mmalloc.h" @@ -94,6 +96,8 @@ #define ADDRESS(B) ((void*) (((ADDR2UINT(B)) - 1) * BLOCKSIZE + (char*) mdp -> heapbase)) +SG_BEGIN_DECL() + /* Doubly linked lists of free fragments. */ struct list { struct list *next; @@ -328,4 +332,6 @@ void mmalloc_ensure_using_mm(int argc, const char** argv); size_t mmalloc_get_bytes_used_remote(size_t heaplimit, const malloc_info* heapinfo); +SG_END_DECL() + #endif /* __MMPRIVATE_H */ -- 2.20.1