* Lesser General Public License for more details.\r
*\r
* You should have received a copy of the GNU Lesser General Public\r
- * License along with QueueUserAPCEx in the file COPYING.LIB;\r
+ * License along with SimGrid in the file LICENSE-LGPL-2.1;\r
* if not, write to the Free Software Foundation, Inc.,\r
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA\r
- */\r
+ */ \r
+ \r
+#include "win32_ucontext.h"\r
\r
-#include "ucontext.h"\r
-\r
-int getcontext(ucontext_t *ucp)\r
+int getcontext(ucontext_t * ucp) \r
{\r
- int ret;\r
-\r
- /* Retrieve the full machine context */\r
- ucp->uc_mcontext.ContextFlags = CONTEXT_FULL;\r
- ret = GetThreadContext(GetCurrentThread(), &ucp->uc_mcontext);\r
-\r
- return (ret == 0) ? -1: 0;\r
+ int ret;\r
+ \r
+ /* Retrieve the full machine context */ \r
+ ucp->uc_mcontext.ContextFlags = CONTEXT_FULL | CONTEXT_DEBUG_REGISTERS;\r
+ ret = GetThreadContext(GetCurrentThread(), &ucp->uc_mcontext);\r
+ return (ret == 0) ? -1 : 0;\r
}\r
\r
-int setcontext(const ucontext_t *ucp)\r
+int setcontext(const ucontext_t * ucp) \r
{\r
- int ret;\r
-\r
- /* Restore the full machine context (already set) */\r
- ret = SetThreadContext(GetCurrentThread(), &ucp->uc_mcontext);\r
-\r
- return (ret == 0) ? -1: 0;\r
+ int ret;\r
+ \r
+ /* Restore the full machine context (already set) */ \r
+ ret = SetThreadContext(GetCurrentThread(), &ucp->uc_mcontext);\r
+ return (ret == 0) ? -1 : 0;\r
}\r
\r
-int makecontext(ucontext_t *ucp, void (*func)(), int argc, ...)\r
+int makecontext(ucontext_t * ucp, void (*func) (), int argc, ...) \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
- /* Reserve stack space for the arguments (maximum possible: argc*(8 bytes per argument)) */\r
- sp -= argc*8;\r
-\r
- if ( sp < (char *)ucp->uc_stack.ss_sp) {\r
- /* errno = ENOMEM;*/\r
- return -1;\r
- }\r
-\r
- /* Set the instruction and the stack pointer */\r
- ucp->uc_mcontext.Eip = (unsigned long) func;\r
- ucp->uc_mcontext.Esp = (unsigned long) sp - 4;\r
-\r
- /* Save/Restore the full machine context */\r
- ucp->uc_mcontext.ContextFlags = CONTEXT_FULL;\r
-\r
- /* Copy the arguments */\r
- va_start (ap, argc);\r
- for (i=0; i<argc; i++) {\r
- memcpy(sp, ap, 8);\r
- ap +=8;\r
- sp += 8;\r
- }\r
- va_end(ap);\r
-\r
- return 0;\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
+ /* Reserve stack space for the arguments (maximum possible: argc*(8 bytes per argument)) */ \r
+ sp -= argc * sizeof(void*);\r
+ if (sp < (char *) ucp->uc_stack.ss_sp) {\r
+ \r
+ /* errno = ENOMEM; */ \r
+ return -1;\r
+ }\r
+ \r
+ /* Set the instruction and the stack pointer */\r
+ #ifdef _I_X86_\r
+ ucp->uc_mcontext.Eip = (DWORD) func;\r
+ ucp->uc_mcontext.Esp = (DWORD) sp - sizeof(void*);\r
+ #endif\r
+ #ifdef _IA64_\r
+ # error "_IA64_"\r
+ #endif\r
+ #ifdef _AMD64_\r
+ ucp->uc_mcontext.Rip = (DWORD64) func;\r
+ ucp->uc_mcontext.Rsp = (DWORD64) sp - sizeof(void*);\r
+ #endif\r
+\r
+ /* Save/Restore the full machine context */ \r
+ ucp->uc_mcontext.ContextFlags = CONTEXT_FULL | CONTEXT_DEBUG_REGISTERS;\r
+ \r
+ /* Copy the arguments */ \r
+ va_start(ap, argc);\r
+ for (i = 0; i < argc; i++) {\r
+ memcpy(sp, ap, sizeof(void*));\r
+ ap += sizeof(void*);\r
+ sp += sizeof(void*);\r
+ }\r
+ va_end(ap);\r
+ return 0;\r
}\r
\r
-int swapcontext(ucontext_t *oucp, const ucontext_t *ucp)\r
+int swapcontext(ucontext_t * oucp, const ucontext_t * ucp) \r
{\r
- int ret;\r
-\r
- if ((oucp == NULL) || (ucp == NULL)) {\r
- /*errno = EINVAL;*/\r
- return -1;\r
- }\r
-\r
- ret = getcontext(oucp);\r
- if (ret == 0) {\r
- ret = setcontext(ucp);\r
- }\r
- return ret;\r
+ int ret;\r
+ if ((oucp == NULL) || (ucp == NULL)) {\r
+ \r
+ /*errno = EINVAL; */ \r
+ return -1;\r
+ }\r
+ ret = getcontext(oucp);\r
+ if (ret == 0) {\r
+ ret = setcontext(ucp);\r
+ }\r
+ return ret;\r
}\r
+\r