summaryrefslogtreecommitdiff
path: root/src/pal/inc
diff options
context:
space:
mode:
Diffstat (limited to 'src/pal/inc')
-rw-r--r--src/pal/inc/mbusafecrt.h16
-rw-r--r--src/pal/inc/pal.h196
-rw-r--r--src/pal/inc/pal_char16.h3
-rw-r--r--src/pal/inc/pal_mstypes.h11
-rw-r--r--src/pal/inc/rt/palrt.h180
-rw-r--r--src/pal/inc/rt/safecrt.h13
-rw-r--r--src/pal/inc/strsafe.h1512
-rw-r--r--src/pal/inc/unixasmmacros.inc4
-rw-r--r--src/pal/inc/unixasmmacrosamd64.inc2
-rw-r--r--src/pal/inc/unixasmmacrosarm.inc3
-rw-r--r--src/pal/inc/unixasmmacrosarm64.inc2
-rw-r--r--src/pal/inc/unixasmmacrosx86.inc87
12 files changed, 222 insertions, 1807 deletions
diff --git a/src/pal/inc/mbusafecrt.h b/src/pal/inc/mbusafecrt.h
index c25676c499..8cf050f419 100644
--- a/src/pal/inc/mbusafecrt.h
+++ b/src/pal/inc/mbusafecrt.h
@@ -31,16 +31,6 @@ typedef int errno_t;
// define the return value for success
#define SAFECRT_SUCCESS 0
-/*
- * Sizes for buffers used by the _makepath() and _splitpath() functions.
- * note that the sizes include space for 0-terminator
- */
-//#define _MAX_PATH 260 /* max. length of full pathname */
-//#define _MAX_DRIVE 3 /* max. length of drive component */
-//#define _MAX_DIR 256 /* max. length of path component */
-//#define _MAX_FNAME 256 /* max. length of file name component */
-//#define _MAX_EXT 256 /* max. length of extension component */
-
#ifdef __cplusplus
extern "C" {
#endif
@@ -65,7 +55,7 @@ extern WCHAR* wcstok_s( WCHAR* inString, const WCHAR* inControl, WCHAR** ioConte
// strnlen is not required unless the source string is completely untrusted (e.g. anonymous input on a website)
#ifndef SUPPRESS_STRNLEN
- extern size_t strnlen( const char* inString, size_t inMaxSize );
+ extern size_t PAL_strnlen( const char* inString, size_t inMaxSize );
extern size_t wcsnlen( const WCHAR* inString, size_t inMaxSize );
#endif
@@ -96,10 +86,10 @@ extern int swprintf_s( WCHAR *string, size_t sizeInWords, const WCHAR *format, .
extern int _snprintf_s( char *string, size_t sizeInBytes, size_t count, const char *format, ... );
extern int _snwprintf_s( WCHAR *string, size_t sizeInWords, size_t count, const WCHAR *format, ... );
-extern int _vsprintf_s( char* string, size_t sizeInBytes, const char* format, va_list arglist );
+extern int vsprintf_s( char* string, size_t sizeInBytes, const char* format, va_list arglist );
extern int _vsnprintf_s( char* string, size_t sizeInBytes, size_t count, const char* format, va_list arglist );
-extern int _vswprintf_s( WCHAR* string, size_t sizeInWords, const WCHAR* format, va_list arglist );
+extern int vswprintf_s( WCHAR* string, size_t sizeInWords, const WCHAR* format, va_list arglist );
extern int _vsnwprintf_s( WCHAR* string, size_t sizeInWords, size_t count, const WCHAR* format, va_list arglist );
extern int sscanf_s( const char *string, const char *format, ... );
diff --git a/src/pal/inc/pal.h b/src/pal/inc/pal.h
index 260528285e..0d7c89e6fa 100644
--- a/src/pal/inc/pal.h
+++ b/src/pal/inc/pal.h
@@ -331,7 +331,7 @@ typedef char * va_list;
PALIMPORT
BOOL
PALAPI
-PAL_IsDebuggerPresent();
+PAL_IsDebuggerPresent(VOID);
#define MAXIMUM_SUSPEND_COUNT MAXCHAR
@@ -507,7 +507,7 @@ PAL_Initialize(
PALIMPORT
int
PALAPI
-PAL_InitializeDLL();
+PAL_InitializeDLL(VOID);
PALIMPORT
DWORD
@@ -581,7 +581,7 @@ PAL_UnregisterForRuntimeStartup(
PALIMPORT
BOOL
PALAPI
-PAL_NotifyRuntimeStarted();
+PAL_NotifyRuntimeStarted(VOID);
static const int MAX_DEBUGGER_TRANSPORT_PIPE_NAME_LENGTH = 64;
@@ -648,6 +648,13 @@ PAL_DeleteExecWatchpoint(
#endif
+PALIMPORT
+BOOL
+PALAPI
+PAL_ProbeMemory(
+ PVOID pBuffer,
+ DWORD cbBuffer,
+ BOOL fWriteAccess);
/******************* winuser.h Entrypoints *******************************/
@@ -671,28 +678,6 @@ CharNextExA(
#endif
-PALIMPORT
-int
-PALAPIV
-wsprintfA(
- OUT LPSTR,
- IN LPCSTR,
- ...);
-
-PALIMPORT
-int
-PALAPIV
-wsprintfW(
- OUT LPWSTR,
- IN LPCWSTR,
- ...);
-
-#ifdef UNICODE
-#define wsprintf wsprintfW
-#else
-#define wsprintf wsprintfA
-#endif
-
#define MB_OK 0x00000000L
#define MB_OKCANCEL 0x00000001L
#define MB_ABORTRETRYIGNORE 0x00000002L
@@ -1853,6 +1838,13 @@ QueueUserAPC(
#define MAXIMUM_SUPPORTED_EXTENSION 512
+#define CONTEXT_XSTATE (CONTEXT_i386 | 0x40L)
+
+#define CONTEXT_EXCEPTION_ACTIVE 0x8000000L
+#define CONTEXT_SERVICE_ACTIVE 0x10000000L
+#define CONTEXT_EXCEPTION_REQUEST 0x40000000L
+#define CONTEXT_EXCEPTION_REPORTING 0x80000000L
+
typedef struct _FLOATING_SAVE_AREA {
DWORD ControlWord;
DWORD StatusWord;
@@ -1911,6 +1903,16 @@ typedef struct _CONTEXT {
// support any other values in the ExtendedRegisters) but we might as well be as accurate as we can.
#define CONTEXT_EXREG_XMM_OFFSET 160
+typedef struct _KNONVOLATILE_CONTEXT_POINTERS {
+
+ // TODO WIP x86/Linux, need to fix this.
+ PDWORD Ebx;
+ PDWORD Esi;
+ PDWORD Edi;
+ PDWORD Ebp;
+
+} KNONVOLATILE_CONTEXT_POINTERS, *PKNONVOLATILE_CONTEXT_POINTERS;
+
#elif defined(_PPC_)
//
@@ -3256,22 +3258,22 @@ TlsFree(
PALIMPORT
void *
PALAPI
-PAL_GetStackBase();
+PAL_GetStackBase(VOID);
PALIMPORT
void *
PALAPI
-PAL_GetStackLimit();
+PAL_GetStackLimit(VOID);
PALIMPORT
DWORD
PALAPI
-PAL_GetLogicalCpuCountFromOS();
+PAL_GetLogicalCpuCountFromOS(VOID);
PALIMPORT
size_t
PALAPI
-PAL_GetLogicalProcessorCacheSizeFromOS();
+PAL_GetLogicalProcessorCacheSizeFromOS(VOID);
typedef BOOL (*ReadMemoryWordCallback)(SIZE_T address, SIZE_T *value);
@@ -3304,6 +3306,8 @@ PALIMPORT BOOL PALAPI PAL_VirtualUnwindOutOfProc(CONTEXT *context,
#define PAL_CS_NATIVE_DATA_SIZE 80
#elif defined(__linux__) && defined(_ARM64_)
#define PAL_CS_NATIVE_DATA_SIZE 116
+#elif defined(__linux__) && defined(__i386__)
+#define PAL_CS_NATIVE_DATA_SIZE 76
#elif defined(__linux__) && defined(__x86_64__)
#define PAL_CS_NATIVE_DATA_SIZE 96
#elif defined(__NetBSD__) && defined(__amd64__)
@@ -3656,16 +3660,6 @@ VirtualQuery(
IN SIZE_T dwLength);
PALIMPORT
-BOOL
-PALAPI
-ReadProcessMemory(
- IN HANDLE hProcess,
- IN LPCVOID lpBaseAddress,
- OUT LPVOID lpBuffer,
- IN SIZE_T nSize,
- OUT SIZE_T * lpNumberOfBytesRead);
-
-PALIMPORT
VOID
PALAPI
RtlMoveMemory(
@@ -4712,19 +4706,12 @@ enum {
//
typedef struct _RUNTIME_FUNCTION {
DWORD BeginAddress;
+#ifdef _AMD64_
DWORD EndAddress;
+#endif
DWORD UnwindData;
} RUNTIME_FUNCTION, *PRUNTIME_FUNCTION;
-PALIMPORT
-BOOL
-PALAPI
-WriteProcessMemory(IN HANDLE hProcess,
- IN LPVOID lpBaseAddress,
- IN LPCVOID lpBuffer,
- IN SIZE_T nSize,
- OUT SIZE_T * lpNumberOfBytesWritten);
-
#define STANDARD_RIGHTS_REQUIRED (0x000F0000L)
#define SYNCHRONIZE (0x00100000L)
#define READ_CONTROL (0x00020000L)
@@ -4801,28 +4788,6 @@ DebugBreak(
VOID);
PALIMPORT
-LPWSTR
-PALAPI
-lstrcatW(
- IN OUT LPWSTR lpString1,
- IN LPCWSTR lpString2);
-
-#ifdef UNICODE
-#define lstrcat lstrcatW
-#endif
-
-PALIMPORT
-LPWSTR
-PALAPI
-lstrcpyW(
- OUT LPWSTR lpString1,
- IN LPCWSTR lpString2);
-
-#ifdef UNICODE
-#define lstrcpy lstrcpyW
-#endif
-
-PALIMPORT
int
PALAPI
lstrlenA(
@@ -4841,19 +4806,6 @@ lstrlenW(
#endif
PALIMPORT
-LPWSTR
-PALAPI
-lstrcpynW(
- OUT LPWSTR lpString1,
- IN LPCWSTR lpString2,
- IN int iMaxLength);
-
-#ifdef UNICODE
-#define lstrcpyn lstrcpynW
-#endif
-
-
-PALIMPORT
DWORD
PALAPI
GetEnvironmentVariableW(
@@ -4937,7 +4889,7 @@ GetTickCount(
PALIMPORT
ULONGLONG
PALAPI
-GetTickCount64();
+GetTickCount64(VOID);
PALIMPORT
BOOL
@@ -5377,7 +5329,7 @@ YieldProcessor(
PALIMPORT
DWORD
PALAPI
-GetCurrentProcessorNumber();
+GetCurrentProcessorNumber(VOID);
/*++
Function:
@@ -5389,7 +5341,7 @@ Checks if GetCurrentProcessorNumber is available in the current environment
PALIMPORT
BOOL
PALAPI
-PAL_HasGetCurrentProcessorNumber();
+PAL_HasGetCurrentProcessorNumber(VOID);
#define FORMAT_MESSAGE_ALLOCATE_BUFFER 0x00000100
#define FORMAT_MESSAGE_IGNORE_INSERTS 0x00000200
@@ -5475,7 +5427,7 @@ ResetWriteWatch(
PALIMPORT
VOID
PALAPI
-FlushProcessWriteBuffers();
+FlushProcessWriteBuffers(VOID);
typedef void (*PAL_ActivationFunction)(CONTEXT *context);
typedef BOOL (*PAL_SafeActivationCheckFunction)(SIZE_T ip, BOOL checkingCurrentThread);
@@ -5715,9 +5667,7 @@ CoCreateGuid(OUT GUID * pguid);
#define printf PAL_printf
#define vprintf PAL_vprintf
#define wprintf PAL_wprintf
-#define sprintf PAL_sprintf
#define swprintf PAL_swprintf
-#define sscanf PAL_sscanf
#define wcsspn PAL_wcsspn
#define wcstod PAL_wcstod
#define wcstol PAL_wcstol
@@ -5791,6 +5741,13 @@ CoCreateGuid(OUT GUID * pguid);
#define log PAL_log
#define log10 PAL_log10
#define pow PAL_pow
+#define acosf PAL_acosf
+#define asinf PAL_asinf
+#define atan2f PAL_atan2f
+#define expf PAL_expf
+#define logf PAL_logf
+#define log10f PAL_log10f
+#define powf PAL_powf
#define malloc PAL_malloc
#define free PAL_free
#define mkstemp PAL_mkstemp
@@ -5802,6 +5759,7 @@ CoCreateGuid(OUT GUID * pguid);
#define _wcstoui64 PAL__wcstoui64
#define _flushall PAL__flushall
#define _vsnprintf PAL__vsnprintf
+#define strnlen PAL_strnlen
#ifdef _AMD64_
#define _mm_getcsr PAL__mm_getcsr
@@ -5878,9 +5836,7 @@ PALIMPORT char * __cdecl strstr(const char *, const char *);
PALIMPORT char * __cdecl strtok(char *, const char *);
PALIMPORT size_t __cdecl strspn(const char *, const char *);
PALIMPORT size_t __cdecl strcspn(const char *, const char *);
-PALIMPORT int __cdecl sprintf(char *, const char *, ...);
PALIMPORT int __cdecl vsprintf(char *, const char *, va_list);
-PALIMPORT int __cdecl sscanf(const char *, const char *, ...);
PALIMPORT int __cdecl atoi(const char *);
PALIMPORT LONG __cdecl atol(const char *);
PALIMPORT ULONG __cdecl strtoul(const char *, char **, int);
@@ -5899,23 +5855,35 @@ PALIMPORT int __cdecl toupper(int);
#endif // PAL_STDCPP_COMPAT
+/* _TRUNCATE */
+#if !defined(_TRUNCATE)
+#define _TRUNCATE ((size_t)-1)
+#endif
+
PALIMPORT errno_t __cdecl memcpy_s(void *, size_t, const void *, size_t);
PALIMPORT errno_t __cdecl memmove_s(void *, size_t, const void *, size_t);
PALIMPORT char * __cdecl _strlwr(char *);
PALIMPORT int __cdecl _stricmp(const char *, const char *);
-PALIMPORT int __cdecl _snprintf(char *, size_t, const char *, ...);
+PALIMPORT int __cdecl vsprintf_s(char *, size_t, const char *, va_list);
PALIMPORT char * __cdecl _gcvt_s(char *, int, double, int);
PALIMPORT char * __cdecl _ecvt(double, int, int *, int *);
PALIMPORT int __cdecl __iscsym(int);
-PALIMPORT size_t __cdecl _mbslen(const unsigned char *);
PALIMPORT unsigned char * __cdecl _mbsinc(const unsigned char *);
PALIMPORT unsigned char * __cdecl _mbsninc(const unsigned char *, size_t);
PALIMPORT unsigned char * __cdecl _mbsdec(const unsigned char *, const unsigned char *);
PALIMPORT int __cdecl _wcsicmp(const WCHAR *, const WCHAR*);
PALIMPORT int __cdecl _wcsnicmp(const WCHAR *, const WCHAR *, size_t);
PALIMPORT int __cdecl _vsnprintf(char *, size_t, const char *, va_list);
-PALIMPORT int __cdecl _vsnwprintf(WCHAR *, size_t, const WCHAR *, va_list);
-PALIMPORT WCHAR * __cdecl _itow(int, WCHAR *, int);
+PALIMPORT int __cdecl _vsnprintf_s(char *, size_t, size_t, const char *, va_list);
+PALIMPORT int __cdecl _vsnwprintf_s(WCHAR *, size_t, size_t, const WCHAR *, va_list);
+PALIMPORT int __cdecl _snwprintf_s(WCHAR *, size_t, size_t, const WCHAR *, ...);
+PALIMPORT int __cdecl _snprintf_s(char *, size_t, size_t, const char *, ...);
+PALIMPORT int __cdecl sprintf_s(char *, size_t, const char *, ... );
+PALIMPORT int __cdecl swprintf_s(WCHAR *, size_t, const WCHAR *, ... );
+PALIMPORT int __cdecl _snwprintf_s(WCHAR *, size_t, size_t, const WCHAR *, ...);
+PALIMPORT int __cdecl vswprintf_s( WCHAR *, size_t, const WCHAR *, va_list);
+PALIMPORT int __cdecl sscanf_s(const char *, const char *, ...);
+PALIMPORT errno_t __cdecl _itow_s(int, WCHAR *, size_t, int);
PALIMPORT size_t __cdecl PAL_wcslen(const WCHAR *);
PALIMPORT int __cdecl PAL_wcscmp(const WCHAR*, const WCHAR*);
@@ -5933,7 +5901,6 @@ PALIMPORT size_t __cdecl PAL_wcscspn(const WCHAR *, const WCHAR *);
PALIMPORT int __cdecl PAL_swprintf(WCHAR *, const WCHAR *, ...);
PALIMPORT int __cdecl PAL_vswprintf(WCHAR *, const WCHAR *, va_list);
PALIMPORT int __cdecl PAL__vsnprintf(LPSTR Buffer, size_t Count, LPCSTR Format, va_list ap);
-PALIMPORT int __cdecl _snwprintf(WCHAR *, size_t, const WCHAR *, ...);
PALIMPORT int __cdecl PAL_swscanf(const WCHAR *, const WCHAR *, ...);
PALIMPORT LONG __cdecl PAL_wcstol(const WCHAR *, WCHAR **, int);
PALIMPORT ULONG __cdecl PAL_wcstoul(const WCHAR *, WCHAR **, int);
@@ -5950,8 +5917,7 @@ PALIMPORT WCHAR __cdecl PAL_towupper(WCHAR);
PALIMPORT WCHAR * __cdecl _wcslwr(WCHAR *);
PALIMPORT ULONGLONG _wcstoui64(const WCHAR *, WCHAR **, int);
-PALIMPORT WCHAR * __cdecl _i64tow(__int64, WCHAR *, int);
-PALIMPORT WCHAR * __cdecl _ui64tow(unsigned __int64, WCHAR *, int);
+PALIMPORT errno_t __cdecl _i64tow_s(long long, WCHAR *, size_t, int);
PALIMPORT int __cdecl _wtoi(const WCHAR *);
#ifdef __cplusplus
@@ -6039,9 +6005,29 @@ PALIMPORT double __cdecl sqrt(double);
PALIMPORT double __cdecl tan(double);
PALIMPORT double __cdecl tanh(double);
+PALIMPORT int __cdecl _finitef(float);
+PALIMPORT int __cdecl _isnanf(float);
+PALIMPORT float __cdecl _copysignf(float, float);
+PALIMPORT float __cdecl acosf(float);
+PALIMPORT float __cdecl asinf(float);
+PALIMPORT float __cdecl atanf(float);
+PALIMPORT float __cdecl atan2f(float, float);
+PALIMPORT float __cdecl ceilf(float);
+PALIMPORT float __cdecl cosf(float);
+PALIMPORT float __cdecl coshf(float);
+PALIMPORT float __cdecl expf(float);
PALIMPORT float __cdecl fabsf(float);
+PALIMPORT float __cdecl floorf(float);
PALIMPORT float __cdecl fmodf(float, float);
+PALIMPORT float __cdecl logf(float);
+PALIMPORT float __cdecl log10f(float);
PALIMPORT float __cdecl modff(float, float*);
+PALIMPORT float __cdecl powf(float, float);
+PALIMPORT float __cdecl sinf(float);
+PALIMPORT float __cdecl sinhf(float);
+PALIMPORT float __cdecl sqrtf(float);
+PALIMPORT float __cdecl tanf(float);
+PALIMPORT float __cdecl tanhf(float);
#ifndef PAL_STDCPP_COMPAT
@@ -6086,14 +6072,8 @@ PALIMPORT void __cdecl qsort(void *, size_t, size_t, int (__cdecl *)(const void
PALIMPORT void * __cdecl bsearch(const void *, const void *, size_t, size_t,
int (__cdecl *)(const void *, const void *));
-PALIMPORT void __cdecl _splitpath(const char *, char *, char *, char *, char *);
-PALIMPORT void __cdecl _wsplitpath(const WCHAR *, WCHAR *, WCHAR *, WCHAR *, WCHAR *);
-PALIMPORT void __cdecl _makepath(char *, const char *, const char *, const char *, const char *);
-PALIMPORT void __cdecl _wmakepath(WCHAR *, const WCHAR *, const WCHAR *, const WCHAR *, const WCHAR *);
PALIMPORT char * __cdecl _fullpath(char *, const char *, size_t);
-PALIMPORT void __cdecl _swab(char *, char *, int);
-
#ifndef PAL_STDCPP_COMPAT
PALIMPORT time_t __cdecl time(time_t *);
@@ -6307,14 +6287,14 @@ PAL_Enter(PAL_Boundary boundary);
PALIMPORT
BOOL
PALAPI
-PAL_HasEntered();
+PAL_HasEntered(VOID);
// Equivalent to PAL_Enter(PAL_BoundaryTop) and is for stub
// code generation use.
PALIMPORT
DWORD
PALAPI
-PAL_EnterTop();
+PAL_EnterTop(VOID);
// This function needs to be called on a thread when it enters
// a region of code that depends on this instance of the PAL
@@ -6349,14 +6329,14 @@ PAL_Leave(PAL_Boundary boundary);
PALIMPORT
VOID
PALAPI
-PAL_LeaveBottom();
+PAL_LeaveBottom(VOID);
// This function is equivalent to PAL_Leave(PAL_BoundaryTop)
// and is available to limit the creation of stub code.
PALIMPORT
VOID
PALAPI
-PAL_LeaveTop();
+PAL_LeaveTop(VOID);
#ifdef __cplusplus
//
diff --git a/src/pal/inc/pal_char16.h b/src/pal/inc/pal_char16.h
index b118e98e31..4600cc7ff6 100644
--- a/src/pal/inc/pal_char16.h
+++ b/src/pal/inc/pal_char16.h
@@ -37,7 +37,8 @@ This file is used to define the wchar_t type as a 16-bit type on Unix.
// Set up the wchar_t type (which got preprocessed to __wchar_16_cpp__).
// In C++11, the standard gives us char16_t, which is what we want (and matches types with u"")
// In C, this doesn't exist, so use unsigned short.
-
+// **** WARNING: Linking C and C++ objects will break with -fstrict-aliasing with GCC/Clang
+// due to conditional typedef
#if !defined(_WCHAR_T_DEFINED) || !defined(_MSC_VER)
#if defined (PLATFORM_UNIX)
#if defined(__cplusplus)
diff --git a/src/pal/inc/pal_mstypes.h b/src/pal/inc/pal_mstypes.h
index df17767747..b9c3ac2e4a 100644
--- a/src/pal/inc/pal_mstypes.h
+++ b/src/pal/inc/pal_mstypes.h
@@ -56,12 +56,6 @@ extern "C" {
#define CDECL __cdecl
#endif
-#ifndef PAL_STDCPP_COMPAT
-#undef __fastcall
-#define __fastcall __stdcall
-#undef _fastcall
-#define _fastcall __fastcall
-#endif // PAL_STDCPP_COMPAT
#else // !defined(__i386__)
@@ -215,6 +209,9 @@ extern "C" {
// Defined in gnu's types.h. For non PAL_IMPLEMENTATION system
// includes are not included, so we need to define them.
#ifndef PAL_IMPLEMENTATION
+
+// OS X already defines these types in 64 bit
+#if !defined(_TARGET_MAC64)
typedef __int64 int64_t;
typedef unsigned __int64 uint64_t;
typedef __int32 int32_t;
@@ -223,6 +220,8 @@ typedef __int16 int16_t;
typedef unsigned __int16 uint16_t;
typedef __int8 int8_t;
typedef unsigned __int8 uint8_t;
+#endif
+
#endif // PAL_IMPLEMENTATION
#ifndef _MSC_VER
diff --git a/src/pal/inc/rt/palrt.h b/src/pal/inc/rt/palrt.h
index 336a13f529..c181f38c2b 100644
--- a/src/pal/inc/rt/palrt.h
+++ b/src/pal/inc/rt/palrt.h
@@ -834,7 +834,6 @@ enum tagMIMECONTF {
// note: diff in NULL handing and calling convetion
#define StrCpyW PAL_wcscpy
-#define StrCpyNW lstrcpynW // note: can't be wcsncpy!
#define StrCatW PAL_wcscat
#define StrChrW (WCHAR*)PAL_wcschr
#define StrCmpW PAL_wcscmp
@@ -850,12 +849,9 @@ STDAPI_(LPWSTR) StrCatBuffW(LPWSTR pszDest, LPCWSTR pszSrc, int cchDestBuffSize)
#define lstrcmpW PAL_wcscmp
#define lstrcmpiW _wcsicmp
-#define wnsprintfW _snwprintf // note: not 100% compatible (wsprintf should be subset of sprintf...)
-#define wvnsprintfW _vsnwprintf // note: not 100% compatible (wsprintf should be subset of sprintf...)
#ifdef UNICODE
#define StrCpy StrCpyW
-#define StrCpyN StrCpyNW
#define StrCat StrCatW
#define StrNCat StrNCatW
#define StrChr StrChrW
@@ -871,7 +867,6 @@ STDAPI_(LPWSTR) StrCatBuffW(LPWSTR pszDest, LPCWSTR pszSrc, int cchDestBuffSize)
#define lstrcmp lstrcmpW
#define lstrcmpi lstrcmpiW
-#define wnsprintf wnsprintfW
#endif
@@ -898,12 +893,8 @@ Remember to fix the errcode defintion in safecrt.h.
*/
#define _wcslwr_s _wcslwr_unsafe
-#define _snwprintf_s _snwprintf_unsafe
-#define _vsnwprintf_s _vsnwprintf_unsafe
#define _snprintf_s _snprintf_unsafe
-#define _vsnprintf_s _vsnprintf_unsafe
#define swscanf_s swscanf
-#define sscanf_s sscanf
#define _wfopen_s _wfopen_unsafe
#define fopen_s _fopen_unsafe
@@ -911,12 +902,8 @@ Remember to fix the errcode defintion in safecrt.h.
#define _strlwr_s _strlwr_unsafe
#define _vscprintf _vscprintf_unsafe
-#define _vscwprintf _vscwprintf_unsafe
-#define sprintf_s _snprintf
-#define swprintf_s _snwprintf
#define vsprintf_s _vsnprintf
-#define vswprintf_s _vsnwprintf
extern "C++" {
@@ -982,51 +969,6 @@ inline int __cdecl _vscprintf_unsafe(const char *_Format, va_list _ArgList)
}
}
-inline int __cdecl _vscwprintf_unsafe(const WCHAR *_Format, va_list _ArgList)
-{
- int guess = 256;
-
- for (;;)
- {
- WCHAR *buf = (WCHAR *)malloc(guess * sizeof(WCHAR));
- if (buf == nullptr)
- return 0;
-
- va_list apcopy;
- va_copy(apcopy, _ArgList);
- int ret = _vsnwprintf(buf, guess, _Format, apcopy);
- free(buf);
- va_end(apcopy);
-
- if ((ret != -1) && (ret < guess))
- return ret;
-
- guess *= 2;
- }
-}
-
-inline int __cdecl _vsnwprintf_unsafe(WCHAR *_Dst, size_t _SizeInWords, size_t _Count, const WCHAR *_Format, va_list _ArgList)
-{
- if (_Count == _TRUNCATE) _Count = _SizeInWords - 1;
- int ret = _vsnwprintf(_Dst, _Count, _Format, _ArgList);
- _Dst[_SizeInWords - 1] = L'\0';
- if (ret < 0 && errno == 0)
- {
- errno = ERANGE;
- }
- return ret;
-}
-
-inline int __cdecl _snwprintf_unsafe(WCHAR *_Dst, size_t _SizeInWords, size_t _Count, const WCHAR *_Format, ...)
-{
- int ret;
- va_list _ArgList;
- va_start(_ArgList, _Format);
- ret = _vsnwprintf_unsafe(_Dst, _SizeInWords, _Count, _Format, _ArgList);
- va_end(_ArgList);
- return ret;
-}
-
inline int __cdecl _vsnprintf_unsafe(char *_Dst, size_t _SizeInWords, size_t _Count, const char *_Format, va_list _ArgList)
{
if (_Count == _TRUNCATE) _Count = _SizeInWords - 1;
@@ -1071,100 +1013,6 @@ inline errno_t __cdecl _fopen_unsafe(PAL_FILE * *ff, const char *fileName, const
}
}
-/* _itow_s */
-_SAFECRT__EXTERN_C
-errno_t __cdecl _itow_s(int _Value, WCHAR *_Dst, size_t _SizeInWords, int _Radix);
-
-#if defined(__cplusplus) && _SAFECRT_USE_CPP_OVERLOADS
-template <size_t _SizeInWords>
-inline
-errno_t __cdecl _itow_s(int _Value, WCHAR (&_Dst)[_SizeInWords], int _Radix)
-{
- return _itow_s(_Value, _Dst, _SizeInWords, _Radix);
-}
-#endif
-
-#if _SAFECRT_USE_INLINES
-
-__inline
-errno_t __cdecl _itow_s(int _Value, WCHAR *_Dst, size_t _SizeInWords, int _Radix)
-{
- /* validation section */
- _SAFECRT__VALIDATE_STRING(_Dst, _SizeInWords);
-
- /* TODO: do not write past buffer size */
- _itow(_Value, _Dst, _Radix);
- return 0;
-}
-
-#endif
-
-/* _i64tow_s */
-_SAFECRT__EXTERN_C
-errno_t __cdecl _i64tow_s(__int64 _Value, WCHAR *_Dst, size_t _SizeInWords, int _Radix);
-
-#if defined(__cplusplus) && _SAFECRT_USE_CPP_OVERLOADS
-template <size_t _SizeInWords>
-inline
-errno_t __cdecl _i64tow_s(__int64 _Value, WCHAR (&_Dst)[_SizeInWords], int _Radix)
-{
- return _i64tow_s(_Value, _Dst, _SizeInWords, _Radix);
-}
-#endif
-
-#if _SAFECRT_USE_INLINES
-
-__inline
-errno_t __cdecl _i64tow_s(__int64 _Value, WCHAR *_Dst, size_t _SizeInWords, int _Radix)
-{
- /* validation section */
- _SAFECRT__VALIDATE_STRING(_Dst, _SizeInWords);
-
- /* TODO: do not write past buffer size */
- _i64tow(_Value, _Dst, _Radix);
- return 0;
-}
-
-#endif
-
-/* getenv_s */
-/*
- * _ReturnValue indicates if the variable has been found and size needed
- */
-_SAFECRT__EXTERN_C
-errno_t __cdecl getenv_s(size_t *_ReturnValue, char *_Dst, size_t _SizeInWords, const char *_Name);
-
-#if defined(__cplusplus) && _SAFECRT_USE_CPP_OVERLOADS
-template <size_t _SizeInWords>
-inline
-errno_t __cdecl getenv_s(size_t *_ReturnValue, char *_Dst, size_t _SizeInWords, const char *_Name)
-{
- return getenv_s(_ReturnValue, _Dst, _SizeInWords, _Name);
-}
-#endif
-
-#if _SAFECRT_USE_INLINES
-
-__inline
-errno_t __cdecl getenv_s(size_t *_ReturnValue, char *_Dst, size_t _SizeInWords, const char *_Name)
-{
- char *szFound;
-
- /* validation section */
- _SAFECRT__VALIDATE_STRING(_Dst, _SizeInWords);
-
- szFound = getenv(_Name);
- if (szFound == nullptr)
- {
- *_ReturnValue = 0;
- return 0;
- }
- *_ReturnValue = strlen(szFound) + 1;
- return strcpy_s(_Dst, _SizeInWords, szFound);
-}
-
-#endif
-
}
#endif /* __cplusplus */
@@ -1247,6 +1095,7 @@ namespace std
typedef decltype(nullptr) nullptr_t;
}
+extern "C++"
template< class T >
typename std::remove_reference<T>::type&& move( T&& t );
#endif // __cplusplus
@@ -1327,7 +1176,7 @@ typedef VOID (__stdcall *WAITORTIMERCALLBACK)(PVOID, BOOLEAN);
// The message in these two macros should not contain any keywords like TODO
// or NYI. It should be just the brief description of the problem.
-#if defined(_TARGET_X86_)
+#ifdef PORTABILITY_CHECK
// Finished ports - compile-time errors
#define PORTABILITY_WARNING(message) NEED_TO_PORT_THIS_ONE(NEED_TO_PORT_THIS_ONE)
#define PORTABILITY_ASSERT(message) NEED_TO_PORT_THIS_ONE(NEED_TO_PORT_THIS_ONE)
@@ -1666,7 +1515,7 @@ typedef struct _DISPATCHER_CONTEXT {
ULONG64 Reserved;
} DISPATCHER_CONTEXT, *PDISPATCHER_CONTEXT;
-#else
+#elif defined(_AMD64_)
typedef struct _DISPATCHER_CONTEXT {
ULONG64 ControlPc;
@@ -1680,6 +1529,29 @@ typedef struct _DISPATCHER_CONTEXT {
PUNWIND_HISTORY_TABLE HistoryTable;
} DISPATCHER_CONTEXT, *PDISPATCHER_CONTEXT;
+#elif defined(_X86_)
+
+typedef struct _EXCEPTION_REGISTRATION_RECORD {
+ struct _EXCEPTION_REGISTRATION_RECORD *Next;
+ PEXCEPTION_ROUTINE Handler;
+} EXCEPTION_REGISTRATION_RECORD;
+
+typedef struct _DISPATCHER_CONTEXT {
+ DWORD ControlPc;
+ DWORD ImageBase;
+ PRUNTIME_FUNCTION FunctionEntry;
+ DWORD EstablisherFrame;
+ DWORD TargetIp;
+ PCONTEXT ContextRecord;
+ PEXCEPTION_ROUTINE LanguageHandler;
+ PVOID HandlerData;
+ PUNWIND_HISTORY_TABLE HistoryTable;
+} DISPATCHER_CONTEXT, *PDISPATCHER_CONTEXT;
+
+#else
+
+#error Unknown architecture for defining DISPATCHER_CONTEXT.
+
#endif
// #endif // !defined(_TARGET_MAC64)
diff --git a/src/pal/inc/rt/safecrt.h b/src/pal/inc/rt/safecrt.h
index 6b95e28dfb..3cc10cef33 100644
--- a/src/pal/inc/rt/safecrt.h
+++ b/src/pal/inc/rt/safecrt.h
@@ -409,7 +409,6 @@ void __cdecl _invalid_parameter(const WCHAR *_Message, const WCHAR *_FunctionNam
#define _tmakepath_s _makepath_s
#define _tsplitpath_s _splitpath_s
#define _stprintf_s sprintf_s
-#define _vstprintf_s vsprintf_s
#define _sntprintf_s _snprintf_s
#define _vsntprintf_s _vsnprintf_s
#define _tscanf_s scanf_s
@@ -428,8 +427,6 @@ void __cdecl _invalid_parameter(const WCHAR *_Message, const WCHAR *_FunctionNam
#define _tmakepath_s _wmakepath_s
#define _tsplitpath_s _wsplitpath_s
#define _stprintf_s swprintf_s
-#define _vstprintf_s vswprintf_s
-#define _sntprintf_s _snwprintf_s
#define _vsntprintf_s _vsnwprintf_s
#define _tscanf_s wscanf_s
#define _tsscanf_s swscanf_s
@@ -447,9 +444,7 @@ void __cdecl _invalid_parameter(const WCHAR *_Message, const WCHAR *_FunctionNam
#define _tmakepath_s _makepath_s
#define _tsplitpath_s _splitpath_s
#define _stprintf_s sprintf_s
-#define _vstprintf_s vsprintf_s
#define _sntprintf_s _snprintf_s
-#define _vsntprintf_s _vsnprintf_s
#define _tscanf_s scanf_s
#define _tsscanf_s sscanf_s
#define _tsnscanf_s _snscanf_s
@@ -3222,7 +3217,7 @@ int __cdecl vswprintf_s(WCHAR *_Dst, size_t _SizeInWords, const WCHAR *_Format,
#if defined(__cplusplus) && _SAFECRT_USE_CPP_OVERLOADS
template <size_t _SizeInWords>
inline
-int __cdecl swprintf_s(char (&_Dst)[_SizeInWords], const char *_Format, ...)
+int __cdecl swprintf_s(WCHAR (&_Dst)[_SizeInWords], const WCHAR *_Format, ...)
{
int ret;
va_list _ArgList;
@@ -3234,7 +3229,7 @@ int __cdecl swprintf_s(char (&_Dst)[_SizeInWords], const char *_Format, ...)
template <size_t _SizeInWords>
inline
-int __cdecl vswprintf_s(char (&_Dst)[_SizeInWords], const char *_Format, va_list _ArgList)
+int __cdecl vswprintf_s(WCHAR (&_Dst)[_SizeInWords], const WCHAR *_Format, va_list _ArgList)
{
return vswprintf_s(_Dst, _SizeInWords, _Format, _ArgList);
}
@@ -3288,14 +3283,12 @@ int __cdecl _vsnprintf_s(char (&_Dst)[_SizeInBytes], size_t _Count, const char *
/* _snwprintf_s, _vsnwprintf_s */
_SAFECRT__EXTERN_C
-int __cdecl _snwprintf_s(WCHAR *_Dst, size_t _SizeInWords, size_t _Count, const WCHAR *_Format, ...);
-_SAFECRT__EXTERN_C
int __cdecl _vsnwprintf_s(WCHAR *_Dst, size_t _SizeInWords, size_t _Count, const WCHAR *_Format, va_list _ArgList);
#if defined(__cplusplus) && _SAFECRT_USE_CPP_OVERLOADS
template <size_t _SizeInWords>
inline
-int __cdecl _snwprintf_s(char (&_Dst)[_SizeInWords], size_t _Count, const char *_Format, ...)
+int __cdecl _snwprintf_s(WCHAR (&_Dst)[_SizeInWords], size_t _Count, const WCHAR *_Format, ...)
{
int ret;
va_list _ArgList;
diff --git a/src/pal/inc/strsafe.h b/src/pal/inc/strsafe.h
index 5a9f0edd43..58749f27ee 100644
--- a/src/pal/inc/strsafe.h
+++ b/src/pal/inc/strsafe.h
@@ -32,7 +32,7 @@
#define _vsnprintf vsnprintf
#endif // defined(PLATFORM_UNIX) && !defined (FEATURE_PAL)
-#include <stdio.h> // for _vsnprintf, _vsnwprintf, getc, getwc
+#include <stdio.h> // for _vsnprintf, getc, getwc
#include <string.h> // for memset
#include <stdarg.h> // for va_start, etc.
@@ -146,10 +146,6 @@ STRSAFEAPI StringCatNWorkerA(char* pszDest, size_t cchDest, const char* pszSrc,
STRSAFEAPI StringCatNWorkerW(WCHAR* pszDest, size_t cchDest, const WCHAR* pszSrc, size_t cchMaxAppend);
STRSAFEAPI StringCatNExWorkerA(char* pszDest, size_t cchDest, size_t cbDest, const char* pszSrc, size_t cchMaxAppend, char** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags);
STRSAFEAPI StringCatNExWorkerW(WCHAR* pszDest, size_t cchDest, size_t cbDest, const WCHAR* pszSrc, size_t cchMaxAppend, WCHAR** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags);
-STRSAFEAPI StringVPrintfWorkerA(char* pszDest, size_t cchDest, const char* pszFormat, va_list argList);
-STRSAFEAPI StringVPrintfWorkerW(WCHAR* pszDest, size_t cchDest, const WCHAR* pszFormat, va_list argList);
-STRSAFEAPI StringVPrintfExWorkerA(char* pszDest, size_t cchDest, size_t cbDest, char** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags, const char* pszFormat, va_list argList);
-STRSAFEAPI StringVPrintfExWorkerW(WCHAR* pszDest, size_t cchDest, size_t cbDest, WCHAR** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags, const WCHAR* pszFormat, va_list argList);
STRSAFEAPI StringLengthWorkerA(const char* psz, size_t cchMax, size_t* pcch);
STRSAFEAPI StringLengthWorkerW(const WCHAR* psz, size_t cchMax, size_t* pcch);
#endif // STRSAFE_INLINE
@@ -2356,1124 +2352,6 @@ STRSAFEAPI StringCbCatNExW(WCHAR* pszDest, size_t cbDest, const WCHAR* pszSrc, s
#ifndef STRSAFE_NO_CCH_FUNCTIONS
/*++
-STDAPI StringCchVPrintf(LPTSTR pszDest,
- size_t cchDest,
- LPCTSTR pszFormat,
- va_list argList);
-
-Routine Description:
-
- This routine is a safer version of the C built-in function 'vsprintf'.
- The size of the destination buffer (in characters) is a parameter and
- this function will not write past the end of this buffer and it will
- ALWAYS null terminate the destination buffer (unless it is zero length).
-
- This function returns a hresult, and not a pointer. It returns a S_OK
- if the string was printed without truncation and null terminated, otherwise
- it will return a failure code. In failure cases it will return a truncated
- version of the ideal result.
-
-Arguments:
-
- pszDest - destination string
-
- cchDest - size of destination buffer in characters
- length must be sufficient to hold the resulting formatted
- string, including the null terminator.
-
- pszFormat - format string which must be null terminated
-
- argList - va_list from the variable arguments according to the
- stdarg.h convention
-
-Notes:
- Behavior is undefined if destination, format strings or any arguments
- strings overlap.
-
- pszDest and pszFormat should not be NULL. See StringCchVPrintfEx if you
- require the handling of NULL values.
-
-Return Value:
-
- S_OK - if there was sufficient space in the dest buffer for
- the resultant string and it was null terminated.
-
- failure - you can use the macro HRESULT_CODE() to get a win32 error
- code for all falure cases
-
- STRSAFE_E_INSUFFICIENT_BUFFER /
- HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER
- - this return value is an indication that the print operation
- failed due to insufficient space. When this error occurs,
- the destination buffer is modified to contain a truncated
- version of the ideal result and is null terminated. This
- is useful for situations where truncation is ok.
-
- It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the
- return value of this function
-
---*/
-
-STRSAFEAPI StringCchVPrintfA(char* pszDest, size_t cchDest, const char* pszFormat, va_list argList);
-STRSAFEAPI StringCchVPrintfW(WCHAR* pszDest, size_t cchDest, const WCHAR* pszFormat, va_list argList);
-#ifdef UNICODE
-#define StringCchVPrintf StringCchVPrintfW
-#else
-#define StringCchVPrintf StringCchVPrintfA
-#endif // !UNICODE
-
-#ifdef STRSAFE_INLINE
-STRSAFEAPI StringCchVPrintfA(char* pszDest, size_t cchDest, const char* pszFormat, va_list argList)
-{
- HRESULT hr;
-
- if (cchDest > STRSAFE_MAX_CCH)
- {
- hr = STRSAFE_E_INVALID_PARAMETER;
- }
- else
- {
- hr = StringVPrintfWorkerA(pszDest, cchDest, pszFormat, argList);
- }
-
- return hr;
-}
-
-#if defined(FEATURE_PAL) || !defined(PLATFORM_UNIX)
-STRSAFEAPI StringCchVPrintfW(WCHAR* pszDest, size_t cchDest, const WCHAR* pszFormat, va_list argList)
-{
- HRESULT hr;
-
- if (cchDest > STRSAFE_MAX_CCH)
- {
- hr = STRSAFE_E_INVALID_PARAMETER;
- }
- else
- {
- hr = StringVPrintfWorkerW(pszDest, cchDest, pszFormat, argList);
- }
-
- return hr;
-}
-#endif // FEATURE_PAL || !PLATFORM_UNIX
-#endif // STRSAFE_INLINE
-#endif // !STRSAFE_NO_CCH_FUNCTIONS
-
-
-#ifndef STRSAFE_NO_CB_FUNCTIONS
-/*++
-
-STDAPI StringCbVPrintf(LPTSTR pszDest,
- size_t cbDest,
- LPCTSTR pszFormat,
- va_list argList);
-
-Routine Description:
-
- This routine is a safer version of the C built-in function 'vsprintf'.
- The size of the destination buffer (in bytes) is a parameter and
- this function will not write past the end of this buffer and it will
- ALWAYS null terminate the destination buffer (unless it is zero length).
-
- This function returns a hresult, and not a pointer. It returns a S_OK
- if the string was printed without truncation and null terminated, otherwise
- it will return a failure code. In failure cases it will return a truncated
- version of the ideal result.
-
-Arguments:
-
- pszDest - destination string
-
- cbDest - size of destination buffer in bytes
- length must be sufficient to hold the resulting formatted
- string, including the null terminator.
-
- pszFormat - format string which must be null terminated
-
- argList - va_list from the variable arguments according to the
- stdarg.h convention
-
-Notes:
- Behavior is undefined if destination, format strings or any arguments
- strings overlap.
-
- pszDest and pszFormat should not be NULL. See StringCbVPrintfEx if you
- require the handling of NULL values.
-
-
-Return Value:
-
- S_OK - if there was sufficient space in the dest buffer for
- the resultant string and it was null terminated.
-
- failure - you can use the macro HRESULT_CODE() to get a win32 error
- code for all falure cases
-
- STRSAFE_E_INSUFFICIENT_BUFFER /
- HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER
- - this return value is an indication that the print operation
- failed due to insufficient space. When this error occurs,
- the destination buffer is modified to contain a truncated
- version of the ideal result and is null terminated. This
- is useful for situations where truncation is ok.
-
- It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the
- return value of this function
-
---*/
-
-STRSAFEAPI StringCbVPrintfA(char* pszDest, size_t cbDest, const char* pszFormat, va_list argList);
-STRSAFEAPI StringCbVPrintfW(WCHAR* pszDest, size_t cbDest, const WCHAR* pszFormat, va_list argList);
-#ifdef UNICODE
-#define StringCbVPrintf StringCbVPrintfW
-#else
-#define StringCbVPrintf StringCbVPrintfA
-#endif // !UNICODE
-
-#ifdef STRSAFE_INLINE
-STRSAFEAPI StringCbVPrintfA(char* pszDest, size_t cbDest, const char* pszFormat, va_list argList)
-{
- HRESULT hr;
- size_t cchDest;
-
- cchDest = cbDest / sizeof(char);
-
- if (cchDest > STRSAFE_MAX_CCH)
- {
- hr = STRSAFE_E_INVALID_PARAMETER;
- }
- else
- {
- hr = StringVPrintfWorkerA(pszDest, cchDest, pszFormat, argList);
- }
-
- return hr;
-}
-
-#if defined(FEATURE_PAL) || !defined(PLATFORM_UNIX)
-STRSAFEAPI StringCbVPrintfW(WCHAR* pszDest, size_t cbDest, const WCHAR* pszFormat, va_list argList)
-{
- HRESULT hr;
- size_t cchDest;
-
- cchDest = cbDest / sizeof(WCHAR);
-
- if (cchDest > STRSAFE_MAX_CCH)
- {
- hr = STRSAFE_E_INVALID_PARAMETER;
- }
- else
- {
- hr = StringVPrintfWorkerW(pszDest, cchDest, pszFormat, argList);
- }
-
- return hr;
-}
-#endif // FEATURE_PAL || !PLATFORM_UNIX
-#endif // STRSAFE_INLINE
-#endif // !STRSAFE_NO_CB_FUNCTIONS
-
-
-#ifndef STRSAFE_NO_CCH_FUNCTIONS
-/*++
-
-STDAPI StringCchPrintf(LPTSTR pszDest,
- size_t cchDest,
- LPCTSTR pszFormat,
- ...);
-
-Routine Description:
-
- This routine is a safer version of the C built-in function 'sprintf'.
- The size of the destination buffer (in characters) is a parameter and
- this function will not write past the end of this buffer and it will
- ALWAYS null terminate the destination buffer (unless it is zero length).
-
- This function returns a hresult, and not a pointer. It returns a S_OK
- if the string was printed without truncation and null terminated, otherwise
- it will return a failure code. In failure cases it will return a truncated
- version of the ideal result.
-
-Arguments:
-
- pszDest - destination string
-
- cchDest - size of destination buffer in characters
- length must be sufficient to hold the resulting formatted
- string, including the null terminator.
-
- pszFormat - format string which must be null terminated
-
- ... - additional parameters to be formatted according to
- the format string
-
-Notes:
- Behavior is undefined if destination, format strings or any arguments
- strings overlap.
-
- pszDest and pszFormat should not be NULL. See StringCchPrintfEx if you
- require the handling of NULL values.
-
-Return Value:
-
- S_OK - if there was sufficient space in the dest buffer for
- the resultant string and it was null terminated.
-
- failure - you can use the macro HRESULT_CODE() to get a win32 error
- code for all falure cases
-
- STRSAFE_E_INSUFFICIENT_BUFFER /
- HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER
- - this return value is an indication that the print operation
- failed due to insufficient space. When this error occurs,
- the destination buffer is modified to contain a truncated
- version of the ideal result and is null terminated. This
- is useful for situations where truncation is ok.
-
- It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the
- return value of this function
-
---*/
-
-STRSAFEAPI StringCchPrintfA(char* pszDest, size_t cchDest, const char* pszFormat, ...);
-STRSAFEAPI StringCchPrintfW(WCHAR* pszDest, size_t cchDest, const WCHAR* pszFormat, ...);
-#ifdef UNICODE
-#define StringCchPrintf StringCchPrintfW
-#else
-#define StringCchPrintf StringCchPrintfA
-#endif // !UNICODE
-
-#ifdef STRSAFE_INLINE
-STRSAFEAPI StringCchPrintfA(char* pszDest, size_t cchDest, const char* pszFormat, ...)
-{
- HRESULT hr;
-
- if (cchDest > STRSAFE_MAX_CCH)
- {
- hr = STRSAFE_E_INVALID_PARAMETER;
- }
- else
- {
- va_list argList;
-
- va_start(argList, pszFormat);
-
- hr = StringVPrintfWorkerA(pszDest, cchDest, pszFormat, argList);
-
- va_end(argList);
- }
-
- return hr;
-}
-
-#if defined(FEATURE_PAL) || !defined(PLATFORM_UNIX)
-STRSAFEAPI StringCchPrintfW(WCHAR* pszDest, size_t cchDest, const WCHAR* pszFormat, ...)
-{
- HRESULT hr;
-
- if (cchDest > STRSAFE_MAX_CCH)
- {
- hr = STRSAFE_E_INVALID_PARAMETER;
- }
- else
- {
- va_list argList;
-
- va_start(argList, pszFormat);
-
- hr = StringVPrintfWorkerW(pszDest, cchDest, pszFormat, argList);
-
- va_end(argList);
- }
-
- return hr;
-}
-#endif // FEATURE_PAL || !PLATFORM_UNIX
-#endif // STRSAFE_INLINE
-#endif // !STRSAFE_NO_CCH_FUNCTIONS
-
-
-#ifndef STRSAFE_NO_CB_FUNCTIONS
-/*++
-
-STDAPI StringCbPrintf(LPTSTR pszDest,
- size_t cbDest,
- LPCTSTR pszFormat,
- ...);
-
-Routine Description:
-
- This routine is a safer version of the C built-in function 'sprintf'.
- The size of the destination buffer (in bytes) is a parameter and
- this function will not write past the end of this buffer and it will
- ALWAYS null terminate the destination buffer (unless it is zero length).
-
- This function returns a hresult, and not a pointer. It returns a S_OK
- if the string was printed without truncation and null terminated, otherwise
- it will return a failure code. In failure cases it will return a truncated
- version of the ideal result.
-
-Arguments:
-
- pszDest - destination string
-
- cbDest - size of destination buffer in bytes
- length must be sufficient to hold the resulting formatted
- string, including the null terminator.
-
- pszFormat - format string which must be null terminated
-
- ... - additional parameters to be formatted according to
- the format string
-
-Notes:
- Behavior is undefined if destination, format strings or any arguments
- strings overlap.
-
- pszDest and pszFormat should not be NULL. See StringCbPrintfEx if you
- require the handling of NULL values.
-
-
-Return Value:
-
- S_OK - if there was sufficient space in the dest buffer for
- the resultant string and it was null terminated.
-
- failure - you can use the macro HRESULT_CODE() to get a win32 error
- code for all falure cases
-
- STRSAFE_E_INSUFFICIENT_BUFFER /
- HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER
- - this return value is an indication that the print operation
- failed due to insufficient space. When this error occurs,
- the destination buffer is modified to contain a truncated
- version of the ideal result and is null terminated. This
- is useful for situations where truncation is ok.
-
- It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the
- return value of this function
-
---*/
-
-STRSAFEAPI StringCbPrintfA(char* pszDest, size_t cbDest, const char* pszFormat, ...);
-STRSAFEAPI StringCbPrintfW(WCHAR* pszDest, size_t cbDest, const WCHAR* pszFormat, ...);
-#ifdef UNICODE
-#define StringCbPrintf StringCbPrintfW
-#else
-#define StringCbPrintf StringCbPrintfA
-#endif // !UNICODE
-
-#ifdef STRSAFE_INLINE
-STRSAFEAPI StringCbPrintfA(char* pszDest, size_t cbDest, const char* pszFormat, ...)
-{
- HRESULT hr;
- size_t cchDest;
-
- cchDest = cbDest / sizeof(char);
-
- if (cchDest > STRSAFE_MAX_CCH)
- {
- hr = STRSAFE_E_INVALID_PARAMETER;
- }
- else
- {
- va_list argList;
-
- va_start(argList, pszFormat);
-
- hr = StringVPrintfWorkerA(pszDest, cchDest, pszFormat, argList);
-
- va_end(argList);
- }
-
- return hr;
-}
-
-#if defined(FEATURE_PAL) || !defined(PLATFORM_UNIX)
-STRSAFEAPI StringCbPrintfW(WCHAR* pszDest, size_t cbDest, const WCHAR* pszFormat, ...)
-{
- HRESULT hr;
- size_t cchDest;
-
- cchDest = cbDest / sizeof(WCHAR);
-
- if (cchDest > STRSAFE_MAX_CCH)
- {
- hr = STRSAFE_E_INVALID_PARAMETER;
- }
- else
- {
- va_list argList;
-
- va_start(argList, pszFormat);
-
- hr = StringVPrintfWorkerW(pszDest, cchDest, pszFormat, argList);
-
- va_end(argList);
- }
-
- return hr;
-}
-#endif // FEATURE_PAL || !PLATFORM_UNIX
-#endif // STRSAFE_INLINE
-#endif // !STRSAFE_NO_CB_FUNCTIONS
-
-
-#ifndef STRSAFE_NO_CCH_FUNCTIONS
-/*++
-
-STDAPI StringCchPrintfEx(LPTSTR pszDest,
- size_t cchDest,
- LPTSTR* ppszDestEnd,
- size_t* pcchRemaining,
- DWORD dwFlags,
- LPCTSTR pszFormat,
- ...);
-
-Routine Description:
-
- This routine is a safer version of the C built-in function 'sprintf' with
- some additional parameters. In addition to functionality provided by
- StringCchPrintf, this routine also returns a pointer to the end of the
- destination string and the number of characters left in the destination string
- including the null terminator. The flags parameter allows additional controls.
-
-Arguments:
-
- pszDest - destination string
-
- cchDest - size of destination buffer in characters.
- length must be sufficient to contain the resulting
- formatted string plus the null terminator.
-
- ppszDestEnd - if ppszDestEnd is non-null, the function will return a
- pointer to the end of the destination string. If the
- function printed any data, the result will point to the
- null termination character
-
- pcchRemaining - if pcchRemaining is non-null, the function will return
- the number of characters left in the destination string,
- including the null terminator
-
- dwFlags - controls some details of the string copy:
-
- STRSAFE_FILL_BEHIND_NULL
- if the function succeeds, the low byte of dwFlags will be
- used to fill the uninitialize part of destination buffer
- behind the null terminator
-
- STRSAFE_IGNORE_NULLS
- treat NULL string pointers like empty strings (TEXT(""))
-
- STRSAFE_FILL_ON_FAILURE
- if the function fails, the low byte of dwFlags will be
- used to fill all of the destination buffer, and it will
- be null terminated. This will overwrite any truncated
- string returned when the failure is
- STRSAFE_E_INSUFFICIENT_BUFFER
-
- STRSAFE_NO_TRUNCATION /
- STRSAFE_NULL_ON_FAILURE
- if the function fails, the destination buffer will be set
- to the empty string. This will overwrite any truncated string
- returned when the failure is STRSAFE_E_INSUFFICIENT_BUFFER.
-
- pszFormat - format string which must be null terminated
-
- ... - additional parameters to be formatted according to
- the format string
-
-Notes:
- Behavior is undefined if destination, format strings or any arguments
- strings overlap.
-
- pszDest and pszFormat should not be NULL unless the STRSAFE_IGNORE_NULLS
- flag is specified. If STRSAFE_IGNORE_NULLS is passed, both pszDest and
- pszFormat may be NULL. An error may still be returned even though NULLS
- are ignored due to insufficient space.
-
-Return Value:
-
- S_OK - if there was source data and it was all concatenated and the
- resultant dest string was null terminated
-
- failure - you can use the macro HRESULT_CODE() to get a win32 error
- code for all falure cases
-
- STRSAFE_E_INSUFFICIENT_BUFFER /
- HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER
- - this return value is an indication that the print operation
- failed due to insufficient space. When this error occurs,
- the destination buffer is modified to contain a truncated
- version of the ideal result and is null terminated. This
- is useful for situations where truncation is ok.
-
- It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the
- return value of this function
-
---*/
-
-STRSAFEAPI StringCchPrintfExA(char* pszDest, size_t cchDest, char** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags, const char* pszFormat, ...);
-STRSAFEAPI StringCchPrintfExW(WCHAR* pszDest, size_t cchDest, WCHAR** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags, const WCHAR* pszFormat, ...);
-#ifdef UNICODE
-#define StringCchPrintfEx StringCchPrintfExW
-#else
-#define StringCchPrintfEx StringCchPrintfExA
-#endif // !UNICODE
-
-#ifdef STRSAFE_INLINE
-STRSAFEAPI StringCchPrintfExA(char* pszDest, size_t cchDest, char** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags, const char* pszFormat, ...)
-{
- HRESULT hr;
-
- if (cchDest > STRSAFE_MAX_CCH)
- {
- hr = STRSAFE_E_INVALID_PARAMETER;
- }
- else
- {
- size_t cbDest;
- va_list argList;
-
- // safe to multiply cchDest * sizeof(char) since cchDest < STRSAFE_MAX_CCH and sizeof(char) is 1
- cbDest = cchDest * sizeof(char);
- va_start(argList, pszFormat);
-
- hr = StringVPrintfExWorkerA(pszDest, cchDest, cbDest, ppszDestEnd, pcchRemaining, dwFlags, pszFormat, argList);
-
- va_end(argList);
- }
-
- return hr;
-}
-
-#if defined(FEATURE_PAL) || !defined(PLATFORM_UNIX)
-STRSAFEAPI StringCchPrintfExW(WCHAR* pszDest, size_t cchDest, WCHAR** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags, const WCHAR* pszFormat, ...)
-{
- HRESULT hr;
-
- if (cchDest > STRSAFE_MAX_CCH)
- {
- hr = STRSAFE_E_INVALID_PARAMETER;
- }
- else
- {
- size_t cbDest;
- va_list argList;
-
- // safe to multiply cchDest * sizeof(WCHAR) since cchDest < STRSAFE_MAX_CCH and sizeof(WCHAR) is 2
- cbDest = cchDest * sizeof(WCHAR);
- va_start(argList, pszFormat);
-
- hr = StringVPrintfExWorkerW(pszDest, cchDest, cbDest, ppszDestEnd, pcchRemaining, dwFlags, pszFormat, argList);
-
- va_end(argList);
- }
-
- return hr;
-}
-#endif // FEATURE_PAL || !PLATFORM_UNIX
-#endif // STRSAFE_INLINE
-#endif // !STRSAFE_NO_CCH_FUNCTIONS
-
-
-#ifndef STRSAFE_NO_CB_FUNCTIONS
-/*++
-
-STDAPI StringCbPrintfEx(LPTSTR pszDest,
- size_t cbDest,
- LPTSTR* ppszDestEnd,
- size_t* pcbRemaining,
- DWORD dwFlags,
- LPCTSTR pszFormat,
- ...);
-
-Routine Description:
-
- This routine is a safer version of the C built-in function 'sprintf' with
- some additional parameters. In addition to functionality provided by
- StringCbPrintf, this routine also returns a pointer to the end of the
- destination string and the number of bytes left in the destination string
- including the null terminator. The flags parameter allows additional controls.
-
-Arguments:
-
- pszDest - destination string
-
- cbDest - size of destination buffer in bytes.
- length must be sufficient to contain the resulting
- formatted string plus the null terminator.
-
- ppszDestEnd - if ppszDestEnd is non-null, the function will return a
- pointer to the end of the destination string. If the
- function printed any data, the result will point to the
- null termination character
-
- pcbRemaining - if pcbRemaining is non-null, the function will return
- the number of bytes left in the destination string,
- including the null terminator
-
- dwFlags - controls some details of the string copy:
-
- STRSAFE_FILL_BEHIND_NULL
- if the function succeeds, the low byte of dwFlags will be
- used to fill the uninitialize part of destination buffer
- behind the null terminator
-
- STRSAFE_IGNORE_NULLS
- treat NULL string pointers like empty strings (TEXT(""))
-
- STRSAFE_FILL_ON_FAILURE
- if the function fails, the low byte of dwFlags will be
- used to fill all of the destination buffer, and it will
- be null terminated. This will overwrite any truncated
- string returned when the failure is
- STRSAFE_E_INSUFFICIENT_BUFFER
-
- STRSAFE_NO_TRUNCATION /
- STRSAFE_NULL_ON_FAILURE
- if the function fails, the destination buffer will be set
- to the empty string. This will overwrite any truncated string
- returned when the failure is STRSAFE_E_INSUFFICIENT_BUFFER.
-
- pszFormat - format string which must be null terminated
-
- ... - additional parameters to be formatted according to
- the format string
-
-Notes:
- Behavior is undefined if destination, format strings or any arguments
- strings overlap.
-
- pszDest and pszFormat should not be NULL unless the STRSAFE_IGNORE_NULLS
- flag is specified. If STRSAFE_IGNORE_NULLS is passed, both pszDest and
- pszFormat may be NULL. An error may still be returned even though NULLS
- are ignored due to insufficient space.
-
-Return Value:
-
- S_OK - if there was source data and it was all concatenated and the
- resultant dest string was null terminated
-
- failure - you can use the macro HRESULT_CODE() to get a win32 error
- code for all falure cases
-
- STRSAFE_E_INSUFFICIENT_BUFFER /
- HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER
- - this return value is an indication that the print operation
- failed due to insufficient space. When this error occurs,
- the destination buffer is modified to contain a truncated
- version of the ideal result and is null terminated. This
- is useful for situations where truncation is ok.
-
- It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the
- return value of this function
-
---*/
-
-STRSAFEAPI StringCbPrintfExA(char* pszDest, size_t cbDest, char** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags, const char* pszFormat, ...);
-STRSAFEAPI StringCbPrintfExW(WCHAR* pszDest, size_t cbDest, WCHAR** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags, const WCHAR* pszFormat, ...);
-#ifdef UNICODE
-#define StringCbPrintfEx StringCbPrintfExW
-#else
-#define StringCbPrintfEx StringCbPrintfExA
-#endif // !UNICODE
-
-#ifdef STRSAFE_INLINE
-STRSAFEAPI StringCbPrintfExA(char* pszDest, size_t cbDest, char** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags, const char* pszFormat, ...)
-{
- HRESULT hr;
- size_t cchDest;
- size_t cchRemaining = 0;
-
- cchDest = cbDest / sizeof(char);
-
- if (cchDest > STRSAFE_MAX_CCH)
- {
- hr = STRSAFE_E_INVALID_PARAMETER;
- }
- else
- {
- va_list argList;
-
- va_start(argList, pszFormat);
-
- hr = StringVPrintfExWorkerA(pszDest, cchDest, cbDest, ppszDestEnd, &cchRemaining, dwFlags, pszFormat, argList);
-
- va_end(argList);
- }
-
- if (SUCCEEDED(hr) || (hr == STRSAFE_E_INSUFFICIENT_BUFFER))
- {
- if (pcbRemaining)
- {
- // safe to multiply cchRemaining * sizeof(char) since cchRemaining < STRSAFE_MAX_CCH and sizeof(char) is 1
- *pcbRemaining = (cchRemaining * sizeof(char)) + (cbDest % sizeof(char));
- }
- }
-
- return hr;
-}
-
-#if defined(FEATURE_PAL) || !defined(PLATFORM_UNIX)
-STRSAFEAPI StringCbPrintfExW(WCHAR* pszDest, size_t cbDest, WCHAR** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags, const WCHAR* pszFormat, ...)
-{
- HRESULT hr;
- size_t cchDest;
- size_t cchRemaining = 0;
-
- cchDest = cbDest / sizeof(WCHAR);
-
- if (cchDest > STRSAFE_MAX_CCH)
- {
- hr = STRSAFE_E_INVALID_PARAMETER;
- }
- else
- {
- va_list argList;
-
- va_start(argList, pszFormat);
-
- hr = StringVPrintfExWorkerW(pszDest, cchDest, cbDest, ppszDestEnd, &cchRemaining, dwFlags, pszFormat, argList);
-
- va_end(argList);
- }
-
- if (SUCCEEDED(hr) || (hr == STRSAFE_E_INSUFFICIENT_BUFFER))
- {
- if (pcbRemaining)
- {
- // safe to multiply cchRemaining * sizeof(WCHAR) since cchRemaining < STRSAFE_MAX_CCH and sizeof(WCHAR) is 2
- *pcbRemaining = (cchRemaining * sizeof(WCHAR)) + (cbDest % sizeof(WCHAR));
- }
- }
-
- return hr;
-}
-#endif // FEATURE_PAL || !PLATFORM_UNIX
-#endif // STRSAFE_INLINE
-#endif // !STRSAFE_NO_CB_FUNCTIONS
-
-
-#ifndef STRSAFE_NO_CCH_FUNCTIONS
-/*++
-
-STDAPI StringCchVPrintfEx(LPTSTR pszDest,
- size_t cchDest,
- LPTSTR* ppszDestEnd,
- size_t* pcchRemaining,
- DWORD dwFlags,
- LPCTSTR pszFormat,
- va_list argList);
-
-Routine Description:
-
- This routine is a safer version of the C built-in function 'vsprintf' with
- some additional parameters. In addition to functionality provided by
- StringCchVPrintf, this routine also returns a pointer to the end of the
- destination string and the number of characters left in the destination string
- including the null terminator. The flags parameter allows additional controls.
-
-Arguments:
-
- pszDest - destination string
-
- cchDest - size of destination buffer in characters.
- length must be sufficient to contain the resulting
- formatted string plus the null terminator.
-
- ppszDestEnd - if ppszDestEnd is non-null, the function will return a
- pointer to the end of the destination string. If the
- function printed any data, the result will point to the
- null termination character
-
- pcchRemaining - if pcchRemaining is non-null, the function will return
- the number of characters left in the destination string,
- including the null terminator
-
- dwFlags - controls some details of the string copy:
-
- STRSAFE_FILL_BEHIND_NULL
- if the function succeeds, the low byte of dwFlags will be
- used to fill the uninitialize part of destination buffer
- behind the null terminator
-
- STRSAFE_IGNORE_NULLS
- treat NULL string pointers like empty strings (TEXT(""))
-
- STRSAFE_FILL_ON_FAILURE
- if the function fails, the low byte of dwFlags will be
- used to fill all of the destination buffer, and it will
- be null terminated. This will overwrite any truncated
- string returned when the failure is
- STRSAFE_E_INSUFFICIENT_BUFFER
-
- STRSAFE_NO_TRUNCATION /
- STRSAFE_NULL_ON_FAILURE
- if the function fails, the destination buffer will be set
- to the empty string. This will overwrite any truncated string
- returned when the failure is STRSAFE_E_INSUFFICIENT_BUFFER.
-
- pszFormat - format string which must be null terminated
-
- argList - va_list from the variable arguments according to the
- stdarg.h convention
-
-Notes:
- Behavior is undefined if destination, format strings or any arguments
- strings overlap.
-
- pszDest and pszFormat should not be NULL unless the STRSAFE_IGNORE_NULLS
- flag is specified. If STRSAFE_IGNORE_NULLS is passed, both pszDest and
- pszFormat may be NULL. An error may still be returned even though NULLS
- are ignored due to insufficient space.
-
-Return Value:
-
- S_OK - if there was source data and it was all concatenated and the
- resultant dest string was null terminated
-
- failure - you can use the macro HRESULT_CODE() to get a win32 error
- code for all falure cases
-
- STRSAFE_E_INSUFFICIENT_BUFFER /
- HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER
- - this return value is an indication that the print operation
- failed due to insufficient space. When this error occurs,
- the destination buffer is modified to contain a truncated
- version of the ideal result and is null terminated. This
- is useful for situations where truncation is ok.
-
- It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the
- return value of this function
-
---*/
-
-STRSAFEAPI StringCchVPrintfExA(char* pszDest, size_t cchDest, char** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags, const char* pszFormat, va_list argList);
-STRSAFEAPI StringCchVPrintfExW(WCHAR* pszDest, size_t cchDest, WCHAR** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags, const WCHAR* pszFormat, va_list argList);
-#ifdef UNICODE
-#define StringCchVPrintfEx StringCchVPrintfExW
-#else
-#define StringCchVPrintfEx StringCchVPrintfExA
-#endif // !UNICODE
-
-#ifdef STRSAFE_INLINE
-STRSAFEAPI StringCchVPrintfExA(char* pszDest, size_t cchDest, char** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags, const char* pszFormat, va_list argList)
-{
- HRESULT hr;
-
- if (cchDest > STRSAFE_MAX_CCH)
- {
- hr = STRSAFE_E_INVALID_PARAMETER;
- }
- else
- {
- size_t cbDest;
-
- // safe to multiply cchDest * sizeof(char) since cchDest < STRSAFE_MAX_CCH and sizeof(char) is 1
- cbDest = cchDest * sizeof(char);
-
- hr = StringVPrintfExWorkerA(pszDest, cchDest, cbDest, ppszDestEnd, pcchRemaining, dwFlags, pszFormat, argList);
- }
-
- return hr;
-}
-
-#if defined(FEATURE_PAL) || !defined(PLATFORM_UNIX)
-STRSAFEAPI StringCchVPrintfExW(WCHAR* pszDest, size_t cchDest, WCHAR** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags, const WCHAR* pszFormat, va_list argList)
-{
- HRESULT hr;
-
- if (cchDest > STRSAFE_MAX_CCH)
- {
- hr = STRSAFE_E_INVALID_PARAMETER;
- }
- else
- {
- size_t cbDest;
-
- // safe to multiply cchDest * sizeof(WCHAR) since cchDest < STRSAFE_MAX_CCH and sizeof(WCHAR) is 2
- cbDest = cchDest * sizeof(WCHAR);
-
- hr = StringVPrintfExWorkerW(pszDest, cchDest, cbDest, ppszDestEnd, pcchRemaining, dwFlags, pszFormat, argList);
- }
-
- return hr;
-}
-#endif // FEATURE_PAL || !PLATFORM_UNIX
-#endif // STRSAFE_INLINE
-#endif // !STRSAFE_NO_CCH_FUNCTIONS
-
-
-#ifndef STRSAFE_NO_CB_FUNCTIONS
-/*++
-
-STDAPI StringCbVPrintfEx(LPTSTR pszDest,
- size_t cbDest,
- LPTSTR* ppszDestEnd,
- size_t* pcbRemaining,
- DWORD dwFlags,
- LPCTSTR pszFormat,
- va_list argList);
-
-Routine Description:
-
- This routine is a safer version of the C built-in function 'vsprintf' with
- some additional parameters. In addition to functionality provided by
- StringCbVPrintf, this routine also returns a pointer to the end of the
- destination string and the number of characters left in the destination string
- including the null terminator. The flags parameter allows additional controls.
-
-Arguments:
-
- pszDest - destination string
-
- cbDest - size of destination buffer in bytes.
- length must be sufficient to contain the resulting
- formatted string plus the null terminator.
-
- ppszDestEnd - if ppszDestEnd is non-null, the function will return
- a pointer to the end of the destination string. If the
- function printed any data, the result will point to the
- null termination character
-
- pcbRemaining - if pcbRemaining is non-null, the function will return
- the number of bytes left in the destination string,
- including the null terminator
-
- dwFlags - controls some details of the string copy:
-
- STRSAFE_FILL_BEHIND_NULL
- if the function succeeds, the low byte of dwFlags will be
- used to fill the uninitialize part of destination buffer
- behind the null terminator
-
- STRSAFE_IGNORE_NULLS
- treat NULL string pointers like empty strings (TEXT(""))
-
- STRSAFE_FILL_ON_FAILURE
- if the function fails, the low byte of dwFlags will be
- used to fill all of the destination buffer, and it will
- be null terminated. This will overwrite any truncated
- string returned when the failure is
- STRSAFE_E_INSUFFICIENT_BUFFER
-
- STRSAFE_NO_TRUNCATION /
- STRSAFE_NULL_ON_FAILURE
- if the function fails, the destination buffer will be set
- to the empty string. This will overwrite any truncated string
- returned when the failure is STRSAFE_E_INSUFFICIENT_BUFFER.
-
- pszFormat - format string which must be null terminated
-
- argList - va_list from the variable arguments according to the
- stdarg.h convention
-
-Notes:
- Behavior is undefined if destination, format strings or any arguments
- strings overlap.
-
- pszDest and pszFormat should not be NULL unless the STRSAFE_IGNORE_NULLS
- flag is specified. If STRSAFE_IGNORE_NULLS is passed, both pszDest and
- pszFormat may be NULL. An error may still be returned even though NULLS
- are ignored due to insufficient space.
-
-Return Value:
-
- S_OK - if there was source data and it was all concatenated and the
- resultant dest string was null terminated
-
- failure - you can use the macro HRESULT_CODE() to get a win32 error
- code for all falure cases
-
- STRSAFE_E_INSUFFICIENT_BUFFER /
- HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER
- - this return value is an indication that the print operation
- failed due to insufficient space. When this error occurs,
- the destination buffer is modified to contain a truncated
- version of the ideal result and is null terminated. This
- is useful for situations where truncation is ok.
-
- It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the
- return value of this function
-
---*/
-
-STRSAFEAPI StringCbVPrintfExA(char* pszDest, size_t cbDest, char** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags, const char* pszFormat, va_list argList);
-STRSAFEAPI StringCbVPrintfExW(WCHAR* pszDest, size_t cbDest, WCHAR** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags, const WCHAR* pszFormat, va_list argList);
-#ifdef UNICODE
-#define StringCbVPrintfEx StringCbVPrintfExW
-#else
-#define StringCbVPrintfEx StringCbVPrintfExA
-#endif // !UNICODE
-
-#ifdef STRSAFE_INLINE
-STRSAFEAPI StringCbVPrintfExA(char* pszDest, size_t cbDest, char** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags, const char* pszFormat, va_list argList)
-{
- HRESULT hr;
- size_t cchDest;
- size_t cchRemaining = 0;
-
- cchDest = cbDest / sizeof(char);
-
- if (cchDest > STRSAFE_MAX_CCH)
- {
- hr = STRSAFE_E_INVALID_PARAMETER;
- }
- else
- {
- hr = StringVPrintfExWorkerA(pszDest, cchDest, cbDest, ppszDestEnd, &cchRemaining, dwFlags, pszFormat, argList);
- }
-
- if (SUCCEEDED(hr) || (hr == STRSAFE_E_INSUFFICIENT_BUFFER))
- {
- if (pcbRemaining)
- {
- // safe to multiply cchRemaining * sizeof(char) since cchRemaining < STRSAFE_MAX_CCH and sizeof(char) is 1
- *pcbRemaining = (cchRemaining * sizeof(char)) + (cbDest % sizeof(char));
- }
- }
-
- return hr;
-}
-
-#if defined(FEATURE_PAL) || !defined(PLATFORM_UNIX)
-STRSAFEAPI StringCbVPrintfExW(WCHAR* pszDest, size_t cbDest, WCHAR** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags, const WCHAR* pszFormat, va_list argList)
-{
- HRESULT hr;
- size_t cchDest;
- size_t cchRemaining = 0;
-
- cchDest = cbDest / sizeof(WCHAR);
-
- if (cchDest > STRSAFE_MAX_CCH)
- {
- hr = STRSAFE_E_INVALID_PARAMETER;
- }
- else
- {
- hr = StringVPrintfExWorkerW(pszDest, cchDest, cbDest, ppszDestEnd, &cchRemaining, dwFlags, pszFormat, argList);
- }
-
- if (SUCCEEDED(hr) || (hr == STRSAFE_E_INSUFFICIENT_BUFFER))
- {
- if (pcbRemaining)
- {
- // safe to multiply cchRemaining * sizeof(WCHAR) since cchRemaining < STRSAFE_MAX_CCH and sizeof(WCHAR) is 2
- *pcbRemaining = (cchRemaining * sizeof(WCHAR)) + (cbDest % sizeof(WCHAR));
- }
- }
-
- return hr;
-}
-#endif // FEATURE_PAL || !PLATFORM_UNIX
-#endif // STRSAFE_INLINE
-#endif // !STRSAFE_NO_CB_FUNCTIONS
-
-
-#ifndef STRSAFE_NO_CCH_FUNCTIONS
-/*++
-
STDAPI StringCchGets(LPTSTR pszDest,
size_t cchDest);
@@ -5543,394 +4421,6 @@ STRSAFEAPI StringCatNExWorkerW(WCHAR* pszDest, size_t cchDest, size_t cbDest, co
}
#endif // FEATURE_PAL || !PLATFORM_UNIX
-STRSAFEAPI StringVPrintfWorkerA(char* pszDest, size_t cchDest, const char* pszFormat, va_list argList)
-{
- HRESULT hr = S_OK;
-
- if (cchDest == 0)
- {
- // can not null terminate a zero-byte dest buffer
- hr = STRSAFE_E_INVALID_PARAMETER;
- }
- else
- {
- int iRet;
- size_t cchMax;
-
- // leave the last space for the null terminator
- cchMax = cchDest - 1;
-
- iRet = _vsnprintf(pszDest, cchMax, pszFormat, argList);
- // ASSERT((iRet < 0) || (((size_t)iRet) <= cchMax));
-
- if ((iRet < 0) || (((size_t)iRet) > cchMax))
- {
- // need to null terminate the string
- pszDest += cchMax;
- *pszDest = '\0';
-
- // we have truncated pszDest
- hr = STRSAFE_E_INSUFFICIENT_BUFFER;
- }
- else if (((size_t)iRet) == cchMax)
- {
- // need to null terminate the string
- pszDest += cchMax;
- *pszDest = '\0';
- }
- }
-
- return hr;
-}
-
-#if defined(FEATURE_PAL) || !defined(PLATFORM_UNIX)
-STRSAFEAPI StringVPrintfWorkerW(WCHAR* pszDest, size_t cchDest, const WCHAR* pszFormat, va_list argList)
-{
- HRESULT hr = S_OK;
-
- if (cchDest == 0)
- {
- // can not null terminate a zero-byte dest buffer
- hr = STRSAFE_E_INVALID_PARAMETER;
- }
- else
- {
- int iRet;
- size_t cchMax;
-
- // leave the last space for the null terminator
- cchMax = cchDest - 1;
-
- iRet = _vsnwprintf(pszDest, cchMax, pszFormat, argList);
- // ASSERT((iRet < 0) || (((size_t)iRet) <= cchMax));
-
- if ((iRet < 0) || (((size_t)iRet) > cchMax))
- {
- // need to null terminate the string
- pszDest += cchMax;
- *pszDest = L'\0';
-
- // we have truncated pszDest
- hr = STRSAFE_E_INSUFFICIENT_BUFFER;
- }
- else if (((size_t)iRet) == cchMax)
- {
- // need to null terminate the string
- pszDest += cchMax;
- *pszDest = L'\0';
- }
- }
-
- return hr;
-}
-#endif // FEATURE_PAL || !PLATFORM_UNIX
-
-STRSAFEAPI StringVPrintfExWorkerA(char* pszDest, size_t cchDest, size_t cbDest, char** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags, const char* pszFormat, va_list argList)
-{
- HRESULT hr = S_OK;
- char* pszDestEnd = pszDest;
- size_t cchRemaining = 0;
-
- // ASSERT(cbDest == (cchDest * sizeof(char)) ||
- // cbDest == (cchDest * sizeof(char)) + (cbDest % sizeof(char)));
-
- // only accept valid flags
- if (dwFlags & (~STRSAFE_VALID_FLAGS))
- {
- hr = STRSAFE_E_INVALID_PARAMETER;
- }
- else
- {
- if (dwFlags & STRSAFE_IGNORE_NULLS)
- {
- if (pszDest == NULL)
- {
- if ((cchDest != 0) || (cbDest != 0))
- {
- // NULL pszDest and non-zero cchDest/cbDest is invalid
- hr = STRSAFE_E_INVALID_PARAMETER;
- }
- }
-
- if (pszFormat == NULL)
- {
- pszFormat = "";
- }
- }
-
- if (SUCCEEDED(hr))
- {
- if (cchDest == 0)
- {
- pszDestEnd = pszDest;
- cchRemaining = 0;
-
- // only fail if there was actually a non-empty format string
- if (*pszFormat != '\0')
- {
- if (pszDest == NULL)
- {
- hr = STRSAFE_E_INVALID_PARAMETER;
- }
- else
- {
- hr = STRSAFE_E_INSUFFICIENT_BUFFER;
- }
- }
- }
- else
- {
- int iRet;
- size_t cchMax;
-
- // leave the last space for the null terminator
- cchMax = cchDest - 1;
-
- iRet = _vsnprintf(pszDest, cchMax, pszFormat, argList);
- // ASSERT((iRet < 0) || (((size_t)iRet) <= cchMax));
-
- if ((iRet < 0) || (((size_t)iRet) > cchMax))
- {
- // we have truncated pszDest
- pszDestEnd = pszDest + cchMax;
- cchRemaining = 1;
-
- // need to null terminate the string
- *pszDestEnd = '\0';
-
- hr = STRSAFE_E_INSUFFICIENT_BUFFER;
- }
- else if (((size_t)iRet) == cchMax)
- {
- // string fit perfectly
- pszDestEnd = pszDest + cchMax;
- cchRemaining = 1;
-
- // need to null terminate the string
- *pszDestEnd = '\0';
- }
- else if (((size_t)iRet) < cchMax)
- {
- // there is extra room
- pszDestEnd = pszDest + iRet;
- cchRemaining = cchDest - iRet;
-
- if (dwFlags & STRSAFE_FILL_BEHIND_NULL)
- {
- memset(pszDestEnd + 1, STRSAFE_GET_FILL_PATTERN(dwFlags), ((cchRemaining - 1) * sizeof(char)) + (cbDest % sizeof(char)));
- }
- }
- }
- }
- }
-
- if (FAILED(hr))
- {
- if (pszDest)
- {
- if (dwFlags & STRSAFE_FILL_ON_FAILURE)
- {
- memset(pszDest, STRSAFE_GET_FILL_PATTERN(dwFlags), cbDest);
-
- if (STRSAFE_GET_FILL_PATTERN(dwFlags) == 0)
- {
- pszDestEnd = pszDest;
- cchRemaining = cchDest;
- }
- else if (cchDest > 0)
- {
- pszDestEnd = pszDest + cchDest - 1;
- cchRemaining = 1;
-
- // null terminate the end of the string
- *pszDestEnd = '\0';
- }
- }
-
- if (dwFlags & (STRSAFE_NULL_ON_FAILURE | STRSAFE_NO_TRUNCATION))
- {
- if (cchDest > 0)
- {
- pszDestEnd = pszDest;
- cchRemaining = cchDest;
-
- // null terminate the beginning of the string
- *pszDestEnd = '\0';
- }
- }
- }
- }
-
- if (SUCCEEDED(hr) || (hr == STRSAFE_E_INSUFFICIENT_BUFFER))
- {
- if (ppszDestEnd)
- {
- *ppszDestEnd = pszDestEnd;
- }
-
- if (pcchRemaining)
- {
- *pcchRemaining = cchRemaining;
- }
- }
-
- return hr;
-}
-
-#if defined(FEATURE_PAL) || !defined(PLATFORM_UNIX)
-STRSAFEAPI StringVPrintfExWorkerW(WCHAR* pszDest, size_t cchDest, size_t cbDest, WCHAR** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags, const WCHAR* pszFormat, va_list argList)
-{
- HRESULT hr = S_OK;
- WCHAR* pszDestEnd = pszDest;
- size_t cchRemaining = 0;
-
- // ASSERT(cbDest == (cchDest * sizeof(WCHAR)) ||
- // cbDest == (cchDest * sizeof(WCHAR)) + (cbDest % sizeof(WCHAR)));
-
- // only accept valid flags
- if (dwFlags & (~STRSAFE_VALID_FLAGS))
- {
- hr = STRSAFE_E_INVALID_PARAMETER;
- }
- else
- {
- if (dwFlags & STRSAFE_IGNORE_NULLS)
- {
- if (pszDest == NULL)
- {
- if ((cchDest != 0) || (cbDest != 0))
- {
- // NULL pszDest and non-zero cchDest/cbDest is invalid
- hr = STRSAFE_E_INVALID_PARAMETER;
- }
- }
-
- if (pszFormat == NULL)
- {
- pszFormat = u"";
- }
- }
-
- if (SUCCEEDED(hr))
- {
- if (cchDest == 0)
- {
- pszDestEnd = pszDest;
- cchRemaining = 0;
-
- // only fail if there was actually a non-empty format string
- if (*pszFormat != L'\0')
- {
- if (pszDest == NULL)
- {
- hr = STRSAFE_E_INVALID_PARAMETER;
- }
- else
- {
- hr = STRSAFE_E_INSUFFICIENT_BUFFER;
- }
- }
- }
- else
- {
- int iRet;
- size_t cchMax;
-
- // leave the last space for the null terminator
- cchMax = cchDest - 1;
-
- iRet = _vsnwprintf(pszDest, cchMax, pszFormat, argList);
- // ASSERT((iRet < 0) || (((size_t)iRet) <= cchMax));
-
- if ((iRet < 0) || (((size_t)iRet) > cchMax))
- {
- // we have truncated pszDest
- pszDestEnd = pszDest + cchMax;
- cchRemaining = 1;
-
- // need to null terminate the string
- *pszDestEnd = L'\0';
-
- hr = STRSAFE_E_INSUFFICIENT_BUFFER;
- }
- else if (((size_t)iRet) == cchMax)
- {
- // string fit perfectly
- pszDestEnd = pszDest + cchMax;
- cchRemaining = 1;
-
- // need to null terminate the string
- *pszDestEnd = L'\0';
- }
- else if (((size_t)iRet) < cchMax)
- {
- // there is extra room
- pszDestEnd = pszDest + iRet;
- cchRemaining = cchDest - iRet;
-
- if (dwFlags & STRSAFE_FILL_BEHIND_NULL)
- {
- memset(pszDestEnd + 1, STRSAFE_GET_FILL_PATTERN(dwFlags), ((cchRemaining - 1) * sizeof(WCHAR)) + (cbDest % sizeof(WCHAR)));
- }
- }
- }
- }
- }
-
- if (FAILED(hr))
- {
- if (pszDest)
- {
- if (dwFlags & STRSAFE_FILL_ON_FAILURE)
- {
- memset(pszDest, STRSAFE_GET_FILL_PATTERN(dwFlags), cbDest);
-
- if (STRSAFE_GET_FILL_PATTERN(dwFlags) == 0)
- {
- pszDestEnd = pszDest;
- cchRemaining = cchDest;
- }
- else if (cchDest > 0)
- {
- pszDestEnd = pszDest + cchDest - 1;
- cchRemaining = 1;
-
- // null terminate the end of the string
- *pszDestEnd = L'\0';
- }
- }
-
- if (dwFlags & (STRSAFE_NULL_ON_FAILURE | STRSAFE_NO_TRUNCATION))
- {
- if (cchDest > 0)
- {
- pszDestEnd = pszDest;
- cchRemaining = cchDest;
-
- // null terminate the beginning of the string
- *pszDestEnd = L'\0';
- }
- }
- }
- }
-
- if (SUCCEEDED(hr) || (hr == STRSAFE_E_INSUFFICIENT_BUFFER))
- {
- if (ppszDestEnd)
- {
- *ppszDestEnd = pszDestEnd;
- }
-
- if (pcchRemaining)
- {
- *pcchRemaining = cchRemaining;
- }
- }
-
- return hr;
-}
-#endif // FEATURE_PAL || !PLATFORM_UNIX
-
STRSAFEAPI StringLengthWorkerA(const char* psz, size_t cchMax, size_t* pcch)
{
HRESULT hr = S_OK;
diff --git a/src/pal/inc/unixasmmacros.inc b/src/pal/inc/unixasmmacros.inc
index 7186645b34..e7a5eba898 100644
--- a/src/pal/inc/unixasmmacros.inc
+++ b/src/pal/inc/unixasmmacros.inc
@@ -28,7 +28,9 @@
.equiv \New, \Old
.endm
-#if defined(_AMD64_)
+#if defined(_X86_)
+#include "unixasmmacrosx86.inc"
+#elif defined(_AMD64_)
#include "unixasmmacrosamd64.inc"
#elif defined(_ARM_)
#include "unixasmmacrosarm.inc"
diff --git a/src/pal/inc/unixasmmacrosamd64.inc b/src/pal/inc/unixasmmacrosamd64.inc
index f221b4406b..c3321ce598 100644
--- a/src/pal/inc/unixasmmacrosamd64.inc
+++ b/src/pal/inc/unixasmmacrosamd64.inc
@@ -8,7 +8,7 @@
#if defined(__APPLE__)
.cfi_personality 0x9b, C_FUNC(\Handler) // 0x9b == DW_EH_PE_indirect | DW_EH_PE_pcrel | DW_EH_PE_sdata4
#else
- .cfi_personality 0, C_FUNC(\Handler) // 0 == DW_EH_PE_absptr
+ .cfi_personality 0x1b, C_FUNC(\Handler) // 0x1b == DW_EH_PE_pcrel | DW_EH_PE_sdata4
#endif
.endif
.endm
diff --git a/src/pal/inc/unixasmmacrosarm.inc b/src/pal/inc/unixasmmacrosarm.inc
index 14b0b4160e..76ea5eb93c 100644
--- a/src/pal/inc/unixasmmacrosarm.inc
+++ b/src/pal/inc/unixasmmacrosarm.inc
@@ -229,7 +229,8 @@ C_FUNC(\Name\()_End):
.endm
.macro EPILOG_STACK_RESTORE_OFFSET Register, Offset
- sub sp, \Register, \Offset
+ sub \Register, \Offset
+ mov sp, \Register
.endm
.macro EPILOG_BRANCH Target
diff --git a/src/pal/inc/unixasmmacrosarm64.inc b/src/pal/inc/unixasmmacrosarm64.inc
index ae60db4d35..60142053b0 100644
--- a/src/pal/inc/unixasmmacrosarm64.inc
+++ b/src/pal/inc/unixasmmacrosarm64.inc
@@ -5,7 +5,7 @@
.macro NESTED_ENTRY Name, Section, Handler
LEAF_ENTRY \Name, \Section
.ifnc \Handler, NoHandler
- .cfi_personality 0, C_FUNC(\Handler) // 0 == DW_EH_PE_absptr
+ .cfi_personality 0x1b, C_FUNC(\Handler) // 0x1b == DW_EH_PE_pcrel | DW_EH_PE_sdata4
.endif
.endm
diff --git a/src/pal/inc/unixasmmacrosx86.inc b/src/pal/inc/unixasmmacrosx86.inc
new file mode 100644
index 0000000000..77b3a63484
--- /dev/null
+++ b/src/pal/inc/unixasmmacrosx86.inc
@@ -0,0 +1,87 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+.macro NESTED_ENTRY Name, Section, Handler
+ LEAF_ENTRY \Name, \Section
+ .ifnc \Handler, NoHandler
+ .cfi_personality 0x1b, C_FUNC(\Handler) // 0x1b == DW_EH_PE_pcrel | DW_EH_PE_sdata4
+ .endif
+.endm
+
+.macro NESTED_END Name, Section
+ LEAF_END \Name, \Section
+.endm
+
+.macro LEAF_ENTRY Name, Section
+ .global C_FUNC(\Name)
+ .type \Name, %function
+C_FUNC(\Name):
+ .cfi_startproc
+.endm
+
+.macro PATCH_LABEL Name
+ .global C_FUNC(\Name)
+C_FUNC(\Name):
+.endm
+
+.macro LEAF_END Name, Section
+ .size \Name, .-\Name
+ .cfi_endproc
+.endm
+
+.macro LEAF_END_MARKED Name, Section
+C_FUNC(\Name\()_End):
+ .global C_FUNC(\Name\()_End)
+ LEAF_END \Name, \Section
+.endm
+
+.macro PROLOG_BEG
+ push ebp
+ .cfi_def_cfa_offset 8
+ .cfi_offset ebp, -8
+ mov ebp, esp
+.endm
+
+.macro PROLOG_PUSH Reg
+ push \Reg
+ .cfi_adjust_cfa_offset 4
+ .cfi_rel_offset \Reg, 0
+.endm
+
+.macro PROLOG_END
+ .cfi_def_cfa_register ebp
+ .cfi_def_cfa_offset 8
+.endm
+
+.macro EPILOG_BEG
+.endm
+
+.macro EPILOG_POP Reg
+ pop \Reg
+ .cfi_restore \Reg
+.endm
+
+.macro EPILOG_END
+ pop ebp
+.endm
+
+.macro PREPARE_EXTERNAL_VAR Name, Reg
+.att_syntax
+ call 0f
+0:
+ popl %\Reg
+1:
+ addl $_GLOBAL_OFFSET_TABLE_ + (1b - 0b), %\Reg
+ movl C_FUNC(\Name)@GOT(%\Reg), %\Reg
+.intel_syntax noprefix
+.endm
+
+.macro CHECK_STACK_ALIGNMENT
+#ifdef _DEBUG
+ test esp, 0Fh
+ je 0f
+ int3
+0:
+#endif // _DEBUG
+.endm