X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/5b20234fb56b5cdbc975868ad32603ac146b9d1a..d89ca681772fdaafdd69049d4d66676a4e98de38:/src/mc/remote/RemoteProcess.cpp diff --git a/src/mc/remote/RemoteProcess.cpp b/src/mc/remote/RemoteProcess.cpp index 1bbc17de96..fcde1d3f42 100644 --- a/src/mc/remote/RemoteProcess.cpp +++ b/src/mc/remote/RemoteProcess.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2014-2021. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2014-2022. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ @@ -19,6 +19,7 @@ #include #include #include +#include #include using simgrid::mc::remote; @@ -34,6 +35,7 @@ namespace mc { static const std::vector filtered_libraries = { #ifdef __linux__ "ld", + "ld-linux-x86", #elif defined __FreeBSD__ "ld-elf", "ld-elf32", @@ -99,8 +101,6 @@ static const std::vector filtered_libraries = { "liblber", "libldap", "libldap_r", - "liblua5.1", - "liblua5.3", "liblzma", "libm", "libmd", @@ -216,12 +216,13 @@ int open_vm(pid_t pid, int flags) RemoteProcess::RemoteProcess(pid_t pid) : AddressSpace(this), pid_(pid), running_(true) {} -void RemoteProcess::init(void* mmalloc_default_mdp, void* maxpid, void* actors, void* dead_actors) +void RemoteProcess::init(xbt_mheap_t mmalloc_default_mdp, unsigned long* maxpid, xbt_dynar_t actors, + xbt_dynar_t dead_actors) { - this->heap_address = mmalloc_default_mdp; - this->maxpid_addr_ = maxpid; - this->actors_addr_ = actors; - this->dead_actors_addr_ = dead_actors; + this->heap_address = remote(mmalloc_default_mdp); + this->maxpid_addr_ = remote(maxpid); + this->actors_addr_ = remote(actors); + this->dead_actors_addr_ = remote(dead_actors); this->memory_map_ = simgrid::xbt::get_memory_map(this->pid_); this->init_memory_map_info(); @@ -262,7 +263,7 @@ void RemoteProcess::refresh_heap() // Read/dereference/refresh the std_heap pointer: if (not this->heap) this->heap = std::make_unique(); - this->read_bytes(this->heap.get(), sizeof(mdesc), remote(this->heap_address)); + this->read(this->heap.get(), this->heap_address); this->cache_flags_ |= RemoteProcess::cache_heap; } @@ -289,15 +290,13 @@ void RemoteProcess::init_memory_map_info() XBT_DEBUG("Get debug information ..."); this->maestro_stack_start_ = nullptr; this->maestro_stack_end_ = nullptr; - this->object_infos.resize(0); + this->object_infos.clear(); this->binary_info = nullptr; std::vector const& maps = this->memory_map_; const char* current_name = nullptr; - this->object_infos.clear(); - for (size_t i = 0; i < maps.size(); i++) { simgrid::xbt::VmMap const& reg = maps[i]; const char* pathname = maps[i].pathname.c_str(); @@ -443,8 +442,8 @@ std::string RemoteProcess::read_string(RemotePtr address) const void* RemoteProcess::read_bytes(void* buffer, std::size_t size, RemotePtr address, ReadOptions /*options*/) const { - if (pread_whole(this->memory_file, buffer, size, (size_t)address.address()) < 0) - xbt_die("Read at %p from process %lli failed", (void*)address.address(), (long long)this->pid_); + xbt_assert(pread_whole(this->memory_file, buffer, size, (size_t)address.address()) != -1, + "Read at %p from process %lli failed", (void*)address.address(), (long long)this->pid_); return buffer; } @@ -456,27 +455,26 @@ void* RemoteProcess::read_bytes(void* buffer, std::size_t size, RemotePtr */ void RemoteProcess::write_bytes(const void* buffer, size_t len, RemotePtr address) const { - if (pwrite_whole(this->memory_file, buffer, len, (size_t)address.address()) < 0) - xbt_die("Write to process %lli failed", (long long)this->pid_); + xbt_assert(pwrite_whole(this->memory_file, buffer, len, (size_t)address.address()) != -1, + "Write to process %lli failed", (long long)this->pid_); } -static const void* zero_buffer; -static const size_t zero_buffer_size = 10 * 4096; - -static void zero_buffer_init() +static void zero_buffer_init(const void** zero_buffer, size_t zero_buffer_size) { int fd = open("/dev/zero", O_RDONLY); xbt_assert(fd >= 0, "Could not open /dev/zero"); - zero_buffer = mmap(nullptr, zero_buffer_size, PROT_READ, MAP_SHARED, fd, 0); - xbt_assert(zero_buffer != MAP_FAILED, "Could not map the zero buffer"); + *zero_buffer = mmap(nullptr, zero_buffer_size, PROT_READ, MAP_SHARED, fd, 0); + xbt_assert(*zero_buffer != MAP_FAILED, "Could not map the zero buffer"); close(fd); } void RemoteProcess::clear_bytes(RemotePtr address, size_t len) const { - pthread_once_t zero_buffer_flag = PTHREAD_ONCE_INIT; + static constexpr size_t zero_buffer_size = 10 * 4096; + static const void* zero_buffer; + static std::once_flag zero_buffer_flag; - pthread_once(&zero_buffer_flag, zero_buffer_init); + std::call_once(zero_buffer_flag, zero_buffer_init, &zero_buffer, zero_buffer_size); while (len) { size_t s = len > zero_buffer_size ? zero_buffer_size : len; this->write_bytes(zero_buffer, s, address); @@ -558,7 +556,7 @@ void RemoteProcess::dump_stack() const if (unw_init_remote(&cursor, as, context) != 0) { _UPT_destroy(context); unw_destroy_addr_space(as); - XBT_ERROR("Could not initialiez ptrace cursor"); + XBT_ERROR("Could not initialize ptrace cursor"); return; } @@ -567,18 +565,5 @@ void RemoteProcess::dump_stack() const _UPT_destroy(context); unw_destroy_addr_space(as); } - -unsigned long RemoteProcess::get_maxpid() const -{ - unsigned long maxpid; - this->read_bytes(&maxpid, sizeof(unsigned long), remote(maxpid_addr_)); - return maxpid; -} - -void RemoteProcess::get_actor_vectors(RemotePtr& actors, RemotePtr& dead_actors) -{ - actors = remote(static_cast(actors_addr_)); - dead_actors = remote(static_cast(dead_actors_addr_)); -} } // namespace mc } // namespace simgrid