Skip to content

Commit b0bffbb

Browse files
committed
compiles
1 parent 32b27f5 commit b0bffbb

File tree

6 files changed

+43
-11
lines changed

6 files changed

+43
-11
lines changed

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@ authors = ["Mikail Bagishov <bagishov.mikail@yandex.ru>"]
55
edition = "2018"
66

77
[dependencies]
8-
98
rand = "0.7.3"
109
serde = { version = "1.0.106", features = ["derive"] }
11-
serde_json = "1.0.51"
1210
backtrace = "0.3.46"
1311
thiserror = "1.0.19"
1412
anyhow = "1.0.32"
@@ -19,6 +17,7 @@ procfs = "0.7.8"
1917
nix = {git = "https://github.com/nix-rust/nix"}
2018
libc = "0.2.68"
2119
errno = "0.2.5"
20+
serde_json = "1.0.51"
2221

2322
[target.'cfg(target_os="windows")'.dependencies]
2423
winapi = { version = "0.3.9", features = ["std", "processthreadsapi", "jobapi2", "errhandlingapi",

minion-ffi/src/lib.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#![cfg_attr(minion_nightly, warn(unsafe_op_in_unsafe_fn))]
33
use minion::{self};
44
use std::{
5-
ffi::{CStr, OsStr, OsString},
5+
ffi::{CStr, OsString},
66
mem::{self},
77
os::raw::c_char,
88
};
@@ -42,11 +42,23 @@ pub enum WaitOutcome {
4242

4343
/// # Safety
4444
/// `buf` must be valid, readable pointer
45+
#[cfg(target_os = "linux")]
4546
unsafe fn get_string(buf: *const c_char) -> OsString {
4647
use std::os::unix::ffi::OsStrExt;
4748
let buf = unsafe { CStr::from_ptr(buf) };
4849
let buf = buf.to_bytes();
49-
let s = OsStr::from_bytes(buf);
50+
let s = std::ffi::OsStr::from_bytes(buf);
51+
s.to_os_string()
52+
}
53+
/// # Safety
54+
/// `buf` must be valid, readable pointer
55+
#[cfg(target_os = "windows")]
56+
unsafe fn get_string(buf: *const c_char) -> OsString {
57+
use std::os::windows::ffi::OsStringExt;
58+
let buf = unsafe { CStr::from_ptr(buf) };
59+
let buf = buf.to_bytes();
60+
assert!(buf.len() % 2 == 0);
61+
let s = OsString::from_wide(unsafe { buf.align_to::<u16>().1 });
5062
s.to_os_string()
5163
}
5264

minion-tests/src/tests/simple.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,16 @@ impl crate::TestCase for TTlFork {
5353
#[cfg(target_os = "linux")]
5454
nix::unistd::fork().unwrap();
5555
#[cfg(target_os = "winfows")]
56-
winapi::um::
56+
unsafe {
57+
winapi::um::processthreadsapi::CreateThread(
58+
std::ptr::null_mut(),
59+
0,
60+
exceed_time_limit,
61+
self,
62+
0,
63+
std::ptr::null_mut(),
64+
);
65+
}
5766
exceed_time_limit()
5867
}
5968
fn check(&self, cp: &mut dyn ChildProcess, _: &dyn Sandbox) {
@@ -74,7 +83,12 @@ impl crate::TestCase for TIdle {
7483
checks that it still will be killed"
7584
}
7685
fn test(&self) -> ! {
86+
#[cfg(target_os = "linux")]
7787
nix::unistd::sleep(1_000_000_000);
88+
#[cfg(target_os = "windows")]
89+
unsafe {
90+
winapi::um::synchapi::Sleep(1_000_000_000);
91+
};
7892
std::process::exit(0)
7993
}
8094
fn check(&self, cp: &mut dyn ChildProcess, _: &dyn Sandbox) {
@@ -150,6 +164,7 @@ impl crate::TestCase for TSecurity {
150164
fn description(&self) -> &'static str {
151165
"verifies that isolated program can not make certain bad things"
152166
}
167+
#[cfg(target_os = "linux")]
153168
fn test(&self) -> ! {
154169
// Check we can not read pid1's environment.
155170
let err = std::fs::read("/proc/1/environ").unwrap_err();
@@ -167,6 +182,11 @@ impl crate::TestCase for TSecurity {
167182
assert!(matches!(err, nix::Error::Sys(nix::errno::Errno::EPERM)));
168183
std::process::exit(24)
169184
}
185+
#[cfg(target_os = "windows")]
186+
fn test(&self) -> ! {
187+
// TODO
188+
std::process::exit(24)
189+
}
170190
fn check(&self, cp: &mut dyn ChildProcess, _sb: &dyn Sandbox) {
171191
super::assert_exit_code(cp, 24);
172192
super::assert_empty(&mut cp.stdout().unwrap());

src/erased.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ pub trait ChildProcess {
5858
&self,
5959
timeout: Option<std::time::Duration>,
6060
) -> anyhow::Result<crate::WaitOutcome>;
61-
fn poll(&self) -> anyhow::Result<()>;
6261
fn is_finished(&self) -> bool;
6362
}
6463

@@ -90,9 +89,6 @@ impl<C: crate::ChildProcess> ChildProcess for C {
9089
) -> anyhow::Result<crate::WaitOutcome> {
9190
self.wait_for_exit(timeout).map_err(Into::into)
9291
}
93-
fn poll(&self) -> anyhow::Result<()> {
94-
self.poll().map_err(Into::into)
95-
}
9692
fn is_finished(&self) -> bool {
9793
self.is_finished()
9894
}

src/windows.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ impl crate::Backend for WindowsBackend {
2727
type ChildProcess = child::WindowsChildProcess;
2828

2929
fn new_sandbox(&self, options: crate::SandboxOptions) -> Result<Self::Sandbox, Self::Error> {
30-
todo!()
30+
sandbox::WindowsSandbox::create()
3131
}
3232

3333
fn spawn(

src/windows/sandbox.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ pub struct WindowsSandbox {
1818
job: HANDLE,
1919
}
2020

21+
impl WindowsSandbox {
22+
pub(in crate::windows) fn create() -> Result<Self, Error> {
23+
todo!()
24+
}
25+
}
26+
2127
impl crate::Sandbox for WindowsSandbox {
2228
type Error = Error;
2329

@@ -78,7 +84,6 @@ impl crate::Sandbox for WindowsSandbox {
7884
let viol = info.ViolationLimitFlags & JOB_OBJECT_LIMIT_JOB_TIME;
7985
Ok(viol != 0)
8086
}
81-
8287
}
8388

8489
fn check_real_tle(&self) -> Result<bool, Self::Error> {

0 commit comments

Comments
 (0)