From ed91b2add33be7f813979c8c64e5cd92758d75fc Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Sat, 5 Aug 2006 13:01:10 +0000 Subject: [PATCH] (w32_valid_pointer_p): New function. --- src/w32.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/w32.c b/src/w32.c index c093eab599e..0da908ff932 100644 --- a/src/w32.c +++ b/src/w32.c @@ -323,6 +323,28 @@ w32_strerror (int error_no) return buf; } +/* Return 1 if P is a valid pointer to an object of size SIZE. Return + 0 if P is NOT a valid pointer. Return -1 if we cannot validate P. + + This is called from alloc.c:valid_pointer_p. */ +int +w32_valid_pointer_p (void *p, int size) +{ + SIZE_T done; + HANDLE h = OpenProcess (PROCESS_VM_READ, FALSE, GetCurrentProcessId ()); + + if (h) + { + unsigned char *buf = alloca (size); + int retval = ReadProcessMemory (h, p, buf, size, &done); + + CloseHandle (h); + return retval; + } + else + return -1; +} + static char startup_dir[MAXPATHLEN]; /* Get the current working directory. */ -- 2.39.2