Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
eb37bbce
R
Rust
项目概览
int
/
Rust
大约 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
eb37bbce
编写于
5月 19, 2022
作者:
D
Dan Gohman
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Document that `BorrowedFd` may be used to do a `dup`.
上级
a4cec974
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
29 addition
and
13 deletion
+29
-13
library/std/src/os/unix/io/mod.rs
library/std/src/os/unix/io/mod.rs
+19
-9
library/std/src/os/windows/io/handle.rs
library/std/src/os/windows/io/handle.rs
+3
-3
library/std/src/os/windows/io/mod.rs
library/std/src/os/windows/io/mod.rs
+6
-0
library/std/src/sys/windows/handle.rs
library/std/src/sys/windows/handle.rs
+1
-1
未找到文件。
library/std/src/os/unix/io/mod.rs
浏览文件 @
eb37bbce
...
...
@@ -26,20 +26,30 @@
//! that they don't outlive the resource they point to. These are safe to
//! use. `BorrowedFd` values may be used in APIs which provide safe access to
//! any system call except for:
//!
//! - `close`, because that would end the dynamic lifetime of the resource
//! without ending the lifetime of the file descriptor.
//!
//! - `dup2`/`dup3`, in the second argument, because this argument is
//! closed and assigned a new resource, which may break the assumptions
//! other code using that file descriptor.
//! This list doesn't include `mmap`, since `mmap` does do a proper borrow of
//! its file descriptor argument. That said, `mmap` is unsafe for other
//! reasons: it operates on raw pointers, and it can have undefined behavior if
//! the underlying storage is mutated. Mutations may come from other processes,
//! or from the same process if the API provides `BorrowedFd` access, since as
//! mentioned earlier, `BorrowedFd` values may be used in APIs which provide
//! safe access to any system call. Consequently, code using `mmap` and
//! presenting a safe API must take full responsibility for ensuring that safe
//! Rust code cannot evoke undefined behavior through it.
//!
//! `BorrowedFd` values may be used in APIs which provide safe access to `dup`
//! system calls, so types implementing `AsFd` or `From<OwnedFd>` should not
//! assume they always have exclusive access to the underlying file
//! description.
//!
//! `BorrowedFd` values may also be used with `mmap`, since `mmap` uses the
//! provided file descriptor in a manner similar to `dup` and does not require
//! the `BorrowedFd` passed to it to live for the lifetime of the resulting
//! mapping. That said, `mmap` is unsafe for other reasons: it operates on raw
//! pointers, and it can have undefined behavior if the underlying storage is
//! mutated. Mutations may come from other processes, or from the same process
//! if the API provides `BorrowedFd` access, since as mentioned earlier,
//! `BorrowedFd` values may be used in APIs which provide safe access to any
//! system call. Consequently, code using `mmap` and presenting a safe API must
//! take full responsibility for ensuring that safe Rust code cannot evoke
//! undefined behavior through it.
//!
//! Like boxes, `OwnedFd` values conceptually own the resource they point to,
//! and free (close) it when they are dropped.
...
...
library/std/src/os/windows/io/handle.rs
浏览文件 @
eb37bbce
...
...
@@ -189,7 +189,7 @@ pub(crate) fn duplicate(
access
:
c
::
DWORD
,
inherit
:
bool
,
options
:
c
::
DWORD
,
)
->
io
::
Result
<
Self
>
{
)
->
io
::
Result
<
OwnedHandle
>
{
let
handle
=
self
.as_raw_handle
();
// `Stdin`, `Stdout`, and `Stderr` can all hold null handles, such as
...
...
@@ -197,7 +197,7 @@ pub(crate) fn duplicate(
// if we passed it a null handle, but we can treat null as a valid
// handle which doesn't do any I/O, and allow it to be duplicated.
if
handle
.is_null
()
{
return
unsafe
{
Ok
(
Self
::
from_raw_handle
(
handle
))
};
return
unsafe
{
Ok
(
OwnedHandle
::
from_raw_handle
(
handle
))
};
}
let
mut
ret
=
ptr
::
null_mut
();
...
...
@@ -213,7 +213,7 @@ pub(crate) fn duplicate(
options
,
)
})
?
;
unsafe
{
Ok
(
Self
::
from_raw_handle
(
ret
))
}
unsafe
{
Ok
(
OwnedHandle
::
from_raw_handle
(
ret
))
}
}
}
...
...
library/std/src/os/windows/io/mod.rs
浏览文件 @
eb37bbce
...
...
@@ -36,6 +36,12 @@
//! dynamic lifetime of the resource without ending the lifetime of the
//! handle or socket.
//!
//! `BorrowedHandle` and `BorrowedSocket` values may be used in APIs which
//! provide safe access to `DuplicateHandle` and `WSADuplicateSocketW` and
//! related functions, so types implementing `AsHandle`, `AsSocket`,
//! `From<OwnedHandle>`, or `From<OwnedSocket>` should not assume they always
//! have exclusive access to the underlying object.
//!
//! Like boxes, `OwnedHandle` and `OwnedSocket` values conceptually own the
//! resource they point to, and free (close) it when they are dropped.
//!
...
...
library/std/src/sys/windows/handle.rs
浏览文件 @
eb37bbce
...
...
@@ -218,7 +218,7 @@ pub fn duplicate(
inherit
:
bool
,
options
:
c
::
DWORD
,
)
->
io
::
Result
<
Self
>
{
Ok
(
Self
(
self
.0
.duplicate
(
access
,
inherit
,
options
)
?
))
Ok
(
Self
(
self
.0
.
as_handle
()
.
duplicate
(
access
,
inherit
,
options
)
?
))
}
/// Performs a synchronous read.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录