Commit 8cf3aee4 authored by Tobias Klauser's avatar Tobias Klauser Committed by Tobias Klauser

unix: add support for linux/riscv64

Add syscall wrappers, error constants and types for linux/riscv64

Switch docker image to Ubuntu 18.10 in order to get qemu supporting
riscv64. Also set the uname release string for qemu to 4.15 (the first
Linux kernel version with riscv64 support), because otherwise running
the generating C program in mkerrors.sh on a host with an older kernel
would fail with a "FATAL: kernel too old".

Note that linux/riscv64 is currently only usable using gccgo.

Updates golang/go#27532

Change-Id: Ic420f842342418443474cac72d38adff14d1b938
Reviewed-on: https://go-review.googlesource.com/133735
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
parent ebe1bf3e
FROM ubuntu:18.04
FROM ubuntu:18.10
# Dependencies to get the git sources and go binaries
RUN apt-get update && apt-get install -y --no-install-recommends \
......@@ -33,7 +33,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
bison gawk make python \
gcc gcc-multilib \
gettext texinfo \
qemu \
qemu-user \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Cross compilers (install recommended packages to get cross libc-dev)
......@@ -42,6 +42,7 @@ RUN apt-get update && apt-get install -y \
gcc-mips-linux-gnu gcc-mips64-linux-gnuabi64 \
gcc-mips64el-linux-gnuabi64 gcc-mipsel-linux-gnu \
gcc-powerpc64-linux-gnu gcc-powerpc64le-linux-gnu \
gcc-riscv64-linux-gnu \
gcc-s390x-linux-gnu gcc-sparc64-linux-gnu \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
......
......@@ -3,7 +3,7 @@
// license that can be found in the LICENSE file.
// linux/mkall.go - Generates all Linux zsysnum, zsyscall, zerror, and ztype
// files for all 11 linux architectures supported by the go compiler. See
// files for all Linux architectures supported by the go compiler. See
// README.md for more information about the build system.
// To run it you must have a git checkout of the Linux kernel and glibc. Once
......@@ -52,7 +52,7 @@ type target struct {
Bits int
}
// List of the 11 Linux targets supported by the go compiler. sparc64 is not
// List of all Linux targets supported by the go compiler. sparc64 is not
// currently supported, though a port is in progress.
var targets = []target{
{
......@@ -119,6 +119,12 @@ var targets = []target{
GNUArch: "powerpc64le-linux-gnu",
Bits: 64,
},
{
GoArch: "riscv64",
LinuxArch: "riscv",
GNUArch: "riscv64-linux-gnu",
Bits: 64,
},
{
GoArch: "s390x",
LinuxArch: "s390",
......@@ -256,6 +262,10 @@ func (t *target) generateFiles() error {
if t.LinuxArch == "powerpc" {
qemuArchName = t.GoArch
}
// Fake uname for QEMU to allow running on Host kernel version < 4.15
if t.LinuxArch == "riscv" {
os.Setenv("QEMU_UNAME", "4.15")
}
os.Setenv("GORUN", "qemu-"+qemuArchName)
} else {
os.Setenv("CC", "gcc")
......
// 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 riscv64,linux
package unix
import "unsafe"
func EpollCreate(size int) (fd int, err error) {
if size <= 0 {
return -1, EINVAL
}
return EpollCreate1(0)
}
//sys EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) = SYS_EPOLL_PWAIT
//sys Fadvise(fd int, offset int64, length int64, advice int) (err error) = SYS_FADVISE64
//sys Fchown(fd int, uid int, gid int) (err error)
//sys Fstat(fd int, stat *Stat_t) (err error)
//sys Fstatat(fd int, path string, stat *Stat_t, flags int) (err error)
//sys Fstatfs(fd int, buf *Statfs_t) (err error)
//sys Ftruncate(fd int, length int64) (err error)
//sysnb Getegid() (egid int)
//sysnb Geteuid() (euid int)
//sysnb Getgid() (gid int)
//sysnb Getrlimit(resource int, rlim *Rlimit) (err error)
//sysnb Getuid() (uid int)
//sys Listen(s int, n int) (err error)
//sys Pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64
//sys Pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64
//sys Seek(fd int, offset int64, whence int) (off int64, err error) = SYS_LSEEK
func Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, err error) {
var ts *Timespec
if timeout != nil {
ts = &Timespec{Sec: timeout.Sec, Nsec: timeout.Usec * 1000}
}
return Pselect(nfd, r, w, e, ts, nil)
}
//sys sendfile(outfd int, infd int, offset *int64, count int) (written int, err error)
//sys Setfsgid(gid int) (err error)
//sys Setfsuid(uid int) (err error)
//sysnb Setregid(rgid int, egid int) (err error)
//sysnb Setresgid(rgid int, egid int, sgid int) (err error)
//sysnb Setresuid(ruid int, euid int, suid int) (err error)
//sysnb Setrlimit(resource int, rlim *Rlimit) (err error)
//sysnb Setreuid(ruid int, euid int) (err error)
//sys Shutdown(fd int, how int) (err error)
//sys Splice(rfd int, roff *int64, wfd int, woff *int64, len int, flags int) (n int64, err error)
func Stat(path string, stat *Stat_t) (err error) {
return Fstatat(AT_FDCWD, path, stat, 0)
}
func Lchown(path string, uid int, gid int) (err error) {
return Fchownat(AT_FDCWD, path, uid, gid, AT_SYMLINK_NOFOLLOW)
}
func Lstat(path string, stat *Stat_t) (err error) {
return Fstatat(AT_FDCWD, path, stat, AT_SYMLINK_NOFOLLOW)
}
//sys Statfs(path string, buf *Statfs_t) (err error)
//sys SyncFileRange(fd int, off int64, n int64, flags int) (err error)
//sys Truncate(path string, length int64) (err error)
func Ustat(dev int, ubuf *Ustat_t) (err error) {
return ENOSYS
}
//sys accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error)
//sys accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error)
//sys bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error)
//sys connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error)
//sysnb getgroups(n int, list *_Gid_t) (nn int, err error)
//sysnb setgroups(n int, list *_Gid_t) (err error)
//sys getsockopt(s int, level int, name int, val unsafe.Pointer, vallen *_Socklen) (err error)
//sys setsockopt(s int, level int, name int, val unsafe.Pointer, vallen uintptr) (err error)
//sysnb socket(domain int, typ int, proto int) (fd int, err error)
//sysnb socketpair(domain int, typ int, proto int, fd *[2]int32) (err error)
//sysnb getpeername(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error)
//sysnb getsockname(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error)
//sys recvfrom(fd int, p []byte, flags int, from *RawSockaddrAny, fromlen *_Socklen) (n int, err error)
//sys sendto(s int, buf []byte, flags int, to unsafe.Pointer, addrlen _Socklen) (err error)
//sys recvmsg(s int, msg *Msghdr, flags int) (n int, err error)
//sys sendmsg(s int, msg *Msghdr, flags int) (n int, err error)
//sys mmap(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (xaddr uintptr, err error)
//sysnb Gettimeofday(tv *Timeval) (err error)
func setTimespec(sec, nsec int64) Timespec {
return Timespec{Sec: sec, Nsec: nsec}
}
func setTimeval(sec, usec int64) Timeval {
return Timeval{Sec: sec, Usec: usec}
}
func futimesat(dirfd int, path string, tv *[2]Timeval) (err error) {
if tv == nil {
return utimensat(dirfd, path, nil, 0)
}
ts := []Timespec{
NsecToTimespec(TimevalToNsec(tv[0])),
NsecToTimespec(TimevalToNsec(tv[1])),
}
return utimensat(dirfd, path, (*[2]Timespec)(unsafe.Pointer(&ts[0])), 0)
}
func Time(t *Time_t) (Time_t, error) {
var tv Timeval
err := Gettimeofday(&tv)
if err != nil {
return 0, err
}
if t != nil {
*t = Time_t(tv.Sec)
}
return Time_t(tv.Sec), nil
}
func Utime(path string, buf *Utimbuf) error {
tv := []Timeval{
{Sec: buf.Actime},
{Sec: buf.Modtime},
}
return Utimes(path, tv)
}
func utimes(path string, tv *[2]Timeval) (err error) {
if tv == nil {
return utimensat(AT_FDCWD, path, nil, 0)
}
ts := []Timespec{
NsecToTimespec(TimevalToNsec(tv[0])),
NsecToTimespec(TimevalToNsec(tv[1])),
}
return utimensat(AT_FDCWD, path, (*[2]Timespec)(unsafe.Pointer(&ts[0])), 0)
}
func Pipe(p []int) (err error) {
if len(p) != 2 {
return EINVAL
}
var pp [2]_C_int
err = pipe2(&pp, 0)
p[0] = int(pp[0])
p[1] = int(pp[1])
return
}
//sysnb pipe2(p *[2]_C_int, flags int) (err error)
func Pipe2(p []int, flags int) (err error) {
if len(p) != 2 {
return EINVAL
}
var pp [2]_C_int
err = pipe2(&pp, flags)
p[0] = int(pp[0])
p[1] = int(pp[1])
return
}
func (r *PtraceRegs) PC() uint64 { return r.Pc }
func (r *PtraceRegs) SetPC(pc uint64) { r.Pc = pc }
func (iov *Iovec) SetLen(length int) {
iov.Len = uint64(length)
}
func (msghdr *Msghdr) SetControllen(length int) {
msghdr.Controllen = uint64(length)
}
func (cmsg *Cmsghdr) SetLen(length int) {
cmsg.Len = uint64(length)
}
func InotifyInit() (fd int, err error) {
return InotifyInit1(0)
}
func Dup2(oldfd int, newfd int) (err error) {
return Dup3(oldfd, newfd, 0)
}
func Pause() (err error) {
_, _, e1 := Syscall6(SYS_PPOLL, 0, 0, 0, 0, 0, 0)
if e1 != 0 {
err = errnoErr(e1)
}
return
}
func Poll(fds []PollFd, timeout int) (n int, err error) {
var ts *Timespec
if timeout >= 0 {
ts = new(Timespec)
*ts = NsecToTimespec(int64(timeout) * 1e6)
}
if len(fds) == 0 {
return ppoll(nil, 0, ts, nil)
}
return ppoll(&fds[0], len(fds), ts, nil)
}
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
// linux/mksysnum.pl -Wall -Werror -static -I/tmp/include /tmp/include/asm/unistd.h
// Code generated by the command above; see README.md. DO NOT EDIT.
// +build riscv64,linux
package unix
const (
SYS_IO_SETUP = 0
SYS_IO_DESTROY = 1
SYS_IO_SUBMIT = 2
SYS_IO_CANCEL = 3
SYS_IO_GETEVENTS = 4
SYS_SETXATTR = 5
SYS_LSETXATTR = 6
SYS_FSETXATTR = 7
SYS_GETXATTR = 8
SYS_LGETXATTR = 9
SYS_FGETXATTR = 10
SYS_LISTXATTR = 11
SYS_LLISTXATTR = 12
SYS_FLISTXATTR = 13
SYS_REMOVEXATTR = 14
SYS_LREMOVEXATTR = 15
SYS_FREMOVEXATTR = 16
SYS_GETCWD = 17
SYS_LOOKUP_DCOOKIE = 18
SYS_EVENTFD2 = 19
SYS_EPOLL_CREATE1 = 20
SYS_EPOLL_CTL = 21
SYS_EPOLL_PWAIT = 22
SYS_DUP = 23
SYS_DUP3 = 24
SYS_FCNTL = 25
SYS_INOTIFY_INIT1 = 26
SYS_INOTIFY_ADD_WATCH = 27
SYS_INOTIFY_RM_WATCH = 28
SYS_IOCTL = 29
SYS_IOPRIO_SET = 30
SYS_IOPRIO_GET = 31
SYS_FLOCK = 32
SYS_MKNODAT = 33
SYS_MKDIRAT = 34
SYS_UNLINKAT = 35
SYS_SYMLINKAT = 36
SYS_LINKAT = 37
SYS_UMOUNT2 = 39
SYS_MOUNT = 40
SYS_PIVOT_ROOT = 41
SYS_NFSSERVCTL = 42
SYS_STATFS = 43
SYS_FSTATFS = 44
SYS_TRUNCATE = 45
SYS_FTRUNCATE = 46
SYS_FALLOCATE = 47
SYS_FACCESSAT = 48
SYS_CHDIR = 49
SYS_FCHDIR = 50
SYS_CHROOT = 51
SYS_FCHMOD = 52
SYS_FCHMODAT = 53
SYS_FCHOWNAT = 54
SYS_FCHOWN = 55
SYS_OPENAT = 56
SYS_CLOSE = 57
SYS_VHANGUP = 58
SYS_PIPE2 = 59
SYS_QUOTACTL = 60
SYS_GETDENTS64 = 61
SYS_LSEEK = 62
SYS_READ = 63
SYS_WRITE = 64
SYS_READV = 65
SYS_WRITEV = 66
SYS_PREAD64 = 67
SYS_PWRITE64 = 68
SYS_PREADV = 69
SYS_PWRITEV = 70
SYS_SENDFILE = 71
SYS_PSELECT6 = 72
SYS_PPOLL = 73
SYS_SIGNALFD4 = 74
SYS_VMSPLICE = 75
SYS_SPLICE = 76
SYS_TEE = 77
SYS_READLINKAT = 78
SYS_FSTATAT = 79
SYS_FSTAT = 80
SYS_SYNC = 81
SYS_FSYNC = 82
SYS_FDATASYNC = 83
SYS_SYNC_FILE_RANGE = 84
SYS_TIMERFD_CREATE = 85
SYS_TIMERFD_SETTIME = 86
SYS_TIMERFD_GETTIME = 87
SYS_UTIMENSAT = 88
SYS_ACCT = 89
SYS_CAPGET = 90
SYS_CAPSET = 91
SYS_PERSONALITY = 92
SYS_EXIT = 93
SYS_EXIT_GROUP = 94
SYS_WAITID = 95
SYS_SET_TID_ADDRESS = 96
SYS_UNSHARE = 97
SYS_FUTEX = 98
SYS_SET_ROBUST_LIST = 99
SYS_GET_ROBUST_LIST = 100
SYS_NANOSLEEP = 101
SYS_GETITIMER = 102
SYS_SETITIMER = 103
SYS_KEXEC_LOAD = 104
SYS_INIT_MODULE = 105
SYS_DELETE_MODULE = 106
SYS_TIMER_CREATE = 107
SYS_TIMER_GETTIME = 108
SYS_TIMER_GETOVERRUN = 109
SYS_TIMER_SETTIME = 110
SYS_TIMER_DELETE = 111
SYS_CLOCK_SETTIME = 112
SYS_CLOCK_GETTIME = 113
SYS_CLOCK_GETRES = 114
SYS_CLOCK_NANOSLEEP = 115
SYS_SYSLOG = 116
SYS_PTRACE = 117
SYS_SCHED_SETPARAM = 118
SYS_SCHED_SETSCHEDULER = 119
SYS_SCHED_GETSCHEDULER = 120
SYS_SCHED_GETPARAM = 121
SYS_SCHED_SETAFFINITY = 122
SYS_SCHED_GETAFFINITY = 123
SYS_SCHED_YIELD = 124
SYS_SCHED_GET_PRIORITY_MAX = 125
SYS_SCHED_GET_PRIORITY_MIN = 126
SYS_SCHED_RR_GET_INTERVAL = 127
SYS_RESTART_SYSCALL = 128
SYS_KILL = 129
SYS_TKILL = 130
SYS_TGKILL = 131
SYS_SIGALTSTACK = 132
SYS_RT_SIGSUSPEND = 133
SYS_RT_SIGACTION = 134
SYS_RT_SIGPROCMASK = 135
SYS_RT_SIGPENDING = 136
SYS_RT_SIGTIMEDWAIT = 137
SYS_RT_SIGQUEUEINFO = 138
SYS_RT_SIGRETURN = 139
SYS_SETPRIORITY = 140
SYS_GETPRIORITY = 141
SYS_REBOOT = 142
SYS_SETREGID = 143
SYS_SETGID = 144
SYS_SETREUID = 145
SYS_SETUID = 146
SYS_SETRESUID = 147
SYS_GETRESUID = 148
SYS_SETRESGID = 149
SYS_GETRESGID = 150
SYS_SETFSUID = 151
SYS_SETFSGID = 152
SYS_TIMES = 153
SYS_SETPGID = 154
SYS_GETPGID = 155
SYS_GETSID = 156
SYS_SETSID = 157
SYS_GETGROUPS = 158
SYS_SETGROUPS = 159
SYS_UNAME = 160
SYS_SETHOSTNAME = 161
SYS_SETDOMAINNAME = 162
SYS_GETRLIMIT = 163
SYS_SETRLIMIT = 164
SYS_GETRUSAGE = 165
SYS_UMASK = 166
SYS_PRCTL = 167
SYS_GETCPU = 168
SYS_GETTIMEOFDAY = 169
SYS_SETTIMEOFDAY = 170
SYS_ADJTIMEX = 171
SYS_GETPID = 172
SYS_GETPPID = 173
SYS_GETUID = 174
SYS_GETEUID = 175
SYS_GETGID = 176
SYS_GETEGID = 177
SYS_GETTID = 178
SYS_SYSINFO = 179
SYS_MQ_OPEN = 180
SYS_MQ_UNLINK = 181
SYS_MQ_TIMEDSEND = 182
SYS_MQ_TIMEDRECEIVE = 183
SYS_MQ_NOTIFY = 184
SYS_MQ_GETSETATTR = 185
SYS_MSGGET = 186
SYS_MSGCTL = 187
SYS_MSGRCV = 188
SYS_MSGSND = 189
SYS_SEMGET = 190
SYS_SEMCTL = 191
SYS_SEMTIMEDOP = 192
SYS_SEMOP = 193
SYS_SHMGET = 194
SYS_SHMCTL = 195
SYS_SHMAT = 196
SYS_SHMDT = 197
SYS_SOCKET = 198
SYS_SOCKETPAIR = 199
SYS_BIND = 200
SYS_LISTEN = 201
SYS_ACCEPT = 202
SYS_CONNECT = 203
SYS_GETSOCKNAME = 204
SYS_GETPEERNAME = 205
SYS_SENDTO = 206
SYS_RECVFROM = 207
SYS_SETSOCKOPT = 208
SYS_GETSOCKOPT = 209
SYS_SHUTDOWN = 210
SYS_SENDMSG = 211
SYS_RECVMSG = 212
SYS_READAHEAD = 213
SYS_BRK = 214
SYS_MUNMAP = 215
SYS_MREMAP = 216
SYS_ADD_KEY = 217
SYS_REQUEST_KEY = 218
SYS_KEYCTL = 219
SYS_CLONE = 220
SYS_EXECVE = 221
SYS_MMAP = 222
SYS_FADVISE64 = 223
SYS_SWAPON = 224
SYS_SWAPOFF = 225
SYS_MPROTECT = 226
SYS_MSYNC = 227
SYS_MLOCK = 228
SYS_MUNLOCK = 229
SYS_MLOCKALL = 230
SYS_MUNLOCKALL = 231
SYS_MINCORE = 232
SYS_MADVISE = 233
SYS_REMAP_FILE_PAGES = 234
SYS_MBIND = 235
SYS_GET_MEMPOLICY = 236
SYS_SET_MEMPOLICY = 237
SYS_MIGRATE_PAGES = 238
SYS_MOVE_PAGES = 239
SYS_RT_TGSIGQUEUEINFO = 240
SYS_PERF_EVENT_OPEN = 241
SYS_ACCEPT4 = 242
SYS_RECVMMSG = 243
SYS_ARCH_SPECIFIC_SYSCALL = 244
SYS_WAIT4 = 260
SYS_PRLIMIT64 = 261
SYS_FANOTIFY_INIT = 262
SYS_FANOTIFY_MARK = 263
SYS_NAME_TO_HANDLE_AT = 264
SYS_OPEN_BY_HANDLE_AT = 265
SYS_CLOCK_ADJTIME = 266
SYS_SYNCFS = 267
SYS_SETNS = 268
SYS_SENDMMSG = 269
SYS_PROCESS_VM_READV = 270
SYS_PROCESS_VM_WRITEV = 271
SYS_KCMP = 272
SYS_FINIT_MODULE = 273
SYS_SCHED_SETATTR = 274
SYS_SCHED_GETATTR = 275
SYS_RENAMEAT2 = 276
SYS_SECCOMP = 277
SYS_GETRANDOM = 278
SYS_MEMFD_CREATE = 279
SYS_BPF = 280
SYS_EXECVEAT = 281
SYS_USERFAULTFD = 282
SYS_MEMBARRIER = 283
SYS_MLOCK2 = 284
SYS_COPY_FILE_RANGE = 285
SYS_PREADV2 = 286
SYS_PWRITEV2 = 287
SYS_PKEY_MPROTECT = 288
SYS_PKEY_ALLOC = 289
SYS_PKEY_FREE = 290
SYS_STATX = 291
SYS_IO_PGETEVENTS = 292
)
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment