Skip to content

Commit 629d57e

Browse files
committed
Auto merge of rust-lang#3574 - RalfJung:deps, r=RalfJung
reduce test_dependencies Also add comments for why we need all these 3 random functions for Windows, and the old Linux syscall interface.
2 parents e43458c + a5baa15 commit 629d57e

File tree

6 files changed

+17
-163
lines changed

6 files changed

+17
-163
lines changed

src/tools/miri/src/shims/unix/linux/foreign_items.rs

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,24 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
117117
// `libc::syscall(NR_GETRANDOM, buf.as_mut_ptr(), buf.len(), GRND_NONBLOCK)`
118118
// is called if a `HashMap` is created the regular way (e.g. HashMap<K, V>).
119119
id if id == sys_getrandom => {
120+
// Used by getrandom 0.1
120121
// The first argument is the syscall id, so skip over it.
121122
if args.len() < 4 {
122123
throw_ub_format!(
123124
"incorrect number of arguments for `getrandom` syscall: got {}, expected at least 4",
124125
args.len()
125126
);
126127
}
127-
getrandom(this, &args[1], &args[2], &args[3], dest)?;
128+
129+
let ptr = this.read_pointer(&args[1])?;
130+
let len = this.read_target_usize(&args[2])?;
131+
// The only supported flags are GRND_RANDOM and GRND_NONBLOCK,
132+
// neither of which have any effect on our current PRNG.
133+
// See <https://github.com/rust-lang/rust/pull/79196> for a discussion of argument sizes.
134+
let _flags = this.read_scalar(&args[3])?.to_i32();
135+
136+
this.gen_random(ptr, len)?;
137+
this.write_scalar(Scalar::from_target_usize(len, this), dest)?;
128138
}
129139
// `futex` is used by some synchronization primitives.
130140
id if id == sys_futex => {
@@ -196,24 +206,3 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
196206
Ok(EmulateItemResult::NeedsJumping)
197207
}
198208
}
199-
200-
// Shims the linux `getrandom` syscall.
201-
fn getrandom<'tcx>(
202-
this: &mut MiriInterpCx<'_, 'tcx>,
203-
ptr: &OpTy<'tcx, Provenance>,
204-
len: &OpTy<'tcx, Provenance>,
205-
flags: &OpTy<'tcx, Provenance>,
206-
dest: &MPlaceTy<'tcx, Provenance>,
207-
) -> InterpResult<'tcx> {
208-
let ptr = this.read_pointer(ptr)?;
209-
let len = this.read_target_usize(len)?;
210-
211-
// The only supported flags are GRND_RANDOM and GRND_NONBLOCK,
212-
// neither of which have any effect on our current PRNG.
213-
// See <https://github.com/rust-lang/rust/pull/79196> for a discussion of argument sizes.
214-
let _flags = this.read_scalar(flags)?.to_i32();
215-
216-
this.gen_random(ptr, len)?;
217-
this.write_scalar(Scalar::from_target_usize(len, this), dest)?;
218-
Ok(())
219-
}

