Skip to content

Commit cdf9d70

Browse files
author
Codex
committed
Fix windows job object build
1 parent f62b498 commit cdf9d70

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

‎Cargo.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ tokio = { version = "1", features = ["macros", "rt-multi-thread", "io-util", "io
2727
[target.'cfg(windows)'.dependencies]
2828
windows = { version = "0.61.1", features = [
2929
"Win32_Foundation",
30+
"Win32_Security",
3031
"Win32_System_JobObjects",
3132
"Win32_System_Threading",
3233
] }

‎src/services/environment/kernel/job.rs‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::app::Result;
1+
use crate::app::{Result, RuntimeError};
22
#[cfg(target_os = "windows")]
33
use std::collections::HashMap;
44
#[cfg(target_os = "windows")]
@@ -26,8 +26,9 @@ pub struct JobHandle {
2626
impl JobHandle {
2727
pub fn create() -> Result<Self> {
2828
unsafe {
29-
let handle = CreateJobObjectW(None, None)
30-
.map_err(|error| format!("Failed to create job object: {}", error))?;
29+
let handle = CreateJobObjectW(None, None).map_err(|error| {
30+
RuntimeError::Internal(format!("Failed to create job object: {}", error))
31+
})?;
3132

3233
let mut info: JOBOBJECT_EXTENDED_LIMIT_INFORMATION = std::mem::zeroed();
3334
info.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE;
@@ -38,7 +39,9 @@ impl JobHandle {
3839
&info as *const _ as *const _,
3940
std::mem::size_of::<JOBOBJECT_EXTENDED_LIMIT_INFORMATION>() as u32,
4041
)
41-
.map_err(|error| format!("Failed to set job object information: {}", error))?;
42+
.map_err(|error| {
43+
RuntimeError::Internal(format!("Failed to set job object information: {}", error))
44+
})?;
4245

4346
Ok(Self { handle })
4447
}
@@ -47,10 +50,13 @@ impl JobHandle {
4750
pub fn assign_process(&self, pid: u32) -> Result<()> {
4851
unsafe {
4952
let process_handle = OpenProcess(PROCESS_SET_QUOTA | PROCESS_TERMINATE, false, pid)
50-
.map_err(|error| format!("Failed to open process {}: {}", pid, error))?;
53+
.map_err(|error| {
54+
RuntimeError::Internal(format!("Failed to open process {}: {}", pid, error))
55+
})?;
5156

52-
AssignProcessToJobObject(self.handle, process_handle)
53-
.map_err(|error| format!("Failed to assign process to job: {}", error))?;
57+
AssignProcessToJobObject(self.handle, process_handle).map_err(|error| {
58+
RuntimeError::Internal(format!("Failed to assign process to job: {}", error))
59+
})?;
5460

5561
let _ = CloseHandle(process_handle);
5662
Ok(())

0 commit comments

Comments
 (0)