Skip to content

Commit e8f7f2a

Browse files
committed
procthreadattrlisf no
1 parent 94358e3 commit e8f7f2a

File tree

6 files changed

+92
-20
lines changed

6 files changed

+92
-20
lines changed

.github/workflows/rust.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,14 @@ jobs:
9191
- name: Collect logs
9292
if: always()
9393
run: |
94-
mkdir /tmp/logs
95-
cp ./strace* /tmp/logs
94+
ls
95+
mkdir D:/ci-logs
96+
cp ./strace* D:/ci-logs
9697
- uses: actions/upload-artifact@v1
9798
if: always()
9899
with:
99-
path: /tmp/logs
100-
name: tests-trace
100+
path: D:/ci-logs
101+
name: tests-ntcalls
101102

102103
nightly-checks:
103104
runs-on: ubuntu-latest

ci/windows.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ if ($LASTEXITCODE -ne 0) {
1919

2020
Write-Output "::group::Running tests"
2121
$env:RUST_BACKTRACE = 1
22-
./out/minion-tests.exe
22+
./out/minion-tests.exe --trace
2323
if ($LASTEXITCODE -ne 0) {
2424
throw "tests failed"
2525
}

minion-tests/src/master.rs

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,53 @@ fn execute_tests(test_cases: &[&dyn TestCase], exec_opts: ExecuteOptions) -> Out
7373
fn execute_single_test(case: &dyn TestCase, exec_opts: ExecuteOptions) -> Outcome {
7474
println!("------ {} ------", case.name());
7575
let self_exe = std::env::current_exe().unwrap();
76+
let tmp = tempfile::tempdir().unwrap();
77+
let mut temp_logs_dir = None;
7678
let mut cmd = if exec_opts.trace {
77-
let mut cmd = std::process::Command::new("strace");
78-
cmd.arg("-f"); // follow forks
79-
cmd.arg("-o").arg(format!("strace-log-{}.txt", case.name()));
80-
cmd.arg(self_exe);
81-
cmd
79+
if cfg!(target_os = "linux") {
80+
let mut cmd = std::process::Command::new("strace");
81+
cmd.arg("-f"); // follow forks
82+
cmd.arg("-o").arg(format!("strace-log-{}.txt", case.name()));
83+
cmd.arg(self_exe);
84+
cmd
85+
} else if cfg!(target_os = "windows") {
86+
let mut cmd = std::process::Command::new(
87+
"C:\\Program Files (x86)\\Windows Kits\\10\\Debuggers\\x64\\cdb.exe",
88+
);
89+
// disable debug heap
90+
cmd.arg("-hd");
91+
// follow children
92+
cmd.arg("-o");
93+
94+
let script_file_path = tmp.path().join("cdb-script.txt");
95+
let logs_path: std::path::PathBuf = format!(".\\strace-ntapi-{}", case.name()).into();
96+
std::fs::create_dir(&logs_path).unwrap();
97+
println!("Saving logs to {}", logs_path.display());
98+
std::fs::write(
99+
&script_file_path,
100+
[
101+
&format!("!logexts.loge {}", logs_path.display()),
102+
"!logexts.logc e *",
103+
"!logexts.logo e d",
104+
"!logexts.logo e t",
105+
"!logexts.logo e v",
106+
"g",
107+
"!logexts.logb f",
108+
"q",
109+
]
110+
.join("\n"),
111+
)
112+
.unwrap();
113+
114+
temp_logs_dir.replace(logs_path);
115+
116+
cmd.arg("-cf").arg(&script_file_path);
117+
118+
cmd.arg(self_exe);
119+
cmd
120+
} else {
121+
panic!("--trace unsupported on this target")
122+
}
82123
} else {
83124
std::process::Command::new(self_exe)
84125
};

minion-tests/src/worker.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ async fn inner_main(test_cases: &[&'static dyn TestCase]) {
5757
}
5858

5959
pub fn main(test_cases: &[&'static dyn TestCase]) {
60-
tracing_subscriber::fmt().pretty().init();
60+
tracing_subscriber::fmt()
61+
.pretty()
62+
.with_writer(std::io::stderr)
63+
.init();
6164
let rt = tokio::runtime::Builder::new_current_thread()
6265
.enable_all()
6366
.build()

src/windows/spawn.rs

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,38 @@ pub(in crate::windows) struct ChildParams {
138138
// TODO: upstream to winapi: https://github.com/retep998/winapi-rs/pull/933/
139139
const MAGIC_PROC_THREAD_ATTRIBUTE_SECURITY_CAPABILITIES: usize = 131081;
140140

141+
struct AlignedMemBlock(*mut u8, usize);
142+
143+
impl AlignedMemBlock {
144+
fn layout(cnt: usize) -> std::alloc::Layout {
145+
assert!(cnt > 0);
146+
std::alloc::Layout::from_size_align(cnt, 8).unwrap()
147+
}
148+
149+
fn new(cnt: usize) -> AlignedMemBlock {
150+
let ptr = unsafe { std::alloc::alloc_zeroed(Self::layout(cnt)) };
151+
AlignedMemBlock(ptr, cnt)
152+
}
153+
154+
fn ptr(&self) -> *mut u8 {
155+
self.0
156+
}
157+
}
158+
159+
impl Drop for AlignedMemBlock {
160+
fn drop(&mut self) {
161+
unsafe {
162+
std::alloc::dealloc(self.0, Self::layout(self.1));
163+
}
164+
}
165+
}
166+
141167
pub(in crate::windows) fn spawn(
142168
sandbox: &WindowsSandbox,
143169
stdio: Stdio,
144170
params: ChildParams,
145171
) -> Result<PROCESS_INFORMATION, Error> {
146-
let mut proc_thread_attr_list_storage: Vec<u64>;
172+
let proc_thread_attr_list_storage;
147173
let mut security_capabilities;
148174
let mut startup_info = unsafe {
149175
let mut startup_info: STARTUPINFOEXW = std::mem::zeroed();
@@ -160,9 +186,8 @@ pub(in crate::windows) fn spawn(
160186
return Err(Error::last());
161187
}
162188
}
163-
proc_thread_attr_list_storage = Vec::with_capacity((proc_thread_attr_list_len - 1) / 8 + 1);
164-
let proc_thread_attr_list: *mut u8 = proc_thread_attr_list_storage.as_mut_ptr().cast();
165-
proc_thread_attr_list.write_bytes(0, proc_thread_attr_list_len);
189+
proc_thread_attr_list_storage = AlignedMemBlock::new(proc_thread_attr_list_len);
190+
let proc_thread_attr_list = proc_thread_attr_list_storage.ptr();
166191
startup_info.lpAttributeList = proc_thread_attr_list.cast();
167192
Cvt::nonzero(InitializeProcThreadAttributeList(
168193
startup_info.lpAttributeList,
@@ -173,11 +198,14 @@ pub(in crate::windows) fn spawn(
173198
security_capabilities = sandbox.profile.get_security_capabilities();
174199
Cvt::nonzero(UpdateProcThreadAttribute(
175200
startup_info.lpAttributeList,
201+
// reserved
176202
0,
177203
MAGIC_PROC_THREAD_ATTRIBUTE_SECURITY_CAPABILITIES,
178204
(&mut security_capabilities as *mut SECURITY_CAPABILITIES).cast(),
179205
std::mem::size_of::<SECURITY_ATTRIBUTES>(),
206+
// reserved
180207
std::ptr::null_mut(),
208+
// reserved
181209
std::ptr::null_mut(),
182210
))?;
183211

@@ -211,13 +239,12 @@ pub(in crate::windows) fn spawn(
211239
// inherit handles
212240
TRUE,
213241
creation_flags,
214-
// TEMP DEBUG
215-
std::ptr::null_mut(),
216-
//env.as_mut_ptr().cast(),
242+
env.as_mut_ptr().cast(),
217243
cwd.as_ptr(),
218244
(&mut startup_info as *mut STARTUPINFOEXW).cast(),
219245
&mut info,
220246
))?;
247+
DeleteProcThreadAttributeList(startup_info.lpAttributeList);
221248
}
222249
Ok(info)
223250
}

src/windows/wait.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use std::{
55
pin::Pin,
66
sync::{
77
atomic::{
8-
AtomicBool, AtomicU32,
9-
Ordering::{Acquire, Relaxed, Release},
8+
AtomicBool,
9+
Ordering::{Acquire, Release},
1010
},
1111
Arc,
1212
},

0 commit comments

Comments
 (0)