github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/libkb/ptrace_osx.go (about)

     1  // Copyright 2018 Keybase, Inc. All rights reserved. Use of
     2  // this source code is governed by the included BSD license.
     3  
     4  //go:build darwin
     5  // +build darwin
     6  
     7  package libkb
     8  
     9  import (
    10  	"syscall"
    11  )
    12  
    13  // Disallow ptrace attachment by using MacOS specific PT_DENY_ATTACH
    14  // ptrace call. This blocks attempts at attaching ptrace to current
    15  // process and drops any other processes that are currently attaching
    16  // to current process.
    17  
    18  const PtDenyAttach = 31
    19  
    20  func ptrace(request, pid int, addr, data uintptr) error {
    21  	_, _, errno := syscall.Syscall6(syscall.SYS_PTRACE, uintptr(request), uintptr(pid), addr, data, 0, 0)
    22  	if errno != 0 {
    23  		return errno
    24  	}
    25  	return nil
    26  }
    27  
    28  func DisableProcessTracing() error {
    29  	return ptrace(PtDenyAttach, 0, 0, 0)
    30  }