Skip to content

Commit

Permalink
Address code review
Browse files Browse the repository at this point in the history
- Merge pthread_attr_getstack shim to unix/foreign_items.rs
  • Loading branch information
b-ncMN committed Jun 26, 2022
1 parent aaa8ebb commit 84a0278
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 43 deletions.
22 changes: 22 additions & 0 deletions src/shims/unix/foreign_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,28 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
this.write_null(dest)?;
}

// Querying system information
"pthread_attr_getstack" => {
// We don't support "pthread_attr_setstack", so we just pretend all stacks have the same values here.
let [attr_place, addr_place, size_place] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
this.deref_operand(attr_place)?;
let addr_place = this.deref_operand(addr_place)?;
let size_place = this.deref_operand(size_place)?;

this.write_scalar(
Scalar::from_uint(STACK_ADDR, this.pointer_size()),
&addr_place.into(),
)?;
this.write_scalar(
Scalar::from_uint(STACK_SIZE, this.pointer_size()),
&size_place.into(),
)?;

// Return success (`0`).
this.write_null(dest)?;
}

| "signal"
| "sigaltstack"
if this.frame_in_std() => {
Expand Down
22 changes: 0 additions & 22 deletions src/shims/unix/freebsd/foreign_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
) -> InterpResult<'tcx, EmulateByNameResult<'mir, 'tcx>> {
let this = self.eval_context_mut();
match link_name.as_str() {
// Querying system information
"pthread_attr_getstack" => {
// We don't support "pthread_attr_setstack", so we just pretend all stacks have the same values here.
let [attr_place, addr_place, size_place] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
this.deref_operand(attr_place)?;
let addr_place = this.deref_operand(addr_place)?;
let size_place = this.deref_operand(size_place)?;

this.write_scalar(
Scalar::from_uint(STACK_ADDR, this.pointer_size()),
&addr_place.into(),
)?;
this.write_scalar(
Scalar::from_uint(STACK_SIZE, this.pointer_size()),
&size_place.into(),
)?;

// Return success (`0`).
this.write_null(dest)?;
}

// Linux's `pthread_getattr_np` equivalent
"pthread_attr_get_np" if this.frame_in_std() => {
let [_thread, _attr] =
Expand Down
22 changes: 1 addition & 21 deletions src/shims/unix/linux/foreign_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,27 +80,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
this.write_scalar(Scalar::from_i32(result), dest)?;
}

// Querying system information
"pthread_attr_getstack" => {
// We don't support "pthread_attr_setstack", so we just pretend all stacks have the same values here.
let [attr_place, addr_place, size_place] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
this.deref_operand(attr_place)?;
let addr_place = this.deref_operand(addr_place)?;
let size_place = this.deref_operand(size_place)?;

this.write_scalar(
Scalar::from_uint(STACK_ADDR, this.pointer_size()),
&addr_place.into(),
)?;
this.write_scalar(
Scalar::from_uint(STACK_SIZE, this.pointer_size()),
&size_place.into(),
)?;

// Return success (`0`).
this.write_null(dest)?;
}


// Threading
"prctl" => {
Expand Down

0 comments on commit 84a0278

Please sign in to comment.