1
0
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:
Felipe Pena 2023-02-21 05:55:03 -03:00 committed by GitHub
parent cd00beb099
commit 82c4338b76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 43 additions and 23 deletions

View 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
}

View 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
}

View 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
}

View 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()
}

View File

@ -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

View File

@ -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"