Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
For win64 it is cast unsigned long long.
[simgrid.git] / src / xbt / win32_ucontext.c
index 5d49317..757eb43 100644 (file)
 #include "win32_ucontext.h"\r
 int getcontext(ucontext_t * ucp) \r
 {\r
-  \rint ret;\r
-  \r\r
+  int ret;\r
+  \r
       /* Retrieve the full machine context */ \r
       ucp->uc_mcontext.ContextFlags = CONTEXT_FULL;\r
-  \rret = GetThreadContext(GetCurrentThread(), &ucp->uc_mcontext);\r
-  \rreturn (ret == 0) ? -1 : 0;\r
-\r}\r
+  ret = GetThreadContext(GetCurrentThread(), &ucp->uc_mcontext);\r
+  return (ret == 0) ? -1 : 0;\r
+}\r
 \r
-\r\rint setcontext(const ucontext_t * ucp) \r
+int setcontext(const ucontext_t * ucp) \r
 {\r
-  \rint ret;\r
-  \r\r
+  int ret;\r
+  \r
       /* Restore the full machine context (already set) */ \r
       ret = SetThreadContext(GetCurrentThread(), &ucp->uc_mcontext);\r
-  \rreturn (ret == 0) ? -1 : 0;\r
-\r}\r
+  return (ret == 0) ? -1 : 0;\r
+}\r
 \r
-\r\rint makecontext(ucontext_t * ucp, void (*func) (), int argc, ...) \r
+int makecontext(ucontext_t * ucp, void (*func) (), int argc, ...) \r
 {\r
-  \rint i;\r
-  \rva_list ap;\r
-  \rchar *sp;\r
-  \r\r
+  int i;\r
+  va_list ap;\r
+  char *sp;\r
+  \r
       /* Stack grows down */ \r
       sp = (char *) (size_t) ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size;\r
-  \r\r
+  \r
       /* Reserve stack space for the arguments (maximum possible: argc*(8 bytes per argument)) */ \r
       sp -= argc * 8;\r
-  \rif (sp < (char *) ucp->uc_stack.ss_sp) {\r
-    \r\r
+  if (sp < (char *) ucp->uc_stack.ss_sp) {\r
+    \r
         /* errno = ENOMEM; */ \r
         return -1;\r
-  \r}\r
-  \r\r
-      /* Set the instruction and the stack pointer */ \r
-      ucp->uc_mcontext.Eip = (unsigned long) func;\r
-  \rucp->uc_mcontext.Esp = (unsigned long) sp - 4;\r
-  \r\r
+  }\r
+  \r
+      /* Set the instruction and the stack pointer */\r
+  #ifdef I_X86_\r
+  ucp->uc_mcontext.Eip = (unsigned long) func;\r
+  ucp->uc_mcontext.Esp = (unsigned long) sp - 4;\r
+  #endif\r
+  #ifdef _IA64_\r
+  #  error "_IA64_"\r
+  #endif\r
+  #ifdef _AMD64_\r
+  ucp->uc_mcontext.Rip = (unsigned long long) func;\r
+  ucp->uc_mcontext.Rsp = (unsigned long long) sp - 8;\r
+  #endif\r
+\r
       /* Save/Restore the full machine context */ \r
       ucp->uc_mcontext.ContextFlags = CONTEXT_FULL;\r
-  \r\r
+  \r
       /* Copy the arguments */ \r
       va_start(ap, argc);\r
-  \rfor (i = 0; i < argc; i++) {\r
-    \rmemcpy(sp, ap, 8);\r
-    \rap += 8;\r
-    \rsp += 8;\r
-  \r}\r
-  \rva_end(ap);\r
-  \rreturn 0;\r
-\r}\r
+  for (i = 0; i < argc; i++) {\r
+    memcpy(sp, ap, 8);\r
+    ap += 8;\r
+    sp += 8;\r
+  }\r
+  va_end(ap);\r
+  return 0;\r
+}\r
 \r
-\r\rint swapcontext(ucontext_t * oucp, const ucontext_t * ucp) \r
+int swapcontext(ucontext_t * oucp, const ucontext_t * ucp) \r
 {\r
-  \rint ret;\r
-  \rif ((oucp == NULL) || (ucp == NULL)) {\r
-    \r\r
+  int ret;\r
+  if ((oucp == NULL) || (ucp == NULL)) {\r
+    \r
         /*errno = EINVAL; */ \r
         return -1;\r
-  \r}\r
-  \rret = getcontext(oucp);\r
-  \rif (ret == 0) {\r
-    \rret = setcontext(ucp);\r
-  \r}\r
-  \rreturn ret;\r
-\r}\r
+  }\r
+  ret = getcontext(oucp);\r
+  if (ret == 0) {\r
+    ret = setcontext(ucp);\r
+  }\r
+  return ret;\r
+}\r
 \r
-\r\r\r