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