mirror of
https://github.com/rwinkhart/sys.git
synced 2026-09-01 14:47:28 -04:00
unix: add IoctlCtlInfo on darwin
For golang/go#41868 Change-Id: I0f4dbeacfe10b9614caf05633a1de3a98a1fc85f Reviewed-on: https://go-review.googlesource.com/c/sys/+/262959 Trust: Tobias Klauser <tobias.klauser@gmail.com> Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Matt Layher <mdlayher@gmail.com>
This commit is contained in:
committed by
Tobias Klauser
parent
98379d014c
commit
eeed37f84f
@@ -59,6 +59,7 @@ includes_Darwin='
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <sys/attr.h>
|
#include <sys/attr.h>
|
||||||
#include <sys/clonefile.h>
|
#include <sys/clonefile.h>
|
||||||
|
#include <sys/kern_control.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/event.h>
|
#include <sys/event.h>
|
||||||
#include <sys/ptrace.h>
|
#include <sys/ptrace.h>
|
||||||
@@ -519,6 +520,7 @@ ccflags="$@"
|
|||||||
$2 ~ /^CAP_/ ||
|
$2 ~ /^CAP_/ ||
|
||||||
$2 ~ /^CP_/ ||
|
$2 ~ /^CP_/ ||
|
||||||
$2 ~ /^CPUSTATES$/ ||
|
$2 ~ /^CPUSTATES$/ ||
|
||||||
|
$2 ~ /^CTLIOCGINFO$/ ||
|
||||||
$2 ~ /^ALG_/ ||
|
$2 ~ /^ALG_/ ||
|
||||||
$2 ~ /^FI(CLONE|DEDUPERANGE)/ ||
|
$2 ~ /^FI(CLONE|DEDUPERANGE)/ ||
|
||||||
$2 ~ /^FS_(POLICY_FLAGS|KEY_DESC|ENCRYPTION_MODE|[A-Z0-9_]+_KEY_SIZE)/ ||
|
$2 ~ /^FS_(POLICY_FLAGS|KEY_DESC|ENCRYPTION_MODE|[A-Z0-9_]+_KEY_SIZE)/ ||
|
||||||
|
|||||||
@@ -94,6 +94,15 @@ func main() {
|
|||||||
b = bytes.Replace(b, s, newNames, 1)
|
b = bytes.Replace(b, s, newNames, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Convert []int8 to []byte in ctl_info ioctl interface
|
||||||
|
convertCtlInfoName := regexp.MustCompile(`(Name)(\s+)\[(\d+)\]int8`)
|
||||||
|
ctlInfoType := regexp.MustCompile(`type CtlInfo struct {[^}]*}`)
|
||||||
|
ctlInfoStructs := ctlInfoType.FindAll(b, -1)
|
||||||
|
for _, s := range ctlInfoStructs {
|
||||||
|
newNames := convertCtlInfoName.ReplaceAll(s, []byte("$1$2[$3]byte"))
|
||||||
|
b = bytes.Replace(b, s, newNames, 1)
|
||||||
|
}
|
||||||
|
|
||||||
// Convert [1024]int8 to [1024]byte in Ptmget members
|
// Convert [1024]int8 to [1024]byte in Ptmget members
|
||||||
convertPtmget := regexp.MustCompile(`([SC]n)(\s+)\[(\d+)\]u?int8`)
|
convertPtmget := regexp.MustCompile(`([SC]n)(\s+)\[(\d+)\]u?int8`)
|
||||||
b = convertPtmget.ReplaceAll(b, []byte("$1[$3]byte"))
|
b = convertPtmget.ReplaceAll(b, []byte("$1[$3]byte"))
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
package unix
|
package unix
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"runtime"
|
||||||
"syscall"
|
"syscall"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
@@ -257,6 +258,12 @@ func Kill(pid int, signum syscall.Signal) (err error) { return kill(pid, int(sig
|
|||||||
|
|
||||||
//sys ioctl(fd int, req uint, arg uintptr) (err error)
|
//sys ioctl(fd int, req uint, arg uintptr) (err error)
|
||||||
|
|
||||||
|
func IoctlCtlInfo(fd int, ctlInfo *CtlInfo) error {
|
||||||
|
err := ioctl(fd, CTLIOCGINFO, uintptr(unsafe.Pointer(ctlInfo)))
|
||||||
|
runtime.KeepAlive(ctlInfo)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
//sys sysctl(mib []_C_int, old *byte, oldlen *uintptr, new *byte, newlen uintptr) (err error) = SYS_SYSCTL
|
//sys sysctl(mib []_C_int, old *byte, oldlen *uintptr, new *byte, newlen uintptr) (err error) = SYS_SYSCTL
|
||||||
|
|
||||||
func Uname(uname *Utsname) error {
|
func Uname(uname *Utsname) error {
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ package unix
|
|||||||
#include <mach/mach.h>
|
#include <mach/mach.h>
|
||||||
#include <mach/message.h>
|
#include <mach/message.h>
|
||||||
#include <sys/event.h>
|
#include <sys/event.h>
|
||||||
|
#include <sys/kern_control.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#include <sys/mount.h>
|
#include <sys/mount.h>
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
@@ -287,3 +288,7 @@ type Utsname C.struct_utsname
|
|||||||
const SizeofClockinfo = C.sizeof_struct_clockinfo
|
const SizeofClockinfo = C.sizeof_struct_clockinfo
|
||||||
|
|
||||||
type Clockinfo C.struct_clockinfo
|
type Clockinfo C.struct_clockinfo
|
||||||
|
|
||||||
|
// ctl_info
|
||||||
|
|
||||||
|
type CtlInfo C.struct_ctl_info
|
||||||
|
|||||||
@@ -251,6 +251,7 @@ const (
|
|||||||
CSTOP = 0x13
|
CSTOP = 0x13
|
||||||
CSTOPB = 0x400
|
CSTOPB = 0x400
|
||||||
CSUSP = 0x1a
|
CSUSP = 0x1a
|
||||||
|
CTLIOCGINFO = 0xc0644e03
|
||||||
CTL_HW = 0x6
|
CTL_HW = 0x6
|
||||||
CTL_KERN = 0x1
|
CTL_KERN = 0x1
|
||||||
CTL_MAXNAME = 0xc
|
CTL_MAXNAME = 0xc
|
||||||
|
|||||||
@@ -251,6 +251,7 @@ const (
|
|||||||
CSTOP = 0x13
|
CSTOP = 0x13
|
||||||
CSTOPB = 0x400
|
CSTOPB = 0x400
|
||||||
CSUSP = 0x1a
|
CSUSP = 0x1a
|
||||||
|
CTLIOCGINFO = 0xc0644e03
|
||||||
CTL_HW = 0x6
|
CTL_HW = 0x6
|
||||||
CTL_KERN = 0x1
|
CTL_KERN = 0x1
|
||||||
CTL_MAXNAME = 0xc
|
CTL_MAXNAME = 0xc
|
||||||
|
|||||||
@@ -251,6 +251,7 @@ const (
|
|||||||
CSTOP = 0x13
|
CSTOP = 0x13
|
||||||
CSTOPB = 0x400
|
CSTOPB = 0x400
|
||||||
CSUSP = 0x1a
|
CSUSP = 0x1a
|
||||||
|
CTLIOCGINFO = 0xc0644e03
|
||||||
CTL_HW = 0x6
|
CTL_HW = 0x6
|
||||||
CTL_KERN = 0x1
|
CTL_KERN = 0x1
|
||||||
CTL_MAXNAME = 0xc
|
CTL_MAXNAME = 0xc
|
||||||
|
|||||||
@@ -251,6 +251,7 @@ const (
|
|||||||
CSTOP = 0x13
|
CSTOP = 0x13
|
||||||
CSTOPB = 0x400
|
CSTOPB = 0x400
|
||||||
CSUSP = 0x1a
|
CSUSP = 0x1a
|
||||||
|
CTLIOCGINFO = 0xc0644e03
|
||||||
CTL_HW = 0x6
|
CTL_HW = 0x6
|
||||||
CTL_KERN = 0x1
|
CTL_KERN = 0x1
|
||||||
CTL_MAXNAME = 0xc
|
CTL_MAXNAME = 0xc
|
||||||
|
|||||||
@@ -498,3 +498,8 @@ type Clockinfo struct {
|
|||||||
Stathz int32
|
Stathz int32
|
||||||
Profhz int32
|
Profhz int32
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CtlInfo struct {
|
||||||
|
Id uint32
|
||||||
|
Name [96]byte
|
||||||
|
}
|
||||||
|
|||||||
@@ -503,3 +503,8 @@ type Clockinfo struct {
|
|||||||
Stathz int32
|
Stathz int32
|
||||||
Profhz int32
|
Profhz int32
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CtlInfo struct {
|
||||||
|
Id uint32
|
||||||
|
Name [96]byte
|
||||||
|
}
|
||||||
|
|||||||
@@ -498,3 +498,8 @@ type Clockinfo struct {
|
|||||||
Stathz int32
|
Stathz int32
|
||||||
Profhz int32
|
Profhz int32
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CtlInfo struct {
|
||||||
|
Id uint32
|
||||||
|
Name [96]byte
|
||||||
|
}
|
||||||
|
|||||||
@@ -503,3 +503,8 @@ type Clockinfo struct {
|
|||||||
Stathz int32
|
Stathz int32
|
||||||
Profhz int32
|
Profhz int32
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CtlInfo struct {
|
||||||
|
Id uint32
|
||||||
|
Name [96]byte
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user