message(STATUS "System processor: x86_64 (${CMAKE_SYSTEM_PROCESSOR}, 64 bits)")
set(PROCESSOR_x86_64 1)
ENDIF()
- if (MSVC)
- message(STATUS "Disable fast raw contextes on Microsoft Visual.")
+ if (WIN32)
+ message(STATUS "Disable fast raw contextes on Windows.")
else()
set(HAVE_RAW_CONTEXTS 1)
endif()
endif()
endif()
+if(WIN32)
+ set(Boost_USE_STATIC_LIBS 1)
+endif()
+
find_package(Boost 1.48)
if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
CHECK_FUNCTION_EXISTS(getdtablesize HAVE_GETDTABLESIZE)
CHECK_FUNCTION_EXISTS(sysconf HAVE_SYSCONF)
CHECK_FUNCTION_EXISTS(popen HAVE_POPEN)
+CHECK_FUNCTION_EXISTS(process_vm_readv HAVE_PROCESS_VM_READV)
+CHECK_FUNCTION_EXISTS(mmap HAVE_MMAP)
CHECK_SYMBOL_EXISTS(vasprintf stdio.h HAVE_VASPRINTF)
if(MINGW)
set(HAVE_VASPRINTF 1)
endif()
-CHECK_FUNCTION_EXISTS(process_vm_readv HAVE_PROCESS_VM_READV)
-CHECK_FUNCTION_EXISTS(mmap HAVE_MMAP)
#Check if __thread is defined
execute_process(
SET(HAVE_MMALLOC 0)
endif()
-set(HAVE_UCONTEXT_CONTEXTS 0)
-set(HAVE_THREAD_CONTEXTS 0)
-
if(enable_jedule)
set(HAVE_JEDULE 1)
endif()
#--------------------------------------------------------------------------------------------------
### Initialize of CONTEXT THREADS
+set(HAVE_THREAD_CONTEXTS 0)
+
if(HAVE_PTHREAD)
### Test that we have a way to create semaphores
message(FATAL_ERROR "Semaphores are not usable (neither sem_open nor sem_init is both compilable and executable), but they are mandatory to threads (you may need to mount /dev).")
endif()
+ set(HAVE_THREAD_CONTEXTS 1)
+ message("-- Support for thread context factory ok.")
endif()
-# This is needed for ucontext on MacOS X:
-if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
- add_definitions(-D_XOPEN_SOURCE=700 -D_DARWIN_C_SOURCE)
+
+set(HAVE_UCONTEXT_CONTEXTS 0)
+if(NOT HAVE_UCONTEXT_H)
+ message("-- No ucontext factory: <ucontext.h> not found.")
+elseif(APPLE)
+ message("-- No ucontext factory: Apple don't want us to use them.")
+ set(HAVE_UCONTEXT_H 0)
+else()
+ try_compile(compile_makecontext ${CMAKE_BINARY_DIR} ${CMAKE_HOME_DIRECTORY}/tools/cmake/test_prog/prog_makecontext.c
+ OUTPUT_VARIABLE compile_makecontext_output)
+
+ #If can have both context
+ if(compile_makecontext)
+ set(HAVE_UCONTEXT_CONTEXTS 1)
+ message("-- Support for ucontext factory ok.")
+ else()
+ message("-- Error: <ucontext.h> exists, but makecontext is not compilable. Compilation output:\n ${compile_makecontext_output}")
+ message("-- No ucontext factory: makecontext() is not compilable.")
+ endif()
+
+ # Stack setup (size and address)
+ try_run(RUN_makecontext_VAR COMPILE_makecontext_VAR
+ ${CMAKE_BINARY_DIR} ${CMAKE_HOME_DIRECTORY}/tools/cmake/test_prog/prog_stacksetup.c
+ RUN_OUTPUT_VARIABLE stack_setup)
+
+ LIST(LENGTH stack_setup stack_setup_len)
+ if("${stack_setup_len}" STREQUAL "2")
+ LIST(GET stack_setup 0 makecontext_addr)
+ LIST(GET stack_setup 1 makecontext_size)
+ set(sg_makecontext_stack_addr "#define sg_makecontext_stack_addr(skaddr) (${makecontext_addr})")
+ set(sg_makecontext_stack_size "#define sg_makecontext_stack_size(sksize) (${makecontext_size})")
+ else()
+ message(FATAL_ERROR "Could not figure out the stack setup. Compil: ${RUN_makecontext_VAR}. Exec: ${COMPILE_makecontext_VAR}. Output: ${stack_setup}")
+ endif()
endif()
-try_compile(HAVE_UCONTEXT
- ${CMAKE_BINARY_DIR}
- ${CMAKE_HOME_DIRECTORY}/tools/cmake/test_prog/prog_AC_CHECK_MCSC.c)
-#If can have both context
-if(HAVE_UCONTEXT)
- set(HAVE_UCONTEXT_CONTEXTS 1)
- message("-- Support for ucontext factory")
+# Stack growth direction (upward or downward). Used for the following contexts: SysV, raw, Boost
+try_run(RUN_stackgrowth_VAR COMPILE_stackgrowth_VAR
+ ${CMAKE_BINARY_DIR}
+ ${CMAKE_HOME_DIRECTORY}/tools/cmake/test_prog/prog_stackgrowth.c
+ RUN_OUTPUT_VARIABLE stack
+ COPY_FILE test_stackgrowth)
+
+if("${stack}" STREQUAL "down")
+ set(PTH_STACKGROWTH "-1")
+elseif("${stack}" STREQUAL "up")
+ set(PTH_STACKGROWTH "1")
+else()
+ if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
+ set(PTH_STACKGROWTH "-1")
+ elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "i686")
+ set(PTH_STACKGROWTH "-1")
+ else()
+ message(FATAL_ERROR "Could not figure out the stack direction. Test prog returned: ${stack}; CMAKE_SYSTEM_PROCESSOR: ${CMAKE_SYSTEM_PROCESSOR}.")
+ endif()
endif()
+# If the test ran well, remove the test binary
+execute_process(COMMAND ${CMAKE_COMMAND} -E remove test_stackgrowth)
+#--------------------------------------------------------------------------------------------------
-if(HAVE_PTHREAD)
- set(HAVE_THREAD_CONTEXTS 1)
- message("-- Support for thread context factory")
+### check for addr2line
+find_path(ADDR2LINE NAMES addr2line PATHS NO_DEFAULT_PATHS)
+if(ADDR2LINE)
+ set(ADDR2LINE "${ADDR2LINE}/addr2line")
endif()
###############
if(GIT_DATE)
set(SIMGRID_VERSION_BANNER "${SIMGRID_VERSION_BANNER} (${GIT_DATE})")
endif()
-#--------------------------------------------------------------------------------------------------
-
-if(HAVE_UCONTEXT_H)
- if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
- set(makecontext_CPPFLAGS "${makecontext_CPPFLAGS} -D_XOPEN_SOURCE=700")
- endif()
-
- file(REMOVE ${CMAKE_BINARY_DIR}/conftestval)
-
- if(NOT CMAKE_CROSSCOMPILING)
- try_run(RUN_makecontext_VAR COMPILE_makecontext_VAR
- ${CMAKE_BINARY_DIR}
- ${CMAKE_HOME_DIRECTORY}/tools/cmake/test_prog/prog_stacksetup.c
- COMPILE_DEFINITIONS "${makecontext_CPPFLAGS}"
- )
- endif()
-
- if(EXISTS ${CMAKE_BINARY_DIR}/conftestval)
- file(READ ${CMAKE_BINARY_DIR}/conftestval MAKECONTEXT_ADDR_SIZE)
- string(REPLACE "\n" "" MAKECONTEXT_ADDR_SIZE "${MAKECONTEXT_ADDR_SIZE}")
- string(REGEX MATCH ;^.*,;MAKECONTEXT_ADDR "${MAKECONTEXT_ADDR_SIZE}")
- string(REGEX MATCH ;,.*$; MAKECONTEXT_SIZE "${MAKECONTEXT_ADDR_SIZE}")
- string(REPLACE "," "" makecontext_addr "${MAKECONTEXT_ADDR}")
- string(REPLACE "," "" makecontext_size "${MAKECONTEXT_SIZE}")
- set(pth_skaddr_makecontext "#define pth_skaddr_makecontext(skaddr,sksize) (${makecontext_addr})")
- set(pth_sksize_makecontext "#define pth_sksize_makecontext(skaddr,sksize) (${makecontext_size})")
- endif()
-endif()
-
-#--------------------------------------------------------------------------------------------------
-
-### check for stackgrowth
-if (NOT CMAKE_CROSSCOMPILING)
- try_run(RUN_stackgrowth_VAR COMPILE_stackgrowth_VAR
- ${CMAKE_BINARY_DIR}
- ${CMAKE_HOME_DIRECTORY}/tools/cmake/test_prog/prog_stackgrowth.c
- RUN_OUTPUT_VARIABLE stack
- COPY_FILE test_stackgrowth
- )
-endif()
-if("${stack}" STREQUAL "down")
- set(PTH_STACKGROWTH "-1")
-elseif("${stack}" STREQUAL "up")
- set(PTH_STACKGROWTH "1")
-else()
- if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
- set(PTH_STACKGROWTH "-1")
- elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "i686")
- set(PTH_STACKGROWTH "-1")
- else()
- message(FATAL_ERROR "Could not figure out the stack direction. Test prog returned: ${stack}; CMAKE_SYSTEM_PROCESSOR: ${CMAKE_SYSTEM_PROCESSOR}.")
- endif()
-endif()
-# If the test ran well, remove the test binary
-execute_process(COMMAND ${CMAKE_COMMAND} -E remove test_stackgrowth)
-
-### check for addr2line
-find_path(ADDR2LINE NAMES addr2line PATHS NO_DEFAULT_PATHS)
-if(ADDR2LINE)
- set(ADDR2LINE "${ADDR2LINE}/addr2line")
-endif()
### Generate the required headers and scripts
#############################################
throw simgrid::xbt::errno_error(errno);
return handle_message(buffer, size);
}
- if (socket_pollfd->revents & POLLERR) {
+ if (socket_pollfd->revents & POLLERR)
throw_socket_error(socket_pollfd->fd);
- }
if (socket_pollfd->revents & POLLHUP)
xbt_die("Socket hang up?");
}
this->handle_signals();
return true;
}
- if (signalfd_pollfd->revents & POLLERR) {
+ if (signalfd_pollfd->revents & POLLERR)
throw_socket_error(signalfd_pollfd->fd);
- }
if (signalfd_pollfd->revents & POLLHUP)
xbt_die("Signalfd hang up?");
}
void ModelChecker::wait_client(simgrid::mc::Process& process)
{
this->resume(process);
- while (this->process().running()) {
+ while (this->process().running())
if (!this->handle_events())
return;
- }
}
void ModelChecker::simcall_handle(simgrid::mc::Process& process, unsigned long pid, int value)
m.value = value;
process.send_message(m);
process.cache_flags = (mc_process_cache_flags_t) 0;
- while (process.running()) {
+ while (process.running())
if (!this->handle_events())
return;
- }
}
}
// This djb2:
std::uint64_t hash = 5381;
- for (std::size_t i = 0; i != n; ++i) {
+ for (std::size_t i = 0; i != n; ++i)
hash = ((hash << 5) + hash) + values[i];
- }
return hash;
}
// by relocating it somewhere else in the virtual memory
// space:
void* memory = ::mmap(nullptr, size << xbt_pagebits, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_POPULATE, -1, 0);
- if (memory == MAP_FAILED) {
+ if (memory == MAP_FAILED)
xbt_die("Could not mmap initial snapshot pages.");
- }
this->top_index_ = 0;
this->capacity_ = size;
// Expand the memory region by moving it into another
// virtual memory address if necessary:
void* new_memory = mremap(this->memory_, old_bytesize, new_bytesize, MREMAP_MAYMOVE);
- if (new_memory == MAP_FAILED) {
+ if (new_memory == MAP_FAILED)
xbt_die("Could not mremap snapshot pages.");
- }
this->capacity_ = size;
this->memory_ = new_memory;
if (this->free_pages_.empty()) {
// Expand the region:
- if (this->top_index_ == this->capacity_) {
+ if (this->top_index_ == this->capacity_)
// All the pages are allocated, we need add more pages:
this->resize(2 * this->capacity_);
- }
// Use a page from the top:
return this->top_index_++;
count -= res;
buffer += res;
offset += res;
- } else if (res==0) {
+ } else if (res==0)
return -1;
- } else if (errno != EINTR) {
+ else if (errno != EINTR) {
perror("pread_whole");
return -1;
}
count -= res;
buffer += res;
offset += res;
- } else if (res==0) {
+ } else if (res==0)
return -1;
- } else if (errno != EINTR) {
+ else if (errno != EINTR)
return -1;
- }
}
return real_count;
}
this->maestro_stack_start_ = nullptr;
this->maestro_stack_end_ = nullptr;
- if (this->memory_file >= 0) {
+ if (this->memory_file >= 0)
close(this->memory_file);
- }
if (this->unw_underlying_addr_space != unw_local_addr_space) {
unw_destroy_addr_space(this->unw_underlying_addr_space);
std::shared_ptr<simgrid::mc::ObjectInformation> Process::find_object_info(RemotePtr<void> addr) const
{
- for (auto const& object_info : this->object_infos) {
+ for (auto const& object_info : this->object_infos)
if (addr.address() >= (std::uint64_t)object_info->start
- && addr.address() <= (std::uint64_t)object_info->end) {
+ && addr.address() <= (std::uint64_t)object_info->end)
return object_info;
- }
- }
return nullptr;
}
std::shared_ptr<ObjectInformation> Process::find_object_info_exec(RemotePtr<void> addr) const
{
- for (std::shared_ptr<ObjectInformation> const& info : this->object_infos) {
+ for (std::shared_ptr<ObjectInformation> const& info : this->object_infos)
if (addr.address() >= (std::uint64_t) info->start_exec
- && addr.address() <= (std::uint64_t) info->end_exec) {
+ && addr.address() <= (std::uint64_t) info->end_exec)
return info;
- }
- }
return nullptr;
}
std::shared_ptr<ObjectInformation> Process::find_object_info_rw(RemotePtr<void> addr) const
{
- for (std::shared_ptr<ObjectInformation> const& info : this->object_infos) {
+ for (std::shared_ptr<ObjectInformation> const& info : this->object_infos)
if (addr.address() >= (std::uint64_t)info->start_rw
- && addr.address() <= (std::uint64_t)info->end_rw) {
+ && addr.address() <= (std::uint64_t)info->end_rw)
return info;
- }
- }
return nullptr;
}
std::size_t position;
if (current_region->addr == addr) {
- if (current_region->size < size) {
+ if (current_region->size < size)
position = cursor + 1;
- } else {
+ else
position = cursor;
- }
- } else if (current_region->addr < addr) {
+ } else if (current_region->addr < addr)
position = cursor + 1;
- } else {
+ else
position = cursor;
- }
ignored_regions_.insert(
ignored_regions_.begin() + position, region);
}
RegionType type, void *start_addr, void* permanent_addr, size_t size,
RegionSnapshot const* ref_region)
{
- if (_sg_mc_sparse_checkpoint) {
+ if (_sg_mc_sparse_checkpoint)
return sparse_region(type, start_addr, permanent_addr, size, ref_region);
- } else {
+ else
return dense_region(type, start_addr, permanent_addr, size);
- }
}
RegionSnapshot sparse_region(RegionType region_type,
* communication is not ready, it can timeout and won't block. */
if (_sg_mc_timeout == 1)
return TRUE;
- } else {
- /* On the other hand if it hasn't a timeout, check if the comm is ready.*/
- if (act->comm.detached && act->comm.src_proc == nullptr
+ }
+ /* On the other hand if it hasn't a timeout, check if the comm is ready.*/
+ else if (act->comm.detached && act->comm.src_proc == nullptr
&& act->comm.type == SIMIX_COMM_READY)
return (act->comm.dst_proc != nullptr);
- }
return (act->comm.src_proc && act->comm.dst_proc);
case SIMCALL_COMM_WAITANY: {
assert(comms_buffer.elmsize == sizeof(act));
buffer_size = comms_buffer.elmsize * comms_buffer.used;
comms = &comms_buffer;
- } else {
+ } else
comms = simcall_comm_waitany__get__comms(req);
- }
+
// Read all the dynar buffer:
char buffer[buffer_size];
if (mc_mode == MC_MODE_SERVER)
int simcall_HANDLER_mc_random(smx_simcall_t simcall, int min, int max)
{
- if (!MC_is_active() && !MC_record_path){
+ if (!MC_is_active() && !MC_record_path)
return prng_random(min, max);
- }
-
return simcall->mc_value;
}
const size_t n = process->object_infos.size();
snapshot->snapshot_regions.resize(n + 1);
int i = 0;
- for (auto const& object_info : process->object_infos) {
- add_region(i, snapshot, simgrid::mc::RegionType::Data,
+ for (auto const& object_info : process->object_infos)
+ add_region(i++, snapshot, simgrid::mc::RegionType::Data,
object_info.get(),
object_info->start_rw, object_info->start_rw,
object_info->end_rw - object_info->start_rw);
- ++i;
- }
xbt_mheap_t heap = process->get_heap();
void *start_heap = heap->base;
process->get_malloc_info());
#ifdef HAVE_SMPI
- if (mc_model_checker->process().privatized() && MC_smpi_process_count()) {
+ if (mc_model_checker->process().privatized() && MC_smpi_process_count())
// snapshot->privatization_index = smpi_loaded_page
mc_model_checker->process().read_variable(
"smpi_loaded_page", &snapshot->privatization_index,
sizeof(snapshot->privatization_index));
- } else
+ else
#endif
- {
snapshot->privatization_index = simgrid::mc::ProcessIndexMissing;
- }
}
/** \brief Fills the position of the segments (executable, read-only, read/write).
// .bss is usually after the .data:
simgrid::xbt::VmMap const& next = maps[i + 1];
if (next.pathname.empty() && (next.prot & PROT_WRITE)
- && next.start_addr == reg.end_addr) {
+ && next.start_addr == reg.end_addr)
result->end_rw = (char*) maps[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",
new_var.region = region_type;
new_var.address = nullptr;
- if (current_variable.address != nullptr) {
+ if (current_variable.address != nullptr)
new_var.address = current_variable.address;
- } else if (!current_variable.location_list.empty()) {
+ else if (!current_variable.location_list.empty()) {
simgrid::dwarf::Location location =
simgrid::dwarf::resolve(
current_variable.location_list,
xbt_die("Cannot handle non-address variable");
new_var.address = location.address();
- } else {
+ } else
xbt_die("No address");
- }
result.push_back(std::move(new_var));
}
unw_cursor_t c;
// TODO, check condition check (unw_init_local==0 means end of frame)
- if (mc_unw_init_cursor(&c, stack_context) != 0) {
-
+ if (mc_unw_init_cursor(&c, stack_context) != 0)
xbt_die("Could not initialize stack unwinding");
- } else
while (1) {
s_mc_stack_frame_t stack_frame;
break;
int ret = unw_step(&c);
- if (ret == 0) {
+ if (ret == 0)
xbt_die("Unexpected end of stack.");
- } else if (ret < 0) {
+ else if (ret < 0)
xbt_die("Error while unwinding stack");
- }
}
if (result.empty()) {
&context, sizeof(context), remote(stack.context));
if (mc_unw_init_context(&st.context, &mc_model_checker->process(),
- &context) < 0) {
+ &context) < 0)
xbt_die("Could not initialise the libunwind context.");
- }
+
st.stack_frames = unwind_stack_frames(&st.context);
st.local_variables = get_local_variables_values(st.stack_frames, stack.process_index);
st.process_index = stack.process_index;
}
// Zero the memory:
- for(auto const& region : mc_model_checker->process().ignored_regions()) {
+ for(auto const& region : mc_model_checker->process().ignored_regions())
snapshot->process()->clear_bytes(remote(region.addr), region.size);
- }
}
const size_t link_size = 200;
char link[200];
res = readlink(source, link, link_size);
- if (res<0) {
+
+ if (res<0)
xbt_die("Could not read link for %s", source);
- }
- if (res==200) {
+ if (res==200)
xbt_die("Buffer to small for link of %s", source);
- }
+
link[res] = '\0';
#ifdef HAVE_SMPI
if (_sg_mc_visited > 0 || strcmp(_sg_mc_property_file, "")) {
snapshot->stacks =
take_snapshot_stacks(&snapshot);
- if (_sg_mc_hash) {
+ if (_sg_mc_hash)
snapshot->hash = simgrid::mc::hash(*snapshot);
- } else {
+ else
snapshot->hash = 0;
- }
- } else {
+ } else
snapshot->hash = 0;
- }
snapshot_ignore_restore(snapshot);
if (use_soft_dirty)
for (auto const& fd : snapshot->current_fds) {
int new_fd = open(fd.filename.c_str(), fd.flags);
- if (new_fd < 0) {
+ if (new_fd < 0)
xbt_die("Could not reopen the file %s fo restoring the file descriptor",
fd.filename.c_str());
- }
if (new_fd != fd.number) {
dup2(new_fd, fd.number);
close(new_fd);
if (!memcmp(comm1->data, comm2->data, comm1->data_size))
return NONE_DIFF;
return DATA_DIFF;
- }else{
+ } else
return DATA_DIFF;
- }
return NONE_DIFF;
}
pattern->rdv = mc_model_checker->process().read_string(remote_name);
pattern->dst_proc = MC_smx_resolve_process(synchro.comm.dst_proc)->pid;
pattern->dst_host = MC_smx_process_get_host_name(issuer);
- } else {
+ } else
xbt_die("Unexpected call_type %i", (int) call_type);
- }
xbt_dynar_push(
xbt_dynar_get_as(incomplete_communications_pattern, issuer->pid, xbt_dynar_t),
int completed = 0;
/* Complete comm pattern */
- xbt_dynar_foreach(xbt_dynar_get_as(incomplete_communications_pattern, issuer, xbt_dynar_t), cursor, current_comm_pattern) {
+ xbt_dynar_foreach(xbt_dynar_get_as(incomplete_communications_pattern, issuer, xbt_dynar_t), cursor, current_comm_pattern)
if (current_comm_pattern->comm_addr == comm_addr) {
update_comm_pattern(current_comm_pattern, comm_addr);
completed = 1;
XBT_DEBUG("Remove incomplete comm pattern for process %u at cursor %u", issuer, cursor);
break;
}
- }
+
if(!completed)
xbt_die("Corresponding communication not found!");
mc_list_comm_pattern_t pattern = xbt_dynar_get_as(
initial_communications_pattern, issuer, mc_list_comm_pattern_t);
- if (!initial_global_state->initial_communications_pattern_done) {
+ if (!initial_global_state->initial_communications_pattern_done)
/* Store comm pattern */
xbt_dynar_push(pattern->list, &comm_pattern);
- } else {
+ else {
/* Evaluate comm determinism */
deterministic_comm_pattern(issuer, comm_pattern, backtracking);
pattern->index_comm++;
XBT_DEBUG("Execute: %s", req_str);
xbt_free(req_str);
- if (dot_output != nullptr) {
+ if (dot_output != nullptr)
req_str = MC_request_get_dot_output(req, value);
- }
MC_state_set_executed_request(state, req, value);
mc_stats->executed_transitions++;
/* TODO : handle test and testany simcalls */
e_mc_call_type_t call = MC_CALL_TYPE_NONE;
- if (_sg_mc_comms_determinism || _sg_mc_send_determinism) {
+ if (_sg_mc_comms_determinism || _sg_mc_send_determinism)
call = MC_get_call_type(req);
- }
/* Answer the request */
MC_simcall_handle(req, value); /* After this call req is no longer useful */
if (dot_output != nullptr)
fprintf(dot_output, "\"%d\" -> \"%d\" [%s];\n", state->num, next_state->num, req_str);
- } else {
-
- if (dot_output != nullptr)
- fprintf(dot_output, "\"%d\" -> \"%d\" [%s];\n", state->num, visited_state->other_num == -1 ? visited_state->num : visited_state->other_num, req_str);
-
- }
+ } else if (dot_output != nullptr)
+ fprintf(dot_output, "\"%d\" -> \"%d\" [%s];\n",
+ state->num, visited_state->other_num == -1 ? visited_state->num : visited_state->other_num, req_str);
xbt_fifo_unshift(mc_stack, next_state);
} else {
- if (xbt_fifo_size(mc_stack) > _sg_mc_max_depth) {
+ if (xbt_fifo_size(mc_stack) > _sg_mc_max_depth)
XBT_WARN("/!\\ Max depth reached ! /!\\ ");
- } else if (visited_state != nullptr) {
+ else if (visited_state != nullptr)
XBT_DEBUG("State already visited (equal to state %d), exploration stopped on this path.", visited_state->other_num == -1 ? visited_state->num : visited_state->other_num);
- } else {
+ else
XBT_DEBUG("There are no more processes to interleave. (depth %d)", xbt_fifo_size(mc_stack));
- }
if (!initial_global_state->initial_communications_pattern_done)
initial_global_state->initial_communications_pattern_done = 1;
return SIMGRID_MC_EXIT_DEADLOCK;
}
- while ((state = (mc_state_t) xbt_fifo_shift(mc_stack)) != nullptr) {
+ while ((state = (mc_state_t) xbt_fifo_shift(mc_stack)) != nullptr)
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);
XBT_DEBUG("Delete state %d at depth %d", state->num, xbt_fifo_size(mc_stack) + 1);
MC_state_delete(state, !state->in_visited_states ? 1 : 0);
}
- }
+
}
}
mc_reduce_kind = e_mc_reduce_none;
mc_model_checker->wait_for_requests();
- if (mc_mode == MC_MODE_CLIENT) {
+ if (mc_mode == MC_MODE_CLIENT)
// This will move somehwere else:
MC_client_handle_messages();
- }
/* Create exploration stack */
mc_stack = xbt_fifo_new();
mc_list_comm_pattern_t list_process_comm;
unsigned int cursor;
- xbt_dynar_foreach(initial_communications_pattern, cursor, list_process_comm){
+ xbt_dynar_foreach(initial_communications_pattern, cursor, list_process_comm)
list_process_comm->index_comm = (int)xbt_dynar_get_as(state->index_comm, cursor, int);
- }
- for (unsigned 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)
);
- }
}
void MC_state_copy_incomplete_communications_pattern(mc_state_t state)
state->index_comm = xbt_dynar_new(sizeof(unsigned int), nullptr);
mc_list_comm_pattern_t list_process_comm;
unsigned int cursor;
- xbt_dynar_foreach(initial_communications_pattern, cursor, list_process_comm){
+ xbt_dynar_foreach(initial_communications_pattern, cursor, list_process_comm)
xbt_dynar_push_as(state->index_comm, unsigned int, list_process_comm->index_comm);
- }
}
void MC_handle_comm_pattern(
void* addr_pointed1 = MC_region_read_pointer(region1, real_area1);
void* addr_pointed2 = MC_region_read_pointer(region2, real_area2);
- if (type->subtype && type->subtype->type == DW_TAG_subroutine_type) {
+ if (type->subtype && type->subtype->type == DW_TAG_subroutine_type)
return (addr_pointed1 != addr_pointed2);
- } else {
-
- if (addr_pointed1 == nullptr && addr_pointed2 == NULL)
- return 0;
- if (addr_pointed1 == nullptr || addr_pointed2 == NULL)
- return 1;
- if (!state.compared_pointers.insert(
- std::make_pair(addr_pointed1, addr_pointed2)).second)
- return 0;
+ if (addr_pointed1 == nullptr && addr_pointed2 == NULL)
+ return 0;
+ if (addr_pointed1 == nullptr || addr_pointed2 == NULL)
+ return 1;
+ if (!state.compared_pointers.insert(
+ std::make_pair(addr_pointed1, addr_pointed2)).second)
+ return 0;
- pointer_level++;
+ pointer_level++;
// Some cases are not handled here:
// * the pointers lead to different areas (one to the heap, the other to the RW segment ...);
return 1;
if (!type->type_id)
return (addr_pointed1 != addr_pointed2);
- else {
+ else
return compare_areas_with_type(state, process_index,
addr_pointed1, snapshot1, region1,
addr_pointed2, snapshot2, region2,
type->subtype, pointer_level);
- }
}
// TODO, We do not handle very well the case where
// it belongs to a different (non-heap) region from the current one.
- else {
+ else
return (addr_pointed1 != addr_pointed2);
- }
- }
+
break;
}
case DW_TAG_structure_type:
#ifdef HAVE_SMPI
if (r1->storage_type() == simgrid::mc::StorageType::Privatized) {
xbt_assert(process_index >= 0);
- if (r2->storage_type() != simgrid::mc::StorageType::Privatized) {
+ if (r2->storage_type() != simgrid::mc::StorageType::Privatized)
return 1;
- }
size_t process_count = MC_smpi_process_count();
xbt_assert(process_count == r1->privatized_data().size()
if (stack1->local_variables.size() != stack2->local_variables.size()) {
XBT_VERB("Different number of local variables");
return 1;
- } else {
+ }
+
unsigned int cursor = 0;
local_variable_t current_var1, current_var2;
int res;
cursor++;
}
return 0;
- }
}
int snapshot_compare(void *state1, void *state2)
#ifndef MC_DEBUG
return 1;
#endif
- } else {
+ } else
XBT_VERB("(%d - %d) Same hash : 0x%" PRIx64, num1, num2, s1->hash);
- }
}
/* Compare enabled processes */
void _mc_cfg_cb_timeout(const char *name, int pos)
{
- if (_sg_cfg_init_status && !(_sg_do_model_check || MC_record_path)) {
+ if (_sg_cfg_init_status && !(_sg_do_model_check || MC_record_path))
xbt_die
("You are specifying a value to enable/disable timeout for wait requests after the initialization (through MSG_config?), but model-checking was not activated at config time (through bu the program was not runned under the model-checker (with simgrid-mc)). This won't work, sorry.");
- }
+
_sg_mc_timeout = xbt_cfg_get_boolean(_sg_cfg_set, name);
}
void _mc_cfg_cb_reduce(const char *name, int pos)
{
- if (_sg_cfg_init_status && !_sg_do_model_check) {
+ if (_sg_cfg_init_status && !_sg_do_model_check)
xbt_die
("You are specifying a reduction strategy after the initialization (through MSG_config?), but model-checking was not activated at config time (through bu the program was not runned under the model-checker (with simgrid-mc)). This won't work, sorry.");
- }
+
char *val = xbt_cfg_get_string(_sg_cfg_set, name);
- if (!strcasecmp(val, "none")) {
+ if (!strcasecmp(val, "none"))
mc_reduce_kind = e_mc_reduce_none;
- } else if (!strcasecmp(val, "dpor")) {
+ else if (!strcasecmp(val, "dpor"))
mc_reduce_kind = e_mc_reduce_dpor;
- } else {
+ else
xbt_die("configuration option %s can only take 'none' or 'dpor' as a value",
name);
- }
}
void _mc_cfg_cb_checkpoint(const char *name, int pos)
{
- if (_sg_cfg_init_status && !_sg_do_model_check) {
+ if (_sg_cfg_init_status && !_sg_do_model_check)
xbt_die
("You are specifying a checkpointing value after the initialization (through MSG_config?), but model-checking was not activated at config time (through bu the program was not runned under the model-checker (with simgrid-mc)). This won't work, sorry.");
- }
+
_sg_mc_checkpoint = xbt_cfg_get_int(_sg_cfg_set, name);
}
void _mc_cfg_cb_sparse_checkpoint(const char *name, int pos) {
- if (_sg_cfg_init_status && !_sg_do_model_check) {
+ if (_sg_cfg_init_status && !_sg_do_model_check)
xbt_die("You are specifying a checkpointing value after the initialization (through MSG_config?), but model-checking was not activated at config time (through bu the program was not runned under the model-checker (with simgrid-mc)). This won't work, sorry.");
- }
+
_sg_mc_sparse_checkpoint = xbt_cfg_get_boolean(_sg_cfg_set, name);
}
"(through MSG_config?), but model-checking was not activated "
"at config time (through --cfg=model-check:1). "
"This won't work, sorry.");
+
_sg_mc_soft_dirty = xbt_cfg_get_boolean(_sg_cfg_set, name);
}
{
if (_sg_cfg_init_status && !_sg_do_model_check)
xbt_die("You are specifying a KSM value after the initialization (through MSG_config?), but model-checking was not activated at config time (through --cfg=model-check:1). This won't work, sorry.");
+
_sg_mc_ksm = xbt_cfg_get_boolean(_sg_cfg_set, name);
}
void _mc_cfg_cb_property(const char *name, int pos)
{
- if (_sg_cfg_init_status && !_sg_do_model_check) {
+ if (_sg_cfg_init_status && !_sg_do_model_check)
xbt_die
("You are specifying a property after the initialization (through MSG_config?), but model-checking was not activated at config time (through bu the program was not runned under the model-checker (with simgrid-mc)). This won't work, sorry.");
- }
+
_sg_mc_property_file = xbt_cfg_get_string(_sg_cfg_set, name);
}
void _mc_cfg_cb_hash(const char *name, int pos)
{
- if (_sg_cfg_init_status && !_sg_do_model_check) {
+ if (_sg_cfg_init_status && !_sg_do_model_check)
xbt_die
("You are specifying a value to enable/disable the use of global hash to speedup state comparaison, but model-checking was not activated at config time (through bu the program was not runned under the model-checker (with simgrid-mc)). This won't work, sorry.");
- }
+
_sg_mc_hash = xbt_cfg_get_boolean(_sg_cfg_set, name);
}
void _mc_cfg_cb_snapshot_fds(const char *name, int pos)
{
- if (_sg_cfg_init_status && !_sg_do_model_check) {
+ if (_sg_cfg_init_status && !_sg_do_model_check)
xbt_die
("You are specifying a value to enable/disable the use of FD snapshoting, but model-checking was not activated at config time (through bu the program was not runned under the model-checker (with simgrid-mc)). This won't work, sorry.");
- }
+
_sg_mc_snapshot_fds = xbt_cfg_get_boolean(_sg_cfg_set, name);
}
void _mc_cfg_cb_max_depth(const char *name, int pos)
{
- if (_sg_cfg_init_status && !_sg_do_model_check) {
+ if (_sg_cfg_init_status && !_sg_do_model_check)
xbt_die
("You are specifying a max depth value after the initialization (through MSG_config?), but model-checking was not activated at config time (through bu the program was not runned under the model-checker (with simgrid-mc)). This won't work, sorry.");
- }
+
_sg_mc_max_depth = xbt_cfg_get_int(_sg_cfg_set, name);
}
void _mc_cfg_cb_visited(const char *name, int pos)
{
- if (_sg_cfg_init_status && !_sg_do_model_check) {
+ if (_sg_cfg_init_status && !_sg_do_model_check)
xbt_die
("You are specifying a number of stored visited states after the initialization (through MSG_config?), but model-checking was not activated at config time (through bu the program was not runned under the model-checker (with simgrid-mc)). This won't work, sorry.");
- }
+
_sg_mc_visited = xbt_cfg_get_int(_sg_cfg_set, name);
}
void _mc_cfg_cb_dot_output(const char *name, int pos)
{
- if (_sg_cfg_init_status && !_sg_do_model_check) {
+ if (_sg_cfg_init_status && !_sg_do_model_check)
xbt_die
("You are specifying a file name for a dot output of graph state after the initialization (through MSG_config?), but model-checking was not activated at config time (through bu the program was not runned under the model-checker (with simgrid-mc)). This won't work, sorry.");
- }
+
_sg_mc_dot_output_file = xbt_cfg_get_string(_sg_cfg_set, name);
}
void _mc_cfg_cb_comms_determinism(const char *name, int pos)
{
- if (_sg_cfg_init_status && !_sg_do_model_check) {
+ if (_sg_cfg_init_status && !_sg_do_model_check)
xbt_die
("You are specifying a value to enable/disable the detection of determinism in the communications schemes after the initialization (through MSG_config?), but model-checking was not activated at config time (through bu the program was not runned under the model-checker (with simgrid-mc)). This won't work, sorry.");
- }
+
_sg_mc_comms_determinism = xbt_cfg_get_boolean(_sg_cfg_set, name);
}
void _mc_cfg_cb_send_determinism(const char *name, int pos)
{
- if (_sg_cfg_init_status && !_sg_do_model_check) {
+ if (_sg_cfg_init_status && !_sg_do_model_check)
xbt_die
("You are specifying a value to enable/disable the detection of send-determinism in the communications schemes after the initialization (through MSG_config?), but model-checking was not activated at config time (through bu the program was not runned under the model-checker (with simgrid-mc)). This won't work, sorry.");
- }
+
_sg_mc_send_determinism = xbt_cfg_get_boolean(_sg_cfg_set, name);
}
void _mc_cfg_cb_termination(const char *name, int pos)
{
- if (_sg_cfg_init_status && !_sg_do_model_check) {
+ if (_sg_cfg_init_status && !_sg_do_model_check)
xbt_die
("You are specifying a value to enable/disable the detection of non progressive cycles after the initialization (through MSG_config?), but model-checking was not activated at config time (through bu the program was not runned under the model-checker (with simgrid-mc)). This won't work, sorry.");
- }
+
_sg_mc_termination = xbt_cfg_get_boolean(_sg_cfg_set, name);
}
unsigned int cursor = 0;
heap_area_pair_t current_pair;
- xbt_dynar_foreach(list, cursor, current_pair) {
+ xbt_dynar_foreach(list, cursor, current_pair)
if (current_pair->block1 == block1 && current_pair->block2 == block2
&& current_pair->fragment1 == fragment1
&& current_pair->fragment2 == fragment2)
return 0;
- }
return 1;
}
unsigned int cursor = 0;
heap_area_pair_t current_pair;
- xbt_dynar_foreach(list, cursor, current_pair) {
+ xbt_dynar_foreach(list, cursor, current_pair)
if (current_pair->fragment1 != -1) {
}
- }
}
/** Check whether two blocks are known to be matching
res_compare =
compare_heap_area(process_index, addr_pointed1, addr_pointed2, snapshot1,
snapshot2, previous, nullptr, 0);
- if (res_compare == 1) {
+ if (res_compare == 1)
return res_compare;
- }
i = pointer_align + sizeof(void *);
continue;
- } else {
+ } else
return 1;
- }
}
&& ((ignore1 = heap_comparison_ignore_size(state->to_ignore1, real_area1))
> 0)
&& ((ignore2 = heap_comparison_ignore_size(state->to_ignore2, real_area2))
- == ignore1)) {
+ == ignore1))
return 0;
- }
simgrid::mc::Type *subtype, *subsubtype;
int res, elm_size;
} else {
if (area_size != -1 && type->byte_size != area_size)
return -1;
- else {
+ else
return (MC_snapshot_region_memcmp(real_area1, heap_region1, real_area2, heap_region2, type->byte_size) != 0);
- }
}
break;
case DW_TAG_enumeration_type:
if (res == 1)
return res;
}
- } else {
+ } else
return -1;
- }
} else {
for(simgrid::mc::Member& member : type->members) {
// TODO, optimize this? (for the offset case)
snapshot1, snapshot2,
previous, member.type, -1,
check_ignore, 0);
- if (res == 1) {
+ if (res == 1)
return res;
- }
}
}
break;
|| (block1 > (ssize_t) state->heapsize1) || (block1 < 1)
|| ((char *) area2 < (char *) state->std_heap_copy.heapbase)
|| (block2 > (ssize_t) state->heapsize2) || (block2 < 1)) {
- if (match_pairs) {
+ if (match_pairs)
xbt_dynar_free(&previous);
- }
return 1;
}
if (heapinfo1->busy_block.size !=
heapinfo2->busy_block.size) {
- if (match_pairs) {
+ if (match_pairs)
xbt_dynar_free(&previous);
- }
return 1;
}
if (heapinfo1->busy_block.busy_size !=
heapinfo2->busy_block.busy_size) {
- if (match_pairs) {
+ if (match_pairs)
xbt_dynar_free(&previous);
- }
return 1;
}
// Remember (basic) type inference.
// The current data structure only allows us to do this for the whole block.
- if (type != nullptr && area1 == real_addr_block1) {
+ if (type != nullptr && area1 == real_addr_block1)
state->types1_(block1, 0) = type;
- }
- if (type != nullptr && area2 == real_addr_block2) {
+ if (type != nullptr && area2 == real_addr_block2)
state->types2_(block2, 0) = type;
- }
if (size <= 0) {
if (match_pairs) {
}
return -1;
} else {
- if (match_pairs) {
+ if (match_pairs)
xbt_dynar_free(&previous);
- }
return 1;
}
}
// Remember (basic) type inference.
// The current data structure only allows us to do this for the whole fragment.
- if (type != nullptr && area1 == real_addr_frag1) {
+ if (type != nullptr && area1 == real_addr_frag1)
state->types1_(block1, frag1) = type;
- }
- if (type != nullptr && area2 == real_addr_frag2) {
+ if (type != nullptr && area2 == real_addr_frag2)
state->types2_(block2, frag2) = type;
- }
+
// The type of the variable is already known:
if (type) {
new_type1 = type;
size = new_size1;
}
- if (offset1 == 0 && offset2 == 0) {
- if (!add_heap_area_pair(previous, block1, frag1, block2, frag2)) {
+ if (offset1 == 0 && offset2 == 0
+ && !add_heap_area_pair(previous, block1, frag1, block2, frag2)) {
if (match_pairs) {
match_equals(state, previous);
xbt_dynar_free(&previous);
}
return 0;
}
- }
if (size <= 0) {
if (match_pairs) {
} else {
- if (match_pairs) {
+ if (match_pairs)
xbt_dynar_free(&previous);
- }
return 1;
}
/* Start comparison */
- if (type) {
+ if (type)
res_compare =
compare_heap_area_with_type(state, process_index, area1, area2, snapshot1, snapshot2,
previous, type, size, check_ignore,
pointer_level);
- } else {
+ else
res_compare =
compare_heap_area_without_type(state, process_index, area1, area2, snapshot1, snapshot2,
previous, size, check_ignore);
- }
+
if (res_compare == 1) {
if (match_pairs)
xbt_dynar_free(&previous);
if (heapinfo[block].type == MMALLOC_TYPE_FREE || heapinfo[block].type == MMALLOC_TYPE_HEAPINFO) { /* Free block */
return -1;
- } else if (heapinfo[block].type == MMALLOC_TYPE_UNFRAGMENTED) { /* Complete block */
+ else if (heapinfo[block].type == MMALLOC_TYPE_UNFRAGMENTED) /* Complete block */
return (int) heapinfo[block].busy_block.busy_size;
- } else {
+ else
frag =
((uintptr_t) (ADDR2UINT(area) % (BLOCKSIZE))) >> heapinfo[block].type;
return (int) heapinfo[block].busy_frag.frag_size[frag];
- }
+
}
#ifndef max
int attribute)
{
Dwarf_Attribute attr;
- if (!dwarf_attr_integrate(die, attribute, &attr)) {
+ if (!dwarf_attr_integrate(die, attribute, &attr))
return nullptr;
- } else {
+ else
return dwarf_formstring(&attr);
- }
}
/** \brief Get the linkage name of a DIE.
if (low_pc) {
// DW_AT_high_pc:
Dwarf_Attribute attr;
- if (!dwarf_attr_integrate(die, DW_AT_high_pc, &attr)) {
+ if (!dwarf_attr_integrate(die, DW_AT_high_pc, &attr))
xbt_die("Missing DW_AT_high_pc matching with DW_AT_low_pc");
- }
Dwarf_Sword offset;
Dwarf_Addr high_pc;
Dwarf_Die child;
int res;
for (res = dwarf_child(die, &child); res == 0;
- res = dwarf_siblingof(&child, &child)) {
+ res = dwarf_siblingof(&child, &child))
MC_dwarf_handle_die(info, &child, unit, frame, ns);
- }
}
static void MC_dwarf_handle_die(simgrid::mc::ObjectInformation* info, Dwarf_Die * die,
break;
// Resolve full_type:
- if (!subtype->name.empty() && subtype->byte_size == 0) {
+ if (!subtype->name.empty() && subtype->byte_size == 0)
for (auto const& object_info : process->object_infos) {
auto i = object_info->full_types_by_name.find(subtype->name);
if (i != object_info->full_types_by_name.end()
break;
}
}
- } else type->full_type = subtype;
+ else type->full_type = subtype;
}
}
MC_ignore_heap(mc_time, simix_process_maxpid * sizeof(double));
smx_process_t process;
- xbt_swag_foreach(process, simix_global->process_list) {
+ xbt_swag_foreach(process, simix_global->process_list)
MC_ignore_heap(&(process->process_hookup), sizeof(process->process_hookup));
- }
}
}
ssize_t s = mc_model_checker->process().receive_message(message);
if (s == -1)
xbt_die("Could not receive message");
- else if (s != sizeof(message) || message.type != MC_MESSAGE_DEADLOCK_CHECK_REPLY) {
+ if (s != sizeof(message) || message.type != MC_MESSAGE_DEADLOCK_CHECK_REPLY)
xbt_die("%s received unexpected message %s (%i, size=%i) "
"expected MC_MESSAGE_DEADLOCK_CHECK_REPLY (%i, size=%i)",
MC_mode_name(mc_mode),
MC_message_type_name(message.type), (int) message.type, (int) s,
(int) MC_MESSAGE_DEADLOCK_CHECK_REPLY, (int) sizeof(message)
);
- }
- else
- return message.value;
+ return message.value;
}
int deadlock = FALSE;
smx_process_t process;
if (xbt_swag_size(simix_global->process_list)) {
deadlock = TRUE;
- xbt_swag_foreach(process, simix_global->process_list) {
+ xbt_swag_foreach(process, simix_global->process_list)
if (MC_process_is_enabled(process)) {
deadlock = FALSE;
break;
}
- }
}
return deadlock;
}
double MC_process_clock_get(smx_process_t process)
{
- if (mc_time) {
- if (process != nullptr)
- return mc_time[process->pid];
- else
- return -1;
- } else {
+ if (!mc_time)
return 0;
- }
+ if (process != nullptr)
+ return mc_time[process->pid];
+ return -1;
}
void MC_process_clock_add(smx_process_t process, double amount)
((char *) stack -
(char *) heap->heapbase) / BLOCKSIZE + 1;
#ifdef HAVE_SMPI
- if (smpi_privatize_global_variables && process) {
+ if (smpi_privatize_global_variables && process)
region.process_index = smpi_process_index_of_smx_process(process);
- } else
+ else
#endif
region.process_index = -1;
new_pair = MC_visited_pair_new(pair->num, pair->automaton_state, pair->atomic_propositions, pair->graph_state);
new_pair->acceptance_pair = 1;
- if (xbt_dynar_is_empty(acceptance_pairs)) {
-
+ if (xbt_dynar_is_empty(acceptance_pairs))
xbt_dynar_push(acceptance_pairs, &new_pair);
-
- } else {
+ else {
int min = -1, max = -1, index;
//int res;
xbt_dynar_insert_at(acceptance_pairs, min, &new_pair);
} else {
pair_test = (mc_visited_pair_t) xbt_dynar_get_as(acceptance_pairs, index, mc_visited_pair_t);
- if (pair_test->nb_processes < new_pair->nb_processes) {
+ if (pair_test->nb_processes < new_pair->nb_processes)
xbt_dynar_insert_at(acceptance_pairs, index + 1, &new_pair);
- } else {
- if (pair_test->heap_bytes_used < new_pair->heap_bytes_used)
- xbt_dynar_insert_at(acceptance_pairs, index + 1, &new_pair);
- else
- xbt_dynar_insert_at(acceptance_pairs, index, &new_pair);
- }
+ else if (pair_test->heap_bytes_used < new_pair->heap_bytes_used)
+ xbt_dynar_insert_at(acceptance_pairs, index + 1, &new_pair);
+ else
+ xbt_dynar_insert_at(acceptance_pairs, index, &new_pair);
}
}
return new_pair;
mc_visited_pair_t pair_test = nullptr;
int pair_found = 0;
- xbt_dynar_foreach(acceptance_pairs, cursor, pair_test) {
+ xbt_dynar_foreach(acceptance_pairs, cursor, pair_test)
if (pair_test->num == pair_num) {
pair_found = 1;
break;
}
- }
if(pair_found == 1) {
xbt_dynar_remove_at(acceptance_pairs, cursor, &pair_test);
}
return -1;
}
- case 4:{
- return 2;
- }
+ case 4:
+ return 2;
default:
return -1;
}
/* It creates the two heap regions: std_heap and mc_heap */
void MC_memory_init()
{
- if (!malloc_use_mmalloc()) {
+ if (!malloc_use_mmalloc())
xbt_die("Model-checking support is not enabled: run with simgrid-mc.");
- }
}
/* Finalize the memory subsystem */
size_t mc_page_count(size_t size)
{
size_t page_count = size >> xbt_pagebits;
- if (size & (xbt_pagesize-1)) {
+ if (size & (xbt_pagesize-1))
page_count ++;
- }
return page_count;
}
MC_mode_name(mc_mode),
MC_message_type_name(*(e_mc_message_type*) message));
- while (send(socket, message, size, 0) == -1) {
+ while (send(socket, message, size, 0) == -1)
if (errno == EINTR)
continue;
else
return errno;
- }
return 0;
}
ssize_t MC_receive_message(int socket, void* message, size_t size, int options)
{
int res = recv(socket, message, size, options);
- if (res != -1) {
+ if (res != -1)
XBT_DEBUG("Protocol [%s] received %s",
MC_mode_name(mc_mode),
MC_message_type_name(*(e_mc_message_type*) message));
- }
return res;
}
args = bprintf("comm=%s (%d of %lu)",
p, value + 1, xbt_dynar_length(&comms));
xbt_free(p);
- } else {
+ } else
args = bprintf("comm at idx %d", value);
- }
break;
}
}
char* str;
- if (args != nullptr) {
+ if (args != nullptr)
str =
bprintf("[(%lu)%s (%s)] %s(%s)", issuer->pid,
MC_smx_process_get_host_name(issuer),
MC_smx_process_get_name(issuer),
type, args);
- } else {
+ else
str =
bprintf("[(%lu)%s (%s)] %s ", issuer->pid,
MC_smx_process_get_host_name(issuer),
MC_smx_process_get_name(issuer),
type);
- }
xbt_free(args);
return str;
}
XBT_DEBUG("Execute: %s", req_str);
xbt_free(req_str);
- if (dot_output != nullptr) {
+ if (dot_output != nullptr)
req_str = MC_request_get_dot_output(req, value);
- }
MC_state_set_executed_request(state, req, value);
mc_stats->executed_transitions++;
if (dot_output != nullptr)
std::fprintf(dot_output, "\"%d\" -> \"%d\" [%s];\n", state->num, next_state->num, req_str);
- } else {
-
- if (dot_output != nullptr)
- std::fprintf(dot_output, "\"%d\" -> \"%d\" [%s];\n", state->num, visited_state->other_num == -1 ? visited_state->num : visited_state->other_num, req_str);
+ } else if (dot_output != nullptr)
+ std::fprintf(dot_output, "\"%d\" -> \"%d\" [%s];\n", state->num, visited_state->other_num == -1 ? visited_state->num : visited_state->other_num, req_str);
- }
xbt_fifo_unshift(mc_stack, next_state);
else
XBT_DEBUG("State already visited (equal to state %d), exploration stopped on this path.", visited_state->other_num == -1 ? visited_state->num : visited_state->other_num);
- } else {
-
+ } else
XBT_DEBUG("There are no more processes to interleave. (depth %d)", xbt_fifo_size(mc_stack) + 1);
- }
-
/* Trash the current state, no longer needed */
xbt_fifo_shift(mc_stack);
XBT_DEBUG("Delete state %d at depth %d", state->num, xbt_fifo_size(mc_stack) + 1);
{
if (mc_mode == MC_MODE_CLIENT)
return smpi_process_count();
- else {
- int res;
- mc_model_checker->process().read_variable("process_count",
- &res, sizeof(res));
- return res;
- }
+ int res;
+ mc_model_checker->process().read_variable("process_count",
+ &res, sizeof(res));
+ return res;
}
#endif
if (region->storage_type() == simgrid::mc::StorageType::Privatized) {
#ifdef HAVE_SMPI
// Use the current process index of the snapshot:
- if (process_index == simgrid::mc::ProcessIndexDisabled) {
+ if (process_index == simgrid::mc::ProcessIndexDisabled)
process_index = snapshot->privatization_index;
- }
- if (process_index < 0) {
+ if (process_index < 0)
xbt_die("Missing process index");
- }
- if (process_index >= (int) region->privatized_data().size()) {
+ if (process_index >= (int) region->privatized_data().size())
xbt_die("Invalid process index");
- }
simgrid::mc::RegionSnapshot& priv_region = region->privatized_data()[process_index];
xbt_assert(priv_region.contain(simgrid::mc::remote(addr)));
return &priv_region;
void* dest = target;
- if (dest==nullptr) {
+ if (dest==nullptr)
xbt_die("Missing destination buffer for fragmented memory access");
- }
// Read each page:
while (mc_page_number(nullptr, addr) != page_end) {
const void* buffer1 = MC_region_read(region1, buffer1a, addr1, size);
const void* buffer2 = MC_region_read(region2, buffer2a, addr2, size);
int res;
- if (buffer1 == buffer2) {
+ if (buffer1 == buffer2)
res = 0;
- } else {
+ else
res = memcmp(buffer1, buffer2, size);
- }
if (!stack_alloc) {
free(buffer1a);
free(buffer2a);
* \param trans The state to be deleted
*/
void MC_state_delete(mc_state_t state, int free_snapshot){
- if (state->system_state && free_snapshot){
+ if (state->system_state && free_snapshot)
delete state->system_state;
- }
if(_sg_mc_comms_determinism || _sg_mc_send_determinism){
xbt_free(state->index_comm);
xbt_free(state->incomplete_comm_pattern);
unsigned int MC_state_interleave_size(mc_state_t state)
{
unsigned int i, size = 0;
-
- for (i = 0; i < state->max_pid; i++) {
+ for (i = 0; i < state->max_pid; i++)
if ((state->proc_status[i].state == MC_INTERLEAVE)
|| (state->proc_status[i].state == MC_MORE_INTERLEAVE))
size++;
- }
-
return size;
}
case SIMCALL_MC_RANDOM: {
state->internal_req = *req;
int random_max = simcall_mc_random__get__max(req);
- if (value != random_max) {
+ if (value != random_max)
for (auto& p : mc_model_checker->process().simix_processes()) {
mc_procstate_t procstate = &state->proc_status[p.copy.pid];
const smx_process_t issuer = MC_smx_simcall_get_issuer(req);
break;
}
}
- }
break;
}
*value = -1;
while (procstate->interleave_count <
read_length(mc_model_checker->process(),
- remote(simcall_comm_testany__get__comms(&process->simcall)))) {
+ remote(simcall_comm_testany__get__comms(&process->simcall))))
if (MC_request_is_enabled_by_idx
(&process->simcall, procstate->interleave_count++)) {
*value = procstate->interleave_count - 1;
break;
}
- }
if (procstate->interleave_count >=
read_length(mc_model_checker->process(),
s_smx_synchro_t act;
mc_model_checker->process().read_bytes(
&act, sizeof(act), remote(remote_act));
- if (act.comm.src_proc && act.comm.dst_proc) {
+ if (act.comm.src_proc && act.comm.dst_proc)
*value = 0;
- } else {
- if (act.comm.src_proc == nullptr && act.comm.type == SIMIX_COMM_READY
+ else if (act.comm.src_proc == nullptr && act.comm.type == SIMIX_COMM_READY
&& act.comm.detached == 1)
- *value = 0;
- else
- *value = -1;
- }
+ *value = 0;
+ else
+ *value = -1;
procstate->state = MC_DONE;
return &process->simcall;
}
case SIMCALL_MC_RANDOM:
if (procstate->state == MC_INTERLEAVE)
*value = simcall_mc_random__get__min(&process->simcall);
- else {
- if (state->req_num < simcall_mc_random__get__max(&process->simcall))
- *value = state->req_num + 1;
- }
+ else if (state->req_num < simcall_mc_random__get__max(&process->simcall))
+ *value = state->req_num + 1;
procstate->state = MC_DONE;
return &process->simcall;
void visited_state_free(mc_visited_state_t state)
{
- if (state) {
- if(!is_exploration_stack_state(state))
- delete state->system_state;
- xbt_free(state);
- }
+ if (!state)
+ return;
+ if(!is_exploration_stack_state(state))
+ delete state->system_state;
+ xbt_free(state);
}
void visited_state_free_voidp(void *s)
nb_processes_test = ((mc_visited_state_t) ref_test)->nb_processes;
heap_bytes_used_test = ((mc_visited_state_t) ref_test)->heap_bytes_used;
}
- if (nb_processes_test < nb_processes) {
+ if (nb_processes_test < nb_processes)
start = cursor + 1;
- } else if (nb_processes_test > nb_processes) {
+ else if (nb_processes_test > nb_processes)
end = cursor - 1;
- } else {
- if (heap_bytes_used_test < heap_bytes_used) {
- start = cursor + 1;
- } else if (heap_bytes_used_test > heap_bytes_used) {
- end = cursor - 1;
- } else {
+ else if (heap_bytes_used_test < heap_bytes_used)
+ start = cursor + 1;
+ else if (heap_bytes_used_test > heap_bytes_used)
+ end = cursor - 1;
+ else {
*min = *max = cursor;
previous_cursor = cursor - 1;
while (previous_cursor >= 0) {
next_cursor++;
}
return -1;
- }
}
}
return cursor;
mc_visited_state_t is_visited_state(mc_state_t graph_state)
{
-
if (_sg_mc_visited == 0)
return nullptr;
XBT_DEBUG("Snapshot %p of visited state %d (exploration stack state %d)", new_state->system_state, new_state->num, graph_state->num);
if (xbt_dynar_is_empty(visited_states)) {
-
xbt_dynar_push(visited_states, &new_state);
return nullptr;
-
- } else {
+ }
int min = -1, max = -1, index;
// The state has not been visited: insert the state in the dynamic array.
mc_visited_state_t state_test = (mc_visited_state_t) xbt_dynar_get_as(visited_states, index, mc_visited_state_t);
- if (state_test->nb_processes < new_state->nb_processes) {
+ if (state_test->nb_processes < new_state->nb_processes)
xbt_dynar_insert_at(visited_states, index + 1, &new_state);
- } else {
- if (state_test->heap_bytes_used < new_state->heap_bytes_used)
- xbt_dynar_insert_at(visited_states, index + 1, &new_state);
- else
- xbt_dynar_insert_at(visited_states, index, &new_state);
- }
+ else if (state_test->heap_bytes_used < new_state->heap_bytes_used)
+ xbt_dynar_insert_at(visited_states, index + 1, &new_state);
+ else
+ xbt_dynar_insert_at(visited_states, index, &new_state);
XBT_DEBUG("Insert new visited state %d (total : %lu)", new_state->num, xbt_dynar_length(visited_states));
}
- // We have reached the maximum number of stored states;
- if ((ssize_t) xbt_dynar_length(visited_states) > _sg_mc_visited) {
+ if ((ssize_t) xbt_dynar_length(visited_states) <= _sg_mc_visited)
+ return nullptr;
+
+ // We have reached the maximum number of stored states;
XBT_DEBUG("Try to remove visited state (maximum number of stored states reached)");
unsigned int index2 = 0;
mc_visited_state_t state_test;
- xbt_dynar_foreach(visited_states, cursor2, state_test){
+ xbt_dynar_foreach(visited_states, cursor2, state_test)
if (!mc_model_checker->is_important_snapshot(*state_test->system_state)
&& state_test->num < min2) {
index2 = cursor2;
min2 = state_test->num;
}
- }
// and drop it:
xbt_dynar_remove_at(visited_states, index2, nullptr);
XBT_DEBUG("Remove visited state (maximum number of stored states reached)");
- }
return nullptr;
- }
}
/**
return -1;
mc_visited_pair_t new_visited_pair = nullptr;
-
- if (visited_pair == nullptr) {
+ if (visited_pair == nullptr)
new_visited_pair = MC_visited_pair_new(pair->num, pair->automaton_state, pair->atomic_propositions, pair->graph_state);
- } else {
+ else
new_visited_pair = visited_pair;
- }
if (xbt_dynar_is_empty(visited_pairs)) {
-
xbt_dynar_push(visited_pairs, &new_visited_pair);
-
- } else {
+ return -1;
+ }
int min = -1, max = -1, index;
//int res;
xbt_dynar_remove_at(visited_pairs, cursor, &pair_test);
xbt_dynar_insert_at(visited_pairs, cursor, &new_visited_pair);
pair_test->visited_removed = 1;
- if (pair_test->acceptance_pair) {
- if (pair_test->acceptance_removed == 1)
- MC_visited_pair_delete(pair_test);
- } else {
+ if (!pair_test->acceptance_pair
+ || pair_test->acceptance_removed == 1)
MC_visited_pair_delete(pair_test);
- }
return new_visited_pair->other_num;
}
}
xbt_dynar_insert_at(visited_pairs, min, &new_visited_pair);
} else {
pair_test = (mc_visited_pair_t) xbt_dynar_get_as(visited_pairs, index, mc_visited_pair_t);
- if (pair_test->nb_processes < new_visited_pair->nb_processes) {
+ if (pair_test->nb_processes < new_visited_pair->nb_processes)
xbt_dynar_insert_at(visited_pairs, index + 1, &new_visited_pair);
- } else {
- if (pair_test->heap_bytes_used < new_visited_pair->heap_bytes_used)
- xbt_dynar_insert_at(visited_pairs, index + 1, &new_visited_pair);
- else
- xbt_dynar_insert_at(visited_pairs, index, &new_visited_pair);
- }
+ else if (pair_test->heap_bytes_used < new_visited_pair->heap_bytes_used)
+ xbt_dynar_insert_at(visited_pairs, index + 1, &new_visited_pair);
+ else
+ xbt_dynar_insert_at(visited_pairs, index, &new_visited_pair);
}
if ((ssize_t) xbt_dynar_length(visited_pairs) > _sg_mc_visited) {
}
xbt_dynar_remove_at(visited_pairs, index2, &pair_test);
pair_test->visited_removed = 1;
- if (pair_test->acceptance_pair) {
- if (pair_test->acceptance_removed)
- MC_visited_pair_delete(pair_test);
- } else {
+ if (!pair_test->acceptance_pair || pair_test->acceptance_removed)
MC_visited_pair_delete(pair_test);
- }
}
-
- }
return -1;
}
* Makecontext expects integer arguments, we the context
* variable is decomposed into a serie of integers and
* each integer is passed as argument to makecontext. */
-static
-void simgrid_makecontext(ucontext_t* ucp, void (*func)(int first, ...), void* arg)
+static void simgrid_makecontext(ucontext_t* ucp, void (*func)(int first, ...), void* arg)
{
int ctx_addr[CTX_ADDR_LEN];
memcpy(ctx_addr, &arg, sizeof(void*));
makecontext(ucp, (void (*)()) func, 2, ctx_addr[0], ctx_addr[1]);
break;
default:
- xbt_die("Ucontexts are not supported on this arch yet (addr len = %zu/%zu = %zu)",
- sizeof(void*), sizeof(int), CTX_ADDR_LEN);
+ xbt_die("Ucontexts are not supported on this arch yet (addr len = %zu/%zu = %zu)", sizeof(void*), sizeof(int), CTX_ADDR_LEN);
}
}
void_pfn_smxprocess_t cleanup_func, smx_process_t process)
: Context(std::move(code), cleanup_func, process)
{
- /* if the user provided a function for the process then use it,
- otherwise it is the context for maestro */
+ /* if the user provided a function for the process then use it, otherwise it is the context for maestro */
if (has_code()) {
this->stack_ = (char*) SIMIX_context_stack_new();
getcontext(&this->uc_);
this->uc_.uc_link = nullptr;
- this->uc_.uc_stack.ss_sp = pth_skaddr_makecontext(
- this->stack_, smx_context_usable_stack_size);
- this->uc_.uc_stack.ss_size = pth_sksize_makecontext(
- this->stack_, smx_context_usable_stack_size);
+ this->uc_.uc_stack.ss_sp = sg_makecontext_stack_addr(this->stack_);
+ this->uc_.uc_stack.ss_size = sg_makecontext_stack_size(smx_context_usable_stack_size);
simgrid_makecontext(&this->uc_, smx_ctx_sysv_wrapper, this);
} else {
if (process != NULL && sysv_maestro_context == NULL)
if (smx_context_guard_size > 0 && !MC_is_active()) {
-#if defined(_WIN32) || (PTH_STACKGROWTH != -1)
+#if !defined(PTH_STACKGROWTH) || (PTH_STACKGROWTH != -1)
static int warned_once = 0;
if (!warned_once) {
- XBT_WARN("Stack overflow protection is known to be broken on your system. Either you're on Windows or PTH_STACKGROWTH != -1 (current value is %d).",
- PTH_STACKGROWTH);
+ XBT_WARN("Stack overflow protection is known to be broken on your system. Either stack grows upwards, or it was not even tested properly.");
warned_once = 1;
}
#endif
nb_threads = xbt_os_get_numcores();
XBT_INFO("Auto-setting contexts/nthreads to %d",nb_threads);
}
-
- if (nb_threads > 1) {
#ifndef HAVE_THREAD_CONTEXTS
- THROWF(arg_error, 0, "The thread factory cannot be run in parallel");
+ xbt_assert(nb_threads == 1, "Parallel runs are impossible when the pthreads are missing.");
#endif
- }
smx_parallel_contexts = nb_threads;
}
+++ /dev/null
-/* xbt_sg_stubs -- empty functions sometimes used in SG (never in RL) */
-
-/* This is always part of SG, never of RL. Content: */
-/* - a bunch of stub functions of the thread related function that we need */
-/* to add to the lib to please the linker when using ucontexts. */
-/* - a bunch of stub functions of the java related function when we don't */
-/* compile java bindings. */
-
-/* In RL, java is useless, and threads are always part of the picture, */
-/* ucontext never */
-
-/* Copyright (c) 2007-2010, 2013-2014. 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. */
-
-#include "src/xbt_modinter.h"
-#include "xbt/sysdep.h"
-#include "xbt/xbt_os_thread.h"
-#include "src/portable.h" /* HAVE_THREAD_CONTEXTS */
-
-#ifndef HAVE_THREAD_CONTEXTS
-#ifndef WIN32
-#ifdef HAVE_PTHREAD
-/* xbt_threads is loaded in libsimgrid when they are used to implement the xbt_context.
- * The decision (and the loading) is made in xbt/context.c.
- */
-
-int xbt_os_thread_atfork(void (*prepare)(void),
- void (*parent)(void), void (*child)(void))
-{
- return 0;
-}
-
-/* Mod_init/exit mecanism */
-void xbt_os_thread_mod_preinit(void)
-{
-}
-
-void xbt_os_thread_mod_postexit(void)
-{
-}
-
-
-/* Main functions */
-
-xbt_os_thread_t xbt_os_thread_create(const char *name,
- pvoid_f_pvoid_t start_routine,
- void *param, void *data)
-{
- xbt_backtrace_display_current();
- xbt_die
- ("No pthread in SG when compiled against the ucontext (xbt_os_thread_create)");
-}
-
-void xbt_os_thread_exit(int *retcode)
-{
- xbt_backtrace_display_current();
- xbt_die
- ("No pthread in SG when compiled against the ucontext (xbt_os_thread_exit)");
-}
-
-void xbt_os_thread_detach(xbt_os_thread_t worker)
-{
- xbt_backtrace_display_current();
- xbt_die
- ("No pthread in SG when compiled against the ucontext (xbt_os_thread_exit)");
-}
-
-xbt_os_thread_t xbt_os_thread_self(void)
-{
- xbt_backtrace_display_current();
- xbt_die
- ("No pthread in SG when compiled against the ucontext (xbt_os_thread_self)");
-}
-
-void xbt_os_thread_yield(void)
-{
- xbt_backtrace_display_current();
- xbt_die
- ("No pthread in SG when compiled against the ucontext (xbt_os_thread_yield)");
-}
-
-
-xbt_os_mutex_t xbt_os_mutex_init(void)
-{
- /*
- xbt_backtrace_display_current();
- xbt_die
- ("No pthread in SG when compiled against the ucontext (xbt_os_mutex_init)");
- */
- return NULL;
-}
-
-void xbt_os_mutex_acquire(xbt_os_mutex_t mutex)
-{
- /*
- xbt_backtrace_display_current();
- xbt_die
- ("No pthread in SG when compiled against the ucontext (xbt_os_mutex_acquire)");
- */
-}
-
-void xbt_os_mutex_release(xbt_os_mutex_t mutex)
-{
- /*
- xbt_backtrace_display_current();
- xbt_die
- ("No pthread in SG when compiled against the ucontext (xbt_os_mutex_release)");
- */
-}
-
-void xbt_os_mutex_destroy(xbt_os_mutex_t mutex)
-{
- /*
- xbt_backtrace_display_current();
- xbt_die
- ("No pthread in SG when compiled against the ucontext (xbt_os_mutex_destroy)");
- */
-}
-
-xbt_os_cond_t xbt_os_cond_init(void)
-{
- xbt_backtrace_display_current();
- xbt_die
- ("No pthread in SG when compiled against the ucontext (xbt_os_cond_init)");
-}
-
-void xbt_os_cond_wait(xbt_os_cond_t cond, xbt_os_mutex_t mutex)
-{
- xbt_backtrace_display_current();
- xbt_die
- ("No pthread in SG when compiled against the ucontext (xbt_os_cond_wait)");
-}
-
-void xbt_os_cond_signal(xbt_os_cond_t cond)
-{
- xbt_backtrace_display_current();
- xbt_die
- ("No pthread in SG when compiled against the ucontext (xbt_os_cond_signal)");
-}
-
-void xbt_os_cond_broadcast(xbt_os_cond_t cond)
-{
- xbt_backtrace_display_current();
- xbt_die
- ("No pthread in SG when compiled against the ucontext (xbt_os_cond_broadcast)");
-}
-
-void xbt_os_cond_destroy(xbt_os_cond_t cond)
-{
- xbt_backtrace_display_current();
- xbt_die
- ("No pthread in SG when compiled against the ucontext (xbt_os_cond_destroy)");
-}
-#endif
-#endif
-#endif
src/surf/host_clm03.cpp
src/surf/HostImpl.cpp
src/surf/ptask_L07.cpp
- src/xbt/xbt_sg_stubs.c
)
set(SIMIX_GENERATED_SRC
tools/cmake/scripts/update_tesh.pl
tools/cmake/UnitTesting.cmake
tools/cmake/src/internal_config.h.in
- tools/cmake/test_prog/prog_AC_CHECK_MCSC.c
tools/cmake/test_prog/prog_gnu_dynlinker.c
+ tools/cmake/test_prog/prog_makecontext.c
tools/cmake/test_prog/prog_mutex_timedlock.c
tools/cmake/test_prog/prog_sem_init.c
tools/cmake/test_prog/prog_sem_open.c
if (HAVE_PTHREAD)
set(SIMGRID_DEP "${SIMGRID_DEP} -lpthread")
endif()
+ if (HAVE_BOOST_CONTEXTS)
+ set(SIMGRID_DEP "${SIMGRID_DEP} ${Boost_CONTEXT_LIBRARY}")
+ endif()
endif()
target_link_libraries(simgrid ${SIMGRID_DEP})
#cmakedefine PROCESSOR_x86_64 @PROCESSOR_x86_64@
#cmakedefine CMAKE_SYSTEM_PROCESSOR @CMAKE_SYSTEM_PROCESSOR@
-/* Variables for the ucontexts */
-@pth_skaddr_makecontext@
-@pth_sksize_makecontext@
+/* Variables for the SysV contexts */
+@sg_makecontext_stack_addr@
+@sg_makecontext_stack_size@
+
+/* Variable for SysV, raw and Boost contexts */
+#cmakedefine PTH_STACKGROWTH @PTH_STACKGROWTH@ /* Does the stack growth upward, or downward? */
/* MC variables */
#cmakedefine HAVE_GETDTABLESIZE @HAVE_GETDTABLESIZE@ /* getdtablesize: get descriptor table size */
/* Other checks */
#cmakedefine ADDR2LINE "@ADDR2LINE@" /* Path to the addr2line tool */
#cmakedefine HAVE_GRAPHVIZ @HAVE_GRAPHVIZ@ /* The graphviz library */
-#cmakedefine PTH_STACKGROWTH @PTH_STACKGROWTH@ /* Does the stack growth upward, or downward? */
-/* Copyright (c) 2010, 2014. The SimGrid Team.
- * All rights reserved. */
+/* Copyright (c) 2010, 2014, 2016. 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. */
+#ifdef __APPLE__
+#define _XOPEN_SOURCE 700
+#endif
+
#include <stdio.h>
#include <stdlib.h>
#include <ucontext.h>
static void child(void)
{
+ /* switch back to the main context */
if (swapcontext(&uc_child, &uc_main) != 0)
exit(2);
}
int main(int argc, char *argv[])
{
- FILE *fp;
- void *stack;
-
- /* the default is that it fails */
- if ((fp = fopen("conftestval", "w")) == NULL)
- exit(3);
- fprintf(fp, "no\n");
- fclose(fp);
+ void *stack = malloc(64 * 1024);
/* configure a child user-space context */
- if ((stack = malloc(64 * 1024)) == NULL)
- exit(4);
+ if (stack == NULL)
+ exit(3);
if (getcontext(&uc_child) != 0)
- exit(5);
+ exit(4);
uc_child.uc_link = NULL;
uc_child.uc_stack.ss_sp = (char *) stack + (32 * 1024);
uc_child.uc_stack.ss_size = 32 * 1024;
/* switch into the user context */
if (swapcontext(&uc_main, &uc_child) != 0)
- exit(6);
+ exit(5);
/* Fine, child came home */
- if ((fp = fopen("conftestval", "w")) == NULL)
- exit(7);
- fprintf(fp, "yes\n");
- fclose(fp);
+ printf("yes\n");
/* die successfully */
- exit(0);
- return 1;
+ return 0;
}
int main(int argc, char *argv[])
{
- FILE *f;
- char result[1024];
int sksize = 32768;
char *skbuf = (char *) malloc(sksize * 2 + 2 * sizeof(union alltypes));
if (skbuf == NULL)
if (handler_addr < skaddr + sksize) {
/* stack was placed into lower area */
if (*(skaddr + sksize) != 'A')
- sprintf(result, "(skaddr)+(sksize)-%d,(sksize)-%d", sizeof(union alltypes), sizeof(union alltypes));
+ printf("(skaddr)+(sksize)-%d;(sksize)-%d", sizeof(union alltypes), sizeof(union alltypes));
else
- strcpy(result, "(skaddr)+(sksize),(sksize)");
+ printf("(skaddr)+(sksize);(sksize)");
} else {
/* stack was placed into higher area */
if (*(skaddr + sksize * 2) != 'A')
- sprintf(result, "(skaddr),(sksize)-%d", sizeof(union alltypes));
+ printf("(skaddr);(sksize)-%d", sizeof(union alltypes));
else
- strcpy(result, "(skaddr),(sksize)");
+ printf("(skaddr);(sksize)");
}
- if ((f = fopen("conftestval", "w")) == NULL)
- exit(1);
- fprintf(f, "%s\n", result);
- fclose(f);
- exit(0);
- return 1;
+ return 0;
}