@@ -70,14 +70,17 @@ pub struct BorrowedFd<'fd> {
70
70
/// so it can be used in FFI in places where a handle is passed as an argument,
71
71
/// it is not captured or consumed, and it is never null.
72
72
///
73
- /// Note that it *may* have the value [`INVALID_HANDLE_VALUE`]. See [here] for
74
- /// the full story.
73
+ /// Note that it *may* have the value `-1`, which in `BorrowedHandle` always
74
+ /// represents a valid handle value, such as [the current process handle], and
75
+ /// not `INVALID_HANDLE_VALUE`, despite the two having the same value. See
76
+ /// [here] for the full story.
75
77
///
76
78
/// This type's `.to_owned()` implementation returns another `BorrowedHandle`
77
79
/// rather than an `OwnedHandle`. It just makes a trivial copy of the raw
78
80
/// handle, which is then borrowed under the same lifetime.
79
81
///
80
82
/// [here]: https://devblogs.microsoft.com/oldnewthing/20040302-00/?p=40443
83
+ /// [the current process handle]: https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-getcurrentprocess#remarks
81
84
#[ cfg( windows) ]
82
85
#[ derive( Copy , Clone ) ]
83
86
#[ repr( transparent) ]
@@ -187,8 +190,10 @@ impl OwnedFd {
187
190
///
188
191
/// This closes the handle on drop.
189
192
///
190
- /// Note that it *may* have the value `INVALID_HANDLE_VALUE` (-1), which is
191
- /// sometimes a valid handle value. See [here] for the full story.
193
+ /// Note that it *may* have the value `-1`, which in `OwnedHandle` always
194
+ /// represents a valid handle value, such as [the current process handle], and
195
+ /// not `INVALID_HANDLE_VALUE`, despite the two having the same value. See
196
+ /// [here] for the full story.
192
197
///
193
198
/// And, it *may* have the value `NULL` (0), which can occur when consoles are
194
199
/// detached from processes, or when `windows_subsystem` is used.
@@ -201,6 +206,7 @@ impl OwnedFd {
201
206
/// [`RegCloseKey`]: https://docs.microsoft.com/en-us/windows/win32/api/winreg/nf-winreg-regclosekey
202
207
///
203
208
/// [here]: https://devblogs.microsoft.com/oldnewthing/20040302-00/?p=40443
209
+ /// [the current process handle]: https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-getcurrentprocess#remarks
204
210
#[ cfg( windows) ]
205
211
#[ repr( transparent) ]
206
212
pub struct OwnedHandle {
@@ -375,11 +381,10 @@ impl OwnedSocket {
375
381
/// `INVALID_HANDLE_VALUE`. This ensures that such FFI calls cannot start using the handle without
376
382
/// checking for `INVALID_HANDLE_VALUE` first.
377
383
///
378
- /// This type concerns any value other than `INVALID_HANDLE_VALUE` to be valid, including `NULL`.
379
- /// This is because APIs that use `INVALID_HANDLE_VALUE` as their sentry value may return `NULL`
380
- /// under `windows_subsystem = "windows"` or other situations where I/O devices are detached.
384
+ /// This type may hold any handle value that [`OwnedHandle`] may hold, except that when it holds
385
+ /// `-1`, that value is interpreted to mean `INVALID_HANDLE_VALUE`.
381
386
///
382
- /// If this holds a valid handle, it will close the handle on drop.
387
+ /// If holds a handle other than `INVALID_HANDLE_VALUE` , it will close the handle on drop.
383
388
#[ cfg( windows) ]
384
389
#[ repr( transparent) ]
385
390
#[ derive( Debug ) ]
@@ -395,11 +400,13 @@ pub struct HandleOrInvalid(RawHandle);
395
400
/// `NULL`. This ensures that such FFI calls cannot start using the handle without
396
401
/// checking for `NULL` first.
397
402
///
398
- /// This type concerns any value other than `NULL` to be valid, including `INVALID_HANDLE_VALUE`.
399
- /// This is because APIs that use `NULL` as their sentry value don't treat `INVALID_HANDLE_VALUE`
400
- /// as special .
403
+ /// This type may hold any handle value that [`OwnedHandle`] may hold. As with `OwnedHandle`, when
404
+ /// it holds `-1`, that value is interpreted as a valid handle value, such as
405
+ /// [the current process handle], and not `INVALID_HANDLE_VALUE` .
401
406
///
402
- /// If this holds a valid handle, it will close the handle on drop.
407
+ /// If this holds a non-null handle, it will close the handle on drop.
408
+ ///
409
+ /// [the current process handle]: https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-getcurrentprocess#remarks
403
410
#[ cfg( windows) ]
404
411
#[ repr( transparent) ]
405
412
#[ derive( Debug ) ]
0 commit comments