From d6e49e3561e3c732da8a1acdbcd651b4ef059424 Mon Sep 17 00:00:00 2001 From: Timo Kreuzer Date: Wed, 25 Mar 2015 22:27:44 +0000 Subject: [PATCH] [INCLUDE] - intsafe.h: Fix some constants to be C++ compatible - sal.h: Implement _Analysis_mode_, __prefast_operator_new_null and __prefast_operator_new_throws annotations - Make probe.h (mostly) C++ compatible svn path=/trunk/; revision=66886 --- reactos/include/ndk/no_sal2.h | 3 +++ reactos/include/psdk/driverspecs.h | 10 +++++++-- reactos/include/psdk/intsafe.h | 36 +++++++++++++++--------------- reactos/include/psdk/sal.h | 11 +++++++-- reactos/include/reactos/probe.h | 9 ++++++-- 5 files changed, 45 insertions(+), 24 deletions(-) diff --git a/reactos/include/ndk/no_sal2.h b/reactos/include/ndk/no_sal2.h index b9515180994..f106e1b3231 100644 --- a/reactos/include/ndk/no_sal2.h +++ b/reactos/include/ndk/no_sal2.h @@ -5,6 +5,7 @@ /* From sal.h */ #define _Always_(annos) +#define _Analysis_mode_(mode) #define _Analysis_noreturn_ #define _Analysis_assume_(expr) __analysis_assume(expr) #define _At_(target, annos) @@ -664,6 +665,8 @@ #define _Kernel_requires_resource_not_held_(kind) #define _Kernel_acquires_resource_(kind) #define _Landmark_(name) +#define __prefast_operator_new_null +#define __prefast_operator_new_throws /* concurrencysal.h */ #define _Benign_race_begin_ __pragma(warning(push)) diff --git a/reactos/include/psdk/driverspecs.h b/reactos/include/psdk/driverspecs.h index 204c2d5a26b..68f9bd34a0c 100644 --- a/reactos/include/psdk/driverspecs.h +++ b/reactos/include/psdk/driverspecs.h @@ -135,8 +135,14 @@ #define __internal_kernel_driver #define __kernel_code #define __kernel_driver -#define __prefast_operator_new_null -#define __prefast_operator_new_throws +#define __prefast_operator_new_null \ + void* __cdecl operator new(size_t size) throw(); \ + void* __cdecl operator new[](size_t size) throw(); \ + _Analysis_mode_(_Analysis_operator_new_null_) +#define __prefast_operator_new_throws \ + void* __cdecl operator new(size_t size) throw(std::bad_alloc); \ + void* __cdecl operator new[](size_t size) throw(std::bad_alloc); \ + _Analysis_mode_(_Analysis_operator_new_throw_) #define __user_code #define __user_driver #define ___drv_unit_internal_kernel_driver diff --git a/reactos/include/psdk/intsafe.h b/reactos/include/psdk/intsafe.h index 0da1c08f5af..d3726214164 100644 --- a/reactos/include/psdk/intsafe.h +++ b/reactos/include/psdk/intsafe.h @@ -147,12 +147,12 @@ C_ASSERT(sizeof(UINT_PTR) == sizeof(ULONG_PTR)); #define INT8_MAX ((signed char)127) #define UINT8_MAX ((unsigned char)0xffU) -#define BYTE_MAX 0xff -#define SHORT_MAX 32767 +#define BYTE_MAX ((unsigned char)0xff) +#define SHORT_MAX ((short)32767) #define INT16_MAX ((short)32767) -#define USHORT_MAX 0xffff -#define UINT16_MAX ((unsigned short)0xffffU) -#define WORD_MAX 0xffff +#define USHORT_MAX ((unsigned short)0xffff) +#define UINT16_MAX ((unsigned short)0xffff) +#define WORD_MAX ((unsigned short)0xffff) #define INT_MAX 2147483647 #define INT32_MAX 2147483647 #define UINT_MAX 0xffffffff @@ -196,15 +196,15 @@ C_ASSERT(sizeof(UINT_PTR) == sizeof(ULONG_PTR)); /* Error values */ #define INT8_ERROR ((signed char)(-1)) #define UINT8_ERROR ((unsigned char)0xff) -#define BYTE_ERROR 0xff -#define SHORT_ERROR (-1) +#define BYTE_ERROR ((unsigned char)0xff) +#define SHORT_ERROR ((short)(-1)) #define INT16_ERROR ((short)(-1)) -#define USHORT_ERROR 0xffff -#define UINT16_ERROR ((unsigned short)0xffffU) -#define WORD_ERROR 0xffff +#define USHORT_ERROR ((unsigned short)0xffff) +#define UINT16_ERROR ((unsigned short)0xffff) +#define WORD_ERROR ((unsigned short)0xffff) #define INT_ERROR (-1) #define INT32_ERROR (-1) -#define UINT_ERROR 0xffffffff +#define UINT_ERROR 0xffffffffU #define UINT32_ERROR 0xffffffffU #define LONG_ERROR (-1L) #define ULONG_ERROR 0xffffffffUL @@ -228,25 +228,25 @@ C_ASSERT(sizeof(UINT_PTR) == sizeof(ULONG_PTR)); #define _SIZE_T_ERROR 0xffffffffffffffffULL #else /* _WIN64 */ #define INT_PTR_ERROR (-1) -#define UINT_PTR_ERROR 0xffffffff +#define UINT_PTR_ERROR 0xffffffffU #define LONG_PTR_ERROR (-1L) #define ULONG_PTR_ERROR 0xffffffffUL #define DWORD_PTR_ERROR 0xffffffffUL #define PTRDIFF_T_ERROR (-1) -#define SIZE_T_ERROR 0xffffffff +#define SIZE_T_ERROR 0xffffffffU #define SSIZE_T_ERROR (-1L) #define _SIZE_T_ERROR 0xffffffffUL #endif /* _WIN64 */ /* special definitons (the CHAR ones should not be defined here!) */ #define _INTSAFE_CHAR CHAR -#define _INTSAFE_CHAR_ERROR 0xff +#define _INTSAFE_CHAR_ERROR ((signed char)(-1)) #ifdef _CHAR_UNSIGNED - #define _INTSAFE_CHAR_MIN 0 - #define _INTSAFE_CHAR_MAX 0xff + #define _INTSAFE_CHAR_MIN ((unsigned char)0) + #define _INTSAFE_CHAR_MAX ((unsigned char)0xff) #else - #define _INTSAFE_CHAR_MIN (-128) - #define _INTSAFE_CHAR_MAX 127 + #define _INTSAFE_CHAR_MIN ((signed char)(-128)) + #define _INTSAFE_CHAR_MAX ((signed char)127) #endif /* _CHAR_UNSIGNED */ #define size_t_ERROR SIZE_T_ERROR diff --git a/reactos/include/psdk/sal.h b/reactos/include/psdk/sal.h index 461a6e7360d..e535ac9448f 100644 --- a/reactos/include/psdk/sal.h +++ b/reactos/include/psdk/sal.h @@ -53,9 +53,12 @@ #error broken #endif // ] -#pragma warning(disable:6320) /* disable warning about SEH filter */ -#pragma warning(disable:28247) /* duplicated model file annotations */ +#pragma warning(disable:6320) /* Disable warning about SEH filter */ +#pragma warning(disable:28247) /* Duplicated model file annotations */ #pragma warning(disable:28251) /* Inconsistent annotation */ +#ifndef _M_IX86 // [ +#pragma warning(disable:28110 28111 28161 28162) /* Floating point save */ +#endif // ] /******************************************************************************/ //#include "codeanalysis\sourceannotations.h" @@ -421,6 +424,9 @@ enum __SAL_YesNo {_SAL_notpresent, _SAL_no, _SAL_maybe, _SAL_yes, _SAL_default}; #define _On_failure_(annos) [SAL_context(p1="SAL_failed")] _Group_(_Post_ _Group_(annos)) #define _Always_(annos) _Group_(annos) _On_failure_(annos) +#define _Analysis_mode_impl_(mode) _SAL2_NAME(_Analysis_mode_impl) _Group_([SAL_annotes(Name="SAL_analysisMode", p1=_SA_SPECSTRIZE(mode))]) +#define _Analysis_mode_(mode) typedef _Analysis_mode_impl_(mode) int __prefast_analysis_mode_flag__COUNTER__; + #define _Analysis_noreturn_ _SAL2_NAME(_Analysis_noreturn_) [SAL_annotes(Name="SAL_terminates")] #define _Analysis_assume_(expr) __assume(expr) #define __analysis_assume(expr) __assume(expr) @@ -1099,6 +1105,7 @@ __PRIMOP(int, _In_function_class_(__In_impl_ char*);) #define __inner_exceptthat #define __inner_typefix(ctype) #define _Always_(annos) +#define _Analysis_mode_(mode) #define _Analysis_noreturn_ #define _Analysis_assume_(expr) ((void)0) #define __analysis_assume(expr) ((void)0) diff --git a/reactos/include/reactos/probe.h b/reactos/include/reactos/probe.h index fffcfb821b0..dfa8f8d8b79 100644 --- a/reactos/include/reactos/probe.h +++ b/reactos/include/reactos/probe.h @@ -12,7 +12,7 @@ static const LARGE_INTEGER __emptyLargeInteger = {{0, 0}}; static const ULARGE_INTEGER __emptyULargeInteger = {{0, 0}}; static const IO_STATUS_BLOCK __emptyIoStatusBlock = {{0}, 0}; -#if defined(_WIN32K_) +#if defined(_WIN32K_) && !defined(__cplusplus) static const LARGE_STRING __emptyLargeString = {0, 0, 0, NULL}; #endif @@ -152,7 +152,12 @@ ProbeAndCaptureUnicodeString(OUT PUNICODE_STRING Dest, { _SEH2_TRY { +#ifdef __cplusplus + ProbeForRead(UnsafeSrc, sizeof(*UnsafeSrc), 1); + RtlCopyMemory(Dest, UnsafeSrc, sizeof(*UnsafeSrc)); +#else *Dest = ProbeForReadUnicodeString(UnsafeSrc); +#endif if(Dest->Buffer != NULL) { if (Dest->Length != 0) @@ -162,7 +167,7 @@ ProbeAndCaptureUnicodeString(OUT PUNICODE_STRING Dest, sizeof(WCHAR)); /* Allocate space for the buffer */ - Buffer = ExAllocatePoolWithTag(PagedPool, + Buffer = (PWCHAR)ExAllocatePoolWithTag(PagedPool, Dest->Length + sizeof(WCHAR), 'RTSU'); if (Buffer == NULL)