X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/eb417d0c8064e83fc1211abc819ae93687505003..573a49afcc1a146f9776a7a772d87efd9db77657:/src/mc/mc_process.cpp diff --git a/src/mc/mc_process.cpp b/src/mc/mc_process.cpp index 476a1a9d45..836cf4b393 100644 --- a/src/mc/mc_process.cpp +++ b/src/mc/mc_process.cpp @@ -48,6 +48,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_process, mc, static const char *const FILTERED_LIBS[] = { "libstdc++", + "libboost_context", "libc++", "libm", "libgcc_s", @@ -190,13 +191,13 @@ Process::Process(pid_t pid, int sockfd) Process* process = this; process->process_flags = MC_PROCESS_NO_FLAG; - process->socket = sockfd; - process->pid = pid; + process->socket_ = sockfd; + process->pid_ = pid; if (pid==getpid()) process->process_flags |= MC_PROCESS_SELF_FLAG; - process->running = true; - process->status = 0; - process->memory_map = MC_get_memory_map(pid); + process->running_ = true; + process->status_ = 0; + process->memory_map_ = get_memory_map(pid); process->cache_flags = MC_PROCESS_CACHE_FLAG_NONE; process->heap = NULL; process->heap_info = NULL; @@ -206,7 +207,7 @@ Process::Process(pid_t pid, int sockfd) if (process->is_self()) process->memory_file = -1; else { - int fd = open_vm(process->pid, O_RDWR); + int fd = open_vm(process->pid_, O_RDWR); if (fd<0) xbt_die("Could not open file for process virtual address space"); process->memory_file = fd; @@ -225,8 +226,6 @@ Process::Process(pid_t pid, int sockfd) process->smx_process_infos = MC_smx_process_info_list_new(); process->smx_old_process_infos = MC_smx_process_info_list_new(); - process->checkpoint_ignore = MC_checkpoint_ignore_new(); - process->unw_addr_space = unw_create_addr_space(&mc_unw_accessors , __BYTE_ORDER); if (process->process_flags & MC_PROCESS_SELF_FLAG) { process->unw_underlying_addr_space = unw_local_addr_space; @@ -241,16 +240,14 @@ Process::~Process() { Process* process = this; - process->process_flags = MC_PROCESS_NO_FLAG; - process->pid = 0; - - MC_free_memory_map(process->memory_map); - process->memory_map = NULL; + if (this->socket_ >= 0 && close(this->socket_) < 0) + xbt_die("Could not close communication socket"); - process->maestro_stack_start = NULL; - process->maestro_stack_end = NULL; + process->process_flags = MC_PROCESS_NO_FLAG; + process->pid_ = 0; - xbt_dynar_free(&process->checkpoint_ignore); + process->maestro_stack_start_ = nullptr; + process->maestro_stack_end_ = nullptr; xbt_dynar_free(&process->smx_process_infos); xbt_dynar_free(&process->smx_old_process_infos); @@ -327,8 +324,8 @@ void Process::refresh_malloc_info() void Process::init_memory_map_info() { XBT_DEBUG("Get debug information ..."); - this->maestro_stack_start = NULL; - this->maestro_stack_end = NULL; + this->maestro_stack_start_ = nullptr; + this->maestro_stack_end_ = nullptr; this->object_infos = NULL; this->object_infos_size = 0; this->binary_info = NULL; @@ -339,25 +336,25 @@ void Process::init_memory_map_info() if(regcomp(&res.so_re, SO_RE, 0) || regcomp(&res.version_re, VERSION_RE, 0)) xbt_die(".so regexp did not compile"); - memory_map_t maps = this->memory_map; + std::vector const& maps = this->memory_map_; const char* current_name = NULL; - for (ssize_t i=0; i < maps->mapsize; i++) { - map_region_t reg = &(maps->regions[i]); - const char* pathname = maps->regions[i].pathname; + for (size_t i=0; i < maps.size(); i++) { + simgrid::mc::VmMap const& reg = maps[i]; + const char* pathname = maps[i].pathname.c_str(); // Nothing to do - if (maps->regions[i].pathname == NULL) { + if (maps[i].pathname.empty()) { current_name = NULL; continue; } // [stack], [vvar], [vsyscall], [vdso] ... if (pathname[0] == '[') { - if ((reg->prot & PROT_WRITE) && !memcmp(pathname, "[stack]", 7)) { - this->maestro_stack_start = reg->start_addr; - this->maestro_stack_end = reg->end_addr; + if ((reg.prot & PROT_WRITE) && !memcmp(pathname, "[stack]", 7)) { + this->maestro_stack_start_ = remote(reg.start_addr); + this->maestro_stack_end_ = remote(reg.end_addr); } current_name = NULL; continue; @@ -367,7 +364,7 @@ void Process::init_memory_map_info() continue; current_name = pathname; - if (!(reg->prot & PROT_READ) && (reg->prot & PROT_EXEC)) + if (!(reg.prot & PROT_READ) && (reg.prot & PROT_EXEC)) continue; const bool is_executable = !i; @@ -383,9 +380,9 @@ void Process::init_memory_map_info() } mc_object_info_t info = - MC_find_object_info(this->memory_map, pathname, is_executable); + MC_find_object_info(this->memory_map_, pathname, is_executable); this->object_infos = (mc_object_info_t*) realloc(this->object_infos, - (this->object_infos_size+1) * sizeof(mc_object_info_t*)); + (this->object_infos_size+1) * sizeof(mc_object_info_t)); this->object_infos[this->object_infos_size] = info; this->object_infos_size++; if (is_executable) @@ -402,8 +399,8 @@ void Process::init_memory_map_info() for (size_t i=0; i!=this->object_infos_size; ++i) MC_post_process_object_info(this, this->object_infos[i]); - xbt_assert(this->maestro_stack_start, "Did not find maestro_stack_start"); - xbt_assert(this->maestro_stack_end, "Did not find maestro_stack_end"); + xbt_assert(this->maestro_stack_start_, "Did not find maestro_stack_start"); + xbt_assert(this->maestro_stack_end_, "Did not find maestro_stack_end"); XBT_DEBUG("Get debug information done !"); } @@ -538,10 +535,21 @@ const void *Process::read_bytes(void* buffer, std::size_t size, if (MC_object_info_is_privatized(info)) { if (process_index < 0) xbt_die("Missing process index"); + if (process_index >= (int) MC_smpi_process_count()) + xbt_die("Invalid process index"); + + // Read smpi_privatisation_regions from MCed: + smpi_privatisation_region_t remote_smpi_privatisation_regions = + mc_model_checker->process().read_variable( + "smpi_privatisation_regions"); + + s_smpi_privatisation_region_t privatisation_region = + mc_model_checker->process().read( + remote(remote_smpi_privatisation_regions + process_index)); + // Address translation in the privaization segment: - // TODO, fix me (broken) size_t offset = address.address() - (std::uint64_t)info->start_rw; - address = remote(address.address() - offset); + address = remote((char*)privatisation_region.address + offset); } } @@ -554,7 +562,7 @@ const void *Process::read_bytes(void* buffer, std::size_t size, } } else { if (pread_whole(this->memory_file, buffer, size, (off_t) address.address()) < 0) - xbt_die("Read from process %lli failed", (long long) this->pid); + xbt_die("Read from process %lli failed", (long long) this->pid_); return buffer; } } @@ -572,7 +580,7 @@ void Process::write_bytes(const void* buffer, size_t len, remote_ptr addre memcpy((void*)address.address(), buffer, len); } else { if (pwrite_whole(this->memory_file, buffer, len, address.address()) < 0) - xbt_die("Write to process %lli failed", (long long) this->pid); + xbt_die("Write to process %lli failed", (long long) this->pid_); } } @@ -591,32 +599,53 @@ void Process::clear_bytes(remote_ptr address, size_t len) } } -} -} +void Process::ignore_region(std::uint64_t addr, std::size_t size) +{ + IgnoredRegion region; + region.addr = addr; + region.size = size; -extern "C" { + if (ignored_regions_.empty()) { + ignored_regions_.push_back(region); + return; + } -const void* MC_process_read_dynar_element(mc_process_t process, - void* local, const void* remote_dynar, size_t i, size_t len) -{ - s_xbt_dynar_t d; - process->read_bytes(&d, sizeof(d), remote(remote_dynar)); - if (i >= d.used) - xbt_die("Out of bound index %zi/%lu", i, d.used); - if (len != d.elmsize) - xbt_die("Bad size in MC_process_read_dynar_element"); - process->read_bytes(local, len, remote(xbt_dynar_get_ptr(&d, i))); - return local; -} + unsigned int cursor = 0; + IgnoredRegion* current_region = nullptr; + + int start = 0; + int end = ignored_regions_.size() - 1; + while (start <= end) { + cursor = (start + end) / 2; + current_region = &ignored_regions_[cursor]; + if (current_region->addr == addr) { + if (current_region->size == size) + return; + else if (current_region->size < size) + start = cursor + 1; + else + end = cursor - 1; + } else if (current_region->addr < addr) + start = cursor + 1; + else + end = cursor - 1; + } -unsigned long MC_process_read_dynar_length(mc_process_t process, const void* remote_dynar) -{ - if (!remote_dynar) - return 0; - unsigned long res; - process->read_bytes(&res, sizeof(res), - remote(&((xbt_dynar_t)remote_dynar)->used)); - return res; + std::size_t position; + if (current_region->addr == addr) { + if (current_region->size < size) { + position = cursor + 1; + } else { + position = cursor; + } + } else if (current_region->addr < addr) { + position = cursor + 1; + } else { + position = cursor; + } + ignored_regions_.insert( + ignored_regions_.begin() + position, region); } } +}