Use rsix to make system calls in Wasmtime. (#3355)
* Use rsix to make system calls in Wasmtime. `rsix` is a system call wrapper crate that we use in `wasi-common`, which can provide the following advantages in the rest of Wasmtime: - It eliminates some `unsafe` blocks in Wasmtime's code. There's still an `unsafe` block in the library, but this way, the `unsafe` is factored out and clearly scoped. - And, it makes error handling more consistent, factoring out code for checking return values and `io::Error::last_os_error()`, and code that does `errno::set_errno(0)`. This doesn't cover *all* system calls; `rsix` doesn't implement signal-handling APIs, and this doesn't cover calls made through `std` or crates like `userfaultfd`, `rand`, and `region`.
This commit is contained in:
3
crates/cache/Cargo.toml
vendored
3
crates/cache/Cargo.toml
vendored
@@ -24,8 +24,7 @@ zstd = { version = "0.9", default-features = false }
|
||||
winapi = "0.3.7"
|
||||
|
||||
[target.'cfg(not(target_os = "windows"))'.dependencies]
|
||||
errno = "0.2.4"
|
||||
libc = "0.2.60"
|
||||
rsix = "0.23.0"
|
||||
|
||||
[dev-dependencies]
|
||||
filetime = "0.2.7"
|
||||
|
||||
22
crates/cache/src/worker.rs
vendored
22
crates/cache/src/worker.rs
vendored
@@ -256,19 +256,15 @@ impl WorkerThread {
|
||||
|
||||
const NICE_DELTA_FOR_BACKGROUND_TASKS: i32 = 3;
|
||||
|
||||
errno::set_errno(errno::Errno(0));
|
||||
let current_nice = unsafe { libc::nice(NICE_DELTA_FOR_BACKGROUND_TASKS) };
|
||||
let errno_val = errno::errno().0;
|
||||
|
||||
if errno_val != 0 {
|
||||
warn!(
|
||||
"Failed to lower worker thread priority. It might affect application performance. \
|
||||
errno: {}",
|
||||
errno_val
|
||||
);
|
||||
} else {
|
||||
debug!("New nice value of worker thread: {}", current_nice);
|
||||
}
|
||||
match rsix::process::nice(NICE_DELTA_FOR_BACKGROUND_TASKS) {
|
||||
Ok(current_nice) => {
|
||||
debug!("New nice value of worker thread: {}", current_nice);
|
||||
}
|
||||
Err(err) => {
|
||||
warn!(
|
||||
"Failed to lower worker thread priority ({:?}). It might affect application performance.", err);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/// Increases the usage counter and recompresses the file
|
||||
|
||||
Reference in New Issue
Block a user