27#include <winpr/cast.h>
28#include <winpr/platform.h>
29#include <winpr/winpr.h>
31#include <winpr/spec.h>
32#include <winpr/string.h>
35WINPR_PRAGMA_DIAG_IGNORED_RESERVED_IDENTIFIER
47#define _strtoui64 strtoull
51#define _strtoi64 strtoll
55static INLINE UINT32 _rotl(UINT32 value,
int shift)
57 return (value << shift) | (value >> (32 - shift));
62static INLINE UINT64 _rotl64(UINT64 value,
int shift)
64 return (value << shift) | (value >> (64 - shift));
69static INLINE UINT32 _rotr(UINT32 value,
int shift)
71 return (value >> shift) | (value << (32 - shift));
76static INLINE UINT64 _rotr64(UINT64 value,
int shift)
78 return (value >> shift) | (value << (64 - shift));
82#if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 2))
84#define _byteswap_ulong(_val) __builtin_bswap32(_val)
85#define _byteswap_uint64(_val) __builtin_bswap64(_val)
89static INLINE UINT32 _byteswap_ulong(UINT32 _val)
91 return (((_val) >> 24) | (((_val)&0x00FF0000) >> 8) | (((_val)&0x0000FF00) << 8) |
95static INLINE UINT64 _byteswap_uint64(UINT64 _val)
97 return (((_val) << 56) | (((_val) << 40) & 0xFF000000000000) |
98 (((_val) << 24) & 0xFF0000000000) | (((_val) << 8) & 0xFF00000000) |
99 (((_val) >> 8) & 0xFF000000) | (((_val) >> 24) & 0xFF0000) | (((_val) >> 40) & 0xFF00) |
105#if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 8))
107#define _byteswap_ushort(_val) __builtin_bswap16(_val)
111static INLINE UINT16 _byteswap_ushort(UINT16 _val)
113 return WINPR_CXX_COMPAT_CAST(UINT16, ((_val) >> 8U) | ((_val) << 8U));
118#define CopyMemory(Destination, Source, Length) memcpy((Destination), (Source), (Length))
119#define MoveMemory(Destination, Source, Length) memmove((Destination), (Source), (Length))
120#define FillMemory(Destination, Length, Fill) memset((Destination), (Fill), (Length))
121#define ZeroMemory(Destination, Length) memset((Destination), 0, (Length))
128 WINPR_API PVOID SecureZeroMemory(PVOID ptr,
size_t cnt);
138WINPR_PRAGMA_DIAG_PUSH
139WINPR_PRAGMA_DIAG_IGNORED_RESERVED_ID_MACRO
141#ifndef _ERRNO_T_DEFINED
142#define _ERRNO_T_DEFINED
157 WINPR_API errno_t _itoa_s(
int value,
char* buffer,
size_t sizeInCharacters,
int radix);
161 WINPR_API errno_t memmove_s(
void* dest,
size_t numberOfElements,
const void* src,
size_t count);
162 WINPR_API errno_t wmemmove_s(WCHAR* dest,
size_t numberOfElements,
const WCHAR* src,
170#if !defined(_WIN32) || (defined(__MINGW32__) && !defined(_UCRT))
176#if defined(WINPR_MSVCR_ALIGNMENT_EMULATE)
177#define _aligned_malloc winpr_aligned_malloc
178#define _aligned_realloc winpr_aligned_realloc
179#define _aligned_recalloc winpr_aligned_recalloc
180#define _aligned_offset_malloc winpr_aligned_offset_malloc
181#define _aligned_offset_realloc winpr_aligned_offset_realloc
182#define _aligned_offset_recalloc winpr_aligned_offset_recalloc
183#define _aligned_msize winpr_aligned_msize
184#define _aligned_free winpr_aligned_free
192 WINPR_API
void winpr_aligned_free(
void* memblock);
194 WINPR_ATTR_MALLOC(winpr_aligned_free, 1)
195 WINPR_API
void* winpr_aligned_malloc(
size_t size,
size_t alignment);
197 WINPR_ATTR_MALLOC(winpr_aligned_free, 1)
198 WINPR_API
void* winpr_aligned_calloc(
size_t count,
size_t size,
size_t alignment);
200 WINPR_ATTR_MALLOC(winpr_aligned_free, 1)
201 WINPR_API
void* winpr_aligned_realloc(
void* memblock,
size_t size,
size_t alignment);
203 WINPR_ATTR_MALLOC(winpr_aligned_free, 1)
204 WINPR_API
void* winpr_aligned_recalloc(
void* memblock,
size_t num,
size_t size,
207 WINPR_ATTR_MALLOC(winpr_aligned_free, 1)
208 WINPR_API
void* winpr_aligned_offset_malloc(
size_t size,
size_t alignment,
size_t offset);
210 WINPR_ATTR_MALLOC(winpr_aligned_free, 1)
211 WINPR_API
void* winpr_aligned_offset_realloc(
void* memblock,
size_t size,
size_t alignment,
214 WINPR_ATTR_MALLOC(winpr_aligned_free, 1)
215 WINPR_API
void* winpr_aligned_offset_recalloc(
void* memblock,
size_t num,
size_t size,
216 size_t alignment,
size_t offset);
218 WINPR_API
size_t winpr_aligned_msize(
void* memblock,
size_t alignment,
size_t offset);
225#define winpr_aligned_malloc _aligned_malloc
226#define winpr_aligned_realloc _aligned_realloc
227#define winpr_aligned_recalloc _aligned_recalloc
228#define winpr_aligned_offset_malloc _aligned_offset_malloc
229#define winpr_aligned_offset_realloc _aligned_offset_realloc
230#define winpr_aligned_offset_recalloc _aligned_offset_recalloc
231#define winpr_aligned_msize _aligned_msize
232#define winpr_aligned_free _aligned_free
235#if defined(_WIN32) && (!defined(__MINGW32__) || defined(_UCRT))
236#define winpr_aligned_calloc(count, size, alignment) _aligned_recalloc(NULL, count, size, alignment)