enable_language(CXX)
+INCLUDE(CheckCCompilerFlag)
+CHECK_C_COMPILER_FLAG(-fstack-cleaner HAVE_C_STACK_CLEANER)
+
if (APPLE) #MAC
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
ADD_TESH(mc-bugged1-liveness-ucontext-sparse --setenv bindir=${CMAKE_BINARY_DIR}/examples/msg/mc --cd ${CMAKE_HOME_DIRECTORY}/examples/msg/mc bugged1_liveness_sparse.tesh)
ADD_TESH(mc-bugged1-liveness-visited-ucontext --setenv bindir=${CMAKE_BINARY_DIR}/examples/msg/mc --cd ${CMAKE_HOME_DIRECTORY}/examples/msg/mc bugged1_liveness_visited.tesh)
ADD_TESH(mc-bugged1-liveness-visited-ucontext-sparse --setenv bindir=${CMAKE_BINARY_DIR}/examples/msg/mc --cd ${CMAKE_HOME_DIRECTORY}/examples/msg/mc bugged1_liveness_visited_sparse.tesh)
+ if(HAVE_C_STACK_CLEANER)
+ # This test checks if the stack cleaner is makign a difference:
+ add_test(mc-bugged1-liveness-stack-cleaner
+ ${CMAKE_HOME_DIRECTORY}/examples/msg/mc/bugged1_liveness_stack_cleaner
+ ${CMAKE_HOME_DIRECTORY}/examples/msg/mc/
+ ${CMAKE_BINARY_DIR}/examples/msg/mc/
+ )
+ endif()
ENDIF()
ENDIF()
target_link_libraries(bugged3 simgrid )
target_link_libraries(electric_fence simgrid )
target_link_libraries(bugged1_liveness simgrid )
- target_link_libraries(bugged2_liveness simgrid )
+ target_link_libraries(bugged2_liveness simgrid )
+
+ if(HAVE_C_STACK_CLEANER)
+ add_executable(bugged1_liveness_cleaner_on bugged1_liveness.c )
+ add_executable(bugged1_liveness_cleaner_off bugged1_liveness.c )
+
+ target_link_libraries(bugged1_liveness_cleaner_on simgrid )
+ target_link_libraries(bugged1_liveness_cleaner_off simgrid )
+
+ set_target_properties(bugged1_liveness_cleaner_on
+ PROPERTIES COMPILE_FLAGS "-DGARBAGE_STACK -fstack-cleaner")
+ set_target_properties(bugged1_liveness_cleaner_off
+ PROPERTIES COMPILE_FLAGS "-DGARBAGE_STACK -fno-stack-cleaner")
+ endif()
endif()
/* LTL property checked : G(r->F(cs)); (r=request of CS, cs=CS ok) */
/******************************************************************************/
+#ifdef GARBAGE_STACK
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#endif
+
#include "msg/msg.h"
#include "mc/mc.h"
#include "xbt/automaton.h"
return cs;
}
+#ifdef GARBAGE_STACK
+/** Do not use a clean stack */
+static void garbage_stack(void) {
+ const size_t size = 256;
+ int fd = open("/dev/urandom", O_RDONLY);
+ char foo[size];
+ read(fd, foo, size);
+ close(fd);
+}
+#endif
int coordinator(int argc, char *argv[])
{
char *my_mailbox = xbt_strdup(argv[1]);
msg_task_t grant = NULL, release = NULL;
-
+
while(1){
XBT_INFO("Ask the request");
MSG_task_send(MSG_task_create("request", 0, 1000, my_mailbox), "coordinator");
return 0;
}
+static int raw_client(int argc, char *argv[])
+{
+#ifdef GARBAGE_STACK
+ // At this point the stack of the callee (client) is probably filled with
+ // zeros and unitialized variables will contain 0. This call will place
+ // random byes in the stack of the callee:
+ garbage_stack();
+#endif
+ return client(argc, argv);
+}
+
int main(int argc, char *argv[])
{
MSG_create_environment(platform_file);
MSG_function_register("coordinator", coordinator);
- MSG_function_register("client", client);
+ MSG_function_register("client", raw_client);
MSG_launch_application(application_file);
MSG_main();
--- /dev/null
+#!/bin/sh
+# Run the same test compiled with -fstack-cleaner / f-no-stack-cleaner
+# and compare the output.
+
+srcdir="$1"
+bindir="$2"
+
+cd "$srcdir"
+
+die() {
+ echo "$@" >&2
+ exit 1
+}
+
+assert() {
+ if ! eval "$1"; then
+ die "Assertion failed: $@"
+ fi
+}
+
+# If we don't have timeout, fake it:
+if ! which timeout > /dev/null; then
+ timeout() {
+ shift
+ "$@"
+ }
+fi
+
+run() {
+ state=$1
+ shift
+ timeout 30s ${bindir:=.}/bugged1_liveness_cleaner_$state \
+ ${srcdir:=.}/../../platforms/platform.xml \
+ ${srcdir:=.}/deploy_bugged1_liveness.xml \
+ --cfg=model-check:1 "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" \
+ --cfg=contexts/factory:ucontext \
+ --cfg=contexts/stack_size:256
+ assert 'test $? = 134'
+}
+
+get_states() {
+ echo "$1" | grep "Expanded pairs = " | sed "s/^.*Expanded pairs = //" | head -n1
+}
+
+RES_ON="$(run on 2>&1 1>/dev/null)"
+RES_OFF="$(run off 2>&1 1>/dev/null)"
+
+STATES_ON=$(get_states "$RES_ON")
+STATES_OFF=$(get_states "$RES_OFF")
+
+# Both runs finished:
+assert 'test -n "$STATES_ON"'
+assert 'test -n "$STATES_OFF"'
+
+# We expect 21 visited pairs with the stack cleaner:
+assert 'test "$STATES_ON" = 21'
+
+# We expect more states without the stack cleaner:
+assert 'test "$STATES_ON" -lt "$STATES_OFF"'