#include <string.h>
/* FIXME: add more architectures. Is there a way to specify this in GCC? */
-#ifdef _X86_
-#define UNALIGNED
+#if defined(_M_AMD64)
+#undef UNALIGNED
+#define UNALIGNED __unaligned
#else
#define UNALIGNED
#endif
#endif
typedef char CHAR;
typedef short SHORT;
-#ifndef __ROS_LONG64__
+#if !defined(__ROS_LONG64__) || defined(_M_AMD64)
typedef long LONG;
#else
typedef int LONG;
#endif
#undef __int64
#define __int64 long long
-#elif defined(__WATCOMC__) && (defined(_INTEGRAL_MAX_BITS) && _INTEGRAL_MAX_BITS >= 64 )
+#elif (defined(__WATCOMC__) || defined(_MSC_VER)) && (defined(_INTEGRAL_MAX_BITS) && _INTEGRAL_MAX_BITS >= 64 )
#define _HAVE_INT64
#endif /* __GNUC__/__WATCOMC */
#if defined(_HAVE_INT64) || (defined(_INTEGRAL_MAX_BITS) && _INTEGRAL_MAX_BITS >= 64)
typedef WORD FSHORT;
typedef DWORD FLONG;
-#define __C_ASSERT_JOIN(X, Y) __C_ASSERT_DO_JOIN(X, Y)
-#define __C_ASSERT_DO_JOIN(X, Y) __C_ASSERT_DO_JOIN2(X, Y)
-#define __C_ASSERT_DO_JOIN2(X, Y) X##Y
-
-#define C_ASSERT(e) typedef char __C_ASSERT_JOIN(__C_ASSERT__, __LINE__)[(e) ? 1 : -1]
-
+#define C_ASSERT(expr) extern char (*c_assert(void)) [(expr) ? 1 : -1]
-#ifdef __GNUC__
#include "intrin.h"
-#endif
#define NTAPI __stdcall
#include <basetsd.h>
#define FILE_CREATE_TREE_CONNECTION 0x00000080
#define FILE_COMPLETE_IF_OPLOCKED 0x00000100
#define FILE_NO_EA_KNOWLEDGE 0x00000200
-#define FILE_OPEN_FOR_RECOVERY 0x00000400
+#define FILE_OPEN_REMOTE_INSTANCE 0x00000400
#define FILE_RANDOM_ACCESS 0x00000800
#define FILE_DELETE_ON_CLOSE 0x00001000
#define FILE_OPEN_BY_FILE_ID 0x00002000
#define FILE_SUPPORTS_ENCRYPTION 0x00020000
#define FILE_NAMED_STREAMS 0x00040000
-/* FIXME: Oh how I wish, I wish the w32api DDK wouldn't include winnt.h... */
-#ifndef _NTDDK_
#define IO_COMPLETION_QUERY_STATE 0x0001
#define IO_COMPLETION_MODIFY_STATE 0x0002
#define IO_COMPLETION_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0x3)
-#endif
/* end ntifs.h */
/* also in ddk/winddk.h */
#define MAILSLOT_NO_MESSAGE ((DWORD)-1)
#define MAILSLOT_WAIT_FOREVER ((DWORD)-1)
-/* FIXME: Oh how I wish, I wish the w32api DDK wouldn't include winnt.h... */
-#ifndef _NTDDK_
#define PROCESS_TERMINATE 1
#define PROCESS_CREATE_THREAD 2
#define PROCESS_SET_SESSIONID 4
#define PROCESS_SUSPEND_RESUME 2048
#define PROCESS_QUERY_LIMITED_INFORMATION 0x1000
#define PROCESS_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0xFFF)
-#endif
#define PROCESS_DUP_HANDLE 64
#define THREAD_TERMINATE 1
#define THREAD_SUSPEND_RESUME 2
#define THREAD_GET_CONTEXT 8
#define THREAD_SET_CONTEXT 16
#define THREAD_SET_INFORMATION 32
-/* FIXME: Oh how I wish, I wish the w32api DDK wouldn't include winnt.h... */
-#ifndef _NTDDK_
#define THREAD_QUERY_INFORMATION 64
#define THREAD_SET_THREAD_TOKEN 128
#define THREAD_IMPERSONATE 256
#define THREAD_DIRECT_IMPERSONATION 0x200
-#endif
#define THREAD_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0x3FF)
-/* FIXME: Oh how I wish, I wish the w32api DDK wouldn't include winnt.h... */
-#ifndef _NTDDK_
#define MUTANT_QUERY_STATE 0x0001
#define MUTANT_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|MUTANT_QUERY_STATE)
#define TIMER_QUERY_STATE 0x0001
#define THREAD_BASE_PRIORITY_MAX 2
#define THREAD_BASE_PRIORITY_MIN (-2)
#define THREAD_BASE_PRIORITY_IDLE (-15)
-#endif
/*
* To prevent gcc compiler warnings, bracket these defines when initialising
* a SID_IDENTIFIER_AUTHORITY, eg.
#define SE_CHANGE_NOTIFY_NAME TEXT("SeChangeNotifyPrivilege")
#define SE_REMOTE_SHUTDOWN_NAME TEXT("SeRemoteShutdownPrivilege")
#define SE_CREATE_GLOBAL_NAME TEXT("SeCreateGlobalPrivilege")
-/* FIXME: Oh how I wish, I wish the w32api DDK wouldn't include winnt.h... */
-#ifndef _NTDDK_
#define SE_GROUP_MANDATORY 1
#define SE_GROUP_ENABLED_BY_DEFAULT 2
#define SE_GROUP_ENABLED 4
#define SE_GROUP_USE_FOR_DENY_ONLY 16
#define SE_GROUP_LOGON_ID 3221225472U
#define SE_GROUP_RESOURCE 536870912
-#endif
#define LANG_NEUTRAL 0x00
#define LANG_INVARIANT 0x7f
#define LANG_AFRIKAANS 0x36
#define LANG_YORUBA 0x6a
#define LANG_ZULU 0x35
-#ifdef _WINE
+/* FIXME: non-standard */
#define LANG_ESPERANTO 0x8f
#define LANG_WALON 0x90
#define LANG_CORNISH 0x91
+/* FIXME: not present in the official headers */
#define LANG_GAELIC 0x94
-#define LANG_MALTESE 0x3a
-#define LANG_ROMANSH 0x17
#define LANG_SAAMI 0x3b
-#define LANG_LOWER_SORBIAN 0x2e
-#define LANG_UPPER_SORBIAN 0x2e
#define LANG_SUTU 0x30
-#define LANG_TAJIK 0x28
#define LANG_TSONGA 0x31
-#define LANG_TSWANA 0x32
#define LANG_VENDA 0x33
-#define LANG_XHOSA 0x34
-#define LANG_ZULU 0x35
-#endif
#define SUBLANG_CUSTOM_UNSPECIFIED 0x04
#define SUBLANG_CUSTOM_DEFAULT 0x03
#define LANG_SYSTEM_DEFAULT MAKELANGID(LANG_NEUTRAL,SUBLANG_SYS_DEFAULT)
#define LANG_USER_DEFAULT MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT)
#define LOCALE_NEUTRAL MAKELCID(MAKELANGID(LANG_NEUTRAL,SUBLANG_NEUTRAL),SORT_DEFAULT)
+#define LOCALE_INVARIANT MAKELCID(MAKELANGID(LANG_INVARIANT, SUBLANG_NEUTRAL), SORT_DEFAULT)
#define ACL_REVISION 2
#define ACL_REVISION_DS 4
#define ACL_REVISION1 1
#define MEM_WRITE_WATCH 0x200000 /* 98/Me */
#define MEM_PHYSICAL 0x400000
#define MEM_4MB_PAGES 0x80000000
-/* FIXME: Oh how I wish, I wish the w32api DDK wouldn't include winnt.h... */
-#ifndef _NTDDK_
#define MEM_IMAGE SEC_IMAGE
#define SEC_NO_CHANGE 0x00400000
#define SEC_FILE 0x00800000
#define SEC_RESERVE 0x04000000
#define SEC_COMMIT 0x08000000
#define SEC_NOCACHE 0x10000000
-#endif
#define SECTION_EXTEND_SIZE 16
#define SECTION_MAP_READ 4
#define SECTION_MAP_WRITE 2
#define SECTION_MAP_EXECUTE 8
#define SECTION_ALL_ACCESS 0xf001f
#define WRITE_WATCH_FLAG_RESET 0x01
-#ifndef _NTDDK_
#define MESSAGE_RESOURCE_UNICODE 1
-#endif
#define RTL_CRITSECT_TYPE 0
#define RTL_RESOURCE_TYPE 1
/* Also in winddk.h */
-#ifndef __GNUC__
-#define FIELD_OFFSET(t,f) ((LONG_PTR)&(((t*)0)->f))
+#if !defined(__GNUC__)
+#define FIELD_OFFSET(t,f) ((LONG)(LONG_PTR)&(((t*) 0)->f))
#else
-#define FIELD_OFFSET(t,f) __builtin_offsetof(t,f)
+#define FIELD_OFFSET(t,f) ((LONG)__builtin_offsetof(t,f))
#endif
#ifndef CONTAINING_RECORD
#define CONTAINING_RECORD(address, type, field) \
ACCESS_MASK GenericExecute;
ACCESS_MASK GenericAll;
} GENERIC_MAPPING, *PGENERIC_MAPPING;
-/* Sigh..when will they learn... */
-#ifndef _NTDDK_
typedef struct _ACE_HEADER {
BYTE AceType;
BYTE AceFlags;
GUID InheritedObjectType;
DWORD SidStart;
} SYSTEM_ALARM_CALLBACK_OBJECT_ACE, *PSYSTEM_ALARM_CALLBACK_OBJECT_ACE;
-#endif
typedef struct _ACL {
BYTE AclRevision;
BYTE Sbz1;
#ifndef PAGE_SIZE
#define PAGE_SIZE 0x1000 // FIXME: This should probably go elsewhere
#endif
-
+
/* The following flags control the contents of the CONTEXT structure. */
#define CONTEXT_ARM 0x0000040
BOOLEAN EffectiveOnly;
SECURITY_IMPERSONATION_LEVEL Level;
} SE_IMPERSONATION_STATE,*PSE_IMPERSONATION_STATE;
-/* Steven you are my hero when you fix the w32api ddk! */
-#if !defined(_NTDDK_)
typedef struct _SID_IDENTIFIER_AUTHORITY {
BYTE Value[6];
} SID_IDENTIFIER_AUTHORITY,*PSID_IDENTIFIER_AUTHORITY,*LPSID_IDENTIFIER_AUTHORITY;
MaxTokenInfoClass
} TOKEN_INFORMATION_CLASS;
-#endif
typedef enum _SID_NAME_USE {
SidTypeUser=1,SidTypeGroup,SidTypeDomain,SidTypeAlias,
SidTypeWellKnownGroup,SidTypeDeletedAccount,SidTypeInvalid,
DWORD Count;
DWORD Size;
} TAPE_CREATE_PARTITION,*PTAPE_CREATE_PARTITION;
-/* Sigh..when will they learn... */
-#ifndef _NTDDK_
typedef struct _MEMORY_BASIC_INFORMATION {
PVOID BaseAddress;
PVOID AllocationBase;
DWORD AllocationProtect;
- DWORD RegionSize;
+ SIZE_T RegionSize;
DWORD State;
DWORD Protect;
DWORD Type;
DWORD NumberOfBlocks;
MESSAGE_RESOURCE_BLOCK Blocks[1];
} MESSAGE_RESOURCE_DATA,*PMESSAGE_RESOURCE_DATA;
-#endif
typedef struct _LIST_ENTRY {
struct _LIST_ENTRY *Flink;
struct _LIST_ENTRY *Blink;
} LIST_ENTRY,*PLIST_ENTRY;
+typedef struct _LIST_ENTRY32 {
+ DWORD Flink;
+ DWORD Blink;
+} LIST_ENTRY32,*PLIST_ENTRY32;
+typedef struct _LIST_ENTRY64 {
+ ULONGLONG Flink;
+ ULONGLONG Blink;
+} LIST_ENTRY64,*PLIST_ENTRY64;
+
typedef struct _SINGLE_LIST_ENTRY {
struct _SINGLE_LIST_ENTRY *Next;
} SINGLE_LIST_ENTRY,*PSINGLE_LIST_ENTRY;
+//
+// Slist Header
+//
#ifndef _SLIST_HEADER_
#define _SLIST_HEADER_
+
+#if defined(_WIN64)
+typedef struct _SLIST_ENTRY *PSLIST_ENTRY;
+typedef struct DECLSPEC_ALIGN(16) _SLIST_ENTRY {
+ PSLIST_ENTRY Next;
+} SLIST_ENTRY;
+typedef union DECLSPEC_ALIGN(16) _SLIST_HEADER {
+ struct {
+ ULONGLONG Alignment;
+ ULONGLONG Region;
+ } DUMMYSTRUCTNAME;
+ struct {
+ ULONGLONG Depth:16;
+ ULONGLONG Sequence:9;
+ ULONGLONG NextEntry:39;
+ ULONGLONG HeaderType:1;
+ ULONGLONG Init:1;
+ ULONGLONG Reserved:59;
+ ULONGLONG Region:3;
+ } Header8;
+ struct {
+ ULONGLONG Depth:16;
+ ULONGLONG Sequence:48;
+ ULONGLONG HeaderType:1;
+ ULONGLONG Init:1;
+ ULONGLONG Reserved:2;
+ ULONGLONG NextEntry:60;
+ } Header16;
+} SLIST_HEADER, *PSLIST_HEADER;
+#else
#define SLIST_ENTRY SINGLE_LIST_ENTRY
#define _SLIST_ENTRY _SINGLE_LIST_ENTRY
#define PSLIST_ENTRY PSINGLE_LIST_ENTRY
typedef union _SLIST_HEADER {
- ULONGLONG Alignment;
- _ANONYMOUS_STRUCT struct {
- SLIST_ENTRY Next;
- WORD Depth;
- WORD Sequence;
- } DUMMYSTRUCTNAME;
-} SLIST_HEADER,*PSLIST_HEADER;
-#endif /* !_SLIST_HEADER_ */
+ ULONGLONG Alignment;
+ struct {
+ SLIST_ENTRY Next;
+ USHORT Depth;
+ USHORT Sequence;
+ } DUMMYSTRUCTNAME;
+} SLIST_HEADER, *PSLIST_HEADER;
+#endif
+
+#endif /* _SLIST_HEADER_ */
+
NTSYSAPI
VOID
IN PSLIST_HEADER ListHead
);
-/* FIXME: Please oh please stop including winnt.h from the DDK... */
-#ifndef _NTDDK_
typedef struct _RTL_CRITICAL_SECTION_DEBUG {
WORD Type;
WORD CreatorBackTraceIndex;
HANDLE LockSemaphore;
ULONG_PTR SpinCount;
} RTL_CRITICAL_SECTION,*PRTL_CRITICAL_SECTION;
-#endif
NTSYSAPI
WORD
struct _NT_TIB *Self;
} NT_TIB,*PNT_TIB;
+typedef struct _NT_TIB32 {
+ DWORD ExceptionList;
+ DWORD StackBase;
+ DWORD StackLimit;
+ DWORD SubSystemTib;
+ union {
+ DWORD FiberData;
+ DWORD Version;
+ };
+ DWORD ArbitraryUserPointer;
+ DWORD Self;
+} NT_TIB32,*PNT_TIB32;
+
+typedef struct _NT_TIB64 {
+ DWORD64 ExceptionList;
+ DWORD64 StackBase;
+ DWORD64 StackLimit;
+ DWORD64 SubSystemTib;
+ union {
+ DWORD64 FiberData;
+ DWORD Version;
+ };
+ DWORD64 ArbitraryUserPointer;
+ DWORD64 Self;
+} NT_TIB64,*PNT_TIB64;
+
typedef struct _REPARSE_GUID_DATA_BUFFER {
DWORD ReparseTag;
WORD ReparseDataLength;
#define JOB_OBJECT_MSG_PROCESS_MEMORY_LIMIT 9
#define JOB_OBJECT_MSG_JOB_MEMORY_LIMIT 10
-/* FIXME: Oh how I wish, I wish the w32api DDK wouldn't include winnt.h... */
-#ifndef _NTDDK_
#define JOB_OBJECT_ASSIGN_PROCESS 1
#define JOB_OBJECT_SET_ATTRIBUTES 2
#define JOB_OBJECT_QUERY 4
DWORD MemberLevel;
DWORD Flags;
} JOB_SET_ARRAY, *PJOB_SET_ARRAY;
-#endif
typedef struct _JOBOBJECT_BASIC_ACCOUNTING_INFORMATION {
LARGE_INTEGER TotalUserTime;
DWORD UIRestrictionsClass;
} JOBOBJECT_BASIC_UI_RESTRICTIONS,*PJOBOBJECT_BASIC_UI_RESTRICTIONS;
-/* Steven you are my hero when you fix the w32api ddk! */
-#ifndef _NTDDK_
typedef struct _JOBOBJECT_SECURITY_LIMIT_INFORMATION {
DWORD SecurityLimitFlags;
HANDLE JobToken;
PTOKEN_PRIVILEGES PrivilegesToDelete;
PTOKEN_GROUPS RestrictedSids;
} JOBOBJECT_SECURITY_LIMIT_INFORMATION,*PJOBOBJECT_SECURITY_LIMIT_INFORMATION;
-#endif
typedef struct _JOBOBJECT_END_OF_JOB_TIME_INFORMATION {
DWORD EndOfJobTimeAction;
ULONG DefaultAlert2;
} SYSTEM_BATTERY_STATE, *PSYSTEM_BATTERY_STATE;
-#ifndef _NTDDK_ /* HACK!!! ntddk.h shouldn't include winnt.h! */
typedef struct _PROCESSOR_POWER_INFORMATION {
ULONG Number;
ULONG MaxMhz;
ULONG MaxIdleState;
ULONG CurrentIdleState;
} PROCESSOR_POWER_INFORMATION, *PPROCESSOR_POWER_INFORMATION;
-#endif
typedef DWORD EXECUTION_STATE;
typedef enum _POWER_INFORMATION_LEVEL {
typedef OSVERSIONINFOEXA OSVERSIONINFOEX,*POSVERSIONINFOEX,*LPOSVERSIONINFOEX;
#endif
+#define VER_SET_CONDITION(lc,t,c) ((lc) = VerSetConditionMask((lc),(t),(c)))
+
#if (_WIN32_WINNT >= 0x0500)
ULONGLONG WINAPI VerSetConditionMask(ULONGLONG,DWORD,BYTE);
#endif
}
#endif
-/* FIXME: Oh how I wish, I wish the w32api DDK wouldn't include winnt.h... */
-#ifndef _NTDDK_
-#ifdef _M_IX86
+#if defined(_M_IX86)
static __inline__ struct _TEB * NtCurrentTeb(void)
{
struct _TEB *ret;
return ret;
}
-#elif _M_ARM
+#elif defined(_M_ARM)
//
// NT-ARM is not documented
//
#include <armddk.h>
-#elif defined (_M_AMD64)
+#elif defined(_M_AMD64)
FORCEINLINE struct _TEB * NtCurrentTeb(VOID)
{
return (struct _TEB *)__readgsqword(FIELD_OFFSET(NT_TIB, Self));
}
-#else
+#elif defined(_M_PPC)
static __inline__ struct _TEB * NtCurrentTeb(void)
{
return __readfsdword_winnt(0x18);
}
-#endif
-#elif defined(_M_PPC)
+#else
static __inline__ struct _TEB * NtCurrentTeb(void)
{
return __readfsdword_winnt(0x18);
#if (_MSC_FULL_VER >= 13012035)
-DWORD __readfsdword(DWORD);
-#pragma intrinsic(__readfsdword)
-
__inline PVOID GetCurrentFiber(void) { return (PVOID)(ULONG_PTR)__readfsdword(0x10); }
__inline struct _TEB * NtCurrentTeb(void) { return (struct _TEB *)(ULONG_PTR)__readfsdword(0x18); }
#error Unknown architecture
#endif
-VOID
-_mm_pause (
- VOID
- );
-
-
#if defined(_M_IX86)
#ifdef _MSC_VER
#pragma intrinsic(_mm_pause)
+#define YieldProcessor _mm_pause
#else
#define YieldProcessor() __asm__ __volatile__("pause");
#endif
#elif defined (_M_AMD64)
#ifdef _MSC_VER
+#pragma intrinsic(_mm_pause)
#define YieldProcessor _mm_pause
#else
#define YieldProcessor() __asm__ __volatile__("pause");