# HG changeset patch # User Eli Zaretskii # Date 1154782870 0 # Node ID 95d41ccb4448137a6f6aa51b45979e6ac848179c # Parent 01c53aa90ed30cb69a0c653a7548a4fe61f27eb3 (w32_valid_pointer_p): New function. diff -r 01c53aa90ed3 -r 95d41ccb4448 src/w32.c --- a/src/w32.c Sat Aug 05 12:33:22 2006 +0000 +++ b/src/w32.c Sat Aug 05 13:01:10 2006 +0000 @@ -323,6 +323,28 @@ 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. */