Merge pull request #581 from alexcb/use-default-ssh-when-missing-v2
include default ssh socket when given an ssh-based git urlpull/583/head
						commit
						adc5f35237
					
				@ -0,0 +1,46 @@
 | 
			
		||||
package gitutil
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"strings"
 | 
			
		||||
 | 
			
		||||
	"github.com/moby/buildkit/util/sshutil"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
const (
 | 
			
		||||
	HTTPProtocol = iota + 1
 | 
			
		||||
	HTTPSProtocol
 | 
			
		||||
	SSHProtocol
 | 
			
		||||
	GitProtocol
 | 
			
		||||
	UnknownProtocol
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// ParseProtocol parses a git URL and returns the remote url and protocol type
 | 
			
		||||
func ParseProtocol(remote string) (string, int) {
 | 
			
		||||
	prefixes := map[string]int{
 | 
			
		||||
		"http://":  HTTPProtocol,
 | 
			
		||||
		"https://": HTTPSProtocol,
 | 
			
		||||
		"git://":   GitProtocol,
 | 
			
		||||
		"ssh://":   SSHProtocol,
 | 
			
		||||
	}
 | 
			
		||||
	protocolType := UnknownProtocol
 | 
			
		||||
	for prefix, potentialType := range prefixes {
 | 
			
		||||
		if strings.HasPrefix(remote, prefix) {
 | 
			
		||||
			remote = strings.TrimPrefix(remote, prefix)
 | 
			
		||||
			protocolType = potentialType
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if protocolType == UnknownProtocol && sshutil.IsImplicitSSHTransport(remote) {
 | 
			
		||||
		protocolType = SSHProtocol
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// remove name from ssh
 | 
			
		||||
	if protocolType == SSHProtocol {
 | 
			
		||||
		parts := strings.SplitN(remote, "@", 2)
 | 
			
		||||
		if len(parts) == 2 {
 | 
			
		||||
			remote = parts[1]
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return remote, protocolType
 | 
			
		||||
}
 | 
			
		||||
@ -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.
 | 
			
		||||
 | 
			
		||||
//go:build (darwin || dragonfly || freebsd || netbsd || openbsd) && gc
 | 
			
		||||
// +build darwin dragonfly freebsd netbsd openbsd
 | 
			
		||||
// +build gc
 | 
			
		||||
 | 
			
		||||
#include "textflag.h"
 | 
			
		||||
 | 
			
		||||
//
 | 
			
		||||
// System call support for AMD64, Darwin
 | 
			
		||||
//
 | 
			
		||||
// 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 2013 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.
 | 
			
		||||
 | 
			
		||||
//go:build (darwin || freebsd || netbsd || openbsd) && gc
 | 
			
		||||
// +build darwin freebsd netbsd openbsd
 | 
			
		||||
// +build gc
 | 
			
		||||
 | 
			
		||||
#include "textflag.h"
 | 
			
		||||
 | 
			
		||||
//
 | 
			
		||||
// System call support for ARM, NetBSD
 | 
			
		||||
//
 | 
			
		||||
// 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.
 | 
			
		||||
 | 
			
		||||
//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,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 gc
 | 
			
		||||
// +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 gc
 | 
			
		||||
// +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 gc
 | 
			
		||||
 | 
			
		||||
#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 gc
 | 
			
		||||
 | 
			
		||||
#include "textflag.h"
 | 
			
		||||
 | 
			
		||||
//
 | 
			
		||||
// System call support for 386, FreeBSD
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
// 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 gc
 | 
			
		||||
 | 
			
		||||
#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 2012 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 gc
 | 
			
		||||
 | 
			
		||||
#include "textflag.h"
 | 
			
		||||
 | 
			
		||||
//
 | 
			
		||||
// System call support for ARM, FreeBSD
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
// 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 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 gc
 | 
			
		||||
 | 
			
		||||
#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 gc
 | 
			
		||||
 | 
			
		||||
#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 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 gc
 | 
			
		||||
 | 
			
		||||
#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 gc
 | 
			
		||||
 | 
			
		||||
#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 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 gc
 | 
			
		||||
 | 
			
		||||
#include "textflag.h"
 | 
			
		||||
 | 
			
		||||
//
 | 
			
		||||
// System call support for AMD64, 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)
 | 
			
		||||
@ -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 gc
 | 
			
		||||
 | 
			
		||||
#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 gc
 | 
			
		||||
 | 
			
		||||
#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
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,74 @@
 | 
			
		||||
// 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 (
 | 
			
		||||
	"runtime"
 | 
			
		||||
	"unsafe"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// ioctl itself should not be exposed directly, but additional get/set
 | 
			
		||||
// functions for specific types are permissible.
 | 
			
		||||
 | 
			
		||||
// IoctlSetInt performs an ioctl operation which sets an integer value
 | 
			
		||||
// on fd, using the specified request number.
 | 
			
		||||
func IoctlSetInt(fd int, req uint, value int) error {
 | 
			
		||||
	return ioctl(fd, req, uintptr(value))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// IoctlSetWinsize performs an ioctl on fd with a *Winsize argument.
 | 
			
		||||
//
 | 
			
		||||
// To change fd's window size, the req argument should be TIOCSWINSZ.
 | 
			
		||||
func IoctlSetWinsize(fd int, req uint, value *Winsize) error {
 | 
			
		||||
	// TODO: if we get the chance, remove the req parameter and
 | 
			
		||||
	// hardcode TIOCSWINSZ.
 | 
			
		||||
	err := ioctl(fd, req, uintptr(unsafe.Pointer(value)))
 | 
			
		||||
	runtime.KeepAlive(value)
 | 
			
		||||
	return err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// IoctlSetTermios performs an ioctl on fd with a *Termios.
 | 
			
		||||
//
 | 
			
		||||
// The req value is expected to be TCSETS, TCSETSW, or TCSETSF
 | 
			
		||||
func IoctlSetTermios(fd int, req uint, value *Termios) error {
 | 
			
		||||
	if (req != TCSETS) && (req != TCSETSW) && (req != TCSETSF) {
 | 
			
		||||
		return ENOSYS
 | 
			
		||||
	}
 | 
			
		||||
	err := Tcsetattr(fd, int(req), value)
 | 
			
		||||
	runtime.KeepAlive(value)
 | 
			
		||||
	return err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// IoctlGetInt performs an ioctl operation which gets an integer value
 | 
			
		||||
// from fd, using the specified request number.
 | 
			
		||||
//
 | 
			
		||||
// A few ioctl requests use the return value as an output parameter;
 | 
			
		||||
// for those, IoctlRetInt should be used instead of this function.
 | 
			
		||||
func IoctlGetInt(fd int, req uint) (int, error) {
 | 
			
		||||
	var value int
 | 
			
		||||
	err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
 | 
			
		||||
	return value, err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func IoctlGetWinsize(fd int, req uint) (*Winsize, error) {
 | 
			
		||||
	var value Winsize
 | 
			
		||||
	err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
 | 
			
		||||
	return &value, err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// IoctlGetTermios performs an ioctl on fd with a *Termios.
 | 
			
		||||
//
 | 
			
		||||
// The req value is expected to be TCGETS
 | 
			
		||||
func IoctlGetTermios(fd int, req uint) (*Termios, error) {
 | 
			
		||||
	var value Termios
 | 
			
		||||
	if req != TCGETS {
 | 
			
		||||
		return &value, ENOSYS
 | 
			
		||||
	}
 | 
			
		||||
	err := Tcgetattr(fd, &value)
 | 
			
		||||
	return &value, err
 | 
			
		||||
}
 | 
			
		||||
Some files were not shown because too many files have changed in this diff Show More
					Loading…
					
					
				
		Reference in New Issue