Skip to content

Commit 1570486

Browse files
committed
Address code review
- Merge pthread_attr_getstack shim to unix/foreign_items.rs
1 parent e9ed909 commit 1570486

File tree

3 files changed

+23
-43
lines changed

3 files changed

+23
-43
lines changed

src/shims/unix/foreign_items.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,28 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
461461
this.write_null(dest)?;
462462
}
463463

464+
// Querying system information
465+
"pthread_attr_getstack" => {
466+
// We don't support "pthread_attr_setstack", so we just pretend all stacks have the same values here.
467+
let [attr_place, addr_place, size_place] =
468+
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
469+
this.deref_operand(attr_place)?;
470+
let addr_place = this.deref_operand(addr_place)?;
471+
let size_place = this.deref_operand(size_place)?;
472+
473+
this.write_scalar(
474+
Scalar::from_uint(STACK_ADDR, this.pointer_size()),
475+
&addr_place.into(),
476+
)?;
477+
this.write_scalar(
478+
Scalar::from_uint(STACK_SIZE, this.pointer_size()),
479+
&size_place.into(),
480+
)?;
481+
482+
// Return success (`0`).
483+
this.write_null(dest)?;
484+
}
485+
464486
| "signal"
465487
| "sigaltstack"
466488
if this.frame_in_std() => {

src/shims/unix/freebsd/foreign_items.rs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
1818
) -> InterpResult<'tcx, EmulateByNameResult<'mir, 'tcx>> {
1919
let this = self.eval_context_mut();
2020
match link_name.as_str() {
21-
// Querying system information
22-
"pthread_attr_getstack" => {
23-
// We don't support "pthread_attr_setstack", so we just pretend all stacks have the same values here.
24-
let [attr_place, addr_place, size_place] =
25-
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
26-
this.deref_operand(attr_place)?;
27-
let addr_place = this.deref_operand(addr_place)?;
28-
let size_place = this.deref_operand(size_place)?;
29-
30-
this.write_scalar(
31-
Scalar::from_uint(STACK_ADDR, this.pointer_size()),
32-
&addr_place.into(),
33-
)?;
34-
this.write_scalar(
35-
Scalar::from_uint(STACK_SIZE, this.pointer_size()),
36-
&size_place.into(),
37-
)?;
38-
39-
// Return success (`0`).
40-
this.write_null(dest)?;
41-
}
42-
4321
// Linux's `pthread_getattr_np` equivalent
4422
"pthread_attr_get_np" if this.frame_in_std() => {
4523
let [_thread, _attr] =

src/shims/unix/linux/foreign_items.rs

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -80,27 +80,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
8080
this.write_scalar(Scalar::from_i32(result), dest)?;
8181
}
8282

83-
// Querying system information
84-
"pthread_attr_getstack" => {
85-
// We don't support "pthread_attr_setstack", so we just pretend all stacks have the same values here.
86-
let [attr_place, addr_place, size_place] =
87-
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
88-
this.deref_operand(attr_place)?;
89-
let addr_place = this.deref_operand(addr_place)?;
90-
let size_place = this.deref_operand(size_place)?;
91-
92-
this.write_scalar(
93-
Scalar::from_uint(STACK_ADDR, this.pointer_size()),
94-
&addr_place.into(),
95-
)?;
96-
this.write_scalar(
97-
Scalar::from_uint(STACK_SIZE, this.pointer_size()),
98-
&size_place.into(),
99-
)?;
100-
101-
// Return success (`0`).
102-
this.write_null(dest)?;
103-
}
83+
10484

10585
// Threading
10686
"prctl" => {

0 commit comments

Comments
 (0)