From: Martin Quinson Date: Mon, 7 Mar 2016 08:04:32 +0000 (+0100) Subject: cmake: further cleanups in the detection of sysv variables X-Git-Tag: v3_13~500^2~11 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/72524c346ddad2bbb97217cf981a423676353b6b cmake: further cleanups in the detection of sysv variables --- diff --git a/CMakeLists.txt b/CMakeLists.txt index b2c21ffc48..ba37530cf8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -291,6 +291,8 @@ CHECK_FUNCTION_EXISTS(nanosleep HAVE_NANOSLEEP) 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) @@ -300,8 +302,6 @@ 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( @@ -588,21 +588,20 @@ if(HAVE_UCONTEXT_H) 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 + ${CMAKE_BINARY_DIR} ${CMAKE_HOME_DIRECTORY}/tools/cmake/test_prog/prog_stacksetup.c + RUN_OUTPUT_VARIABLE stack_setup 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})") + 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() diff --git a/src/simix/UContext.cpp b/src/simix/UContext.cpp index f3ff9bb2b9..42ee16b14e 100644 --- a/src/simix/UContext.cpp +++ b/src/simix/UContext.cpp @@ -30,8 +30,7 @@ * 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*)); @@ -43,8 +42,7 @@ void simgrid_makecontext(ucontext_t* ucp, void (*func)(int first, ...), void* ar 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); } } @@ -210,16 +208,13 @@ UContext::UContext(std::function code, 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) diff --git a/tools/cmake/src/internal_config.h.in b/tools/cmake/src/internal_config.h.in index 3ba5aaf9d2..4ee6bcb139 100644 --- a/tools/cmake/src/internal_config.h.in +++ b/tools/cmake/src/internal_config.h.in @@ -37,9 +37,10 @@ #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@ +#cmakedefine PTH_STACKGROWTH @PTH_STACKGROWTH@ /* Does the stack growth upward, or downward? */ /* MC variables */ #cmakedefine HAVE_GETDTABLESIZE @HAVE_GETDTABLESIZE@ /* getdtablesize: get descriptor table size */ @@ -63,4 +64,3 @@ /* 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? */ diff --git a/tools/cmake/test_prog/prog_stacksetup.c b/tools/cmake/test_prog/prog_stacksetup.c index 46f0563d0e..542847d17d 100644 --- a/tools/cmake/test_prog/prog_stacksetup.c +++ b/tools/cmake/test_prog/prog_stacksetup.c @@ -35,8 +35,6 @@ void handler(void) 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) @@ -59,20 +57,15 @@ int main(int argc, char *argv[]) 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; }