Open Bug 1720523 Opened 3 years ago Updated 3 years ago

Make kInvalidProcessHandle and kInvalidProcessId more invalid

Categories

(Core :: IPC, enhancement, P3)

enhancement

Tracking

()

People

(Reporter: jld, Assigned: jld)

Details

ipc/glue/ProtocolUtils.h defines the cross-platform constants kInvalidProcessHandle and kInvalidProcessId`, but they're not as invalid as they should be:

  • On Windows the former is INVALID_HANDLE_VALUE, which is equal to GetCurrentProcess() (i.e., it's returned in error cases but when used as an argument it can indicate the current process, like (pid_t)0 on Unix); nullptr is better, assuming that it's not being used to check for errors.
  • On Unix, both types are pid_t and the “invalid” values are -1, which can indicate “all processes” (e.g., for kill). In this case 0 also isn't great because it can indicate the current process, and -N for N ≠ 1 means process group N. But the minimum value of the type should be safe because (assuming two's complement) it isn't the negation of any positive pid_t. But also, -1 is returned for errors, so the same caution about how it's used applies.

But also, there's code which implicitly converts from 0, and code which compares with both 0 and kInvalidProcessHandle, and code which compares only against 0. Arguably 0 is a better choice than those constants as currently defined, but that also ought to be cleaned up.

You need to log in before you can comment on or make changes to this bug.