src/tools/miri/src/shims/windows/foreign_items.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
513513
throw_machine_stop!(TerminationInfo::Exit { code: code.into(), leak_check: false });
514514
}
515515
"SystemFunction036" => {
516+
// used by getrandom 0.1
516517
// This is really 'RtlGenRandom'.
517518
let [ptr, len] =
518519
this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?;
@@ -522,6 +523,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
522523
this.write_scalar(Scalar::from_bool(true), dest)?;
523524
}
524525
"ProcessPrng" => {
526+
// used by `std`
525527
let [ptr, len] =
526528
this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?;
527529
let ptr = this.read_pointer(ptr)?;
@@ -530,6 +532,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
530532
this.write_scalar(Scalar::from_i32(1), dest)?;
531533
}
532534
"BCryptGenRandom" => {
535+
// used by getrandom 0.2
533536
let [algorithm, ptr, len, flags] =
534537
this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?;
535538
let algorithm = this.read_scalar(algorithm)?;

src/tools/miri/test_dependencies/Cargo.lock

Lines changed: 0 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@ version = "1.0.2"
1717
source = "registry+https://github.com/rust-lang/crates.io-index"
1818
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
1919

20-
[[package]]
21-
name = "autocfg"
22-
version = "1.3.0"
23-
source = "registry+https://github.com/rust-lang/crates.io-index"
24-
checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0"
25-
2620
[[package]]
2721
name = "backtrace"
2822
version = "0.3.71"
@@ -50,12 +44,6 @@ version = "3.16.0"
5044
source = "registry+https://github.com/rust-lang/crates.io-index"
5145
checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c"
5246

53-
[[package]]
54-
name = "bytes"
55-
version = "1.6.0"
56-
source = "registry+https://github.com/rust-lang/crates.io-index"
57-
checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9"
58-
5947
[[package]]
6048
name = "cc"
6149
version = "1.0.96"
@@ -141,16 +129,6 @@ version = "0.4.13"
141129
source = "registry+https://github.com/rust-lang/crates.io-index"
142130
checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c"
143131

144-
[[package]]
145-
name = "lock_api"
146-
version = "0.4.12"
147-
source = "registry+https://github.com/rust-lang/crates.io-index"
148-
checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17"
149-
dependencies = [
150-
"autocfg",
151-
"scopeguard",
152-
]
153-
154132
[[package]]
155133
name = "log"
156134
version = "0.4.21"
@@ -192,7 +170,6 @@ dependencies = [
192170
"libc",
193171
"num_cpus",
194172
"page_size",
195-
"rand",
196173
"tempfile",
197174
"tokio",
198175
"windows-sys 0.52.0",
@@ -233,41 +210,12 @@ dependencies = [
233210
"winapi",
234211
]
235212

236-
[[package]]
237-
name = "parking_lot"
238-
version = "0.12.2"
239-
source = "registry+https://github.com/rust-lang/crates.io-index"
240-
checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb"
241-
dependencies = [
242-
"lock_api",
243-
"parking_lot_core",
244-
]
245-
246-
[[package]]
247-
name = "parking_lot_core"
248-
version = "0.9.10"
249-
source = "registry+https://github.com/rust-lang/crates.io-index"
250-
checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8"
251-
dependencies = [
252-
"cfg-if",
253-
"libc",
254-
"redox_syscall",
255-
"smallvec",
256-
"windows-targets 0.52.5",
257-
]
258-
259213
[[package]]
260214
name = "pin-project-lite"
261215
version = "0.2.14"
262216
source = "registry+https://github.com/rust-lang/crates.io-index"
263217
checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02"
264218

265-
[[package]]
266-
name = "ppv-lite86"
267-
version = "0.2.17"
268-
source = "registry+https://github.com/rust-lang/crates.io-index"
269-
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
270-
271219
[[package]]
272220
name = "proc-macro2"
273221
version = "1.0.81"
@@ -286,45 +234,6 @@ dependencies = [
286234
"proc-macro2",
287235
]
288236

289-
[[package]]
290-
name = "rand"
291-
version = "0.8.5"
292-
source = "registry+https://github.com/rust-lang/crates.io-index"
293-
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
294-
dependencies = [
295-
"libc",
296-
"rand_chacha",
297-
"rand_core",
298-
]
299-
300-
[[package]]
301-
name = "rand_chacha"
302-
version = "0.3.1"
303-
source = "registry+https://github.com/rust-lang/crates.io-index"
304-
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
305-
dependencies = [
306-
"ppv-lite86",
307-
"rand_core",
308-
]
309-
310-
[[package]]
311-
name = "rand_core"
312-
version = "0.6.4"
313-
source = "registry+https://github.com/rust-lang/crates.io-index"
314-
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
315-
dependencies = [
316-
"getrandom 0.2.14",
317-
]
318-
319-
[[package]]
320-
name = "redox_syscall"
321-
version = "0.5.1"
322-
source = "registry+https://github.com/rust-lang/crates.io-index"
323-
checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e"
324-
dependencies = [
325-
"bitflags",
326-
]
327-
328237
[[package]]
329238
name = "rustc-demangle"
330239
version = "0.1.23"
@@ -344,27 +253,6 @@ dependencies = [
344253
"windows-sys 0.52.0",
345254
]
346255

347-
[[package]]
348-
name = "scopeguard"
349-
version = "1.2.0"
350-
source = "registry+https://github.com/rust-lang/crates.io-index"
351-
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
352-
353-
[[package]]
354-
name = "signal-hook-registry"
355-
version = "1.4.2"
356-
source = "registry+https://github.com/rust-lang/crates.io-index"
357-
checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1"
358-
dependencies = [
359-
"libc",
360-
]
361-
362-
[[package]]
363-
name = "smallvec"
364-
version = "1.13.2"
365-
source = "registry+https://github.com/rust-lang/crates.io-index"
366-
checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67"
367-
368256
[[package]]
369257
name = "socket2"
370258
version = "0.5.7"
@@ -405,13 +293,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
405293
checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787"
406294
dependencies = [
407295
"backtrace",
408-
"bytes",
409296
"libc",
410297
"mio",
411298
"num_cpus",
412-
"parking_lot",
413299
"pin-project-lite",
414-
"signal-hook-registry",
415300
"socket2",
416301
"tokio-macros",
417302
"windows-sys 0.48.0",

src/tools/miri/test_dependencies/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@ tempfile = "3"
1515

1616
getrandom_01 = { package = "getrandom", version = "0.1" }
1717
getrandom_02 = { package = "getrandom", version = "0.2", features = ["js"] }
18-
rand = { version = "0.8", features = ["small_rng"] }
1918

2019
[target.'cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))'.dependencies]
2120
page_size = "0.6"
22-
tokio = { version = "1.24", features = ["full"] }
21+
tokio = { version = "1.24", features = ["macros", "rt-multi-thread", "time", "net"] }
2322

2423
[target.'cfg(windows)'.dependencies]
2524
windows-sys = { version = "0.52", features = [ "Win32_Foundation", "Win32_System_Threading" ] }

src/tools/miri/tests/pass-dep/getrandom.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
// mac-os `getrandom_01` does some pointer shenanigans
22
//@compile-flags: -Zmiri-permissive-provenance
3+
//@revisions: isolation no_isolation
4+
//@[no_isolation]compile-flags: -Zmiri-disable-isolation
35

46
/// Test direct calls of getrandom 0.1 and 0.2.
5-
/// Make sure they work even with isolation enabled (i.e., we do not hit a file-based fallback path).
67
fn main() {
78
let mut data = vec![0; 16];
89
getrandom_01::getrandom(&mut data).unwrap();

src/tools/miri/tests/pass-dep/rand.rs

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)