forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#3609 - tiif:feat/socketpair, r=RalfJung
Add socketpair shim Fixes rust-lang#3442 Design proposal: https://hackmd.io/`@tiif/Skhc1t0-C`
- Loading branch information
Showing
6 changed files
with
366 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/tools/miri/tests/fail-dep/libc/socketpair_read_blocking.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
//@ignore-target-windows: no libc socketpair on Windows | ||
|
||
// This is temporarily here because blocking on fd is not supported yet. | ||
// When blocking is eventually supported, this will be moved to pass-dep/libc/libc-socketpair | ||
|
||
fn main() { | ||
let mut fds = [-1, -1]; | ||
let _ = unsafe { libc::socketpair(libc::AF_UNIX, libc::SOCK_STREAM, 0, fds.as_mut_ptr()) }; | ||
// The read below will be blocked because the buffer is empty. | ||
let mut buf: [u8; 3] = [0; 3]; | ||
let _res = unsafe { libc::read(fds[1], buf.as_mut_ptr().cast(), buf.len() as libc::size_t) }; //~ERROR: blocking isn't supported | ||
} |
14 changes: 14 additions & 0 deletions
14
src/tools/miri/tests/fail-dep/libc/socketpair_read_blocking.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
error: unsupported operation: socketpair read: blocking isn't supported yet | ||
--> $DIR/socketpair_read_blocking.rs:LL:CC | ||
| | ||
LL | let _res = unsafe { libc::read(fds[1], buf.as_mut_ptr().cast(), buf.len() as libc::size_t) }; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ socketpair read: blocking isn't supported yet | ||
| | ||
= help: this is likely not a bug in the program; it indicates that the program performed an operation that Miri does not support | ||
= note: BACKTRACE: | ||
= note: inside `main` at $DIR/socketpair_read_blocking.rs:LL:CC | ||
|
||
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace | ||
|
||
error: aborting due to 1 previous error | ||
|
16 changes: 16 additions & 0 deletions
16
src/tools/miri/tests/fail-dep/libc/socketpair_write_blocking.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
//@ignore-target-windows: no libc socketpair on Windows | ||
// This is temporarily here because blocking on fd is not supported yet. | ||
// When blocking is eventually supported, this will be moved to pass-dep/libc/libc-socketpair | ||
fn main() { | ||
let mut fds = [-1, -1]; | ||
let _ = unsafe { libc::socketpair(libc::AF_UNIX, libc::SOCK_STREAM, 0, fds.as_mut_ptr()) }; | ||
// Write size > buffer capacity | ||
// Used up all the space in the buffer. | ||
let arr1: [u8; 212992] = [1; 212992]; | ||
let _ = unsafe { libc::write(fds[0], arr1.as_ptr() as *const libc::c_void, 212992) }; | ||
let data = "abc".as_bytes().as_ptr(); | ||
// The write below will be blocked as the buffer is full. | ||
let _ = unsafe { libc::write(fds[0], data as *const libc::c_void, 3) }; //~ERROR: blocking isn't supported | ||
let mut buf: [u8; 3] = [0; 3]; | ||
let _res = unsafe { libc::read(fds[1], buf.as_mut_ptr().cast(), buf.len() as libc::size_t) }; | ||
} |
14 changes: 14 additions & 0 deletions
14
src/tools/miri/tests/fail-dep/libc/socketpair_write_blocking.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
error: unsupported operation: socketpair write: blocking isn't supported yet | ||
--> $DIR/socketpair_write_blocking.rs:LL:CC | ||
| | ||
LL | let _ = unsafe { libc::write(fds[0], data as *const libc::c_void, 3) }; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ socketpair write: blocking isn't supported yet | ||
| | ||
= help: this is likely not a bug in the program; it indicates that the program performed an operation that Miri does not support | ||
= note: BACKTRACE: | ||
= note: inside `main` at $DIR/socketpair_write_blocking.rs:LL:CC | ||
|
||
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace | ||
|
||
error: aborting due to 1 previous error | ||
|
Oops, something went wrong.