From: Eli Zaretskii Date: Sat, 5 Aug 2006 13:01:10 +0000 (+0000) Subject: (w32_valid_pointer_p): New function. X-Git-Tag: emacs-pretest-22.0.90~1099 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=ed91b2add33be7f813979c8c64e5cd92758d75fc;p=emacs.git (w32_valid_pointer_p): New function. --- 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. */