Skip to content

Commit 116ac1f

Browse files
committed
Properly untag fd in FileDesc::into_raw.
1 parent e9d4540 commit 116ac1f

File tree

1 file changed

+25
-0
lines changed
  • library/std/src/sys/unix

1 file changed

+25
-0
lines changed

library/std/src/sys/unix/fd.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,22 @@ mod android {
4545
}
4646
}
4747

48+
pub fn untag(&mut self, fd: c_int) {
49+
weak!(fn android_fdsan_exchange_owner_tag(c_int, u64, u64) -> u64);
50+
match android_fdsan_exchange_owner_tag.get() {
51+
Some(f) => {
52+
let prev = unsafe { f(fd, self.0, 0) };
53+
if prev != self.0 {
54+
panic!("attempted to release ownership of not-owned file descriptor");
55+
}
56+
}
57+
58+
None => {}
59+
}
60+
61+
self.0 = 0;
62+
}
63+
4864
pub fn close(&mut self, fd: c_int) {
4965
weak!(fn android_fdsan_close_with_tag(c_int, u64) -> c_int);
5066
match android_fdsan_close_with_tag.get() {
@@ -99,6 +115,15 @@ impl FileDesc {
99115
}
100116

101117
/// Extracts the actual file descriptor without closing it.
118+
#[cfg(target_os = "android")]
119+
pub fn into_raw(mut self) -> c_int {
120+
let fd = self.fd;
121+
self.tag.untag(fd);
122+
mem::forget(self);
123+
fd
124+
}
125+
126+
#[cfg(not(target_os = "android"))]
102127
pub fn into_raw(self) -> c_int {
103128
let fd = self.fd;
104129
mem::forget(self);

0 commit comments

Comments
 (0)