diff --git a/src/filelock.c b/src/filelock.c index d4a4747955a..43ede30975e 100644 --- a/src/filelock.c +++ b/src/filelock.c @@ -47,6 +47,7 @@ along with GNU Emacs. If not, see . */ #ifdef WINDOWSNT #include #include /* for fcntl */ +#include "w32common.h" #endif #ifndef MSDOS @@ -353,7 +354,7 @@ integer_prefixed (char const *s) /* Whether the integer P could identify an individual process. On most platforms this simply checks for positive pid_t, but on some - Microsoft ports our headers #define it to to some other test. */ + MS-Windows ports our headers #define it to to some other test. */ #ifndef VALID_PROCESS_ID # define VALID_PROCESS_ID(p) (0 < (p) && (p) <= TYPE_MAXIMUM (pid_t)) #endif diff --git a/src/w32common.h b/src/w32common.h index 9475481b64e..8a5c7c03bca 100644 --- a/src/w32common.h +++ b/src/w32common.h @@ -53,6 +53,8 @@ extern void cache_system_info (void); #ifdef WINDOWSNT /* Return a static buffer with the MS-Windows version string. */ extern char * w32_version_string (void); +extern bool w32_valid_process_id (intmax_t); +# define VALID_PROCESS_ID(p) w32_valid_process_id(p) #endif typedef void (* VOIDFNPTR) (void); diff --git a/src/w32proc.c b/src/w32proc.c index 55ead13647b..4d237992b14 100644 --- a/src/w32proc.c +++ b/src/w32proc.c @@ -2676,6 +2676,19 @@ count_children: return nr; } +/* This is called from filelock.c:current_lock_owner to validate a PID. + Return true if PID could identify a process on the current host, + false otherwise. */ +bool +w32_valid_process_id (intmax_t id) +{ + if (id == -1 || id == 0 /* always invalid */ + || id > UINT32_MAX /* PID is actually a DWORD */ + || id < INT32_MIN) /* Windows 9X can report negative PIDs */ + return false; + return true; +} + /* Substitute for certain kill () operations */ static BOOL CALLBACK