Skip to content

Commit 9f37953

Browse files
Add Win32-specialized code for killing tasks
1 parent dffd093 commit 9f37953

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

Sources/Fuzzilli/Util/JavaScriptExecutor.swift

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414

1515
import Foundation
1616

17+
#if os(Windows)
18+
import WinSDK
19+
#endif /* os(Windows) */
20+
1721
public class JavaScriptExecutor {
1822
/// Path to the js shell binary.
1923
let executablePath: String
@@ -103,11 +107,21 @@ public class JavaScriptExecutor {
103107
break
104108
}
105109
}
106-
if task.isRunning {
110+
runningCheck: if task.isRunning {
111+
timedOut = true
112+
#if os(Windows)
113+
guard let processHandle = OpenProcess(DWORD(PROCESS_TERMINATE), false, DWORD(task.processIdentifier)) else {
114+
// Fall back to built-in termination
115+
task.terminate()
116+
break runningCheck
117+
}
118+
defer { CloseHandle(processHandle) }
119+
TerminateProcess(processHandle, 1)
120+
#else
107121
// Properly kill the task now with SIGKILL as it might be stuck
108122
// in Wasm, where SIGTERM is not enough.
109123
kill(task.processIdentifier, SIGKILL)
110-
timedOut = true
124+
#endif /* os(Windows) */
111125
}
112126
}
113127

0 commit comments

Comments
 (0)