mirror of https://github.com/go-gitea/gitea
parent
0d7afb02c0
commit
558b0005ff
@ -1,6 +1,7 @@ |
||||
// Code generated by running "go generate" in golang.org/x/text. DO NOT EDIT.
|
||||
|
||||
// +build go1.14
|
||||
//go:build go1.14 && !go1.16
|
||||
// +build go1.14,!go1.16
|
||||
|
||||
package idna |
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,173 @@ |
||||
// Copyright 2020 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.
|
||||
|
||||
package cpu |
||||
|
||||
import ( |
||||
"syscall" |
||||
"unsafe" |
||||
) |
||||
|
||||
// Minimal copy of functionality from x/sys/unix so the cpu package can call
|
||||
// sysctl without depending on x/sys/unix.
|
||||
|
||||
const ( |
||||
_CTL_QUERY = -2 |
||||
|
||||
_SYSCTL_VERS_1 = 0x1000000 |
||||
) |
||||
|
||||
var _zero uintptr |
||||
|
||||
func sysctl(mib []int32, old *byte, oldlen *uintptr, new *byte, newlen uintptr) (err error) { |
||||
var _p0 unsafe.Pointer |
||||
if len(mib) > 0 { |
||||
_p0 = unsafe.Pointer(&mib[0]) |
||||
} else { |
||||
_p0 = unsafe.Pointer(&_zero) |
||||
} |
||||
_, _, errno := syscall.Syscall6( |
||||
syscall.SYS___SYSCTL, |
||||
uintptr(_p0), |
||||
uintptr(len(mib)), |
||||
uintptr(unsafe.Pointer(old)), |
||||
uintptr(unsafe.Pointer(oldlen)), |
||||
uintptr(unsafe.Pointer(new)), |
||||
uintptr(newlen)) |
||||
if errno != 0 { |
||||
return errno |
||||
} |
||||
return nil |
||||
} |
||||
|
||||
type sysctlNode struct { |
||||
Flags uint32 |
||||
Num int32 |
||||
Name [32]int8 |
||||
Ver uint32 |
||||
__rsvd uint32 |
||||
Un [16]byte |
||||
_sysctl_size [8]byte |
||||
_sysctl_func [8]byte |
||||
_sysctl_parent [8]byte |
||||
_sysctl_desc [8]byte |
||||
} |
||||
|
||||
func sysctlNodes(mib []int32) ([]sysctlNode, error) { |
||||
var olen uintptr |
||||
|
||||
// Get a list of all sysctl nodes below the given MIB by performing
|
||||
// a sysctl for the given MIB with CTL_QUERY appended.
|
||||
mib = append(mib, _CTL_QUERY) |
||||
qnode := sysctlNode{Flags: _SYSCTL_VERS_1} |
||||
qp := (*byte)(unsafe.Pointer(&qnode)) |
||||
sz := unsafe.Sizeof(qnode) |
||||
if err := sysctl(mib, nil, &olen, qp, sz); err != nil { |
||||
return nil, err |
||||
} |
||||
|
||||
// Now that we know the size, get the actual nodes.
|
||||
nodes := make([]sysctlNode, olen/sz) |
||||
np := (*byte)(unsafe.Pointer(&nodes[0])) |
||||
if err := sysctl(mib, np, &olen, qp, sz); err != nil { |
||||
return nil, err |
||||
} |
||||
|
||||
return nodes, nil |
||||
} |
||||
|
||||
func nametomib(name string) ([]int32, error) { |
||||
// Split name into components.
|
||||
var parts []string |
||||
last := 0 |
||||
for i := 0; i < len(name); i++ { |
||||
if name[i] == '.' { |
||||
parts = append(parts, name[last:i]) |
||||
last = i + 1 |
||||
} |
||||
} |
||||
parts = append(parts, name[last:]) |
||||
|
||||
mib := []int32{} |
||||
// Discover the nodes and construct the MIB OID.
|
||||
for partno, part := range parts { |
||||
nodes, err := sysctlNodes(mib) |
||||
if err != nil { |
||||
return nil, err |
||||
} |
||||
for _, node := range nodes { |
||||
n := make([]byte, 0) |
||||
for i := range node.Name { |
||||
if node.Name[i] != 0 { |
||||
n = append(n, byte(node.Name[i])) |
||||
} |
||||
} |
||||
if string(n) == part { |
||||
mib = append(mib, int32(node.Num)) |
||||
break |
||||
} |
||||
} |
||||
if len(mib) != partno+1 { |
||||
return nil, err |
||||
} |
||||
} |
||||
|
||||
return mib, nil |
||||
} |
||||
|
||||
// aarch64SysctlCPUID is struct aarch64_sysctl_cpu_id from NetBSD's <aarch64/armreg.h>
|
||||
type aarch64SysctlCPUID struct { |
||||
midr uint64 /* Main ID Register */ |
||||
revidr uint64 /* Revision ID Register */ |
||||
mpidr uint64 /* Multiprocessor Affinity Register */ |
||||
aa64dfr0 uint64 /* A64 Debug Feature Register 0 */ |
||||
aa64dfr1 uint64 /* A64 Debug Feature Register 1 */ |
||||
aa64isar0 uint64 /* A64 Instruction Set Attribute Register 0 */ |
||||
aa64isar1 uint64 /* A64 Instruction Set Attribute Register 1 */ |
||||
aa64mmfr0 uint64 /* A64 Memory Model Feature Register 0 */ |
||||
aa64mmfr1 uint64 /* A64 Memory Model Feature Register 1 */ |
||||
aa64mmfr2 uint64 /* A64 Memory Model Feature Register 2 */ |
||||
aa64pfr0 uint64 /* A64 Processor Feature Register 0 */ |
||||
aa64pfr1 uint64 /* A64 Processor Feature Register 1 */ |
||||
aa64zfr0 uint64 /* A64 SVE Feature ID Register 0 */ |
||||
mvfr0 uint32 /* Media and VFP Feature Register 0 */ |
||||
mvfr1 uint32 /* Media and VFP Feature Register 1 */ |
||||
mvfr2 uint32 /* Media and VFP Feature Register 2 */ |
||||
pad uint32 |
||||
clidr uint64 /* Cache Level ID Register */ |
||||
ctr uint64 /* Cache Type Register */ |
||||
} |
||||
|
||||
func sysctlCPUID(name string) (*aarch64SysctlCPUID, error) { |
||||
mib, err := nametomib(name) |
||||
if err != nil { |
||||
return nil, err |
||||
} |
||||
|
||||
out := aarch64SysctlCPUID{} |
||||
n := unsafe.Sizeof(out) |
||||
_, _, errno := syscall.Syscall6( |
||||
syscall.SYS___SYSCTL, |
||||
uintptr(unsafe.Pointer(&mib[0])), |
||||
uintptr(len(mib)), |
||||
uintptr(unsafe.Pointer(&out)), |
||||
uintptr(unsafe.Pointer(&n)), |
||||
uintptr(0), |
||||
uintptr(0)) |
||||
if errno != 0 { |
||||
return nil, errno |
||||
} |
||||
return &out, nil |
||||
} |
||||
|
||||
func doinit() { |
||||
cpuid, err := sysctlCPUID("machdep.cpu0.cpu_id") |
||||
if err != nil { |
||||
setMinimalFeatures() |
||||
return |
||||
} |
||||
parseARM64SystemRegisters(cpuid.aa64isar0, cpuid.aa64isar1, cpuid.aa64pfr0) |
||||
|
||||
Initialized = true |
||||
} |
@ -0,0 +1,13 @@ |
||||
// Copyright 2020 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 !linux && (mips64 || mips64le)
|
||||
// +build !linux
|
||||
// +build mips64 mips64le
|
||||
|
||||
package cpu |
||||
|
||||
func archInit() { |
||||
Initialized = true |
||||
} |
@ -0,0 +1,10 @@ |
||||
// Copyright 2020 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.
|
||||
|
||||
package cpu |
||||
|
||||
func archInit() { |
||||
doinit() |
||||
Initialized = true |
||||
} |
@ -0,0 +1,25 @@ |
||||
// Copyright 2020 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.
|
||||
|
||||
package cpu |
||||
|
||||
func initS390Xbase() { |
||||
// get the facilities list
|
||||
facilities := stfle() |
||||
|
||||
// mandatory
|
||||
S390X.HasZARCH = facilities.Has(zarch) |
||||
S390X.HasSTFLE = facilities.Has(stflef) |
||||
S390X.HasLDISP = facilities.Has(ldisp) |
||||
S390X.HasEIMM = facilities.Has(eimm) |
||||
|
||||
// optional
|
||||
S390X.HasETF3EH = facilities.Has(etf3eh) |
||||
S390X.HasDFP = facilities.Has(dfp) |
||||
S390X.HasMSA = facilities.Has(msa) |
||||
S390X.HasVX = facilities.Has(vx) |
||||
if S390X.HasVX { |
||||
S390X.HasVXE = facilities.Has(vxe) |
||||
} |
||||
} |
@ -1,14 +1,14 @@ |
||||
// Copyright 2009 The Go Authors. All rights reserved. |
||||
// Copyright 2021 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. |
||||
|
||||
// +build !gccgo |
||||
//go:build (darwin || dragonfly || freebsd || netbsd || openbsd) && gc |
||||
// +build darwin dragonfly freebsd netbsd openbsd |
||||
// +build gc |
||||
|
||||
#include "textflag.h" |
||||
|
||||
// |
||||
// System call support for AMD64, OpenBSD |
||||
// |
||||
// System call support for AMD64 BSD |
||||
|
||||
// Just jump to package syscall's implementation for all these functions. |
||||
// The runtime may know about them. |
@ -1,14 +1,14 @@ |
||||
// Copyright 2012 The Go Authors. All rights reserved. |
||||
// Copyright 2021 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. |
||||
|
||||
// +build !gccgo |
||||
//go:build (darwin || freebsd || netbsd || openbsd) && gc |
||||
// +build darwin freebsd netbsd openbsd |
||||
// +build gc |
||||
|
||||
#include "textflag.h" |
||||
|
||||
// |
||||
// System call support for ARM, FreeBSD |
||||
// |
||||
// System call support for ARM BSD |
||||
|
||||
// Just jump to package syscall's implementation for all these functions. |
||||
// The runtime may know about them. |
@ -1,14 +1,14 @@ |
||||
// Copyright 2009 The Go Authors. All rights reserved. |
||||
// Copyright 2021 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. |
||||
|
||||
// +build !gccgo |
||||
//go:build (darwin || freebsd || netbsd || openbsd) && gc |
||||
// +build darwin freebsd netbsd openbsd |
||||
// +build gc |
||||
|
||||
#include "textflag.h" |
||||
|
||||
// |
||||
// System call support for AMD64, NetBSD |
||||
// |
||||
// System call support for ARM64 BSD |
||||
|
||||
// Just jump to package syscall's implementation for all these functions. |
||||
// The runtime may know about them. |
@ -1,29 +0,0 @@ |
||||
// Copyright 2009 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. |
||||
|
||||
// +build !gccgo |
||||
|
||||
#include "textflag.h" |
||||
|
||||
// |
||||
// System call support for 386, Darwin |
||||
// |
||||
|
||||
// Just jump to package syscall's implementation for all these functions. |
||||
// The runtime may know about them. |
||||
|
||||
TEXT ·Syscall(SB),NOSPLIT,$0-28 |
||||
JMP syscall·Syscall(SB) |
||||
|
||||
TEXT ·Syscall6(SB),NOSPLIT,$0-40 |
||||
JMP syscall·Syscall6(SB) |
||||
|
||||
TEXT ·Syscall9(SB),NOSPLIT,$0-52 |
||||
JMP syscall·Syscall9(SB) |
||||
|
||||
TEXT ·RawSyscall(SB),NOSPLIT,$0-28 |
||||
JMP syscall·RawSyscall(SB) |
||||
|
||||
TEXT ·RawSyscall6(SB),NOSPLIT,$0-40 |
||||
JMP syscall·RawSyscall6(SB) |
@ -1,29 +0,0 @@ |
||||
// Copyright 2009 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. |
||||
|
||||
// +build !gccgo |
||||
|
||||
#include "textflag.h" |
||||
|
||||
// |
||||
// System call support for AMD64, Darwin |
||||
// |
||||
|
||||
// Just jump to package syscall's implementation for all these functions. |
||||
// The runtime may know about them. |
||||
|
||||
TEXT ·Syscall(SB),NOSPLIT,$0-56 |
||||
JMP syscall·Syscall(SB) |
||||
|
||||
TEXT ·Syscall6(SB),NOSPLIT,$0-80 |
||||
JMP syscall·Syscall6(SB) |
||||
|
||||
TEXT ·Syscall9(SB),NOSPLIT,$0-104 |
||||
JMP syscall·Syscall9(SB) |
||||
|
||||
TEXT ·RawSyscall(SB),NOSPLIT,$0-56 |
||||
JMP syscall·RawSyscall(SB) |
||||
|
||||
TEXT ·RawSyscall6(SB),NOSPLIT,$0-80 |
||||
JMP syscall·RawSyscall6(SB) |
@ -1,30 +0,0 @@ |
||||
// 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. |
||||
|
||||
// +build !gccgo |
||||
// +build arm,darwin |
||||
|
||||
#include "textflag.h" |
||||
|
||||
// |
||||
// System call support for ARM, Darwin |
||||
// |
||||
|
||||
// Just jump to package syscall's implementation for all these functions. |
||||
// The runtime may know about them. |
||||
|
||||
TEXT ·Syscall(SB),NOSPLIT,$0-28 |
||||
B syscall·Syscall(SB) |
||||
|
||||
TEXT ·Syscall6(SB),NOSPLIT,$0-40 |
||||
B syscall·Syscall6(SB) |
||||
|
||||
TEXT ·Syscall9(SB),NOSPLIT,$0-52 |
||||
B syscall·Syscall9(SB) |
||||
|
||||
TEXT ·RawSyscall(SB),NOSPLIT,$0-28 |
||||
B syscall·RawSyscall(SB) |
||||
|
||||
TEXT ·RawSyscall6(SB),NOSPLIT,$0-40 |
||||
B syscall·RawSyscall6(SB) |
@ -1,30 +0,0 @@ |
||||
// 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. |
||||
|
||||
// +build !gccgo |
||||
// +build arm64,darwin |
||||
|
||||
#include "textflag.h" |
||||
|
||||
// |
||||
// System call support for AMD64, Darwin |
||||
// |
||||
|
||||
// Just jump to package syscall's implementation for all these functions. |
||||
// The runtime may know about them. |
||||
|
||||
TEXT ·Syscall(SB),NOSPLIT,$0-56 |
||||
B syscall·Syscall(SB) |
||||
|
||||
TEXT ·Syscall6(SB),NOSPLIT,$0-80 |
||||
B syscall·Syscall6(SB) |
||||
|
||||
TEXT ·Syscall9(SB),NOSPLIT,$0-104 |
||||
B syscall·Syscall9(SB) |
||||
|
||||
TEXT ·RawSyscall(SB),NOSPLIT,$0-56 |
||||
B syscall·RawSyscall(SB) |
||||
|
||||
TEXT ·RawSyscall6(SB),NOSPLIT,$0-80 |
||||
B syscall·RawSyscall6(SB) |
@ -1,29 +0,0 @@ |
||||
// Copyright 2009 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. |
||||
|
||||
// +build !gccgo |
||||
|
||||
#include "textflag.h" |
||||
|
||||
// |
||||
// System call support for AMD64, DragonFly |
||||
// |
||||
|
||||
// Just jump to package syscall's implementation for all these functions. |
||||
// The runtime may know about them. |
||||
|
||||
TEXT ·Syscall(SB),NOSPLIT,$0-56 |
||||
JMP syscall·Syscall(SB) |
||||
|
||||
TEXT ·Syscall6(SB),NOSPLIT,$0-80 |
||||
JMP syscall·Syscall6(SB) |
||||
|
||||
TEXT ·Syscall9(SB),NOSPLIT,$0-104 |
||||
JMP syscall·Syscall9(SB) |
||||
|
||||
TEXT ·RawSyscall(SB),NOSPLIT,$0-56 |
||||
JMP syscall·RawSyscall(SB) |
||||
|
||||
TEXT ·RawSyscall6(SB),NOSPLIT,$0-80 |
||||
JMP syscall·RawSyscall6(SB) |
@ -1,29 +0,0 @@ |
||||
// Copyright 2009 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. |
||||
|
||||
// +build !gccgo |
||||
|
||||
#include "textflag.h" |
||||
|
||||
// |
||||
// System call support for AMD64, FreeBSD |
||||
// |
||||
|
||||
// Just jump to package syscall's implementation for all these functions. |
||||
// The runtime may know about them. |
||||
|
||||
TEXT ·Syscall(SB),NOSPLIT,$0-56 |
||||
JMP syscall·Syscall(SB) |
||||
|
||||
TEXT ·Syscall6(SB),NOSPLIT,$0-80 |
||||
JMP syscall·Syscall6(SB) |
||||
|
||||
TEXT ·Syscall9(SB),NOSPLIT,$0-104 |
||||
JMP syscall·Syscall9(SB) |
||||
|
||||
TEXT ·RawSyscall(SB),NOSPLIT,$0-56 |
||||
JMP syscall·RawSyscall(SB) |
||||
|
||||
TEXT ·RawSyscall6(SB),NOSPLIT,$0-80 |
||||
JMP syscall·RawSyscall6(SB) |
@ -1,29 +0,0 @@ |
||||
// Copyright 2018 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. |
||||
|
||||
// +build !gccgo |
||||
|
||||
#include "textflag.h" |
||||
|
||||
// |
||||
// System call support for ARM64, FreeBSD |
||||
// |
||||
|
||||
// Just jump to package syscall's implementation for all these functions. |
||||
// The runtime may know about them. |
||||
|
||||
TEXT ·Syscall(SB),NOSPLIT,$0-56 |
||||
JMP syscall·Syscall(SB) |
||||
|
||||
TEXT ·Syscall6(SB),NOSPLIT,$0-80 |
||||
JMP syscall·Syscall6(SB) |
||||
|
||||
TEXT ·Syscall9(SB),NOSPLIT,$0-104 |
||||
JMP syscall·Syscall9(SB) |
||||
|
||||
TEXT ·RawSyscall(SB),NOSPLIT,$0-56 |
||||
JMP syscall·RawSyscall(SB) |
||||
|
||||
TEXT ·RawSyscall6(SB),NOSPLIT,$0-80 |
||||
JMP syscall·RawSyscall6(SB) |
@ -1,29 +0,0 @@ |
||||
// Copyright 2009 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. |
||||
|
||||
// +build !gccgo |
||||
|
||||
#include "textflag.h" |
||||
|
||||
// |
||||
// System call support for 386, NetBSD |
||||
// |
||||
|
||||
// Just jump to package syscall's implementation for all these functions. |
||||
// The runtime may know about them. |
||||
|
||||
TEXT ·Syscall(SB),NOSPLIT,$0-28 |
||||
JMP syscall·Syscall(SB) |
||||
|
||||
TEXT ·Syscall6(SB),NOSPLIT,$0-40 |
||||
JMP syscall·Syscall6(SB) |
||||
|
||||
TEXT ·Syscall9(SB),NOSPLIT,$0-52 |
||||
JMP syscall·Syscall9(SB) |
||||
|
||||
TEXT ·RawSyscall(SB),NOSPLIT,$0-28 |
||||
JMP syscall·RawSyscall(SB) |
||||
|
||||
TEXT ·RawSyscall6(SB),NOSPLIT,$0-40 |
||||
JMP syscall·RawSyscall6(SB) |
@ -1,29 +0,0 @@ |
||||
// Copyright 2013 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. |
||||
|
||||
// +build !gccgo |
||||
|
||||
#include "textflag.h" |
||||
|
||||
// |
||||
// System call support for ARM, NetBSD |
||||
// |
||||
|
||||
// Just jump to package syscall's implementation for all these functions. |
||||
// The runtime may know about them. |
||||
|
||||
TEXT ·Syscall(SB),NOSPLIT,$0-28 |
||||
B syscall·Syscall(SB) |
||||
|
||||
TEXT ·Syscall6(SB),NOSPLIT,$0-40 |
||||
B syscall·Syscall6(SB) |
||||
|
||||
TEXT ·Syscall9(SB),NOSPLIT,$0-52 |
||||
B syscall·Syscall9(SB) |
||||
|
||||
TEXT ·RawSyscall(SB),NOSPLIT,$0-28 |
||||
B syscall·RawSyscall(SB) |
||||
|
||||
TEXT ·RawSyscall6(SB),NOSPLIT,$0-40 |
||||
B syscall·RawSyscall6(SB) |
@ -1,29 +0,0 @@ |
||||
// Copyright 2019 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. |
||||
|
||||
// +build !gccgo |
||||
|
||||
#include "textflag.h" |
||||
|
||||
// |
||||
// System call support for ARM64, NetBSD |
||||
// |
||||
|
||||
// Just jump to package syscall's implementation for all these functions. |
||||
// The runtime may know about them. |
||||
|
||||
TEXT ·Syscall(SB),NOSPLIT,$0-56 |
||||
B syscall·Syscall(SB) |
||||
|
||||
TEXT ·Syscall6(SB),NOSPLIT,$0-80 |
||||
B syscall·Syscall6(SB) |
||||
|
||||
TEXT ·Syscall9(SB),NOSPLIT,$0-104 |
||||
B syscall·Syscall9(SB) |
||||
|
||||
TEXT ·RawSyscall(SB),NOSPLIT,$0-56 |
||||
B syscall·RawSyscall(SB) |
||||
|
||||
TEXT ·RawSyscall6(SB),NOSPLIT,$0-80 |
||||
B syscall·RawSyscall6(SB) |
@ -1,29 +0,0 @@ |
||||
// Copyright 2009 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. |
||||
|
||||
// +build !gccgo |
||||
|
||||
#include "textflag.h" |
||||
|
||||
// |
||||
// System call support for 386, OpenBSD |
||||
// |
||||
|
||||
// Just jump to package syscall's implementation for all these functions. |
||||
// The runtime may know about them. |
||||
|
||||
TEXT ·Syscall(SB),NOSPLIT,$0-28 |
||||
JMP syscall·Syscall(SB) |
||||
|
||||
TEXT ·Syscall6(SB),NOSPLIT,$0-40 |
||||
JMP syscall·Syscall6(SB) |
||||
|
||||
TEXT ·Syscall9(SB),NOSPLIT,$0-52 |
||||
JMP syscall·Syscall9(SB) |
||||
|
||||
TEXT ·RawSyscall(SB),NOSPLIT,$0-28 |
||||
JMP syscall·RawSyscall(SB) |
||||
|
||||
TEXT ·RawSyscall6(SB),NOSPLIT,$0-40 |
||||
JMP syscall·RawSyscall6(SB) |
@ -1,29 +0,0 @@ |
||||
// Copyright 2017 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. |
||||
|
||||
// +build !gccgo |
||||
|
||||
#include "textflag.h" |
||||
|
||||
// |
||||
// System call support for ARM, OpenBSD |
||||
// |
||||
|
||||
// Just jump to package syscall's implementation for all these functions. |
||||
// The runtime may know about them. |
||||
|
||||
TEXT ·Syscall(SB),NOSPLIT,$0-28 |
||||
B syscall·Syscall(SB) |
||||
|
||||
TEXT ·Syscall6(SB),NOSPLIT,$0-40 |
||||
B syscall·Syscall6(SB) |
||||
|
||||
TEXT ·Syscall9(SB),NOSPLIT,$0-52 |
||||
B syscall·Syscall9(SB) |
||||
|
||||
TEXT ·RawSyscall(SB),NOSPLIT,$0-28 |
||||
B syscall·RawSyscall(SB) |
||||
|
||||
TEXT ·RawSyscall6(SB),NOSPLIT,$0-40 |
||||
B syscall·RawSyscall6(SB) |
@ -1,29 +0,0 @@ |
||||
// Copyright 2019 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. |
||||
|
||||
// +build !gccgo |
||||
|
||||
#include "textflag.h" |
||||
|
||||
// |
||||
// System call support for arm64, OpenBSD |
||||
// |
||||
|
||||
// Just jump to package syscall's implementation for all these functions. |
||||
// The runtime may know about them. |
||||
|
||||
TEXT ·Syscall(SB),NOSPLIT,$0-56 |
||||
JMP syscall·Syscall(SB) |
||||
|
||||
TEXT ·Syscall6(SB),NOSPLIT,$0-80 |
||||
JMP syscall·Syscall6(SB) |
||||
|
||||
TEXT ·Syscall9(SB),NOSPLIT,$0-104 |
||||
JMP syscall·Syscall9(SB) |
||||
|
||||
TEXT ·RawSyscall(SB),NOSPLIT,$0-56 |
||||
JMP syscall·RawSyscall(SB) |
||||
|
||||
TEXT ·RawSyscall6(SB),NOSPLIT,$0-80 |
||||
JMP syscall·RawSyscall6(SB) |
@ -0,0 +1,426 @@ |
||||
// Copyright 2020 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 zos && s390x && gc |
||||
// +build zos |
||||
// +build s390x |
||||
// +build gc |
||||
|
||||
#include "textflag.h" |
||||
|
||||
#define PSALAA 1208(R0) |
||||
#define GTAB64(x) 80(x) |
||||
#define LCA64(x) 88(x) |
||||
#define CAA(x) 8(x) |
||||
#define EDCHPXV(x) 1016(x) // in the CAA |
||||
#define SAVSTACK_ASYNC(x) 336(x) // in the LCA |
||||
|
||||
// SS_*, where x=SAVSTACK_ASYNC |
||||
#define SS_LE(x) 0(x) |
||||
#define SS_GO(x) 8(x) |
||||
#define SS_ERRNO(x) 16(x) |
||||
#define SS_ERRNOJR(x) 20(x) |
||||
|
||||
#define LE_CALL BYTE $0x0D; BYTE $0x76; // BL R7, R6
|
||||
|
||||
TEXT ·clearErrno(SB),NOSPLIT,$0-0 |
||||
BL addrerrno<>(SB) |
||||
MOVD $0, 0(R3) |
||||
RET |
||||
|
||||
// Returns the address of errno in R3. |
||||
TEXT addrerrno<>(SB),NOSPLIT|NOFRAME,$0-0 |
||||
// Get library control area (LCA). |
||||
MOVW PSALAA, R8 |
||||
MOVD LCA64(R8), R8 |
||||
|
||||
// Get __errno FuncDesc. |
||||
MOVD CAA(R8), R9 |
||||
MOVD EDCHPXV(R9), R9 |
||||
ADD $(0x156*16), R9 |
||||
LMG 0(R9), R5, R6 |
||||
|
||||
// Switch to saved LE stack. |
||||
MOVD SAVSTACK_ASYNC(R8), R9 |
||||
MOVD 0(R9), R4 |
||||
MOVD $0, 0(R9) |
||||
|
||||
// Call __errno function. |
||||
LE_CALL |
||||
NOPH |
||||
|
||||
// Switch back to Go stack. |
||||
XOR R0, R0 // Restore R0 to $0. |
||||
MOVD R4, 0(R9) // Save stack pointer. |
||||
RET |
||||
|
||||
TEXT ·syscall_syscall(SB),NOSPLIT,$0-56 |
||||
BL runtime·entersyscall(SB) |
||||
MOVD a1+8(FP), R1 |
||||
MOVD a2+16(FP), R2 |
||||
MOVD a3+24(FP), R3 |
||||
|
||||
// Get library control area (LCA). |
||||
MOVW PSALAA, R8 |
||||
MOVD LCA64(R8), R8 |
||||
|
||||
// Get function. |
||||
MOVD CAA(R8), R9 |
||||
MOVD EDCHPXV(R9), R9 |
||||
MOVD trap+0(FP), R5 |
||||
SLD $4, R5 |
||||
ADD R5, R9 |
||||
LMG 0(R9), R5, R6 |
||||
|
||||
// Restore LE stack. |
||||
MOVD SAVSTACK_ASYNC(R8), R9 |
||||
MOVD 0(R9), R4 |
||||
MOVD $0, 0(R9) |
||||
|
||||
// Call function. |
||||
LE_CALL |
||||
NOPH |
||||
XOR R0, R0 // Restore R0 to $0. |
||||
MOVD R4, 0(R9) // Save stack pointer. |
||||
|
||||
MOVD R3, r1+32(FP) |
||||
MOVD R0, r2+40(FP) |
||||
MOVD R0, err+48(FP) |
||||
MOVW R3, R4 |
||||
CMP R4, $-1 |
||||
BNE done |
||||
BL addrerrno<>(SB) |
||||
MOVWZ 0(R3), R3 |
||||
MOVD R3, err+48(FP) |
||||
done: |
||||
BL runtime·exitsyscall(SB) |
||||
RET |
||||
|
||||
TEXT ·syscall_rawsyscall(SB),NOSPLIT,$0-56 |
||||
MOVD a1+8(FP), R1 |
||||
MOVD a2+16(FP), R2 |
||||
MOVD a3+24(FP), R3 |
||||
|
||||
// Get library control area (LCA). |
||||
MOVW PSALAA, R8 |
||||
MOVD LCA64(R8), R8 |
||||
|
||||
// Get function. |
||||
MOVD CAA(R8), R9 |
||||
MOVD EDCHPXV(R9), R9 |
||||
MOVD trap+0(FP), R5 |
||||
SLD $4, R5 |
||||
ADD R5, R9 |
||||
LMG 0(R9), R5, R6 |
||||
|
||||
// Restore LE stack. |
||||
MOVD SAVSTACK_ASYNC(R8), R9 |
||||
MOVD 0(R9), R4 |
||||
MOVD $0, 0(R9) |
||||
|
||||
// Call function. |
||||
LE_CALL |
||||
NOPH |
||||
XOR R0, R0 // Restore R0 to $0. |
||||
MOVD R4, 0(R9) // Save stack pointer. |
||||
|
||||
MOVD R3, r1+32(FP) |
||||
MOVD R0, r2+40(FP) |
||||
MOVD R0, err+48(FP) |
||||
MOVW R3, R4 |
||||
CMP R4, $-1 |
||||
BNE done |
||||
BL addrerrno<>(SB) |
||||
MOVWZ 0(R3), R3 |
||||
MOVD R3, err+48(FP) |
||||
done: |
||||
RET |
||||
|
||||
TEXT ·syscall_syscall6(SB),NOSPLIT,$0-80 |
||||
BL runtime·entersyscall(SB) |
||||
MOVD a1+8(FP), R1 |
||||
MOVD a2+16(FP), R2 |
||||
MOVD a3+24(FP), R3 |
||||
|
||||
// Get library control area (LCA). |
||||
MOVW PSALAA, R8 |
||||
MOVD LCA64(R8), R8 |
||||
|
||||
// Get function. |
||||
MOVD CAA(R8), R9 |
||||
MOVD EDCHPXV(R9), R9 |
||||
MOVD trap+0(FP), R5 |
||||
SLD $4, R5 |
||||
ADD R5, R9 |
||||
LMG 0(R9), R5, R6 |
||||
|
||||
// Restore LE stack. |
||||
MOVD SAVSTACK_ASYNC(R8), R9 |
||||
MOVD 0(R9), R4 |
||||
MOVD $0, 0(R9) |
||||
|
||||
// Fill in parameter list. |
||||
MOVD a4+32(FP), R12 |
||||
MOVD R12, (2176+24)(R4) |
||||
MOVD a5+40(FP), R12 |
||||
MOVD R12, (2176+32)(R4) |
||||
MOVD a6+48(FP), R12 |
||||
MOVD R12, (2176+40)(R4) |
||||
|
||||
// Call function. |
||||
LE_CALL |
||||
NOPH |
||||
XOR R0, R0 // Restore R0 to $0. |
||||
MOVD R4, 0(R9) // Save stack pointer. |
||||
|
||||
MOVD R3, r1+56(FP) |
||||
MOVD R0, r2+64(FP) |
||||
MOVD R0, err+72(FP) |
||||
MOVW R3, R4 |
||||
CMP R4, $-1 |
||||
BNE done |
||||
BL addrerrno<>(SB) |
||||
MOVWZ 0(R3), R3 |
||||
MOVD R3, err+72(FP) |
||||
done: |
||||
BL runtime·exitsyscall(SB) |
||||
RET |
||||
|
||||
TEXT ·syscall_rawsyscall6(SB),NOSPLIT,$0-80 |
||||
MOVD a1+8(FP), R1 |
||||
MOVD a2+16(FP), R2 |
||||
MOVD a3+24(FP), R3 |
||||
|
||||
// Get library control area (LCA). |
||||
MOVW PSALAA, R8 |
||||
MOVD LCA64(R8), R8 |
||||
|
||||
// Get function. |
||||
MOVD CAA(R8), R9 |
||||
MOVD EDCHPXV(R9), R9 |
||||
MOVD trap+0(FP), R5 |
||||
SLD $4, R5 |
||||
ADD R5, R9 |
||||
LMG 0(R9), R5, R6 |
||||
|
||||
// Restore LE stack. |
||||
MOVD SAVSTACK_ASYNC(R8), R9 |
||||
MOVD 0(R9), R4 |
||||
MOVD $0, 0(R9) |
||||
|
||||
// Fill in parameter list. |
||||
MOVD a4+32(FP), R12 |
||||
MOVD R12, (2176+24)(R4) |
||||
MOVD a5+40(FP), R12 |
||||
MOVD R12, (2176+32)(R4) |
||||
MOVD a6+48(FP), R12 |
||||
MOVD R12, (2176+40)(R4) |
||||
|
||||
// Call function. |
||||
LE_CALL |
||||
NOPH |
||||
XOR R0, R0 // Restore R0 to $0. |
||||
MOVD R4, 0(R9) // Save stack pointer. |
||||
|
||||
MOVD R3, r1+56(FP) |
||||
MOVD R0, r2+64(FP) |
||||
MOVD R0, err+72(FP) |
||||
MOVW R3, R4 |
||||
CMP R4, $-1 |
||||
BNE done |
||||
BL ·rrno<>(SB) |
||||
MOVWZ 0(R3), R3 |
||||
MOVD R3, err+72(FP) |
||||
done: |
||||
RET |
||||
|
||||
TEXT ·syscall_syscall9(SB),NOSPLIT,$0 |
||||
BL runtime·entersyscall(SB) |
||||
MOVD a1+8(FP), R1 |
||||
MOVD a2+16(FP), R2 |
||||
MOVD a3+24(FP), R3 |
||||
|
||||
// Get library control area (LCA). |
||||
MOVW PSALAA, R8 |
||||
MOVD LCA64(R8), R8 |
||||
|
||||
// Get function. |
||||
MOVD CAA(R8), R9 |
||||
MOVD EDCHPXV(R9), R9 |
||||
MOVD trap+0(FP), R5 |
||||
SLD $4, R5 |
||||
ADD R5, R9 |
||||
LMG 0(R9), R5, R6 |
||||
|
||||
// Restore LE stack. |
||||
MOVD SAVSTACK_ASYNC(R8), R9 |
||||
MOVD 0(R9), R4 |
||||
MOVD $0, 0(R9) |
||||
|
||||
// Fill in parameter list. |
||||
MOVD a4+32(FP), R12 |
||||
MOVD R12, (2176+24)(R4) |
||||
MOVD a5+40(FP), R12 |
||||
MOVD R12, (2176+32)(R4) |
||||
MOVD a6+48(FP), R12 |
||||
MOVD R12, (2176+40)(R4) |
||||
MOVD a7+56(FP), R12 |
||||
MOVD R12, (2176+48)(R4) |
||||
MOVD a8+64(FP), R12 |
||||
MOVD R12, (2176+56)(R4) |
||||
MOVD a9+72(FP), R12 |
||||
MOVD R12, (2176+64)(R4) |
||||
|
||||
// Call function. |
||||
LE_CALL |
||||
NOPH |
||||
XOR R0, R0 // Restore R0 to $0. |
||||
MOVD R4, 0(R9) // Save stack pointer. |
||||
|
||||
MOVD R3, r1+80(FP) |
||||
MOVD R0, r2+88(FP) |
||||
MOVD R0, err+96(FP) |
||||
MOVW R3, R4 |
||||
CMP R4, $-1 |
||||
BNE done |
||||
BL addrerrno<>(SB) |
||||
MOVWZ 0(R3), R3 |
||||
MOVD R3, err+96(FP) |
||||
done: |
||||
BL runtime·exitsyscall(SB) |
||||
RET |
||||
|
||||
TEXT ·syscall_rawsyscall9(SB),NOSPLIT,$0 |
||||
MOVD a1+8(FP), R1 |
||||
MOVD a2+16(FP), R2 |
||||
MOVD a3+24(FP), R3 |
||||
|
||||
// Get library control area (LCA). |
||||
MOVW PSALAA, R8 |
||||
MOVD LCA64(R8), R8 |
||||
|
||||
// Get function. |
||||
MOVD CAA(R8), R9 |
||||
MOVD EDCHPXV(R9), R9 |
||||
MOVD trap+0(FP), R5 |
||||
SLD $4, R5 |
||||
ADD R5, R9 |
||||
LMG 0(R9), R5, R6 |
||||
|
||||
// Restore LE stack. |
||||
MOVD SAVSTACK_ASYNC(R8), R9 |
||||
MOVD 0(R9), R4 |
||||
MOVD $0, 0(R9) |
||||
|
||||
// Fill in parameter list. |
||||
MOVD a4+32(FP), R12 |
||||
MOVD R12, (2176+24)(R4) |
||||
MOVD a5+40(FP), R12 |
||||
MOVD R12, (2176+32)(R4) |
||||
MOVD a6+48(FP), R12 |
||||
MOVD R12, (2176+40)(R4) |
||||
MOVD a7+56(FP), R12 |
||||
MOVD R12, (2176+48)(R4) |
||||
MOVD a8+64(FP), R12 |
||||
MOVD R12, (2176+56)(R4) |
||||
MOVD a9+72(FP), R12 |
||||
MOVD R12, (2176+64)(R4) |
||||
|
||||
// Call function. |
||||
LE_CALL |
||||
NOPH |
||||
XOR R0, R0 // Restore R0 to $0. |
||||
MOVD R4, 0(R9) // Save stack pointer. |
||||
|
||||
MOVD R3, r1+80(FP) |
||||
MOVD R0, r2+88(FP) |
||||
MOVD R0, err+96(FP) |
||||
MOVW R3, R4 |
||||
CMP R4, $-1 |
||||
BNE done |
||||
BL addrerrno<>(SB) |
||||
MOVWZ 0(R3), R3 |
||||
MOVD R3, err+96(FP) |
||||
done: |
||||
RET |
||||
|
||||
// func svcCall(fnptr unsafe.Pointer, argv *unsafe.Pointer, dsa *uint64) |
||||
TEXT ·svcCall(SB),NOSPLIT,$0 |
||||
BL runtime·save_g(SB) // Save g and stack pointer |
||||
MOVW PSALAA, R8 |
||||
MOVD LCA64(R8), R8 |
||||
MOVD SAVSTACK_ASYNC(R8), R9 |
||||
MOVD R15, 0(R9) |
||||
|
||||
MOVD argv+8(FP), R1 // Move function arguments into registers |
||||
MOVD dsa+16(FP), g |
||||
MOVD fnptr+0(FP), R15 |
||||
|
||||
BYTE $0x0D // Branch to function |
||||
BYTE $0xEF |
||||
|
||||
BL runtime·load_g(SB) // Restore g and stack pointer |
||||
MOVW PSALAA, R8 |
||||
MOVD LCA64(R8), R8 |
||||
MOVD SAVSTACK_ASYNC(R8), R9 |
||||
MOVD 0(R9), R15 |
||||
|
||||
RET |
||||
|
||||
// func svcLoad(name *byte) unsafe.Pointer |
||||
TEXT ·svcLoad(SB),NOSPLIT,$0 |
||||
MOVD R15, R2 // Save go stack pointer |
||||
MOVD name+0(FP), R0 // Move SVC args into registers |
||||
MOVD $0x80000000, R1 |
||||
MOVD $0, R15 |
||||
BYTE $0x0A // SVC 08 LOAD |
||||
BYTE $0x08 |
||||
MOVW R15, R3 // Save return code from SVC |
||||
MOVD R2, R15 // Restore go stack pointer |
||||
CMP R3, $0 // Check SVC return code |
||||
BNE error |
||||
|
||||
MOVD $-2, R3 // Reset last bit of entry point to zero |
||||
AND R0, R3 |
||||
MOVD R3, addr+8(FP) // Return entry point returned by SVC |
||||
CMP R0, R3 // Check if last bit of entry point was set |
||||
BNE done |
||||
|
||||
MOVD R15, R2 // Save go stack pointer |
||||
MOVD $0, R15 // Move SVC args into registers (entry point still in r0 from SVC 08) |
||||
BYTE $0x0A // SVC 09 DELETE |
||||
BYTE $0x09 |
||||
MOVD R2, R15 // Restore go stack pointer |
||||
|
||||
error: |
||||
MOVD $0, addr+8(FP) // Return 0 on failure |
||||
done: |
||||
XOR R0, R0 // Reset r0 to 0 |
||||
RET |
||||
|
||||
// func svcUnload(name *byte, fnptr unsafe.Pointer) int64 |
||||
TEXT ·svcUnload(SB),NOSPLIT,$0 |
||||
MOVD R15, R2 // Save go stack pointer |
||||
MOVD name+0(FP), R0 // Move SVC args into registers |
||||
MOVD addr+8(FP), R15 |
||||
BYTE $0x0A // SVC 09 |
||||
BYTE $0x09 |
||||
XOR R0, R0 // Reset r0 to 0 |
||||
MOVD R15, R1 // Save SVC return code |
||||
MOVD R2, R15 // Restore go stack pointer |
||||
MOVD R1, rc+0(FP) // Return SVC return code |
||||
RET |
||||
|
||||
// func gettid() uint64 |
||||
TEXT ·gettid(SB), NOSPLIT, $0 |
||||
// Get library control area (LCA). |
||||
MOVW PSALAA, R8 |
||||
MOVD LCA64(R8), R8 |
||||
|
||||
// Get CEECAATHDID |
||||
MOVD CAA(R8), R9 |
||||
MOVD 0x3D0(R9), R9 |
||||
MOVD R9, ret+0(FP) |
||||
|
||||
RET |
@ -0,0 +1,29 @@ |
||||
// Copyright 2020 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 zos && s390x
|
||||
// +build zos,s390x
|
||||
|
||||
// Functions to access/create device major and minor numbers matching the
|
||||
// encoding used by z/OS.
|
||||
//
|
||||
// The information below is extracted and adapted from <sys/stat.h> macros.
|
||||
|
||||
package unix |
||||
|
||||
// Major returns the major component of a z/OS device number.
|
||||
func Major(dev uint64) uint32 { |
||||
return uint32((dev >> 16) & 0x0000FFFF) |
||||
} |
||||
|
||||
// Minor returns the minor component of a z/OS device number.
|
||||
func Minor(dev uint64) uint32 { |
||||
return uint32(dev & 0x0000FFFF) |
||||
} |
||||
|
||||
// Mkdev returns a z/OS device number generated from the given major and minor
|
||||
// components.
|
||||
func Mkdev(major, minor uint32) uint64 { |
||||
return (uint64(major) << 16) | uint64(minor) |
||||
} |
@ -0,0 +1,221 @@ |
||||
// Copyright 2020 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 zos && s390x
|
||||
// +build zos,s390x
|
||||
|
||||
package unix |
||||
|
||||
import ( |
||||
"sync" |
||||
) |
||||
|
||||
// This file simulates epoll on z/OS using poll.
|
||||
|
||||
// Analogous to epoll_event on Linux.
|
||||
// TODO(neeilan): Pad is because the Linux kernel expects a 96-bit struct. We never pass this to the kernel; remove?
|
||||
type EpollEvent struct { |
||||
Events uint32 |
||||
Fd int32 |
||||
Pad int32 |
||||
} |
||||
|
||||
const ( |
||||
EPOLLERR = 0x8 |
||||
EPOLLHUP = 0x10 |
||||
EPOLLIN = 0x1 |
||||
EPOLLMSG = 0x400 |
||||
EPOLLOUT = 0x4 |
||||
EPOLLPRI = 0x2 |
||||
EPOLLRDBAND = 0x80 |
||||
EPOLLRDNORM = 0x40 |
||||
EPOLLWRBAND = 0x200 |
||||
EPOLLWRNORM = 0x100 |
||||
EPOLL_CTL_ADD = 0x1 |
||||
EPOLL_CTL_DEL = 0x2 |
||||
EPOLL_CTL_MOD = 0x3 |
||||
// The following constants are part of the epoll API, but represent
|
||||
// currently unsupported functionality on z/OS.
|
||||
// EPOLL_CLOEXEC = 0x80000
|
||||
// EPOLLET = 0x80000000
|
||||
// EPOLLONESHOT = 0x40000000
|
||||
// EPOLLRDHUP = 0x2000 // Typically used with edge-triggered notis
|
||||
// EPOLLEXCLUSIVE = 0x10000000 // Exclusive wake-up mode
|
||||
// EPOLLWAKEUP = 0x20000000 // Relies on Linux's BLOCK_SUSPEND capability
|
||||
) |
||||
|
||||
// TODO(neeilan): We can eliminate these epToPoll / pToEpoll calls by using identical mask values for POLL/EPOLL
|
||||
// constants where possible The lower 16 bits of epoll events (uint32) can fit any system poll event (int16).
|
||||
|
||||
// epToPollEvt converts epoll event field to poll equivalent.
|
||||
// In epoll, Events is a 32-bit field, while poll uses 16 bits.
|
||||
func epToPollEvt(events uint32) int16 { |
||||
var ep2p = map[uint32]int16{ |
||||
EPOLLIN: POLLIN, |
||||
EPOLLOUT: POLLOUT, |
||||
EPOLLHUP: POLLHUP, |
||||
EPOLLPRI: POLLPRI, |
||||
EPOLLERR: POLLERR, |
||||
} |
||||
|
||||
var pollEvts int16 = 0 |
||||
for epEvt, pEvt := range ep2p { |
||||
if (events & epEvt) != 0 { |
||||
pollEvts |= pEvt |
||||
} |
||||
} |
||||
|
||||
return pollEvts |
||||
} |
||||
|
||||
// pToEpollEvt converts 16 bit poll event bitfields to 32-bit epoll event fields.
|
||||
func pToEpollEvt(revents int16) uint32 { |
||||
var p2ep = map[int16]uint32{ |
||||
POLLIN: EPOLLIN, |
||||
POLLOUT: EPOLLOUT, |
||||
POLLHUP: EPOLLHUP, |
||||
POLLPRI: EPOLLPRI, |
||||
POLLERR: EPOLLERR, |
||||
} |
||||
|
||||
var epollEvts uint32 = 0 |
||||
for pEvt, epEvt := range p2ep { |
||||
if (revents & pEvt) != 0 { |
||||
epollEvts |= epEvt |
||||
} |
||||
} |
||||
|
||||
return epollEvts |
||||
} |
||||
|
||||
// Per-process epoll implementation.
|
||||
type epollImpl struct { |
||||
mu sync.Mutex |
||||
epfd2ep map[int]*eventPoll |
||||
nextEpfd int |
||||
} |
||||
|
||||
// eventPoll holds a set of file descriptors being watched by the process. A process can have multiple epoll instances.
|
||||
// On Linux, this is an in-kernel data structure accessed through a fd.
|
||||
type eventPoll struct { |
||||
mu sync.Mutex |
||||
fds map[int]*EpollEvent |
||||
} |
||||
|
||||
// epoll impl for this process.
|
||||
var impl epollImpl = epollImpl{ |
||||
epfd2ep: make(map[int]*eventPoll), |
||||
nextEpfd: 0, |
||||
} |
||||
|
||||
func (e *epollImpl) epollcreate(size int) (epfd int, err error) { |
||||
e.mu.Lock() |
||||
defer e.mu.Unlock() |
||||
epfd = e.nextEpfd |
||||
e.nextEpfd++ |
||||
|
||||
e.epfd2ep[epfd] = &eventPoll{ |
||||
fds: make(map[int]*EpollEvent), |
||||
} |
||||
return epfd, nil |
||||
} |
||||
|
||||
func (e *epollImpl) epollcreate1(flag int) (fd int, err error) { |
||||
return e.epollcreate(4) |
||||
} |
||||
|
||||
func (e *epollImpl) epollctl(epfd int, op int, fd int, event *EpollEvent) (err error) { |
||||
e.mu.Lock() |
||||
defer e.mu.Unlock() |
||||
|
||||
ep, ok := e.epfd2ep[epfd] |
||||
if !ok { |
||||
|
||||
return EBADF |
||||
} |
||||
|
||||
switch op { |
||||
case EPOLL_CTL_ADD: |
||||
// TODO(neeilan): When we make epfds and fds disjoint, detect epoll
|
||||
// loops here (instances watching each other) and return ELOOP.
|
||||
if _, ok := ep.fds[fd]; ok { |
||||
return EEXIST |
||||
} |
||||
ep.fds[fd] = event |
||||
case EPOLL_CTL_MOD: |
||||
if _, ok := ep.fds[fd]; !ok { |
||||
return ENOENT |
||||
} |
||||
ep.fds[fd] = event |
||||
case EPOLL_CTL_DEL: |
||||
if _, ok := ep.fds[fd]; !ok { |
||||
return ENOENT |
||||
} |
||||
delete(ep.fds, fd) |
||||
|
||||
} |
||||
return nil |
||||
} |
||||
|
||||
// Must be called while holding ep.mu
|
||||
func (ep *eventPoll) getFds() []int { |
||||
fds := make([]int, len(ep.fds)) |
||||
for fd := range ep.fds { |
||||
fds = append(fds, fd) |
||||
} |
||||
return fds |
||||
} |
||||
|
||||
func (e *epollImpl) epollwait(epfd int, events []EpollEvent, msec int) (n int, err error) { |
||||
e.mu.Lock() // in [rare] case of concurrent epollcreate + epollwait
|
||||
ep, ok := e.epfd2ep[epfd] |
||||
|
||||
if !ok { |
||||
e.mu.Unlock() |
||||
return 0, EBADF |
||||
} |
||||
|
||||
pollfds := make([]PollFd, 4) |
||||
for fd, epollevt := range ep.fds { |
||||
pollfds = append(pollfds, PollFd{Fd: int32(fd), Events: epToPollEvt(epollevt.Events)}) |
||||
} |
||||
e.mu.Unlock() |
||||
|
||||
n, err = Poll(pollfds, msec) |
||||
if err != nil { |
||||
return n, err |
||||
} |
||||
|
||||
i := 0 |
||||
for _, pFd := range pollfds { |
||||
if pFd.Revents != 0 { |
||||
events[i] = EpollEvent{Fd: pFd.Fd, Events: pToEpollEvt(pFd.Revents)} |
||||
i++ |
||||
} |
||||
|
||||
if i == n { |
||||
break |
||||
} |
||||
} |
||||
|
||||
return n, nil |
||||
} |
||||
|
||||
func EpollCreate(size int) (fd int, err error) { |
||||
return impl.epollcreate(size) |
||||
} |
||||
|
||||
func EpollCreate1(flag int) (fd int, err error) { |
||||
return impl.epollcreate1(flag) |
||||
} |
||||
|
||||
func EpollCtl(epfd int, op int, fd int, event *EpollEvent) (err error) { |
||||
return impl.epollctl(epfd, op, fd, event) |
||||
} |
||||
|
||||
// Because EpollWait mutates events, the caller is expected to coordinate
|
||||
// concurrent access if calling with the same epfd from multiple goroutines.
|
||||
func EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) { |
||||
return impl.epollwait(epfd, events, msec) |
||||
} |
@ -0,0 +1,164 @@ |
||||
// Copyright 2020 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 zos && s390x
|
||||
// +build zos,s390x
|
||||
|
||||
package unix |
||||
|
||||
import ( |
||||
"unsafe" |
||||
) |
||||
|
||||
// This file simulates fstatfs on z/OS using fstatvfs and w_getmntent.
|
||||
|
||||
func Fstatfs(fd int, stat *Statfs_t) (err error) { |
||||
var stat_v Statvfs_t |
||||
err = Fstatvfs(fd, &stat_v) |
||||
if err == nil { |
||||
// populate stat
|
||||
stat.Type = 0 |
||||
stat.Bsize = stat_v.Bsize |
||||
stat.Blocks = stat_v.Blocks |
||||
stat.Bfree = stat_v.Bfree |
||||
stat.Bavail = stat_v.Bavail |
||||
stat.Files = stat_v.Files |
||||
stat.Ffree = stat_v.Ffree |
||||
stat.Fsid = stat_v.Fsid |
||||
stat.Namelen = stat_v.Namemax |
||||
stat.Frsize = stat_v.Frsize |
||||
stat.Flags = stat_v.Flag |
||||
for passn := 0; passn < 5; passn++ { |
||||
switch passn { |
||||
case 0: |
||||
err = tryGetmntent64(stat) |
||||
break |
||||
case 1: |
||||
err = tryGetmntent128(stat) |
||||
break |
||||
case 2: |
||||
err = tryGetmntent256(stat) |
||||
break |
||||
case 3: |
||||
err = tryGetmntent512(stat) |
||||
break |
||||
case 4: |
||||
err = tryGetmntent1024(stat) |
||||
break |
||||
default: |
||||
break |
||||
} |
||||
//proceed to return if: err is nil (found), err is nonnil but not ERANGE (another error occurred)
|
||||
if err == nil || err != nil && err != ERANGE { |
||||
break |
||||
} |
||||
} |
||||
} |
||||
return err |
||||
} |
||||
|
||||
func tryGetmntent64(stat *Statfs_t) (err error) { |
||||
var mnt_ent_buffer struct { |
||||
header W_Mnth |
||||
filesys_info [64]W_Mntent |
||||
} |
||||
var buffer_size int = int(unsafe.Sizeof(mnt_ent_buffer)) |
||||
fs_count, err := W_Getmntent((*byte)(unsafe.Pointer(&mnt_ent_buffer)), buffer_size) |
||||
if err != nil { |
||||
return err |
||||
} |
||||
err = ERANGE //return ERANGE if no match is found in this batch
|
||||
for i := 0; i < fs_count; i++ { |
||||
if stat.Fsid == uint64(mnt_ent_buffer.filesys_info[i].Dev) { |
||||
stat.Type = uint32(mnt_ent_buffer.filesys_info[i].Fstname[0]) |
||||
err = nil |
||||
break |
||||
} |
||||
} |
||||
return err |
||||
} |
||||
|
||||
func tryGetmntent128(stat *Statfs_t) (err error) { |
||||
var mnt_ent_buffer struct { |
||||
header W_Mnth |
||||
filesys_info [128]W_Mntent |
||||
} |
||||
var buffer_size int = int(unsafe.Sizeof(mnt_ent_buffer)) |
||||
fs_count, err := W_Getmntent((*byte)(unsafe.Pointer(&mnt_ent_buffer)), buffer_size) |
||||
if err != nil { |
||||
return err |
||||
} |
||||
err = ERANGE //return ERANGE if no match is found in this batch
|
||||
for i := 0; i < fs_count; i++ { |
||||
if stat.Fsid == uint64(mnt_ent_buffer.filesys_info[i].Dev) { |
||||
stat.Type = uint32(mnt_ent_buffer.filesys_info[i].Fstname[0]) |
||||
err = nil |
||||
break |
||||
} |
||||
} |
||||
return err |
||||
} |
||||
|
||||
func tryGetmntent256(stat *Statfs_t) (err error) { |
||||
var mnt_ent_buffer struct { |
||||
header W_Mnth |
||||
filesys_info [256]W_Mntent |
||||
} |
||||
var buffer_size int = int(unsafe.Sizeof(mnt_ent_buffer)) |
||||
fs_count, err := W_Getmntent((*byte)(unsafe.Pointer(&mnt_ent_buffer)), buffer_size) |
||||
if err != nil { |
||||
return err |
||||
} |
||||
err = ERANGE //return ERANGE if no match is found in this batch
|
||||
for i := 0; i < fs_count; i++ { |
||||
if stat.Fsid == uint64(mnt_ent_buffer.filesys_info[i].Dev) { |
||||
stat.Type = uint32(mnt_ent_buffer.filesys_info[i].Fstname[0]) |
||||
err = nil |
||||
break |
||||
} |
||||
} |
||||
return err |
||||
} |
||||
|
||||
func tryGetmntent512(stat *Statfs_t) (err error) { |
||||
var mnt_ent_buffer struct { |
||||
header W_Mnth |
||||
filesys_info [512]W_Mntent |
||||
} |
||||
var buffer_size int = int(unsafe.Sizeof(mnt_ent_buffer)) |
||||
fs_count, err := W_Getmntent((*byte)(unsafe.Pointer(&mnt_ent_buffer)), buffer_size) |
||||
if err != nil { |
||||
return err |
||||
} |
||||
err = ERANGE //return ERANGE if no match is found in this batch
|
||||
for i := 0; i < fs_count; i++ { |
||||
if stat.Fsid == uint64(mnt_ent_buffer.filesys_info[i].Dev) { |
||||
stat.Type = uint32(mnt_ent_buffer.filesys_info[i].Fstname[0]) |
||||
err = nil |
||||
break |
||||
} |
||||
} |
||||
return err |
||||
} |
||||
|
||||
func tryGetmntent1024(stat *Statfs_t) (err error) { |
||||
var mnt_ent_buffer struct { |
||||
header W_Mnth |
||||
filesys_info [1024]W_Mntent |
||||
} |
||||
var buffer_size int = int(unsafe.Sizeof(mnt_ent_buffer)) |
||||
fs_count, err := W_Getmntent((*byte)(unsafe.Pointer(&mnt_ent_buffer)), buffer_size) |
||||
if err != nil { |
||||
return err |
||||
} |
||||
err = ERANGE //return ERANGE if no match is found in this batch
|
||||
for i := 0; i < fs_count; i++ { |
||||
if stat.Fsid == uint64(mnt_ent_buffer.filesys_info[i].Dev) { |
||||
stat.Type = uint32(mnt_ent_buffer.filesys_info[i].Fstname[0]) |
||||
err = nil |
||||
break |
||||
} |
||||
} |
||||
return err |
||||
} |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue