Skip to content

Commit 0b21259

Browse files
committed
fix compile
1 parent 2d44025 commit 0b21259

2 files changed

Lines changed: 21 additions & 20 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ jobs:
6161
PROJECT_DIR: ${{ github.workspace }}
6262
run: sh .github/workflows/ci.sh
6363
- name: Run preemptive tests
64-
if: ${{ contains(matrix.os, 'ubuntu') && !contains(matrix.target, 'loongarch64') || contains(matrix.os, 'macos') }}
64+
if: ${{ !contains(matrix.target, 'loongarch64') }}
6565
env:
6666
CHANNEL: ${{ matrix.channel }}
6767
CROSS: ${{ !startsWith(matrix.target, 'x86_64') && contains(matrix.target, 'linux') && '1' || '0' }}

core/src/monitor.rs

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -199,23 +199,28 @@ impl Monitor {
199199
fn preempt_thread(thread_id: u32) -> bool {
200200
use windows_sys::Win32::Foundation::CloseHandle;
201201
use windows_sys::Win32::System::Diagnostics::Debug::CONTEXT;
202+
use windows_sys::Win32::System::Diagnostics::Debug::{GetThreadContext, SetThreadContext};
202203
use windows_sys::Win32::System::Threading::{
203-
GetThreadContext, OpenThread, ResumeThread, SetThreadContext, SuspendThread,
204-
THREAD_GET_CONTEXT, THREAD_SET_CONTEXT, THREAD_SUSPEND_RESUME,
204+
OpenThread, ResumeThread, SuspendThread, THREAD_GET_CONTEXT, THREAD_SET_CONTEXT,
205+
THREAD_SUSPEND_RESUME,
205206
};
206207

208+
extern "C" {
209+
fn preempt_asm();
210+
}
211+
207212
unsafe {
208213
let handle = OpenThread(
209214
THREAD_SUSPEND_RESUME | THREAD_GET_CONTEXT | THREAD_SET_CONTEXT,
210215
0,
211216
thread_id,
212217
);
213-
if handle == 0 {
218+
if handle.is_null() {
214219
return false;
215220
}
216221

217222
if SuspendThread(handle) == u32::MAX {
218-
CloseHandle(handle);
223+
_ = CloseHandle(handle);
219224
return false;
220225
}
221226

@@ -230,44 +235,40 @@ impl Monitor {
230235
}
231236
}
232237

233-
if GetThreadContext(handle, &mut context) == 0 {
234-
ResumeThread(handle);
235-
CloseHandle(handle);
238+
if GetThreadContext(handle, &raw mut context) == 0 {
239+
_ = ResumeThread(handle);
240+
_ = CloseHandle(handle);
236241
return false;
237242
}
238243

239-
extern "C" {
240-
fn preempt_asm();
241-
}
242-
243244
cfg_if::cfg_if! {
244245
if #[cfg(target_arch = "x86_64")] {
245246
// Push original instruction pointer onto the thread's stack
246247
// so preempt_asm can RET to it after preemption.
247248
// Safety: the target thread runs on a coroutine stack allocated
248249
// by corosensei, which has ample space below the current RSP.
249250
context.Rsp -= 8;
250-
*(context.Rsp as usize as *mut u64) = context.Rip;
251-
context.Rip = preempt_asm as usize as u64;
251+
*(context.Rsp as *mut u64) = context.Rip;
252+
context.Rip = preempt_asm as *const () as u64;
252253
} else if #[cfg(target_arch = "x86")] {
253254
// Push original instruction pointer onto the thread's stack
254255
// so preempt_asm can RET to it after preemption.
255256
// Safety: the target thread runs on a coroutine stack allocated
256257
// by corosensei, which has ample space below the current ESP.
257258
context.Esp -= 4;
258259
*(context.Esp as usize as *mut u32) = context.Eip;
259-
context.Eip = preempt_asm as usize as u32;
260+
context.Eip = preempt_asm as *const () as u32;
260261
}
261262
}
262263

263-
if SetThreadContext(handle, &context) == 0 {
264-
ResumeThread(handle);
265-
CloseHandle(handle);
264+
if SetThreadContext(handle, &raw const context) == 0 {
265+
_ = ResumeThread(handle);
266+
_ = CloseHandle(handle);
266267
return false;
267268
}
268269

269-
ResumeThread(handle);
270-
CloseHandle(handle);
270+
_ = ResumeThread(handle);
271+
_ = CloseHandle(handle);
271272
true
272273
}
273274
}

0 commit comments

Comments
 (0)