From b7ccfed9af60392e44d281770d55789f1d59df13 Mon Sep 17 00:00:00 2001 From: flysand7 Date: Sun, 14 Jul 2024 15:59:18 +1100 Subject: [PATCH] [os2/process]: Implement process_kill --- core/os/os2/process.odin | 50 +++++++------------------------- core/os/os2/process_windows.odin | 11 +++++-- 2 files changed, 19 insertions(+), 42 deletions(-) diff --git a/core/os/os2/process.odin b/core/os/os2/process.odin index 212032259..905aa2182 100644 --- a/core/os/os2/process.odin +++ b/core/os/os2/process.odin @@ -26,11 +26,11 @@ args := get_args() typically is the path to the currently running executable. */ get_args :: proc() -> []string { - args := make([]string, len(runtime.args__), allocator = context.allocator) + result := make([]string, len(runtime.args__), allocator = context.allocator) for rt_arg, i in runtime.args__ { - args[i] = cast(string) rt_arg + result[i] = cast(string) rt_arg } - return args[:] + return result[:] } /* @@ -387,42 +387,12 @@ process_close :: proc(process: Process) -> (Error) { return _process_close(process) } -// Process_Attributes :: struct { -// dir: string, -// env: []string, -// files: []^File, -// sys: ^Process_Attributes_OS_Specific, -// } - -// Process_Attributes_OS_Specific :: struct{} - -// Process_Error :: enum { -// None, -// } - - - -// Signal :: #type proc() - -// Kill: Signal = nil -// Interrupt: Signal = nil - -// process_start :: proc(name: string, argv: []string, attr: ^Process_Attributes) -> (^Process, Process_Error) { -// return nil, .None -// } - -// process_release :: proc(p: ^Process) -> Process_Error { -// return .None -// } - -// process_kill :: proc(p: ^Process) -> Process_Error { -// return .None -// } - -// process_signal :: proc(p: ^Process, sig: Signal) -> Process_Error { -// return .None -// } - - +/* + Terminate a process. + This procedure terminates a process, specified by it's handle, `process`. +*/ +process_kill :: proc(process: Process) -> (Error) { + return _process_kill(process) +} diff --git a/core/os/os2/process_windows.odin b/core/os/os2/process_windows.odin index 4e7c7e62d..251900020 100644 --- a/core/os/os2/process_windows.odin +++ b/core/os/os2/process_windows.odin @@ -577,6 +577,13 @@ _process_close :: proc(process: Process) -> (Error) { return nil } +_process_kill :: proc(process: Process) -> (Error) { + if !windows.TerminateProcess(windows.HANDLE(process.handle), 9) { + return _get_platform_error() + } + return nil +} + @(private) _filetime_to_duration :: proc(filetime: windows.FILETIME) -> time.Duration { ticks := u64(filetime.dwHighDateTime)<<32 | u64(filetime.dwLowDateTime) @@ -695,8 +702,8 @@ _parse_command_line :: proc(cmd_line_w: [^]u16, allocator: runtime.Allocator) -> for arg_w, i in argv_w[:argc] { arg, arg_err := windows.wstring_to_utf8(arg_w, -1, allocator) if arg_err != nil { - for arg in argv[:i] { - delete(arg, allocator) + for s in argv[:i] { + delete(s, allocator) } delete(argv, allocator) return nil, arg_err