mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
os: move pub fn debugger_present() bool{
to platform-specific files (better ptrace portability handling) (#17373)
This commit is contained in:
parent
cd00beb099
commit
82c4338b76
7
vlib/os/debugger_default.c.v
Normal file
7
vlib/os/debugger_default.c.v
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
module os
|
||||||
|
|
||||||
|
// debugger_present returns a bool indicating if the process is being debugged
|
||||||
|
[inline]
|
||||||
|
pub fn debugger_present() bool {
|
||||||
|
return false
|
||||||
|
}
|
13
vlib/os/debugger_linux.c.v
Normal file
13
vlib/os/debugger_linux.c.v
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
module os
|
||||||
|
|
||||||
|
#include <sys/ptrace.h>
|
||||||
|
|
||||||
|
fn C.ptrace(u32, u32, voidptr, voidptr) u64
|
||||||
|
|
||||||
|
// debugger_present returns a bool indicating if the process is being debugged
|
||||||
|
[inline]
|
||||||
|
pub fn debugger_present() bool {
|
||||||
|
// check if the parent could trace its process,
|
||||||
|
// if not a debugger must be present
|
||||||
|
return C.ptrace(C.PTRACE_TRACEME, 0, 1, 0) == -1
|
||||||
|
}
|
13
vlib/os/debugger_macos.c.v
Normal file
13
vlib/os/debugger_macos.c.v
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
module os
|
||||||
|
|
||||||
|
#include <sys/ptrace.h>
|
||||||
|
|
||||||
|
fn C.ptrace(int, u32, voidptr, int) int
|
||||||
|
|
||||||
|
// debugger_present returns a bool indicating if the process is being debugged
|
||||||
|
[inline]
|
||||||
|
pub fn debugger_present() bool {
|
||||||
|
// check if the parent could trace its process,
|
||||||
|
// if not a debugger must be present
|
||||||
|
return C.ptrace(C.PT_TRACE_ME, 0, voidptr(1), 0) == -1
|
||||||
|
}
|
10
vlib/os/debugger_windows.c.v
Normal file
10
vlib/os/debugger_windows.c.v
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
module os
|
||||||
|
|
||||||
|
// this is defined in builtin_windows.c.v in builtin
|
||||||
|
// fn C.IsDebuggerPresent() bool
|
||||||
|
|
||||||
|
// debugger_present returns a bool indicating if the process is being debugged
|
||||||
|
[inline]
|
||||||
|
pub fn debugger_present() bool {
|
||||||
|
return C.IsDebuggerPresent()
|
||||||
|
}
|
@ -8,9 +8,6 @@ import strings
|
|||||||
#include <sys/utsname.h>
|
#include <sys/utsname.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <utime.h>
|
#include <utime.h>
|
||||||
$if !solaris && !haiku && !emscripten ? {
|
|
||||||
#include <sys/ptrace.h>
|
|
||||||
}
|
|
||||||
|
|
||||||
pub const (
|
pub const (
|
||||||
path_separator = '/'
|
path_separator = '/'
|
||||||
@ -64,8 +61,6 @@ fn C.getgid() int
|
|||||||
|
|
||||||
fn C.getegid() int
|
fn C.getegid() int
|
||||||
|
|
||||||
fn C.ptrace(u32, u32, voidptr, voidptr) u64
|
|
||||||
|
|
||||||
enum GlobMatch {
|
enum GlobMatch {
|
||||||
exact
|
exact
|
||||||
ends_with
|
ends_with
|
||||||
@ -434,18 +429,6 @@ pub fn (mut f File) close() {
|
|||||||
C.fclose(f.cfile)
|
C.fclose(f.cfile)
|
||||||
}
|
}
|
||||||
|
|
||||||
[inline]
|
|
||||||
pub fn debugger_present() bool {
|
|
||||||
// check if the parent could trace its process,
|
|
||||||
// if not a debugger must be present
|
|
||||||
$if linux {
|
|
||||||
return C.ptrace(C.PTRACE_TRACEME, 0, 1, 0) == -1
|
|
||||||
} $else $if macos {
|
|
||||||
return C.ptrace(C.PT_TRACE_ME, 0, voidptr(1), 0) == -1
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
fn C.mkstemp(stemplate &u8) int
|
fn C.mkstemp(stemplate &u8) int
|
||||||
|
|
||||||
// ensure_folder_is_writable checks that `folder` exists, and is writable to the process
|
// ensure_folder_is_writable checks that `folder` exists, and is writable to the process
|
||||||
|
@ -452,12 +452,6 @@ pub fn add_vectored_exception_handler(first bool, handler VectoredExceptionHandl
|
|||||||
C.AddVectoredExceptionHandler(u32(first), C.PVECTORED_EXCEPTION_HANDLER(handler))
|
C.AddVectoredExceptionHandler(u32(first), C.PVECTORED_EXCEPTION_HANDLER(handler))
|
||||||
}
|
}
|
||||||
|
|
||||||
// this is defined in builtin_windows.c.v in builtin
|
|
||||||
// fn C.IsDebuggerPresent() bool
|
|
||||||
pub fn debugger_present() bool {
|
|
||||||
return C.IsDebuggerPresent()
|
|
||||||
}
|
|
||||||
|
|
||||||
// uname returns information about the platform on which the program is running.
|
// uname returns information about the platform on which the program is running.
|
||||||
// Currently `uname` on windows is not standardized, so it just mimics current practices from other popular software/language implementations:
|
// Currently `uname` on windows is not standardized, so it just mimics current practices from other popular software/language implementations:
|
||||||
// busybox-v1.35.0 * `busybox uname -a` => "Windows_NT HOSTNAME 10.0 19044 x86_64 MS/Windows"
|
// busybox-v1.35.0 * `busybox uname -a` => "Windows_NT HOSTNAME 10.0 19044 x86_64 MS/Windows"
|
||||||
|
Loading…
Reference in New Issue
Block a user