@@ -22,8 +22,10 @@ use crate::sys_common::{AsInner, FromInner, IntoInner};
22
22
/// so it can be used in FFI in places where a handle is passed as an argument,
23
23
/// it is not captured or consumed.
24
24
///
25
- /// Note that it *may* have the value `INVALID_HANDLE_VALUE` (-1), which is
26
- /// sometimes a valid handle value. See [here] for the full story.
25
+ /// Note that it *may* have the value `-1`, which in `BorrowedHandle` always
26
+ /// represents a valid handle value, such as [the current process handle], and
27
+ /// not `INVALID_HANDLE_VALUE`, despite the two having the same value. See
28
+ /// [here] for the full story.
27
29
///
28
30
/// And, it *may* have the value `NULL` (0), which can occur when consoles are
29
31
/// detached from processes, or when `windows_subsystem` is used.
@@ -33,6 +35,7 @@ use crate::sys_common::{AsInner, FromInner, IntoInner};
33
35
/// handle, which is then borrowed under the same lifetime.
34
36
///
35
37
/// [here]: https://devblogs.microsoft.com/oldnewthing/20040302-00/?p=40443
38
+ /// [the current process handle]: https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-getcurrentprocess#remarks
36
39
#[ derive( Copy , Clone ) ]
37
40
#[ repr( transparent) ]
38
41
#[ unstable( feature = "io_safety" , issue = "87074" ) ]
@@ -45,8 +48,10 @@ pub struct BorrowedHandle<'handle> {
45
48
///
46
49
/// This closes the handle on drop.
47
50
///
48
- /// Note that it *may* have the value `INVALID_HANDLE_VALUE` (-1), which is
49
- /// sometimes a valid handle value. See [here] for the full story.
51
+ /// Note that it *may* have the value `-1`, which in `OwnedHandle` always
52
+ /// represents a valid handle value, such as [the current process handle], and
53
+ /// not `INVALID_HANDLE_VALUE`, despite the two having the same value. See
54
+ /// [here] for the full story.
50
55
///
51
56
/// And, it *may* have the value `NULL` (0), which can occur when consoles are
52
57
/// detached from processes, or when `windows_subsystem` is used.
@@ -59,6 +64,7 @@ pub struct BorrowedHandle<'handle> {
59
64
/// [`RegCloseKey`]: https://docs.microsoft.com/en-us/windows/win32/api/winreg/nf-winreg-regclosekey
60
65
///
61
66
/// [here]: https://devblogs.microsoft.com/oldnewthing/20040302-00/?p=40443
67
+ /// [the current process handle]: https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-getcurrentprocess#remarks
62
68
#[ repr( transparent) ]
63
69
#[ unstable( feature = "io_safety" , issue = "87074" ) ]
64
70
pub struct OwnedHandle {
@@ -75,11 +81,13 @@ pub struct OwnedHandle {
75
81
/// `NULL`. This ensures that such FFI calls cannot start using the handle without
76
82
/// checking for `NULL` first.
77
83
///
78
- /// This type considers any value other than `NULL` to be valid, including `INVALID_HANDLE_VALUE`.
79
- /// This is because APIs that use `NULL` as their sentry value don't treat `INVALID_HANDLE_VALUE`
80
- /// as special .
84
+ /// This type may hold any handle value that [`OwnedHandle`] may hold. As with `OwnedHandle`, when
85
+ /// it holds `-1`, that value is interpreted as a valid handle value, such as
86
+ /// [the current process handle], and not `INVALID_HANDLE_VALUE` .
81
87
///
82
- /// If this holds a valid handle, it will close the handle on drop.
88
+ /// If this holds a non-null handle, it will close the handle on drop.
89
+ ///
90
+ /// [the current process handle]: https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-getcurrentprocess#remarks
83
91
#[ repr( transparent) ]
84
92
#[ unstable( feature = "io_safety" , issue = "87074" ) ]
85
93
#[ derive( Debug ) ]
@@ -95,11 +103,10 @@ pub struct HandleOrNull(OwnedHandle);
95
103
/// `INVALID_HANDLE_VALUE`. This ensures that such FFI calls cannot start using the handle without
96
104
/// checking for `INVALID_HANDLE_VALUE` first.
97
105
///
98
- /// This type considers any value other than `INVALID_HANDLE_VALUE` to be valid, including `NULL`.
99
- /// This is because APIs that use `INVALID_HANDLE_VALUE` as their sentry value may return `NULL`
100
- /// under `windows_subsystem = "windows"` or other situations where I/O devices are detached.
106
+ /// This type may hold any handle value that [`OwnedHandle`] may hold, except that when it holds
107
+ /// `-1`, that value is interpreted to mean `INVALID_HANDLE_VALUE`.
101
108
///
102
- /// If this holds a valid handle, it will close the handle on drop.
109
+ /// If holds a handle other than `INVALID_HANDLE_VALUE` , it will close the handle on drop.
103
110
#[ repr( transparent) ]
104
111
#[ unstable( feature = "io_safety" , issue = "87074" ) ]
105
112
#[ derive( Debug ) ]
0 commit comments