Author SHA1 Message Date
RandyTheSilly 93a64518fe Update README.md 2025-08-17 12:46:53 -04:00
RandyTheSilly f340b74c01 Add patch for PID support in FreeBSD 13+ xucred 2025-08-17 12:32:37 -04:00
28 changed files with 726 additions and 748 deletions
+115
View File
@@ -0,0 +1,115 @@
diff --git a/unix/ztypes_freebsd_386.go b/unix/ztypes_freebsd_386.go
index 51e13eb0..5212328e 100644
--- a/unix/ztypes_freebsd_386.go
+++ b/unix/ztypes_freebsd_386.go
@@ -203,7 +203,8 @@ type Xucred struct {
Uid uint32
Ngroups int16
Groups [16]uint32
- _ *byte
+ _ byte
+ Pid uint32
}
type Linger struct {
@@ -268,7 +269,7 @@ const (
SizeofSockaddrAny = 0x6c
SizeofSockaddrUnix = 0x6a
SizeofSockaddrDatalink = 0x36
- SizeofXucred = 0x50
+ SizeofXucred = 0x54
SizeofLinger = 0x8
SizeofIovec = 0x8
SizeofIPMreq = 0x8
diff --git a/unix/ztypes_freebsd_amd64.go b/unix/ztypes_freebsd_amd64.go
index d002d8ef..1673b4e8 100644
--- a/unix/ztypes_freebsd_amd64.go
+++ b/unix/ztypes_freebsd_amd64.go
@@ -200,7 +200,8 @@ type Xucred struct {
Uid uint32
Ngroups int16
Groups [16]uint32
- _ *byte
+ _ byte
+ Pid uint32
}
type Linger struct {
@@ -265,7 +266,7 @@ const (
SizeofSockaddrAny = 0x6c
SizeofSockaddrUnix = 0x6a
SizeofSockaddrDatalink = 0x36
- SizeofXucred = 0x58
+ SizeofXucred = 0x54
SizeofLinger = 0x8
SizeofIovec = 0x10
SizeofIPMreq = 0x8
diff --git a/unix/ztypes_freebsd_arm.go b/unix/ztypes_freebsd_arm.go
index 3f863d89..a54f4570 100644
--- a/unix/ztypes_freebsd_arm.go
+++ b/unix/ztypes_freebsd_arm.go
@@ -202,7 +202,8 @@ type Xucred struct {
Uid uint32
Ngroups int16
Groups [16]uint32
- _ *byte
+ _ byte
+ Pid uint32
}
type Linger struct {
@@ -267,7 +268,7 @@ const (
SizeofSockaddrAny = 0x6c
SizeofSockaddrUnix = 0x6a
SizeofSockaddrDatalink = 0x36
- SizeofXucred = 0x50
+ SizeofXucred = 0x54
SizeofLinger = 0x8
SizeofIovec = 0x8
SizeofIPMreq = 0x8
diff --git a/unix/ztypes_freebsd_arm64.go b/unix/ztypes_freebsd_arm64.go
index 61c72931..a91ccc72 100644
--- a/unix/ztypes_freebsd_arm64.go
+++ b/unix/ztypes_freebsd_arm64.go
@@ -200,7 +200,8 @@ type Xucred struct {
Uid uint32
Ngroups int16
Groups [16]uint32
- _ *byte
+ _ byte
+ Pid uint32
}
type Linger struct {
@@ -265,7 +266,7 @@ const (
SizeofSockaddrAny = 0x6c
SizeofSockaddrUnix = 0x6a
SizeofSockaddrDatalink = 0x36
- SizeofXucred = 0x58
+ SizeofXucred = 0x54
SizeofLinger = 0x8
SizeofIovec = 0x10
SizeofIPMreq = 0x8
diff --git a/unix/ztypes_freebsd_riscv64.go b/unix/ztypes_freebsd_riscv64.go
index b5d17414..596538d9 100644
--- a/unix/ztypes_freebsd_riscv64.go
+++ b/unix/ztypes_freebsd_riscv64.go
@@ -200,7 +200,8 @@ type Xucred struct {
Uid uint32
Ngroups int16
Groups [16]uint32
- _ *byte
+ _ byte
+ Pid uint32
}
type Linger struct {
@@ -265,7 +266,7 @@ const (
SizeofSockaddrAny = 0x6c
SizeofSockaddrUnix = 0x6a
SizeofSockaddrDatalink = 0x36
- SizeofXucred = 0x58
+ SizeofXucred = 0x54
SizeofLinger = 0x8
SizeofIovec = 0x10
SizeofIPMreq = 0x8
+5 -15
View File
@@ -1,17 +1,7 @@
# sys
# sys - rwinkhart patches
This repository holds my custom patches atop the Go sys module.
[![Go Reference](https://pkg.go.dev/badge/golang.org/x/sys.svg)](https://pkg.go.dev/golang.org/x/sys)
The only changes in the master branch are this README and the patches in the `1patches` directory. The patches are applied on other branches and tagged releases are available for import from the releases page.
This repository holds supplemental Go packages for low-level interactions with
the operating system.
## Report Issues / Send Patches
This repository uses Gerrit for code changes. To learn how to submit changes to
this repository, see https://go.dev/doc/contribute.
The git repository is https://go.googlesource.com/sys.
The main issue tracker for the sys repository is located at
https://go.dev/issues. Prefix your issue with "x/sys:" in the
subject line, so it is easy to find.
# How To?
Copy the desired patch file(s) into a new branch (cloned from upstream master) and apply with `patch -p1 < patchfile.patch`.
+21
View File
@@ -0,0 +1,21 @@
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build go1.5
package plan9
import "syscall"
func fixwd() {
syscall.Fixwd()
}
func Getwd() (wd string, err error) {
return syscall.Getwd()
}
func Chdir(path string) error {
return syscall.Chdir(path)
}
+9 -5
View File
@@ -2,18 +2,22 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !go1.5
package plan9
import "syscall"
func fixwd() {
syscall.Fixwd()
}
func Getwd() (wd string, err error) {
return syscall.Getwd()
fd, err := open(".", O_RDONLY)
if err != nil {
return "", err
}
defer Close(fd)
return Fd2path(fd)
}
func Chdir(path string) error {
return syscall.Chdir(path)
return chdir(path)
}
+1 -8
View File
@@ -38,15 +38,8 @@ func SchedSetaffinity(pid int, set *CPUSet) error {
// Zero clears the set s, so that it contains no CPUs.
func (s *CPUSet) Zero() {
clear(s[:])
}
// Fill adds all possible CPU bits to the set s. On Linux, [SchedSetaffinity]
// will silently ignore any invalid CPU bits in [CPUSet] so this is an
// efficient way of resetting the CPU affinity of a process.
func (s *CPUSet) Fill() {
for i := range s {
s[i] = ^cpuMask(0)
s[i] = 0
}
}
+5 -5
View File
@@ -12,7 +12,7 @@ import (
"os"
"path/filepath"
"runtime"
"slices"
"sort"
"strconv"
"strings"
"testing"
@@ -72,7 +72,7 @@ func TestDirent(t *testing.T) {
}
}
slices.Sort(names)
sort.Strings(names)
t.Logf("names: %q", names)
if len(names) != 10 {
@@ -145,9 +145,9 @@ func TestDirentRepeat(t *testing.T) {
}
// Check results
slices.Sort(files)
slices.Sort(files2)
if !slices.Equal(files, files2) {
sort.Strings(files)
sort.Strings(files2)
if strings.Join(files, "|") != strings.Join(files2, "|") {
t.Errorf("bad file list: want\n%q\ngot\n%q", files, files2)
}
}
+3 -1
View File
@@ -23,5 +23,7 @@ func (fds *FdSet) IsSet(fd int) bool {
// Zero clears the set fds.
func (fds *FdSet) Zero() {
clear(fds.Bits[:])
for i := range fds.Bits {
fds.Bits[i] = 0
}
}
+5 -4
View File
@@ -10,7 +10,8 @@ import (
"fmt"
"os"
"path/filepath"
"slices"
"sort"
"strings"
"testing"
"golang.org/x/sys/unix"
@@ -70,9 +71,9 @@ func testGetdirentries(t *testing.T, count int) {
}
}
slices.Sort(names)
slices.Sort(names2)
if !slices.Equal(names, names2) {
sort.Strings(names)
sort.Strings(names2)
if strings.Join(names, ":") != strings.Join(names2, ":") {
t.Errorf("names don't match\n names: %q\nnames2: %q", names, names2)
}
}
-47
View File
@@ -1,47 +0,0 @@
// Copyright 2023 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build netbsd
package unix_test
import (
"os/exec"
"testing"
"golang.org/x/sys/unix"
)
func TestGetvfsstat(t *testing.T) {
n, err := unix.Getvfsstat(nil, unix.MNT_NOWAIT)
if err != nil {
t.Fatal(err)
}
data := make([]unix.Statvfs_t, n)
n2, err := unix.Getvfsstat(data, unix.MNT_NOWAIT)
if err != nil {
t.Fatal(err)
}
if n != n2 {
t.Errorf("Getvfsstat(nil) = %d, but subsequent Getvfsstat(slice) = %d", n, n2)
}
for i, stat := range data {
if stat == (unix.Statvfs_t{}) {
t.Errorf("index %v is an empty Statvfs_t struct", i)
}
t.Logf("%s on %s", unix.ByteSliceToString(stat.Mntfromname[:]), unix.ByteSliceToString(stat.Mntonname[:]))
}
if t.Failed() {
for i, stat := range data[:n2] {
t.Logf("data[%v] = %+v", i, stat)
}
mount, err := exec.Command("mount").CombinedOutput()
if err != nil {
t.Logf("mount: %v\n%s", err, mount)
} else {
t.Logf("mount: %s", mount)
}
}
}
+3 -1
View File
@@ -111,7 +111,9 @@ func (ifr *Ifreq) SetUint32(v uint32) {
// clear zeroes the ifreq's union field to prevent trailing garbage data from
// being sent to the kernel if an ifreq is reused.
func (ifr *Ifreq) clear() {
clear(ifr.raw.Ifru[:])
for i := range ifr.raw.Ifru {
ifr.raw.Ifru[i] = 0
}
}
// TODO(mdlayher): export as IfreqData? For now we can provide helpers such as
+1 -36
View File
@@ -121,7 +121,6 @@ struct termios2 {
#include <linux/hidraw.h>
#include <linux/icmp.h>
#include <linux/icmpv6.h>
#include <linux/if_addrlabel.h>
#include <linux/if_alg.h>
#include <linux/if_bridge.h>
#include <linux/if_packet.h>
@@ -879,8 +878,6 @@ const (
IFA_FLAGS = C.IFA_FLAGS
IFA_RT_PRIORITY = C.IFA_RT_PRIORITY
IFA_TARGET_NETNSID = C.IFA_TARGET_NETNSID
IFAL_LABEL = C.IFAL_LABEL
IFAL_ADDRESS = C.IFAL_ADDRESS
RT_SCOPE_UNIVERSE = C.RT_SCOPE_UNIVERSE
RT_SCOPE_SITE = C.RT_SCOPE_SITE
RT_SCOPE_LINK = C.RT_SCOPE_LINK
@@ -938,7 +935,6 @@ const (
SizeofRtAttr = C.sizeof_struct_rtattr
SizeofIfInfomsg = C.sizeof_struct_ifinfomsg
SizeofIfAddrmsg = C.sizeof_struct_ifaddrmsg
SizeofIfAddrlblmsg = C.sizeof_struct_ifaddrlblmsg
SizeofIfaCacheinfo = C.sizeof_struct_ifa_cacheinfo
SizeofRtMsg = C.sizeof_struct_rtmsg
SizeofRtNexthop = C.sizeof_struct_rtnexthop
@@ -960,8 +956,6 @@ type IfInfomsg C.struct_ifinfomsg
type IfAddrmsg C.struct_ifaddrmsg
type IfAddrlblmsg C.struct_ifaddrlblmsg
type IfaCacheinfo C.struct_ifa_cacheinfo
type RtMsg C.struct_rtmsg
@@ -3119,25 +3113,8 @@ const (
)
// generated by:
// perl -nlE '/^\s*((RTNLGRP_|TCA_)\w+)/ && say "$1 = C.$1"' include/uapi/linux/rtnetlink.h
// perl -nlE '/^\s*(RTNLGRP_\w+)/ && say "$1 = C.$1"' include/uapi/linux/rtnetlink.h
const (
TCA_UNSPEC = C.TCA_UNSPEC
TCA_KIND = C.TCA_KIND
TCA_OPTIONS = C.TCA_OPTIONS
TCA_STATS = C.TCA_STATS
TCA_XSTATS = C.TCA_XSTATS
TCA_RATE = C.TCA_RATE
TCA_FCNT = C.TCA_FCNT
TCA_STATS2 = C.TCA_STATS2
TCA_STAB = C.TCA_STAB
TCA_PAD = C.TCA_PAD
TCA_DUMP_INVISIBLE = C.TCA_DUMP_INVISIBLE
TCA_CHAIN = C.TCA_CHAIN
TCA_HW_OFFLOAD = C.TCA_HW_OFFLOAD
TCA_INGRESS_BLOCK = C.TCA_INGRESS_BLOCK
TCA_EGRESS_BLOCK = C.TCA_EGRESS_BLOCK
TCA_DUMP_FLAGS = C.TCA_DUMP_FLAGS
TCA_EXT_WARN_MSG = C.TCA_EXT_WARN_MSG
RTNLGRP_NONE = C.RTNLGRP_NONE
RTNLGRP_LINK = C.RTNLGRP_LINK
RTNLGRP_NOTIFY = C.RTNLGRP_NOTIFY
@@ -3172,18 +3149,6 @@ const (
RTNLGRP_IPV6_MROUTE_R = C.RTNLGRP_IPV6_MROUTE_R
RTNLGRP_NEXTHOP = C.RTNLGRP_NEXTHOP
RTNLGRP_BRVLAN = C.RTNLGRP_BRVLAN
RTNLGRP_MCTP_IFADDR = C.RTNLGRP_MCTP_IFADDR
RTNLGRP_TUNNEL = C.RTNLGRP_TUNNEL
RTNLGRP_STATS = C.RTNLGRP_STATS
RTNLGRP_IPV4_MCADDR = C.RTNLGRP_IPV4_MCADDR
RTNLGRP_IPV6_MCADDR = C.RTNLGRP_IPV6_MCADDR
RTNLGRP_IPV6_ACADDR = C.RTNLGRP_IPV6_ACADDR
TCA_ROOT_UNSPEC = C.TCA_ROOT_UNSPEC
TCA_ROOT_TAB = C.TCA_ROOT_TAB
TCA_ROOT_FLAGS = C.TCA_ROOT_FLAGS
TCA_ROOT_COUNT = C.TCA_ROOT_COUNT
TCA_ROOT_TIME_DELTA = C.TCA_ROOT_TIME_DELTA
TCA_ROOT_EXT_WARN_MSG = C.TCA_ROOT_EXT_WARN_MSG
)
// Capabilities
-1
View File
@@ -49,7 +49,6 @@ esac
if [[ "$GOOS" = "linux" ]]; then
# Use the Docker-based build system
# Files generated through docker (use $cmd so you can Ctl-C the build or run)
set -e
$cmd docker build --tag generate:$GOOS $GOOS
$cmd docker run --interactive --tty --volume $(cd -- "$(dirname -- "$0")/.." && pwd):/build generate:$GOOS
exit
+3 -1
View File
@@ -801,7 +801,9 @@ func (sa *SockaddrPPPoE) sockaddr() (unsafe.Pointer, _Socklen, error) {
// one. The kernel expects SID to be in network byte order.
binary.BigEndian.PutUint16(sa.raw[6:8], sa.SID)
copy(sa.raw[8:14], sa.Remote)
clear(sa.raw[14 : 14+IFNAMSIZ])
for i := 14; i < 14+IFNAMSIZ; i++ {
sa.raw[i] = 0
}
copy(sa.raw[14:], sa.Dev)
return unsafe.Pointer(&sa.raw), SizeofSockaddrPPPoX, nil
}
-17
View File
@@ -248,23 +248,6 @@ func Statvfs(path string, buf *Statvfs_t) (err error) {
return Statvfs1(path, buf, ST_WAIT)
}
func Getvfsstat(buf []Statvfs_t, flags int) (n int, err error) {
var (
_p0 unsafe.Pointer
bufsize uintptr
)
if len(buf) > 0 {
_p0 = unsafe.Pointer(&buf[0])
bufsize = unsafe.Sizeof(Statvfs_t{}) * uintptr(len(buf))
}
r0, _, e1 := Syscall(SYS_GETVFSSTAT, uintptr(_p0), bufsize, uintptr(flags))
n = int(r0)
if e1 != 0 {
err = e1
}
return
}
/*
* Exposed directly
*/
+1 -1
View File
@@ -629,7 +629,7 @@ func Sendfile(outfd int, infd int, offset *int64, count int) (written int, err e
//sys Kill(pid int, signum syscall.Signal) (err error)
//sys Lchown(path string, uid int, gid int) (err error)
//sys Link(path string, link string) (err error)
//sys Listen(s int, backlog int) (err error) = libsocket.__xnet_listen
//sys Listen(s int, backlog int) (err error) = libsocket.__xnet_llisten
//sys Lstat(path string, stat *Stat_t) (err error)
//sys Madvise(b []byte, advice int) (err error)
//sys Mkdir(path string, mode uint32) (err error)
+4 -4
View File
@@ -72,7 +72,7 @@ import (
//go:cgo_import_dynamic libc_kill kill "libc.so"
//go:cgo_import_dynamic libc_lchown lchown "libc.so"
//go:cgo_import_dynamic libc_link link "libc.so"
//go:cgo_import_dynamic libc___xnet_listen __xnet_listen "libsocket.so"
//go:cgo_import_dynamic libc___xnet_llisten __xnet_llisten "libsocket.so"
//go:cgo_import_dynamic libc_lstat lstat "libc.so"
//go:cgo_import_dynamic libc_madvise madvise "libc.so"
//go:cgo_import_dynamic libc_mkdir mkdir "libc.so"
@@ -221,7 +221,7 @@ import (
//go:linkname procKill libc_kill
//go:linkname procLchown libc_lchown
//go:linkname procLink libc_link
//go:linkname proc__xnet_listen libc___xnet_listen
//go:linkname proc__xnet_llisten libc___xnet_llisten
//go:linkname procLstat libc_lstat
//go:linkname procMadvise libc_madvise
//go:linkname procMkdir libc_mkdir
@@ -371,7 +371,7 @@ var (
procKill,
procLchown,
procLink,
proc__xnet_listen,
proc__xnet_llisten,
procLstat,
procMadvise,
procMkdir,
@@ -1178,7 +1178,7 @@ func Link(path string, link string) (err error) {
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
func Listen(s int, backlog int) (err error) {
_, _, e1 := sysvicall6(uintptr(unsafe.Pointer(&proc__xnet_listen)), 2, uintptr(s), uintptr(backlog), 0, 0, 0, 0)
_, _, e1 := sysvicall6(uintptr(unsafe.Pointer(&proc__xnet_llisten)), 2, uintptr(s), uintptr(backlog), 0, 0, 0, 0)
if e1 != 0 {
err = errnoErr(e1)
}
+2 -3
View File
@@ -203,8 +203,7 @@ type Xucred struct {
Uid uint32
Ngroups int16
Groups [16]uint32
_ byte
Pid uint32
_ *byte
}
type Linger struct {
@@ -269,7 +268,7 @@ const (
SizeofSockaddrAny = 0x6c
SizeofSockaddrUnix = 0x6a
SizeofSockaddrDatalink = 0x36
SizeofXucred = 0x54
SizeofXucred = 0x50
SizeofLinger = 0x8
SizeofIovec = 0x8
SizeofIPMreq = 0x8
+2 -3
View File
@@ -200,8 +200,7 @@ type Xucred struct {
Uid uint32
Ngroups int16
Groups [16]uint32
_ byte
Pid uint32
_ *byte
}
type Linger struct {
@@ -266,7 +265,7 @@ const (
SizeofSockaddrAny = 0x6c
SizeofSockaddrUnix = 0x6a
SizeofSockaddrDatalink = 0x36
SizeofXucred = 0x54
SizeofXucred = 0x58
SizeofLinger = 0x8
SizeofIovec = 0x10
SizeofIPMreq = 0x8
+2 -3
View File
@@ -202,8 +202,7 @@ type Xucred struct {
Uid uint32
Ngroups int16
Groups [16]uint32
_ byte
Pid uint32
_ *byte
}
type Linger struct {
@@ -268,7 +267,7 @@ const (
SizeofSockaddrAny = 0x6c
SizeofSockaddrUnix = 0x6a
SizeofSockaddrDatalink = 0x36
SizeofXucred = 0x54
SizeofXucred = 0x50
SizeofLinger = 0x8
SizeofIovec = 0x8
SizeofIPMreq = 0x8
+2 -3
View File
@@ -200,8 +200,7 @@ type Xucred struct {
Uid uint32
Ngroups int16
Groups [16]uint32
_ byte
Pid uint32
_ *byte
}
type Linger struct {
@@ -266,7 +265,7 @@ const (
SizeofSockaddrAny = 0x6c
SizeofSockaddrUnix = 0x6a
SizeofSockaddrDatalink = 0x36
SizeofXucred = 0x54
SizeofXucred = 0x58
SizeofLinger = 0x8
SizeofIovec = 0x10
SizeofIPMreq = 0x8
+2 -3
View File
@@ -200,8 +200,7 @@ type Xucred struct {
Uid uint32
Ngroups int16
Groups [16]uint32
_ byte
Pid uint32
_ *byte
}
type Linger struct {
@@ -266,7 +265,7 @@ const (
SizeofSockaddrAny = 0x6c
SizeofSockaddrUnix = 0x6a
SizeofSockaddrDatalink = 0x36
SizeofXucred = 0x54
SizeofXucred = 0x58
SizeofLinger = 0x8
SizeofIovec = 0x10
SizeofIPMreq = 0x8
-41
View File
@@ -632,8 +632,6 @@ const (
IFA_FLAGS = 0x8
IFA_RT_PRIORITY = 0x9
IFA_TARGET_NETNSID = 0xa
IFAL_LABEL = 0x2
IFAL_ADDRESS = 0x1
RT_SCOPE_UNIVERSE = 0x0
RT_SCOPE_SITE = 0xc8
RT_SCOPE_LINK = 0xfd
@@ -691,7 +689,6 @@ const (
SizeofRtAttr = 0x4
SizeofIfInfomsg = 0x10
SizeofIfAddrmsg = 0x8
SizeofIfAddrlblmsg = 0xc
SizeofIfaCacheinfo = 0x10
SizeofRtMsg = 0xc
SizeofRtNexthop = 0x8
@@ -743,15 +740,6 @@ type IfAddrmsg struct {
Index uint32
}
type IfAddrlblmsg struct {
Family uint8
_ uint8
Prefixlen uint8
Flags uint8
Index uint32
Seq uint32
}
type IfaCacheinfo struct {
Prefered uint32
Valid uint32
@@ -3064,23 +3052,6 @@ const (
)
const (
TCA_UNSPEC = 0x0
TCA_KIND = 0x1
TCA_OPTIONS = 0x2
TCA_STATS = 0x3
TCA_XSTATS = 0x4
TCA_RATE = 0x5
TCA_FCNT = 0x6
TCA_STATS2 = 0x7
TCA_STAB = 0x8
TCA_PAD = 0x9
TCA_DUMP_INVISIBLE = 0xa
TCA_CHAIN = 0xb
TCA_HW_OFFLOAD = 0xc
TCA_INGRESS_BLOCK = 0xd
TCA_EGRESS_BLOCK = 0xe
TCA_DUMP_FLAGS = 0xf
TCA_EXT_WARN_MSG = 0x10
RTNLGRP_NONE = 0x0
RTNLGRP_LINK = 0x1
RTNLGRP_NOTIFY = 0x2
@@ -3115,18 +3086,6 @@ const (
RTNLGRP_IPV6_MROUTE_R = 0x1f
RTNLGRP_NEXTHOP = 0x20
RTNLGRP_BRVLAN = 0x21
RTNLGRP_MCTP_IFADDR = 0x22
RTNLGRP_TUNNEL = 0x23
RTNLGRP_STATS = 0x24
RTNLGRP_IPV4_MCADDR = 0x25
RTNLGRP_IPV6_MCADDR = 0x26
RTNLGRP_IPV6_ACADDR = 0x27
TCA_ROOT_UNSPEC = 0x0
TCA_ROOT_TAB = 0x1
TCA_ROOT_FLAGS = 0x2
TCA_ROOT_COUNT = 0x3
TCA_ROOT_TIME_DELTA = 0x4
TCA_ROOT_EXT_WARN_MSG = 0x5
)
type CapUserHeader struct {
+45 -9
View File
@@ -62,6 +62,7 @@ import (
"path/filepath"
"runtime"
"sort"
"strconv"
"strings"
"text/template"
)
@@ -542,9 +543,47 @@ func (f *Fn) ParamPrintList() string {
return join(f.Params, func(p *Param) string { return fmt.Sprintf(`"%s=", %s, `, p.Name, p.Name) }, `", ", `)
}
// SyscallN returns a string representing the SyscallN function.
func (f *Fn) SyscallN() string {
return syscalldot() + "SyscallN"
// ParamCount return number of syscall parameters for function f.
func (f *Fn) ParamCount() int {
n := 0
for _, p := range f.Params {
n += len(p.SyscallArgList())
}
return n
}
// SyscallParamCount determines which version of Syscall/Syscall6/Syscall9/...
// to use. It returns parameter count for correspondent SyscallX function.
func (f *Fn) SyscallParamCount() int {
n := f.ParamCount()
switch {
case n <= 3:
return 3
case n <= 6:
return 6
case n <= 9:
return 9
case n <= 12:
return 12
case n <= 15:
return 15
case n <= 42: // current SyscallN limit
return n
default:
panic("too many arguments to system call")
}
}
// Syscall determines which SyscallX function to use for function f.
func (f *Fn) Syscall() string {
c := f.SyscallParamCount()
if c == 3 {
return syscalldot() + "Syscall"
}
if c > 15 {
return syscalldot() + "SyscallN"
}
return syscalldot() + "Syscall" + strconv.Itoa(c)
}
// SyscallParamList returns source code for SyscallX parameters for function f.
@@ -553,12 +592,9 @@ func (f *Fn) SyscallParamList() string {
for _, p := range f.Params {
a = append(a, p.SyscallArgList()...)
}
// Check if the number exceeds the current SyscallN limit
if len(a) > 42 {
panic("too many arguments to system call")
for len(a) < f.SyscallParamCount() {
a = append(a, "0")
}
return strings.Join(a, ", ")
}
@@ -979,7 +1015,7 @@ func {{.HelperName}}({{.HelperParamList}}) {{template "results" .}}{
{{define "results"}}{{if .Rets.List}}{{.Rets.List}} {{end}}{{end}}
{{define "syscall"}}{{.Rets.SetReturnValuesCode}}{{.SyscallN}}(proc{{.DLLFuncName}}.Addr(), {{.SyscallParamList}}){{end}}
{{define "syscall"}}{{.Rets.SetReturnValuesCode}}{{.Syscall}}(proc{{.DLLFuncName}}.Addr(),{{if le .ParamCount 15}} {{.ParamCount}},{{end}} {{.SyscallParamList}}){{end}}
{{define "tmpvarsreadback"}}{{range .Params}}{{if .TmpVarReadbackCode}}
{{.TmpVarReadbackCode}}{{end}}{{end}}{{end}}
+4 -4
View File
@@ -50,7 +50,7 @@ func TestDLLFilenameEscaping(t *testing.T) {
}
}
func TestSyscallNGeneration(t *testing.T) {
func TestSyscallXGeneration(t *testing.T) {
tests := []struct {
name string
wantsysfunc string
@@ -58,17 +58,17 @@ func TestSyscallNGeneration(t *testing.T) {
}{
{
name: "syscall with 2 params",
wantsysfunc: "syscall.SyscallN",
wantsysfunc: "syscall.Syscall",
sig: "Example(a1 *uint16, a2 *uint16) = ",
},
{
name: "syscall with 6 params",
wantsysfunc: "syscall.SyscallN",
wantsysfunc: "syscall.Syscall6",
sig: "Example(a1 *uint, a2 *uint, a3 *uint, a4 *uint, a5 *uint, a6 *uint) = ",
},
{
name: "syscall with 15 params",
wantsysfunc: "syscall.SyscallN",
wantsysfunc: "syscall.Syscall15",
sig: strings.ReplaceAll(`Example(a1 *uint, a2 *uint, a3 *uint, a4 *uint, a5 *uint, a6 *uint,
a7 *uint, a8 *uint, a9 *uint, a10 *uint, a11 *uint, a12 *uint,
a13 *uint, a14 *uint, a15 *uint) = `, "\n", ""),
+8 -8
View File
@@ -52,7 +52,7 @@ var (
)
func regConnectRegistry(machinename *uint16, key syscall.Handle, result *syscall.Handle) (regerrno error) {
r0, _, _ := syscall.SyscallN(procRegConnectRegistryW.Addr(), uintptr(unsafe.Pointer(machinename)), uintptr(key), uintptr(unsafe.Pointer(result)))
r0, _, _ := syscall.Syscall(procRegConnectRegistryW.Addr(), 3, uintptr(unsafe.Pointer(machinename)), uintptr(key), uintptr(unsafe.Pointer(result)))
if r0 != 0 {
regerrno = syscall.Errno(r0)
}
@@ -60,7 +60,7 @@ func regConnectRegistry(machinename *uint16, key syscall.Handle, result *syscall
}
func regCreateKeyEx(key syscall.Handle, subkey *uint16, reserved uint32, class *uint16, options uint32, desired uint32, sa *syscall.SecurityAttributes, result *syscall.Handle, disposition *uint32) (regerrno error) {
r0, _, _ := syscall.SyscallN(procRegCreateKeyExW.Addr(), uintptr(key), uintptr(unsafe.Pointer(subkey)), uintptr(reserved), uintptr(unsafe.Pointer(class)), uintptr(options), uintptr(desired), uintptr(unsafe.Pointer(sa)), uintptr(unsafe.Pointer(result)), uintptr(unsafe.Pointer(disposition)))
r0, _, _ := syscall.Syscall9(procRegCreateKeyExW.Addr(), 9, uintptr(key), uintptr(unsafe.Pointer(subkey)), uintptr(reserved), uintptr(unsafe.Pointer(class)), uintptr(options), uintptr(desired), uintptr(unsafe.Pointer(sa)), uintptr(unsafe.Pointer(result)), uintptr(unsafe.Pointer(disposition)))
if r0 != 0 {
regerrno = syscall.Errno(r0)
}
@@ -68,7 +68,7 @@ func regCreateKeyEx(key syscall.Handle, subkey *uint16, reserved uint32, class *
}
func regDeleteKey(key syscall.Handle, subkey *uint16) (regerrno error) {
r0, _, _ := syscall.SyscallN(procRegDeleteKeyW.Addr(), uintptr(key), uintptr(unsafe.Pointer(subkey)))
r0, _, _ := syscall.Syscall(procRegDeleteKeyW.Addr(), 2, uintptr(key), uintptr(unsafe.Pointer(subkey)), 0)
if r0 != 0 {
regerrno = syscall.Errno(r0)
}
@@ -76,7 +76,7 @@ func regDeleteKey(key syscall.Handle, subkey *uint16) (regerrno error) {
}
func regDeleteValue(key syscall.Handle, name *uint16) (regerrno error) {
r0, _, _ := syscall.SyscallN(procRegDeleteValueW.Addr(), uintptr(key), uintptr(unsafe.Pointer(name)))
r0, _, _ := syscall.Syscall(procRegDeleteValueW.Addr(), 2, uintptr(key), uintptr(unsafe.Pointer(name)), 0)
if r0 != 0 {
regerrno = syscall.Errno(r0)
}
@@ -84,7 +84,7 @@ func regDeleteValue(key syscall.Handle, name *uint16) (regerrno error) {
}
func regEnumValue(key syscall.Handle, index uint32, name *uint16, nameLen *uint32, reserved *uint32, valtype *uint32, buf *byte, buflen *uint32) (regerrno error) {
r0, _, _ := syscall.SyscallN(procRegEnumValueW.Addr(), uintptr(key), uintptr(index), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(nameLen)), uintptr(unsafe.Pointer(reserved)), uintptr(unsafe.Pointer(valtype)), uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(buflen)))
r0, _, _ := syscall.Syscall9(procRegEnumValueW.Addr(), 8, uintptr(key), uintptr(index), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(nameLen)), uintptr(unsafe.Pointer(reserved)), uintptr(unsafe.Pointer(valtype)), uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(buflen)), 0)
if r0 != 0 {
regerrno = syscall.Errno(r0)
}
@@ -92,7 +92,7 @@ func regEnumValue(key syscall.Handle, index uint32, name *uint16, nameLen *uint3
}
func regLoadMUIString(key syscall.Handle, name *uint16, buf *uint16, buflen uint32, buflenCopied *uint32, flags uint32, dir *uint16) (regerrno error) {
r0, _, _ := syscall.SyscallN(procRegLoadMUIStringW.Addr(), uintptr(key), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(buf)), uintptr(buflen), uintptr(unsafe.Pointer(buflenCopied)), uintptr(flags), uintptr(unsafe.Pointer(dir)))
r0, _, _ := syscall.Syscall9(procRegLoadMUIStringW.Addr(), 7, uintptr(key), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(buf)), uintptr(buflen), uintptr(unsafe.Pointer(buflenCopied)), uintptr(flags), uintptr(unsafe.Pointer(dir)), 0, 0)
if r0 != 0 {
regerrno = syscall.Errno(r0)
}
@@ -100,7 +100,7 @@ func regLoadMUIString(key syscall.Handle, name *uint16, buf *uint16, buflen uint
}
func regSetValueEx(key syscall.Handle, valueName *uint16, reserved uint32, vtype uint32, buf *byte, bufsize uint32) (regerrno error) {
r0, _, _ := syscall.SyscallN(procRegSetValueExW.Addr(), uintptr(key), uintptr(unsafe.Pointer(valueName)), uintptr(reserved), uintptr(vtype), uintptr(unsafe.Pointer(buf)), uintptr(bufsize))
r0, _, _ := syscall.Syscall6(procRegSetValueExW.Addr(), 6, uintptr(key), uintptr(unsafe.Pointer(valueName)), uintptr(reserved), uintptr(vtype), uintptr(unsafe.Pointer(buf)), uintptr(bufsize))
if r0 != 0 {
regerrno = syscall.Errno(r0)
}
@@ -108,7 +108,7 @@ func regSetValueEx(key syscall.Handle, valueName *uint16, reserved uint32, vtype
}
func expandEnvironmentStrings(src *uint16, dst *uint16, size uint32) (n uint32, err error) {
r0, _, e1 := syscall.SyscallN(procExpandEnvironmentStringsW.Addr(), uintptr(unsafe.Pointer(src)), uintptr(unsafe.Pointer(dst)), uintptr(size))
r0, _, e1 := syscall.Syscall(procExpandEnvironmentStringsW.Addr(), 3, uintptr(unsafe.Pointer(src)), uintptr(unsafe.Pointer(dst)), uintptr(size))
n = uint32(r0)
if n == 0 {
err = errnoErr(e1)
-2
View File
@@ -321,8 +321,6 @@ func NewCallbackCDecl(fn interface{}) uintptr {
//sys SetConsoleOutputCP(cp uint32) (err error) = kernel32.SetConsoleOutputCP
//sys WriteConsole(console Handle, buf *uint16, towrite uint32, written *uint32, reserved *byte) (err error) = kernel32.WriteConsoleW
//sys ReadConsole(console Handle, buf *uint16, toread uint32, read *uint32, inputControl *byte) (err error) = kernel32.ReadConsoleW
//sys GetNumberOfConsoleInputEvents(console Handle, numevents *uint32) (err error) = kernel32.GetNumberOfConsoleInputEvents
//sys FlushConsoleInputBuffer(console Handle) (err error) = kernel32.FlushConsoleInputBuffer
//sys resizePseudoConsole(pconsole Handle, size uint32) (hr error) = kernel32.ResizePseudoConsole
//sys CreateToolhelp32Snapshot(flags uint32, processId uint32) (handle Handle, err error) [failretval==InvalidHandle] = kernel32.CreateToolhelp32Snapshot
//sys Module32First(snapshot Handle, moduleEntry *ModuleEntry32) (err error) = kernel32.Module32FirstW
-22
View File
@@ -65,22 +65,6 @@ var signals = [...]string{
15: "terminated",
}
// File flags for [os.OpenFile]. The O_ prefix is used to indicate
// that these flags are specific to the OpenFile function.
const (
O_FILE_FLAG_OPEN_NO_RECALL = FILE_FLAG_OPEN_NO_RECALL
O_FILE_FLAG_OPEN_REPARSE_POINT = FILE_FLAG_OPEN_REPARSE_POINT
O_FILE_FLAG_SESSION_AWARE = FILE_FLAG_SESSION_AWARE
O_FILE_FLAG_POSIX_SEMANTICS = FILE_FLAG_POSIX_SEMANTICS
O_FILE_FLAG_BACKUP_SEMANTICS = FILE_FLAG_BACKUP_SEMANTICS
O_FILE_FLAG_DELETE_ON_CLOSE = FILE_FLAG_DELETE_ON_CLOSE
O_FILE_FLAG_SEQUENTIAL_SCAN = FILE_FLAG_SEQUENTIAL_SCAN
O_FILE_FLAG_RANDOM_ACCESS = FILE_FLAG_RANDOM_ACCESS
O_FILE_FLAG_NO_BUFFERING = FILE_FLAG_NO_BUFFERING
O_FILE_FLAG_OVERLAPPED = FILE_FLAG_OVERLAPPED
O_FILE_FLAG_WRITE_THROUGH = FILE_FLAG_WRITE_THROUGH
)
const (
FILE_READ_DATA = 0x00000001
FILE_READ_ATTRIBUTES = 0x00000080
@@ -1992,12 +1976,6 @@ const (
SYMBOLIC_LINK_FLAG_DIRECTORY = 0x1
)
// FILE_ZERO_DATA_INFORMATION from winioctl.h
type FileZeroDataInformation struct {
FileOffset int64
BeyondFinalZero int64
}
const (
ComputerNameNetBIOS = 0
ComputerNameDnsHostname = 1
File diff suppressed because it is too large Load Diff