Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
cmake: further cleanups in the detection of sysv variables
authorMartin Quinson <martin.quinson@loria.fr>
Mon, 7 Mar 2016 08:04:32 +0000 (09:04 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Mon, 7 Mar 2016 08:04:32 +0000 (09:04 +0100)
CMakeLists.txt
src/simix/UContext.cpp
tools/cmake/src/internal_config.h.in
tools/cmake/test_prog/prog_stacksetup.c

index b2c21ff..ba37530 100644 (file)
@@ -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(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) 
 
 CHECK_SYMBOL_EXISTS(vasprintf stdio.h HAVE_VASPRINTF)
 if(MINGW) 
@@ -300,8 +302,6 @@ if(MINGW)
   set(HAVE_VASPRINTF 1)
 endif()
 
   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(
 
 #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
 
   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()
 
       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()
 
   endif()
 endif()
 
index f3ff9bb..42ee16b 100644 (file)
@@ -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. */
  * 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*));
 {
   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:
     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<void()> code,
     void_pfn_smxprocess_t cleanup_func, smx_process_t process)
   : Context(std::move(code), cleanup_func, process)
 {
     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;
   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)
     simgrid_makecontext(&this->uc_, smx_ctx_sysv_wrapper, this);
   } else {
     if (process != NULL && sysv_maestro_context == NULL)
index 3ba5aaf..4ee6bcb 100644 (file)
 #cmakedefine PROCESSOR_x86_64 @PROCESSOR_x86_64@
 #cmakedefine CMAKE_SYSTEM_PROCESSOR @CMAKE_SYSTEM_PROCESSOR@
 
 #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 */
 
 /* 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 */
 /* 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? */
index 46f0563..542847d 100644 (file)
@@ -35,8 +35,6 @@ void handler(void)
 
 int main(int argc, char *argv[])
 {
 
 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)
   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')
   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
     else
-      strcpy(result, "(skaddr)+(sksize),(sksize)");
+      printf("(skaddr)+(sksize);(sksize)");
   } else {
     /* stack was placed into higher area */
     if (*(skaddr + sksize * 2) != 'A')
   } 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
     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;
 }
 }