diff --git a/CMakeLists.txt b/CMakeLists.txt index 431744a..3301961 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,15 @@ set(CMAKE_C_FLAGS add_definitions(-DMD_HAVE_EPOLL -DLINUX) +# check for valgrind. this should really be in FindValgrind.cmake +# http://www.itk.org/Wiki/CMake:How_To_Find_Installed_Software +find_file(VALGRIND_H valgrind.h /usr/include/valgrind /usr/local/include/valgrind) +message("valgrind headers: ${VALGRIND_H}") +if(NOT VALGRIND_H) +# this will remove valgrind stack tracking support from state-threads +add_definitions(-DNVALGRIND) +endif(NOT VALGRIND_H) + exec_program(${CMAKE_COMMAND} ARGS -E copy ${CMAKE_CURRENT_SOURCE_DIR}/public.h ${CMAKE_CURRENT_BINARY_DIR}/st.h) # use gcc for the asm file because it needs to be # pre-processed by cpp first @@ -22,3 +31,6 @@ add_library(st STATIC md.S event.c io.c key.c sched.c stk.c sync.c) include_directories(${CMAKE_CURRENT_BINARY_DIR}) #add_executable(server examples/server.c examples/error.c) #target_link_libraries(server st) + +add_executable(lookupdns examples/lookupdns.c examples/res.c) +target_link_libraries(lookupdns st resolv) diff --git a/common.h b/common.h index 4df39e9..84eb251 100644 --- a/common.h +++ b/common.h @@ -149,6 +149,11 @@ typedef struct _st_stack { #ifdef __ia64__ void *bsp; /* Register stack backing store pointer */ #endif +#ifndef NVALGRIND + /* id returned by VALGRIND_STACK_REGISTER */ + /* http://valgrind.org/docs/manual/manual-core-adv.html */ + unsigned int valgrind_stack_id; +#endif } _st_stack_t; diff --git a/sched.c b/sched.c index d9c393c..a754b4b 100644 --- a/sched.c +++ b/sched.c @@ -47,6 +47,9 @@ #include #include "common.h" +#ifndef NVALGRIND +#include +#endif /* Global data */ _st_vp_t _st_this_vp; /* This VP */ @@ -263,6 +266,12 @@ void st_thread_exit(void *retval) _ST_DEL_THREADQ(thread); #endif +#ifndef NVALGRIND + if (!(thread->flags & _ST_FL_PRIMORDIAL)) { + VALGRIND_STACK_DEREGISTER(thread->stack->valgrind_stack_id); + } +#endif + if (!(thread->flags & _ST_FL_PRIMORDIAL)) _st_stack_free(thread->stack); @@ -610,6 +619,11 @@ _st_thread_t *st_thread_create(void *(*start)(void *arg), void *arg, _ST_ADD_THREADQ(thread); #endif +#ifndef NVALGRIND + thread->stack->valgrind_stack_id = + VALGRIND_STACK_REGISTER(thread->stack->stk_top, thread->stack->stk_bottom); +#endif + return thread; }