Hi, just ran into a problem which boils down to the following at least with Windows 7:
char *p = (char*)malloc(0x80000000UL); //works fine, allocates memory as requested memset(p, 0, 0x80000000UL); //Watch process segfault. The RtlFillMemory either crashes or underfills the buffer depending on the size given. Looks like internally it treats size as a signed 4-byte integer. Please apply the patch below or implement an alternative. Roman. From 60ed745b75d16755769653f19882335ef69960dd Mon Sep 17 00:00:00 2001 From: Roman Petrovski <rpetrov...@illumina.com> Date: Wed, 29 Jul 2015 06:45:45 -0700 Subject: [PATCH] RtlFillMemory fails on block sizes over 0x7fffffff --- winsup/cygwin/miscfuncs.cc | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/winsup/cygwin/miscfuncs.cc b/winsup/cygwin/miscfuncs.cc index 4a7a1b8..7308498 100644 --- a/winsup/cygwin/miscfuncs.cc +++ b/winsup/cygwin/miscfuncs.cc @@ -904,17 +904,35 @@ err: extern "C" void NTAPI RtlFillMemory (PVOID, SIZE_T, BYTE); extern "C" void NTAPI RtlCopyMemory (PVOID, const VOID *, SIZE_T); + +static const size_t RTL_MAX_SIZE = 0x7fffffff; extern "C" void * memset (void *s, int c, size_t n) { - RtlFillMemory (s, n, c); + char *p = (char*)s; + while (n) + { + size_t size = min(RTL_MAX_SIZE, n); + RtlFillMemory (p, size, c); + p += size; + n -= size; + } return s; } extern "C" void * memcpy(void *__restrict dest, const void *__restrict src, size_t n) { - RtlCopyMemory (dest, src, n); + char *d = (char*)dest; + char *s = (char*)src; + while (n) + { + size_t size = min(RTL_MAX_SIZE, n); + RtlCopyMemory (d, s, n); + d += size; + s += size; + n -= size; + } return dest; } #endif -- 2.4.5