avoid some unnecessary Scalar-i32-Scalar roundtrips

This commit is contained in:
Ralf Jung 2024-04-23 10:01:00 +02:00
parent ccb43b6a95
commit ccb87f1baa
2 changed files with 10 additions and 10 deletions

View File

@ -23,7 +23,7 @@ fn mremap(
// old_address must be a multiple of the page size // old_address must be a multiple of the page size
#[allow(clippy::arithmetic_side_effects)] // PAGE_SIZE is nonzero #[allow(clippy::arithmetic_side_effects)] // PAGE_SIZE is nonzero
if old_address.addr().bytes() % this.machine.page_size != 0 || new_size == 0 { if old_address.addr().bytes() % this.machine.page_size != 0 || new_size == 0 {
this.set_last_error(Scalar::from_i32(this.eval_libc_i32("EINVAL")))?; this.set_last_error(this.eval_libc("EINVAL"))?;
return Ok(this.eval_libc("MAP_FAILED")); return Ok(this.eval_libc("MAP_FAILED"));
} }
@ -37,7 +37,7 @@ fn mremap(
if flags & this.eval_libc_i32("MREMAP_MAYMOVE") == 0 { if flags & this.eval_libc_i32("MREMAP_MAYMOVE") == 0 {
// We only support MREMAP_MAYMOVE, so not passing the flag is just a failure // We only support MREMAP_MAYMOVE, so not passing the flag is just a failure
this.set_last_error(Scalar::from_i32(this.eval_libc_i32("EINVAL")))?; this.set_last_error(this.eval_libc("EINVAL"))?;
return Ok(this.eval_libc("MAP_FAILED")); return Ok(this.eval_libc("MAP_FAILED"));
} }

View File

@ -53,11 +53,11 @@ fn mmap(
// First, we do some basic argument validation as required by mmap // First, we do some basic argument validation as required by mmap
if (flags & (map_private | map_shared)).count_ones() != 1 { if (flags & (map_private | map_shared)).count_ones() != 1 {
this.set_last_error(Scalar::from_i32(this.eval_libc_i32("EINVAL")))?; this.set_last_error(this.eval_libc("EINVAL"))?;
return Ok(this.eval_libc("MAP_FAILED")); return Ok(this.eval_libc("MAP_FAILED"));
} }
if length == 0 { if length == 0 {
this.set_last_error(Scalar::from_i32(this.eval_libc_i32("EINVAL")))?; this.set_last_error(this.eval_libc("EINVAL"))?;
return Ok(this.eval_libc("MAP_FAILED")); return Ok(this.eval_libc("MAP_FAILED"));
} }
@ -77,7 +77,7 @@ fn mmap(
// //
// Miri doesn't support MAP_FIXED or any any protections other than PROT_READ|PROT_WRITE. // Miri doesn't support MAP_FIXED or any any protections other than PROT_READ|PROT_WRITE.
if flags & map_fixed != 0 || prot != prot_read | prot_write { if flags & map_fixed != 0 || prot != prot_read | prot_write {
this.set_last_error(Scalar::from_i32(this.eval_libc_i32("ENOTSUP")))?; this.set_last_error(this.eval_libc("ENOTSUP"))?;
return Ok(this.eval_libc("MAP_FAILED")); return Ok(this.eval_libc("MAP_FAILED"));
} }
@ -96,11 +96,11 @@ fn mmap(
let align = this.machine.page_align(); let align = this.machine.page_align();
let Some(map_length) = length.checked_next_multiple_of(this.machine.page_size) else { let Some(map_length) = length.checked_next_multiple_of(this.machine.page_size) else {
this.set_last_error(Scalar::from_i32(this.eval_libc_i32("EINVAL")))?; this.set_last_error(this.eval_libc("EINVAL"))?;
return Ok(this.eval_libc("MAP_FAILED")); return Ok(this.eval_libc("MAP_FAILED"));
}; };
if map_length > this.target_usize_max() { if map_length > this.target_usize_max() {
this.set_last_error(Scalar::from_i32(this.eval_libc_i32("EINVAL")))?; this.set_last_error(this.eval_libc("EINVAL"))?;
return Ok(this.eval_libc("MAP_FAILED")); return Ok(this.eval_libc("MAP_FAILED"));
} }
@ -131,16 +131,16 @@ fn munmap(
// as a dealloc. // as a dealloc.
#[allow(clippy::arithmetic_side_effects)] // PAGE_SIZE is nonzero #[allow(clippy::arithmetic_side_effects)] // PAGE_SIZE is nonzero
if addr.addr().bytes() % this.machine.page_size != 0 { if addr.addr().bytes() % this.machine.page_size != 0 {
this.set_last_error(Scalar::from_i32(this.eval_libc_i32("EINVAL")))?; this.set_last_error(this.eval_libc("EINVAL"))?;
return Ok(Scalar::from_i32(-1)); return Ok(Scalar::from_i32(-1));
} }
let Some(length) = length.checked_next_multiple_of(this.machine.page_size) else { let Some(length) = length.checked_next_multiple_of(this.machine.page_size) else {
this.set_last_error(Scalar::from_i32(this.eval_libc_i32("EINVAL")))?; this.set_last_error(this.eval_libc("EINVAL"))?;
return Ok(Scalar::from_i32(-1)); return Ok(Scalar::from_i32(-1));
}; };
if length > this.target_usize_max() { if length > this.target_usize_max() {
this.set_last_error(Scalar::from_i32(this.eval_libc_i32("EINVAL")))?; this.set_last_error(this.eval_libc("EINVAL"))?;
return Ok(this.eval_libc("MAP_FAILED")); return Ok(this.eval_libc("MAP_FAILED"));
} }