[KMTESTS:KE]
[reactos.git] / rostests / kmtests / ntos_ex / ExInterlocked.c
index 6131f03..9b32db4 100644 (file)
@@ -2,21 +2,21 @@
  * PROJECT:         ReactOS kernel-mode tests
  * LICENSE:         GPLv2+ - See COPYING in the top level directory
  * PURPOSE:         Kernel-Mode Test Suite Interlocked function test
- * PROGRAMMER:      Thomas Faber <thfabba@gmx.de>
+ * PROGRAMMER:      Thomas Faber <thomas.faber@reactos.org>
  */
 
+#include <stddef.h>
+
 /* missing prototypes >:| */
-#ifndef _MSC_VER
-typedef long long __int64;
-#endif
-struct _KSPIN_LOCK;
 __declspec(dllimport)   long            __fastcall  InterlockedCompareExchange(volatile long *, long, long);
 __declspec(dllimport)   __int64         __fastcall  ExInterlockedCompareExchange64(volatile __int64 *, __int64 *, __int64 *, void *);
 __declspec(dllimport)   __int64         __fastcall  ExfInterlockedCompareExchange64(volatile __int64 *, __int64 *, __int64 *);
 __declspec(dllimport)   long            __fastcall  InterlockedExchange(volatile long *, long);
 __declspec(dllimport)   unsigned long   __stdcall   ExInterlockedExchangeUlong(unsigned long *, unsigned long, void *);
 __declspec(dllimport)   long            __fastcall  InterlockedExchangeAdd(volatile long *, long);
-__declspec(dllimport)   unsigned long   __stdcall   ExInterlockedAddUlong(unsigned long *, unsigned long, void *);
+#ifdef _X86_
+__declspec(dllimport)   unsigned long   __stdcall   ExInterlockedAddUlong(unsigned long *, unsigned long, unsigned long *);
+#endif
 __declspec(dllimport)   unsigned long   __stdcall   Exi386InterlockedExchangeUlong(unsigned long *, unsigned long);
 __declspec(dllimport)   long            __fastcall  InterlockedIncrement(long *);
 __declspec(dllimport)   long            __fastcall  InterlockedDecrement(long *);
@@ -50,6 +50,8 @@ typedef struct
 typedef int PROCESSOR_STATE;
 #endif
 
+/* TODO: these need to be rewritten in proper assembly to account for registers
+ *       saved by the caller */
 #if defined(_MSC_VER) && defined(_M_IX86)
 #define SaveState(State) do                                                 \
 {                                                                           \
@@ -63,7 +65,8 @@ typedef int PROCESSOR_STATE;
 
 #define CheckState(OldState, NewState) do                                   \
 {                                                                           \
-    ok_eq_hex((OldState)->esi, (NewState)->esi);                            \
+    /* TODO: MSVC uses esi and saves it before, so this is okay */          \
+    /*ok_eq_hex((OldState)->esi, (NewState)->esi);*/                        \
     ok_eq_hex((OldState)->edi, (NewState)->edi);                            \
     ok_eq_hex((OldState)->ebx, (NewState)->ebx);                            \
     ok_eq_hex((OldState)->ebp, (NewState)->ebp);                            \
@@ -73,38 +76,36 @@ typedef int PROCESSOR_STATE;
 #elif defined(__GNUC__) && defined(_M_IX86)
 #define SaveState(State)                                                    \
     asm volatile(                                                           \
-        ".intel_syntax noprefix\n\t"                                        \
-        "mov\t[ecx], esi\n\t"                                               \
-        "mov\t[ecx+4], edi\n\t"                                             \
-        "mov\t[ecx+8], ebx\n\t"                                             \
-        "mov\t[ecx+12], ebp\n\t"                                            \
-        "mov\t[ecx+16], esp\n\t"                                            \
-        ".att_syntax prefix"                                                \
+        "movl\t%%esi, (%%ecx)\n\t"                                          \
+        "movl\t%%edi, 4(%%ecx)\n\t"                                         \
+        "movl\t%%ebx, 8(%%ecx)\n\t"                                         \
+        "movl\t%%ebp, 12(%%ecx)\n\t"                                        \
+        "movl\t%%esp, 16(%%ecx)"                                            \
         : : "c" (&State) : "memory"                                         \
     );
 
 #define CheckState(OldState, NewState) do                                   \
 {                                                                           \
-    ok_eq_hex((OldState)->esi, (NewState)->esi);                            \
+    /* TODO: GCC 4.7 uses esi and saves it before, so this is okay */       \
+    /*ok_eq_hex((OldState)->esi, (NewState)->esi);*/                        \
     ok_eq_hex((OldState)->edi, (NewState)->edi);                            \
-    ok_eq_hex((OldState)->ebx, (NewState)->ebx);                            \
+    /* TODO: GCC 4.4 uses ebx and saves it before, so this is okay */       \
+    /*ok_eq_hex((OldState)->ebx, (NewState)->ebx);*/                        \
     ok_eq_hex((OldState)->ebp, (NewState)->ebp);                            \
     ok_eq_hex((OldState)->esp, (NewState)->esp);                            \
 } while (0)
 #elif defined(__GNUC__) && defined(_M_AMD64)
 #define SaveState(State)                                                    \
     asm volatile(                                                           \
-        ".intel_syntax noprefix\n\t"                                        \
-        "mov\t[rcx], rsi\n\t"                                               \
-        "mov\t[rcx+8], rdi\n\t"                                             \
-        "mov\t[rcx+16], rbx\n\t"                                            \
-        "mov\t[rcx+24], rbp\n\t"                                            \
-        "mov\t[rcx+32], rsp\n\t"                                            \
-        "mov\t[rcx+40], r12\n\t"                                            \
-        "mov\t[rcx+48], r13\n\t"                                            \
-        "mov\t[rcx+56], r14\n\t"                                            \
-        "mov\t[rcx+64], r15\n\t"                                            \
-        ".att_syntax prefix"                                                \
+        "mov\t%%rsi, (%%rcx)\n\t"                                           \
+        "mov\t%%rdi, 8(%%rcx)\n\t"                                          \
+        "mov\t%%rbx, 16(%%rcx)\n\t"                                         \
+        "mov\t%%rbp, 24(%%rcx)\n\t"                                         \
+        "mov\t%%rsp, 32(%%rcx)\n\t"                                         \
+        "mov\t%%r12, 40(%%rcx)\n\t"                                         \
+        "mov\t%%r13, 48(%%rcx)\n\t"                                         \
+        "mov\t%%r14, 56(%%rcx)\n\t"                                         \
+        "mov\t%%r15, 64(%%rcx)"                                             \
         : : "c" (&State) : "memory"                                         \
     );
 
@@ -122,7 +123,11 @@ typedef int PROCESSOR_STATE;
 } while (0)
 #else
 #define SaveState(State)
-#define CheckState(OldState, NewState)
+#define CheckState(OldState, NewState) do                                   \
+{                                                                           \
+    (void)OldState;                                                         \
+    (void)NewState;                                                         \
+} while (0)
 #endif
 
 static