Skip to content

Commit

Permalink
syscall: generate readlen/writelen for openbsd libc
Browse files Browse the repository at this point in the history
Rather than hand rolling readlen and writelen, move it to being generated
via mksyscall.pl, as is done for most other functions.

Updates #36435

Change-Id: I649aed7b182b41c8639686feae25ce19dab812c3
Reviewed-on: https://go-review.googlesource.com/c/go/+/287532
Trust: Joel Sing <joel@sing.id.au>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
  • Loading branch information
4a6f656c committed Jan 28, 2021
1 parent 41bb49b commit c8bd801
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 22 deletions.
28 changes: 6 additions & 22 deletions src/syscall/syscall_openbsd_libc.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ package syscall

import "unsafe"

func init() {
execveOpenBSD = execve
}

//sys directSyscall(trap uintptr, a1 uintptr, a2 uintptr, a3 uintptr, a4 uintptr, a5 uintptr) (ret uintptr, err error) = SYS_syscall

func syscallInternal(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno) {
Expand Down Expand Up @@ -56,6 +60,8 @@ func funcPC(f func()) uintptr {
return **(**uintptr)(unsafe.Pointer(&f))
}

//sys readlen(fd int, buf *byte, nbuf int) (n int, err error) = SYS_read
//sys writelen(fd int, buf *byte, nbuf int) (n int, err error) = SYS_write
//sys Seek(fd int, offset int64, whence int) (newoffset int64, err error) = SYS_lseek
//sys getcwd(buf []byte) (n int, err error)
//sys sysctl(mib []_C_int, old *byte, oldlen *uintptr, new *byte, newlen uintptr) (err error)
Expand All @@ -69,25 +75,3 @@ func funcPC(f func()) uintptr {
//sys fcntlPtr(fd int, cmd int, arg unsafe.Pointer) (val int, err error) = SYS_fcntl
//sys unlinkat(fd int, path string, flags int) (err error)
//sys openat(fd int, path string, flags int, perm uint32) (fdret int, err error)

func init() {
execveOpenBSD = execve
}

func readlen(fd int, buf *byte, nbuf int) (n int, err error) {
r0, _, e1 := syscall(funcPC(libc_read_trampoline), uintptr(fd), uintptr(unsafe.Pointer(buf)), uintptr(nbuf))
n = int(r0)
if e1 != 0 {
err = errnoErr(e1)
}
return
}

func writelen(fd int, buf *byte, nbuf int) (n int, err error) {
r0, _, e1 := syscall(funcPC(libc_write_trampoline), uintptr(fd), uintptr(unsafe.Pointer(buf)), uintptr(nbuf))
n = int(r0)
if e1 != 0 {
err = errnoErr(e1)
}
return
}
22 changes: 22 additions & 0 deletions src/syscall/zsyscall_openbsd_amd64.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions src/syscall/zsyscall_openbsd_arm64.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c8bd801

Please sign in to comment.