diff --git a/SDK/CRT/STDIO/wprintf.c b/SDK/CRT/STDIO/wprintf.c index 196f60d..174dad9 100644 --- a/SDK/CRT/STDIO/wprintf.c +++ b/SDK/CRT/STDIO/wprintf.c @@ -5,7 +5,7 @@ Provided under the BSD 3-Clause license. Module Name: - printf.c + wprintf.c Abstract: diff --git a/SDK/CRT/STRING/mem.c b/SDK/CRT/STRING/mem.c index 544029d..f756caf 100644 --- a/SDK/CRT/STRING/mem.c +++ b/SDK/CRT/STRING/mem.c @@ -64,21 +64,17 @@ memmove ( /* Check for overlap */ if (src > dest || ((char *)src + count) < (char *)dest) { - /* Low-to-high copy, like memcpy() */ - while (count--) { - *(char *)dest = *(char *)src; - dest = (char *)dest + 1; - src = (char *)src + 1; - } - } else { - /* High-to-low copy */ - dest = (char *)dest + count - 1; - src = (char *)src + count - 1; - while (count--) { - *(char *)dest = *(char *)src; - dest = (char *)dest - 1; - src = (char *)src - 1; - } + /* Low-to-high copy, use memcpy() */ + return memcpy(dest, src, count); + } + + /* High-to-low copy */ + dest = (char *)dest + count - 1; + src = (char *)src + count - 1; + while (count--) { + *(char *)dest = *(char *)src; + dest = (char *)dest - 1; + src = (char *)src - 1; } return ptr; diff --git a/SDK/CRT/STRING/str.c b/SDK/CRT/STRING/str.c index f578e0d..2d4c5cd 100644 --- a/SDK/CRT/STRING/str.c +++ b/SDK/CRT/STRING/str.c @@ -24,9 +24,11 @@ strlen ( const char *ptr; ptr = str; - while (*ptr++); + while (*ptr) { + ptr++; + } - return ptr - str - sizeof(char); + return ptr - str; } size_t @@ -36,12 +38,14 @@ strnlen ( ) { - size_t len; + const char *ptr; - len = 0; - while (len < maxlen && str[len++]); + ptr = str; + while (maxlen-- && *ptr) { + ptr++; + } - return len - sizeof(char); + return ptr - str; } int diff --git a/SDK/CRT/STRING/wmem.c b/SDK/CRT/STRING/wmem.c index 0cecd08..6cb49a5 100644 --- a/SDK/CRT/STRING/wmem.c +++ b/SDK/CRT/STRING/wmem.c @@ -26,8 +26,7 @@ wmemset ( wchar_t *ptr = dest; while (count--) { - *(wchar_t *)dest = c; - dest = (wchar_t *)dest + 1; + *dest++ = c; } return ptr; @@ -44,9 +43,7 @@ wmemcpy ( wchar_t *ptr = dest; while (count--) { - *(wchar_t *)dest = *(wchar_t *)src; - dest = (wchar_t *)dest + 1; - src = (wchar_t *)src + 1; + *dest++ = *src++; } return ptr; @@ -64,21 +61,17 @@ wmemmove ( /* Check for overlap */ if (src > dest || ((wchar_t *)src + count) < (wchar_t *)dest) { - /* Low-to-high copy, like memcpy() */ - while (count--) { - *(wchar_t *)dest = *(wchar_t *)src; - dest = (wchar_t *)dest + 1; - src = (wchar_t *)src + 1; - } - } else { - /* High-to-low copy */ - dest = (wchar_t *)dest + count - 1; - src = (wchar_t *)src + count - 1; - while (count--) { - *(wchar_t *)dest = *(wchar_t *)src; - dest = (wchar_t *)dest - 1; - src = (wchar_t *)src - 1; - } + /* Low-to-high copy, use wmemcpy() */ + return wmemcpy(dest, src, count); + } + + /* High-to-low copy */ + dest = (wchar_t *)dest + count - 1; + src = (wchar_t *)src + count - 1; + while (count--) { + *(wchar_t *)dest = *(wchar_t *)src; + dest = (wchar_t *)dest - 1; + src = (wchar_t *)src - 1; } return ptr; diff --git a/SDK/CRT/STRING/wstr.c b/SDK/CRT/STRING/wstr.c index a8111bd..c6f67d2 100644 --- a/SDK/CRT/STRING/wstr.c +++ b/SDK/CRT/STRING/wstr.c @@ -24,7 +24,9 @@ wcslen ( const wchar_t *ptr; ptr = str; - while (*ptr++); + while (*ptr) { + ptr++; + } return ptr - str; } @@ -36,15 +38,14 @@ wcsnlen ( ) { - size_t len; + const wchar_t *ptr; - len = 0; - while (len < maxlen && *str) { - len++; - str++; + ptr = str; + while (maxlen-- && *ptr) { + ptr++; } - return len; + return ptr - str; } int diff --git a/SDK/INC/CRT/stddef.h b/SDK/INC/CRT/stddef.h index e29727f..37df529 100644 --- a/SDK/INC/CRT/stddef.h +++ b/SDK/INC/CRT/stddef.h @@ -53,6 +53,8 @@ typedef long int ptrdiff_t; typedef unsigned short wchar_t; #endif +#define offsetof(type, member) __builtin_offsetof(type, member) + #ifdef __cplusplus } #endif diff --git a/SDK/INC/CRT/string.h b/SDK/INC/CRT/string.h index 86fe987..cd71851 100644 --- a/SDK/INC/CRT/string.h +++ b/SDK/INC/CRT/string.h @@ -18,11 +18,15 @@ Abstract: #ifndef _STRING_H #define _STRING_H +#include + #ifdef __cplusplus extern "C" { #endif -#include +void *memset(void *dest, int c, size_t count); +void *memcpy(void *dest, const void *src, size_t count); +void *memmove(void *dest, const void *src, size_t count); size_t strlen(const char *str); size_t strnlen(const char *str, size_t maxlen); @@ -31,10 +35,6 @@ int strncmp(const char* s1, const char* s2, size_t n); char *strchr(const char *s, int c); char *strstr(const char *haystack, const char *needle); -void *memset(void *dest, int c, size_t count); -void *memcpy(void *dest, const void *src, size_t count); -void *memmove(void *dest, const void *src, size_t count); - #ifdef __cplusplus } #endif diff --git a/SDK/INC/CRT/wchar.h b/SDK/INC/CRT/wchar.h index 4ecd5d9..c5b4e31 100644 --- a/SDK/INC/CRT/wchar.h +++ b/SDK/INC/CRT/wchar.h @@ -18,12 +18,16 @@ Abstract: #ifndef _WCHAR_H #define _WCHAR_H +#include +#include + #ifdef __cplusplus extern "C" { #endif -#include -#include +wchar_t *wmemset(wchar_t *dest, wchar_t c, size_t count); +wchar_t *wmemcpy(wchar_t *dest, const wchar_t *src, size_t count); +wchar_t *wmemmove(wchar_t *dest, const wchar_t *src, size_t count); size_t wcslen(const wchar_t *str); size_t wcsnlen(const wchar_t *str, size_t maxlen); @@ -34,10 +38,6 @@ wchar_t *wcsstr(const wchar_t *haystack, const wchar_t *needle); wchar_t *wcscpy_s(wchar_t *dest, size_t maxlen, const wchar_t *src); wchar_t *wcscat_s(wchar_t *dest, size_t maxlen, const wchar_t *src); -wchar_t *wmemset(wchar_t *dest, wchar_t c, size_t count); -wchar_t *wmemcpy(wchar_t *dest, const wchar_t *src, size_t count); -wchar_t *wmemmove(wchar_t *dest, const wchar_t *src, size_t count); - int vswprintf(wchar_t *wcs, size_t maxlen, const wchar_t *format, va_list args); #ifdef __cplusplus diff --git a/SDK/INC/NT/ntdef.h b/SDK/INC/NT/ntdef.h index 0983d13..ca4acaa 100644 --- a/SDK/INC/NT/ntdef.h +++ b/SDK/INC/NT/ntdef.h @@ -111,44 +111,19 @@ typedef long long LONGLONG; typedef unsigned long long ULONGLONG; #endif -typedef LONGLONG *PLONGLONG; -typedef ULONGLONG *PULONGLONG; - #define MAXLONGLONG 0x7fffffffffffffff #define MAXULONGLONG 0xffffffffffffffff -#define LODWORD(x) ((ULONG)(x)) -#define HIDWORD(x) ((ULONG)((x) >> 32)) - -#define LOWORD(x) ((USHORT)(x)) -#define HIWORD(x) ((USHORT)((x) >> 16)) - -#define LOBYTE(x) ((UCHAR)(x)) -#define HIBYTE(x) ((UCHAR)((x) >> 8)) - // // Logical/boolean value types. // typedef ULONG LOGICAL; -typedef ULONG *PLOGICAL; typedef int BOOL; -typedef BOOL *PBOOL; typedef UCHAR BOOLEAN; -typedef BOOLEAN *PBOOLEAN; #define TRUE 1 #define FALSE 0 -// -// Basic pointer types. -// -typedef VOID *PVOID; -typedef CHAR *PCHAR; -typedef SHORT *PSHORT; -typedef UCHAR *PUCHAR; -typedef USHORT *PUSHORT; -typedef ULONG *PULONG; - // // Numeric pointer types. // @@ -160,6 +135,29 @@ typedef LONG LONG_PTR; typedef ULONG ULONG_PTR; #endif +// +// Basic type pointers. +// +typedef VOID *PVOID; +typedef CHAR *PCHAR; +typedef SHORT *PSHORT; +typedef UCHAR *PUCHAR; +typedef USHORT *PUSHORT; +typedef ULONG *PULONG; + +// +// Long long type pointers. +// +typedef LONGLONG *PLONGLONG; +typedef ULONGLONG *PULONGLONG; + +// +// Logical/boolean type pointers. +// +typedef ULONG *PLOGICAL; +typedef BOOL *PBOOL; +typedef BOOLEAN *PBOOLEAN; + // // String types. // @@ -210,6 +208,16 @@ typedef NTSTATUS *PNTSTATUS; #define ALIGN_DOWN(x, a) ((x) & ~((a) - 1)) #define ALIGN_UP(x, a) ALIGN_DOWN((x) + (a) - 1, a) +// +// Bit extraction helpers. +// +#define LODWORD(x) ((ULONG)(x)) +#define HIDWORD(x) ((ULONG)((x) >> 32)) +#define LOWORD(x) ((USHORT)(x)) +#define HIWORD(x) ((USHORT)((x) >> 16)) +#define LOBYTE(x) ((UCHAR)(x)) +#define HIBYTE(x) ((UCHAR)((x) >> 8)) + // // Large (64-bit) integer value. // @@ -234,135 +242,6 @@ typedef union ULARGE_INTEGER { ULONGLONG QuadPart; } ULARGE_INTEGER, *PULARGE_INTEGER; -// -// Doubly-linked list entry. -// -typedef struct _LIST_ENTRY { - struct _LIST_ENTRY *Flink; - struct _LIST_ENTRY *Blink; -} LIST_ENTRY, *PLIST_ENTRY; - -FORCEINLINE -VOID -InitializeListHead ( - IN PLIST_ENTRY Head - ) - -/*++ - -Routine Description: - - Initializes a list head. - -Arguments: - - Head - the list head. - -Return Value: - - None. - ---*/ - -{ - Head->Blink = Head; - Head->Flink = Head; -} - -FORCEINLINE -VOID -InsertHeadList ( - IN PLIST_ENTRY Head, - IN PLIST_ENTRY Entry - ) - -/*++ - -Routine Description: - - Inserts a list entry at the head of a list. - -Arguments: - - Entry - The list entry. - -Return Value: - - None. - ---*/ - -{ - Entry->Flink = Head->Flink; - Entry->Blink = Head; - Head->Flink->Blink = Entry; - Head->Flink = Entry; -} - -FORCEINLINE -VOID -InsertTailList ( - IN PLIST_ENTRY Head, - IN PLIST_ENTRY Entry - ) - -/*++ - -Routine Description: - - Inserts a list entry at the tail of a list. - -Arguments: - - Entry - The list entry. - -Return Value: - - None. - ---*/ - -{ - Entry->Blink = Head->Blink; - Entry->Flink = Head; - Head->Blink->Flink = Entry; - Head->Blink = Entry; -} - -FORCEINLINE -BOOLEAN -RemoveEntryList ( - IN PLIST_ENTRY Entry - ) - -/*++ - -Routine Description: - - Removes a list entry from a list. - -Arguments: - - Entry - the entry to remove. - -Return Value: - - True if the list is now empty, - False if the list still has at least one entry. - ---*/ - -{ - PLIST_ENTRY Blink, Flink; - - Blink = Entry->Blink; - Flink = Entry->Flink; - Blink->Flink = Flink; - Flink->Blink = Blink; - - return (BOOLEAN)(Flink == Blink); -} - // // Unicode string. // @@ -377,6 +256,14 @@ typedef CONST UNICODE_STRING *PCUNICODE_STRING; #define MAX_USTRING ALIGN_DOWN(MAXUSHORT, sizeof(WCHAR)) +// +// Doubly-linked list entry. +// +typedef struct _LIST_ENTRY { + struct _LIST_ENTRY *Flink; + struct _LIST_ENTRY *Blink; +} LIST_ENTRY, *PLIST_ENTRY; + #include #endif /* !_NTDEF_H */ diff --git a/SDK/INC/NT/ntimage.h b/SDK/INC/NT/ntimage.h index 6100e0e..2c5318b 100644 --- a/SDK/INC/NT/ntimage.h +++ b/SDK/INC/NT/ntimage.h @@ -19,7 +19,7 @@ Abstract: // // Machine type values. // -#define IMAGE_FILE_MACHINE_UNKNOWN 0 +#define IMAGE_FILE_MACHINE_UNKNOWN 0x0000 #define IMAGE_FILE_MACHINE_I386 0x014c #define IMAGE_FILE_MACHINE_AMD64 0x8664 diff --git a/SDK/INC/NT/ntrtl.h b/SDK/INC/NT/ntrtl.h index 25ca4ae..f19b70c 100644 --- a/SDK/INC/NT/ntrtl.h +++ b/SDK/INC/NT/ntrtl.h @@ -16,9 +16,9 @@ Abstract: #ifndef _NTRTL_H #define _NTRTL_H -#include -#include -#include +#ifdef __cplusplus +extern "C" { +#endif // // Memory operations. @@ -28,7 +28,128 @@ Abstract: #define RtlFillMemory(Destination, Length, Fill) memset((Destination), (Fill), (Length)) #define RtlZeroMemory(Destination, Length) memset((Destination), 0, (Length)) -#define ULONG_ERROR 0xFFFFFFFFUL +FORCEINLINE +VOID +InitializeListHead ( + IN PLIST_ENTRY Head + ) + +/*++ + +Routine Description: + + Initializes a list head. + +Arguments: + + Head - Pointer to the list's head. + +Return Value: + + None. + +--*/ + +{ + Head->Blink = Head; + Head->Flink = Head; +} + +FORCEINLINE +VOID +InsertHeadList ( + IN PLIST_ENTRY Head, + IN PLIST_ENTRY Entry + ) + +/*++ + +Routine Description: + + Inserts an entry at the head of a list. + +Arguments: + + Entry - Pointer to the list entry to insert. + +Return Value: + + None. + +--*/ + +{ + Entry->Flink = Head->Flink; + Entry->Blink = Head; + Head->Flink->Blink = Entry; + Head->Flink = Entry; +} + +FORCEINLINE +VOID +InsertTailList ( + IN PLIST_ENTRY Head, + IN PLIST_ENTRY Entry + ) + +/*++ + +Routine Description: + + Inserts an entry at the tail of a list. + +Arguments: + + Entry - Pointer to the list entry to insert. + +Return Value: + + None. + +--*/ + +{ + Entry->Blink = Head->Blink; + Entry->Flink = Head; + Head->Blink->Flink = Entry; + Head->Blink = Entry; +} + +FORCEINLINE +BOOLEAN +RemoveEntryList ( + IN PLIST_ENTRY Entry + ) + +/*++ + +Routine Description: + + Removes an entry from a list. + +Arguments: + + Entry - Pointer to the entry to remove. + +Return Value: + + TRUE if the list is now empty, + FALSE if the list still has at least one entry. + +--*/ + +{ + PLIST_ENTRY Blink, Flink; + + Blink = Entry->Blink; + Flink = Entry->Flink; + Blink->Flink = Flink; + Flink->Blink = Blink; + + return (BOOLEAN)(Flink == Blink); +} + +#define ULONG_ERROR 0xffffffffUL FORCEINLINE NTSTATUS @@ -83,4 +204,8 @@ RtlGUIDFromString ( OUT GUID *Guid ); +#ifdef __cplusplus +} +#endif + #endif /* !_NTRTL_H */ diff --git a/SDK/RTL/guid.c b/SDK/RTL/guid.c index 19e36fe..469dfbd 100644 --- a/SDK/RTL/guid.c +++ b/SDK/RTL/guid.c @@ -13,8 +13,7 @@ Abstract: --*/ -#include -#include +#include #include int diff --git a/SDK/RTL/string.c b/SDK/RTL/string.c index e24a8ff..7a6de1e 100644 --- a/SDK/RTL/string.c +++ b/SDK/RTL/string.c @@ -13,7 +13,7 @@ Abstract: --*/ -#include +#include #include VOID @@ -32,9 +32,9 @@ Routine Description: Arguments: - Destination - A pointer to the unicode string structure. + Destination - Pointer to the unicode string structure. - Source - Optionally, a pointer to a null-terminated string to initialize + Source - Optionally, a pointer to a NULL-terminated string to initialize the unicode string structure with. Return Value: