From: Gabriel Corona Date: Tue, 19 May 2015 09:46:22 +0000 (+0200) Subject: [mc] Add remote_ptr for marking pointers-to/addresses-in the remote process X-Git-Tag: v3_12~725 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/54dc4437fa893572ced42c3e9174f4a9888b0258 [mc] Add remote_ptr for marking pointers-to/addresses-in the remote process --- diff --git a/src/mc/AddressSpace.hpp b/src/mc/AddressSpace.hpp index 07f18df8a7..1f4d176efa 100644 --- a/src/mc/AddressSpace.hpp +++ b/src/mc/AddressSpace.hpp @@ -19,6 +19,58 @@ namespace simgrid { namespace mc { +/** Pointer to a remote address-space (process, snapshot) + * + * With this we can clearly identify the expected type of an address in the + * remote process whild avoiding to use native local pointers. + */ +template class remote_ptr { + std::uint64_t address_; +public: + remote_ptr() : address_(nullptr) {} + remote_ptr(std::uint64_t address) : address_(address) {} + remote_ptr(T* address) : address_((std::uint64_t)address) {} + std::uint64_t address() const { return address_; } + operator bool() const + { + return address_; + } + operator remote_ptr() const + { + return remote_ptr(address_); + } + remote_ptr operator+(std::uint64_t n) const + { + return remote_ptr(address_ + n * sizeof(T)); + } + remote_ptr operator-(std::uint64_t n) const + { + return remote_ptr(address_ - n * sizeof(T)); + } + remote_ptr& operator+=(std::uint64_t n) const + { + address_ += n * sizeof(T); + return *this; + } + remote_ptr& operator-=(std::uint64_t n) const + { + address_ -= n * sizeof(T); + return *this; + } +}; + +template inline +remote_ptr remote(T *p) +{ + return remote_ptr(p); +} + +template inline +remote_ptr remote(uint64_t p) +{ + return remote_ptr(p); +} + /** Process index used when no process is available * * The expected behaviour is that if a process index is needed it will fail. @@ -46,14 +98,21 @@ public: }; virtual ~AddressSpace(); virtual const void* read_bytes(void* buffer, std::size_t size, - std::uint64_t address, int process_index = ProcessIndexAny, + remote_ptr address, int process_index = ProcessIndexAny, ReadMode mode = Normal) = 0; - template - T read(uint64_t address, int process_index = ProcessIndexMissing) + + template inline + void read(T *buffer, remote_ptr ptr, int process_index = ProcessIndexAny) + { + this->read_bytes(buffer, sizeof(T), ptr, process_index); + } + + template inline + T read(remote_ptr ptr, int process_index = ProcessIndexMissing) { static_assert(std::is_trivial::value, "Cannot read a non-trivial type"); T res; - return *(T*)this->read_bytes(&res, sizeof(T), address, process_index); + return *(T*)this->read_bytes(&res, sizeof(T), ptr, process_index); } }; diff --git a/src/mc/mc_base.cpp b/src/mc/mc_base.cpp index 358ee1d13d..008f129bd8 100644 --- a/src/mc/mc_base.cpp +++ b/src/mc/mc_base.cpp @@ -22,6 +22,8 @@ #include "mc_server.h" #endif +using simgrid::mc::remote; + extern "C" { XBT_LOG_NEW_CATEGORY(mc, "All MC categories"); @@ -69,8 +71,7 @@ int MC_request_is_enabled(smx_simcall_t req) #ifdef HAVE_MC // Fetch from MCed memory: if (mc_mode == MC_MODE_SERVER) { - mc_model_checker->process().read_bytes( - &temp_synchro, sizeof(temp_synchro), (std::uint64_t)act); + mc_model_checker->process().read(&temp_synchro, remote(act)); act = &temp_synchro; } #endif @@ -96,9 +97,8 @@ int MC_request_is_enabled(smx_simcall_t req) size_t buffer_size = 0; if (mc_mode == MC_MODE_SERVER) { // Read dynar: - mc_model_checker->process().read_bytes( - &comms_buffer, sizeof(comms_buffer), - (std::uint64_t)simcall_comm_waitany__get__comms(req)); + mc_model_checker->process().read( + &comms_buffer, remote(simcall_comm_waitany__get__comms(req))); assert(comms_buffer.elmsize == sizeof(act)); buffer_size = comms_buffer.elmsize * comms_buffer.used; comms = &comms_buffer; @@ -109,7 +109,7 @@ int MC_request_is_enabled(smx_simcall_t req) char buffer[buffer_size]; if (mc_mode == MC_MODE_SERVER) mc_model_checker->process().read_bytes(buffer, sizeof(buffer), - (std::uint64_t)comms->data); + remote(comms->data)); #else comms = simcall_comm_waitany__get__comms(req); #endif @@ -119,8 +119,7 @@ int MC_request_is_enabled(smx_simcall_t req) // Fetch act from MCed memory: if (mc_mode == MC_MODE_SERVER) { memcpy(&act, buffer + comms->elmsize * index, sizeof(act)); - mc_model_checker->process().read_bytes( - &temp_synchro, sizeof(temp_synchro), (std::uint64_t)act); + mc_model_checker->process().read(&temp_synchro, remote(act)); act = &temp_synchro; } else @@ -137,8 +136,7 @@ int MC_request_is_enabled(smx_simcall_t req) #ifdef HAVE_MC s_smx_mutex_t temp_mutex; if (mc_mode == MC_MODE_SERVER) { - mc_model_checker->process().read_bytes( - &temp_mutex, sizeof(temp_mutex), (std::uint64_t)mutex); + mc_model_checker->process().read(&temp_mutex, remote(mutex)); mutex = &temp_mutex; } #endif diff --git a/src/mc/mc_checkpoint.cpp b/src/mc/mc_checkpoint.cpp index 48f67d6728..1822189672 100644 --- a/src/mc/mc_checkpoint.cpp +++ b/src/mc/mc_checkpoint.cpp @@ -35,6 +35,8 @@ #include "mc_protocol.h" #include "mc_smx.h" +using simgrid::mc::remote; + extern "C" { XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_checkpoint, mc, @@ -113,7 +115,7 @@ static mc_mem_region_t mc_region_new_dense( region->size = size; region->flat.data = xbt_malloc(size); mc_model_checker->process().read_bytes(region->flat.data, size, - (std::uint64_t)permanent_addr, + remote(permanent_addr), simgrid::mc::ProcessIndexDisabled); XBT_DEBUG("New region : type : %d, data : %p (real addr %p), size : %zu", region_type, region->flat.data, permanent_addr, size); @@ -191,7 +193,7 @@ static mc_mem_region_t MC_region_new_privatized( s_smpi_privatisation_region_t privatisation_regions[process_count]; mc_model_checker->process().read_bytes( &privatisation_regions, sizeof(privatisation_regions), - (std::uint64_t)remote_smpi_privatisation_regions); + remote(remote_smpi_privatisation_regions)); for (size_t i = 0; i < process_count; i++) { region->privatized.regions[i] = @@ -236,7 +238,7 @@ static void MC_get_memory_regions(mc_process_t process, mc_snapshot_t snapshot) object_info->end_rw - object_info->start_rw); } - xbt_mheap_t heap = MC_process_get_heap(process); + xbt_mheap_t heap = process->get_heap(); void *start_heap = heap->base; void *end_heap = heap->breakval; @@ -245,7 +247,7 @@ static void MC_get_memory_regions(mc_process_t process, mc_snapshot_t snapshot) (char *) end_heap - (char *) start_heap); snapshot->heap_bytes_used = mmalloc_get_bytes_used_remote( heap->heaplimit, - MC_process_get_malloc_info(process)); + process->get_malloc_info()); #ifdef HAVE_SMPI if (smpi_privatize_global_variables && MC_smpi_process_count()) { @@ -510,7 +512,7 @@ static xbt_dynar_t MC_take_snapshot_stacks(mc_snapshot_t * snapshot) // Read the context from remote process: unw_context_t context; mc_model_checker->process().read_bytes( - &context, sizeof(context), (std::uint64_t) current_stack->context); + &context, sizeof(context), remote(current_stack->context)); st->context = xbt_new0(s_mc_unw_context_t, 1); if (mc_unw_init_context(st->context, &mc_model_checker->process(), @@ -582,7 +584,7 @@ static void MC_snapshot_handle_ignore(mc_snapshot_t snapshot) ignored_data.data = malloc(region->size); // TODO, we should do this once per privatization segment: snapshot->process->read_bytes( - ignored_data.data, region->size, (std::uint64_t) region->addr, + ignored_data.data, region->size, remote(region->addr), simgrid::mc::ProcessIndexDisabled); xbt_dynar_push(snapshot->ignored_data, &ignored_data); } diff --git a/src/mc/mc_comm_determinism.cpp b/src/mc/mc_comm_determinism.cpp index 20236c1170..6bb42f7b6e 100644 --- a/src/mc/mc_comm_determinism.cpp +++ b/src/mc/mc_comm_determinism.cpp @@ -13,6 +13,8 @@ #include "mc_smx.h" #include "mc_client.h" +using simgrid::mc::remote; + extern "C" { XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_comm_determinism, mc, @@ -91,8 +93,7 @@ static char* print_determinism_result(e_mc_comm_pattern_difference_t diff, int p static void update_comm_pattern(mc_comm_pattern_t comm_pattern, smx_synchro_t comm_addr) { s_smx_synchro_t comm; - mc_model_checker->process().read_bytes( - &comm, sizeof(comm), (std::uint64_t)comm_addr); + mc_model_checker->process().read(&comm, remote(comm_addr)); smx_process_t src_proc = MC_smx_resolve_process(comm.comm.src_proc); smx_process_t dst_proc = MC_smx_resolve_process(comm.comm.dst_proc); @@ -102,13 +103,13 @@ static void update_comm_pattern(mc_comm_pattern_t comm_pattern, smx_synchro_t co comm_pattern->dst_host = MC_smx_process_get_host_name(dst_proc); if (comm_pattern->data_size == -1 && comm.comm.src_buff != NULL) { size_t buff_size; - mc_model_checker->process().read_bytes( - &buff_size, sizeof(buff_size), (std::uint64_t)comm.comm.dst_buff_size); + mc_model_checker->process().read( + &buff_size, remote(comm.comm.dst_buff_size)); comm_pattern->data_size = buff_size; comm_pattern->data = xbt_malloc0(comm_pattern->data_size); mc_model_checker->process().read_bytes( comm_pattern->data, comm_pattern->data_size, - (std::uint64_t) comm.comm.src_buff); + remote(comm.comm.src_buff)); } } @@ -204,7 +205,7 @@ void MC_get_comm_pattern(xbt_dynar_t list, smx_simcall_t request, e_mc_call_type pattern->data_size = synchro.comm.src_buff_size; pattern->data = xbt_malloc0(pattern->data_size); mc_model_checker->process().read_bytes( - pattern->data, pattern->data_size, (std::uint64_t)synchro.comm.src_buff); + pattern->data, pattern->data_size, remote(synchro.comm.src_buff)); } if(mpi_request.detached){ if (!initial_global_state->initial_communications_pattern_done) { @@ -228,19 +229,16 @@ void MC_get_comm_pattern(xbt_dynar_t list, smx_simcall_t request, e_mc_call_type pattern->comm_addr = simcall_comm_irecv__get__result(request); struct s_smpi_mpi_request mpi_request; - mc_model_checker->process().read_bytes( - &mpi_request, sizeof(mpi_request), - (std::uint64_t) simcall_comm_irecv__get__data(request)); + mc_model_checker->process().read( + &mpi_request, remote((struct s_smpi_mpi_request*)simcall_comm_irecv__get__data(request))); pattern->tag = mpi_request.tag; s_smx_synchro_t synchro; - mc_model_checker->process().read_bytes( - &synchro, sizeof(synchro), (std::uint64_t)pattern->comm_addr); + mc_model_checker->process().read(&synchro, remote(pattern->comm_addr)); char* remote_name; - mc_model_checker->process().read_bytes( - &remote_name, sizeof(remote_name), - (std::uint64_t)(synchro.comm.rdv ? &synchro.comm.rdv->name : &synchro.comm.rdv_cpy->name)); + mc_model_checker->process().read(&remote_name, + remote(synchro.comm.rdv ? &synchro.comm.rdv->name : &synchro.comm.rdv_cpy->name)); pattern->rdv = MC_process_read_string(&mc_model_checker->process(), remote_name); pattern->dst_proc = MC_smx_resolve_process(synchro.comm.dst_proc)->pid; diff --git a/src/mc/mc_compare.cpp b/src/mc/mc_compare.cpp index 3374e5ce4c..2a5a53d7b7 100644 --- a/src/mc/mc_compare.cpp +++ b/src/mc/mc_compare.cpp @@ -26,6 +26,8 @@ #include +using simgrid::mc::remote; + typedef struct s_pointers_pair { void *p1; void *p2; @@ -494,11 +496,11 @@ int snapshot_compare(void *state1, void *state2) /* Init heap information used in heap comparison algorithm */ xbt_mheap_t heap1 = (xbt_mheap_t)s1->read_bytes( alloca(sizeof(struct mdesc)), sizeof(struct mdesc), - (std::uint64_t)process->heap_address, + remote(process->heap_address), simgrid::mc::ProcessIndexMissing, simgrid::mc::AddressSpace::Lazy); xbt_mheap_t heap2 = (xbt_mheap_t)s2->read_bytes( alloca(sizeof(struct mdesc)), sizeof(struct mdesc), - (std::uint64_t)process->heap_address, + remote(process->heap_address), simgrid::mc::ProcessIndexMissing, simgrid::mc::AddressSpace::Lazy); res_init = init_heap_information(heap1, heap2, s1->to_ignore, s2->to_ignore); if (res_init == -1) { diff --git a/src/mc/mc_diff.cpp b/src/mc/mc_diff.cpp index dd2a16f672..82c1d0af66 100644 --- a/src/mc/mc_diff.cpp +++ b/src/mc/mc_diff.cpp @@ -366,7 +366,7 @@ int init_heap_information(xbt_mheap_t heap1, xbt_mheap_t heap2, xbt_dynar_t i1, state->heaplimit = ((struct mdesc *) heap1)->heaplimit; - state->std_heap_copy = *MC_process_get_heap(&mc_model_checker->process()); + state->std_heap_copy = *mc_model_checker->process().get_heap(); state->heapsize1 = heap1->heapsize; state->heapsize2 = heap2->heapsize; @@ -1610,7 +1610,7 @@ int mmalloc_linear_compare_heap(xbt_mheap_t heap1, xbt_mheap_t heap2) /* Heap information */ state->heaplimit = ((struct mdesc *) heap1)->heaplimit; - state->std_heap_copy = *MC_process_get_heap(&mc_model_checker->process()); + state->std_heap_copy = *mc_model_checker->process().get_heap(); state->heapbase1 = (char *) heap1 + BLOCKSIZE; state->heapbase2 = (char *) heap2 + BLOCKSIZE; diff --git a/src/mc/mc_dwarf_expression.cpp b/src/mc/mc_dwarf_expression.cpp index c10df75660..33a01b9d74 100644 --- a/src/mc/mc_dwarf_expression.cpp +++ b/src/mc/mc_dwarf_expression.cpp @@ -13,6 +13,8 @@ #include "mc_object_info.h" #include "mc_private.h" +using simgrid::mc::remote; + extern "C" { static int mc_dwarf_push_value(mc_expression_state_t state, Dwarf_Off value) @@ -406,7 +408,7 @@ int mc_dwarf_execute_expression(size_t n, const Dwarf_Op * ops, xbt_die("Missing address space"); state->address_space->read_bytes( &state->stack[state->stack_size - 1], sizeof(uintptr_t), - address, state->process_index); + remote(address), state->process_index); } break; diff --git a/src/mc/mc_page_snapshot.cpp b/src/mc/mc_page_snapshot.cpp index eaaacada59..5c02208369 100644 --- a/src/mc/mc_page_snapshot.cpp +++ b/src/mc/mc_page_snapshot.cpp @@ -14,6 +14,8 @@ #include +using simgrid::mc::remote; + extern "C" { // ***** Region management: @@ -29,7 +31,7 @@ size_t* mc_take_page_snapshot_region(mc_process_t process, { size_t* pagenos = (size_t*) malloc(page_count * sizeof(size_t)); - const bool is_self = MC_process_is_self(process); + const bool is_self = process->is_self(); void* temp = NULL; if (!is_self) @@ -54,7 +56,7 @@ size_t* mc_take_page_snapshot_region(mc_process_t process, */ page_data = temp; process->read_bytes( - temp, xbt_pagesize, (std::uint64_t) page, + temp, xbt_pagesize, remote(page), simgrid::mc::ProcessIndexDisabled); } pagenos[i] = mc_model_checker->page_store().store_page(page_data); diff --git a/src/mc/mc_process.cpp b/src/mc/mc_process.cpp index 5372a63071..b0ba0dedce 100644 --- a/src/mc/mc_process.cpp +++ b/src/mc/mc_process.cpp @@ -150,42 +150,52 @@ Process::~Process() process->heap_info = NULL; } -} -} - -extern "C" { - -void MC_process_refresh_heap(mc_process_t process) +/** Refresh the information about the process + * + * Do not use direclty, this is used by the getters when appropriate + * in order to have fresh data. + */ +void Process::refresh_heap() { xbt_assert(mc_mode == MC_MODE_SERVER); - xbt_assert(!MC_process_is_self(process)); + xbt_assert(!this->is_self()); // Read/dereference/refresh the std_heap pointer: - if (!process->heap) { - process->heap = (struct mdesc*) malloc(sizeof(struct mdesc)); + if (!this->heap) { + this->heap = (struct mdesc*) malloc(sizeof(struct mdesc)); } - MC_process_read(process, simgrid::mc::AddressSpace::Normal, - process->heap, process->heap_address, sizeof(struct mdesc), + MC_process_read(this, simgrid::mc::AddressSpace::Normal, + this->heap, this->heap_address, sizeof(struct mdesc), simgrid::mc::ProcessIndexDisabled ); - process->cache_flags |= MC_PROCESS_CACHE_FLAG_HEAP; + this->cache_flags |= MC_PROCESS_CACHE_FLAG_HEAP; } -void MC_process_refresh_malloc_info(mc_process_t process) +/** Refresh the information about the process + * + * Do not use direclty, this is used by the getters when appropriate + * in order to have fresh data. + * */ +void Process::refresh_malloc_info() { xbt_assert(mc_mode == MC_MODE_SERVER); - xbt_assert(!MC_process_is_self(process)); - if (!(process->cache_flags & MC_PROCESS_CACHE_FLAG_HEAP)) - MC_process_refresh_heap(process); + xbt_assert(!this->is_self()); + if (!(this->cache_flags & MC_PROCESS_CACHE_FLAG_HEAP)) + this->refresh_heap(); // Refresh process->heapinfo: size_t malloc_info_bytesize = - (process->heap->heaplimit + 1) * sizeof(malloc_info); - process->heap_info = (malloc_info*) realloc(process->heap_info, malloc_info_bytesize); - MC_process_read(process, simgrid::mc::AddressSpace::Normal, - process->heap_info, - process->heap->heapinfo, malloc_info_bytesize, + (this->heap->heaplimit + 1) * sizeof(malloc_info); + this->heap_info = (malloc_info*) realloc(this->heap_info, malloc_info_bytesize); + MC_process_read(this, simgrid::mc::AddressSpace::Normal, + this->heap_info, + this->heap->heapinfo, malloc_info_bytesize, simgrid::mc::ProcessIndexDisabled); - process->cache_flags |= MC_PROCESS_CACHE_FLAG_MALLOC_INFO; + this->cache_flags |= MC_PROCESS_CACHE_FLAG_MALLOC_INFO; +} + } +} + +extern "C" { #define SO_RE "\\.so[\\.0-9]*$" #define VERSION_RE "-[\\.0-9]*$" @@ -427,7 +437,7 @@ char* MC_process_read_string(mc_process_t process, void* address) { if (!address) return NULL; - if (MC_process_is_self(process)) + if (process->is_self()) return strdup((char*) address); off_t len = 128; @@ -473,7 +483,7 @@ int MC_process_vm_open(pid_t pid, int flags) static void MC_process_open_memory_file(mc_process_t process) { - if (MC_process_is_self(process) || process->memory_file >= 0) + if (process->is_self() || process->memory_file >= 0) return; int fd = MC_process_vm_open(process->pid, O_RDWR); @@ -526,31 +536,31 @@ namespace simgrid { namespace mc { const void *Process::read_bytes(void* buffer, std::size_t size, - std::uint64_t address, int process_index, + remote_ptr address, int process_index, AddressSpace::ReadMode mode) { if (process_index != simgrid::mc::ProcessIndexDisabled) { - mc_object_info_t info = MC_process_find_object_info_rw(this, (void*)address); + mc_object_info_t info = MC_process_find_object_info_rw(this, (void*)address.address()); // Segment overlap is not handled. if (MC_object_info_is_privatized(info)) { if (process_index < 0) xbt_die("Missing process index"); // Address translation in the privaization segment: // TODO, fix me (broken) - size_t offset = address - (std::uint64_t)info->start_rw; - address = address - offset; + size_t offset = address.address() - (std::uint64_t)info->start_rw; + address = remote(address.address() - offset); } } - if (MC_process_is_self(this)) { + if (this->is_self()) { if (mode == simgrid::mc::AddressSpace::Lazy) - return (void*)address; + return (void*)address.address(); else { - memcpy(buffer, (void*)address, size); + memcpy(buffer, (void*)address.address(), size); return buffer; } } else { - if (pread_whole(this->memory_file, buffer, size, (off_t) address) < 0) + if (pread_whole(this->memory_file, buffer, size, (off_t) address.address()) < 0) xbt_die("Read from process %lli failed", (long long) this->pid); return buffer; } @@ -576,7 +586,7 @@ const void* MC_process_read_dynar_element(mc_process_t process, void MC_process_write(mc_process_t process, const void* local, void* remote, size_t len) { - if (MC_process_is_self(process)) { + if (process->is_self()) { memcpy(remote, local, len); } else { if (pwrite_whole(process->memory_file, local, len, (off_t) remote) < 0) @@ -611,7 +621,7 @@ static void MC_zero_buffer_init(void) void MC_process_clear_memory(mc_process_t process, void* remote, size_t len) { - if (MC_process_is_self(process)) { + if (process->is_self()) { memset(remote, 0, len); } else { pthread_once(&zero_buffer_flag, MC_zero_buffer_init); diff --git a/src/mc/mc_process.h b/src/mc/mc_process.h index 19640aa8a8..743fb2f4a8 100644 --- a/src/mc/mc_process.h +++ b/src/mc/mc_process.h @@ -54,8 +54,27 @@ public: Process(pid_t pid, int sockfd); ~Process(); const void* read_bytes(void* buffer, std::size_t size, - std::uint64_t address, int process_index = ProcessIndexAny, + remote_ptr address, int process_index = ProcessIndexAny, ReadMode mode = Normal) override; + xbt_mheap_t get_heap() + { + if (!(this->cache_flags & MC_PROCESS_CACHE_FLAG_HEAP)) + this->refresh_heap(); + return this->heap; + } + malloc_info* get_malloc_info() + { + if (!(this->cache_flags & MC_PROCESS_CACHE_FLAG_MALLOC_INFO)) + this->refresh_malloc_info(); + return this->heap_info; + } + bool is_self() + { + return this->process_flags & MC_PROCESS_SELF_FLAG; + } +private: + void refresh_heap(); + void refresh_malloc_info(); public: // to be private mc_process_flags_t process_flags; pid_t pid; @@ -92,7 +111,7 @@ public: // to be private * * This is refreshed with the `MC_process_refresh` call. * This is not used if the process is the current one: - * use `MC_process_get_heap_info` in order to use it. + * use `get_heap_info()` in order to use it. */ xbt_mheap_t heap; @@ -100,7 +119,7 @@ public: // to be private * * This is refreshed with the `MC_process_refresh` call. * This is not used if the process is the current one: - * use `MC_process_get_malloc_info` in order to use it. + * use `get_malloc_info()` in order to use it. */ malloc_info* heap_info; @@ -133,27 +152,9 @@ public: // to be private SG_BEGIN_DECL() -int MC_process_vm_open(pid_t pid, int flags); - -/** Refresh the information about the process - * - * Do not use direclty, this is used by the getters when appropriate - * in order to have fresh data. +/** Open a FD to a remote process memory (`/dev/$pid/mem`) */ -XBT_INTERNAL void MC_process_refresh_heap(mc_process_t process); - -/** Refresh the information about the process - * - * Do not use direclty, this is used by the getters when appropriate - * in order to have fresh data. - * */ -XBT_INTERNAL void MC_process_refresh_malloc_info(mc_process_t process); - -static inline -bool MC_process_is_self(mc_process_t process) -{ - return process->process_flags & MC_PROCESS_SELF_FLAG; -} +int MC_process_vm_open(pid_t pid, int flags); /* Process memory access: */ @@ -202,20 +203,6 @@ XBT_INTERNAL dw_frame_t MC_process_find_function(mc_process_t process, const voi XBT_INTERNAL void MC_process_read_variable(mc_process_t process, const char* name, void* target, size_t size); XBT_INTERNAL char* MC_process_read_string(mc_process_t, void* address); -static inline xbt_mheap_t MC_process_get_heap(mc_process_t process) -{ - if (!(process->cache_flags & MC_PROCESS_CACHE_FLAG_HEAP)) - MC_process_refresh_heap(process); - return process->heap; -} - -static inline malloc_info* MC_process_get_malloc_info(mc_process_t process) -{ - if (!(process->cache_flags & MC_PROCESS_CACHE_FLAG_MALLOC_INFO)) - MC_process_refresh_malloc_info(process); - return process->heap_info; -} - /** Find (one occurence of) the named variable definition */ XBT_INTERNAL dw_variable_t MC_process_find_variable_by_name(mc_process_t process, const char* name); diff --git a/src/mc/mc_smx.cpp b/src/mc/mc_smx.cpp index 6def3fdf5e..6260b0cabb 100644 --- a/src/mc/mc_smx.cpp +++ b/src/mc/mc_smx.cpp @@ -87,7 +87,7 @@ static void MC_process_refresh_simix_process_list( void MC_process_smx_refresh(mc_process_t process) { xbt_assert(mc_mode == MC_MODE_SERVER); - xbt_assert(!MC_process_is_self(process)); + xbt_assert(!process->is_self()); if (process->cache_flags & MC_PROCESS_CACHE_FLAG_SIMIX_PROCESSES) return; diff --git a/src/mc/mc_snapshot.cpp b/src/mc/mc_snapshot.cpp index 857d47d38f..57e229d3c4 100644 --- a/src/mc/mc_snapshot.cpp +++ b/src/mc/mc_snapshot.cpp @@ -183,12 +183,12 @@ Snapshot::~Snapshot() } const void* Snapshot::read_bytes(void* buffer, std::size_t size, - std::uint64_t address, int process_index, + remote_ptr address, int process_index, AddressSpace::ReadMode mode) { - mc_mem_region_t region = mc_get_snapshot_region((void*)address, this, process_index); + mc_mem_region_t region = mc_get_snapshot_region((void*)address.address(), this, process_index); if (region) { - const void* res = MC_region_read(region, buffer, (void*)address, size); + const void* res = MC_region_read(region, buffer, (void*)address.address(), size); if (buffer == res || mode == AddressSpace::Lazy) return res; else { @@ -197,7 +197,7 @@ const void* Snapshot::read_bytes(void* buffer, std::size_t size, } } else - return MC_process_read(this->process, mode, buffer, (void*)address, size, process_index); + return MC_process_read(this->process, mode, buffer, (void*)address.address(), size, process_index); } } diff --git a/src/mc/mc_snapshot.h b/src/mc/mc_snapshot.h index 7d5654b569..c9da67deb0 100644 --- a/src/mc/mc_snapshot.h +++ b/src/mc/mc_snapshot.h @@ -209,7 +209,7 @@ public: Snapshot(); ~Snapshot(); const void* read_bytes(void* buffer, std::size_t size, - std::uint64_t address, int process_index = ProcessIndexAny, + remote_ptr address, int process_index = ProcessIndexAny, ReadMode mode = Normal) override; public: // To be private mc_process_t process; @@ -300,7 +300,8 @@ const void* MC_snapshot_read(mc_snapshot_t snapshot, simgrid::mc::AddressSpace::ReadMode mode, void* target, const void* addr, size_t size, int process_index) { - return snapshot->read_bytes(target, size, (uint64_t)addr, process_index, mode); + return snapshot->read_bytes(target, size, simgrid::mc::remote(addr), + process_index, mode); } MC_SHOULD_BE_INTERNAL int MC_snapshot_region_memcmp( @@ -323,7 +324,7 @@ const void* mc_snapshot_get_heap_end(mc_snapshot_t snapshot) { if(snapshot==NULL) xbt_die("snapshot is NULL"); - return MC_process_get_heap(&mc_model_checker->process())->breakval; + return mc_model_checker->process().get_heap()->breakval; } /** @brief Read memory from a snapshot region diff --git a/src/mc/mc_unw.cpp b/src/mc/mc_unw.cpp index 6df54b80e3..cb213124e7 100644 --- a/src/mc/mc_unw.cpp +++ b/src/mc/mc_unw.cpp @@ -22,6 +22,8 @@ #include "mc_process.h" #include "mc_unw.h" +using simgrid::mc::remote; + extern "C" { // ***** Implementation @@ -81,7 +83,7 @@ static int access_mem(unw_addr_space_t as, mc_unw_context_t context = (mc_unw_context_t) arg; if (write) return - UNW_EREADONLYREG; - context->address_space->read_bytes(valp, sizeof(unw_word_t), addr); + context->address_space->read_bytes(valp, sizeof(unw_word_t), remote(addr)); return 0; } @@ -231,7 +233,7 @@ int mc_unw_init_cursor(unw_cursor_t *cursor, mc_unw_context_t context) mc_address_space_t as = context->address_space; mc_process_t process = dynamic_cast(as); - if (process && MC_process_is_self(process)) + if (process && process->is_self()) return unw_init_local(cursor, &context->context); return unw_init_remote(cursor, context->process->unw_addr_space, context); diff --git a/src/mc/mc_visited.cpp b/src/mc/mc_visited.cpp index d0f79873f7..4b19189c74 100644 --- a/src/mc/mc_visited.cpp +++ b/src/mc/mc_visited.cpp @@ -57,10 +57,10 @@ static mc_visited_state_t visited_state_new() mc_process_t process = &(mc_model_checker->process()); mc_visited_state_t new_state = xbt_new0(s_mc_visited_state_t, 1); new_state->heap_bytes_used = mmalloc_get_bytes_used_remote( - MC_process_get_heap(process)->heaplimit, - MC_process_get_malloc_info(process)); + process->get_heap()->heaplimit, + process->get_malloc_info()); - if (MC_process_is_self(&mc_model_checker->process())) { + if (mc_model_checker->process().is_self()) { new_state->nb_processes = xbt_swag_size(simix_global->process_list); } else { MC_process_smx_refresh(&mc_model_checker->process()); @@ -83,9 +83,9 @@ mc_visited_pair_t MC_visited_pair_new(int pair_num, xbt_automaton_state_t automa if(pair->graph_state->system_state == NULL) pair->graph_state->system_state = MC_take_snapshot(pair_num); pair->heap_bytes_used = mmalloc_get_bytes_used_remote( - MC_process_get_heap(process)->heaplimit, - MC_process_get_malloc_info(process)); - if (MC_process_is_self(&mc_model_checker->process())) { + process->get_heap()->heaplimit, + process->get_malloc_info()); + if (mc_model_checker->process().is_self()) { pair->nb_processes = xbt_swag_size(simix_global->process_list); } else { MC_process_smx_refresh(&mc_model_checker->process());