runtime: testing runtime
This commit is contained in:
@@ -16,16 +16,28 @@
|
||||
|
||||
package abi
|
||||
|
||||
// llgo:skipall
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/goplus/llgo/runtime/abi"
|
||||
)
|
||||
|
||||
// llgo:skipall
|
||||
type _abi struct{}
|
||||
|
||||
type InterfaceType = abi.InterfaceType
|
||||
|
||||
func NoEscape(p unsafe.Pointer) unsafe.Pointer {
|
||||
x := uintptr(p)
|
||||
return unsafe.Pointer(x ^ 0)
|
||||
}
|
||||
|
||||
func FuncPCABI0(f interface{}) uintptr {
|
||||
words := (*[2]unsafe.Pointer)(unsafe.Pointer(&f))
|
||||
return *(*uintptr)(unsafe.Pointer(words[1]))
|
||||
}
|
||||
|
||||
func FuncPCABIInternal(f interface{}) uintptr {
|
||||
words := (*[2]unsafe.Pointer)(unsafe.Pointer(&f))
|
||||
return *(*uintptr)(unsafe.Pointer(words[1]))
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package bytealg
|
||||
|
||||
// llgo:skip init CompareString
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
@@ -24,6 +23,9 @@ import (
|
||||
"github.com/goplus/llgo/runtime/internal/runtime"
|
||||
)
|
||||
|
||||
// llgo:skip init CompareString
|
||||
type _bytealg struct{}
|
||||
|
||||
func IndexByte(b []byte, ch byte) int {
|
||||
ptr := unsafe.Pointer(unsafe.SliceData(b))
|
||||
ret := c.Memchr(ptr, c.Int(ch), uintptr(len(b)))
|
||||
|
||||
1
runtime/internal/lib/internal/cpu/cpu.go
Normal file
1
runtime/internal/lib/internal/cpu/cpu.go
Normal file
@@ -0,0 +1 @@
|
||||
package cpu
|
||||
40
runtime/internal/lib/internal/cpu/cpu_x86.go
Normal file
40
runtime/internal/lib/internal/cpu/cpu_x86.go
Normal file
@@ -0,0 +1,40 @@
|
||||
//go:build 386 || amd64
|
||||
|
||||
package cpu
|
||||
|
||||
/*
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
static void getcpuid(unsigned int eax, unsigned int ecx,
|
||||
unsigned int *a, unsigned int *b,
|
||||
unsigned int *c, unsigned int *d) {
|
||||
#if defined(__i386__) || defined(__x86_64__)
|
||||
__asm__ __volatile__(
|
||||
"pushq %%rbp\n\t"
|
||||
"movq %%rsp, %%rbp\n\t"
|
||||
"andq $-16, %%rsp\n\t" // 16-byte align stack
|
||||
"cpuid\n\t"
|
||||
"movq %%rbp, %%rsp\n\t"
|
||||
"popq %%rbp\n\t"
|
||||
: "=a"(*a), "=b"(*b), "=c"(*c), "=d"(*d)
|
||||
: "a"(eax), "c"(ecx)
|
||||
: "memory"
|
||||
);
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
#error This code requires GCC or Clang
|
||||
#endif
|
||||
*/
|
||||
import "C"
|
||||
|
||||
func cpuid(eaxArg, ecxArg uint32) (eax, ebx, ecx, edx uint32) {
|
||||
C.getcpuid(
|
||||
C.uint(eaxArg),
|
||||
C.uint(ecxArg),
|
||||
(*C.uint)(&eax),
|
||||
(*C.uint)(&ebx),
|
||||
(*C.uint)(&ecx),
|
||||
(*C.uint)(&edx),
|
||||
)
|
||||
return
|
||||
}
|
||||
@@ -8,12 +8,14 @@
|
||||
// that are valid map keys.
|
||||
package fmtsort
|
||||
|
||||
// llgo:skipall
|
||||
import (
|
||||
"reflect"
|
||||
"sort"
|
||||
)
|
||||
|
||||
// llgo:skipall
|
||||
type _fmtsort struct{}
|
||||
|
||||
// Note: Throughout this package we avoid calling reflect.Value.Interface as
|
||||
// it is not always legal to do so and it's easier to avoid the issue than to face it.
|
||||
|
||||
|
||||
13
runtime/internal/lib/internal/godebug/godebug.go
Normal file
13
runtime/internal/lib/internal/godebug/godebug.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package godebug
|
||||
|
||||
func setUpdate(update func(string, string)) {
|
||||
println("todo: godebug.setUpdate")
|
||||
}
|
||||
|
||||
func registerMetric(name string, read func() uint64) {
|
||||
println("todo: godebug.registerMetric")
|
||||
}
|
||||
|
||||
func setNewIncNonDefault(newIncNonDefault func(string) func()) {
|
||||
println("todo: godebug.setNewIncNonDefault")
|
||||
}
|
||||
@@ -4,9 +4,11 @@
|
||||
|
||||
// Simple conversions to avoid depending on strconv.
|
||||
|
||||
// llgo:skipall
|
||||
package itoa
|
||||
|
||||
// llgo:skipall
|
||||
type _itoa struct{}
|
||||
|
||||
// Itoa converts val to a decimal string.
|
||||
func Itoa(val int) string {
|
||||
if val < 0 {
|
||||
|
||||
@@ -7,9 +7,11 @@
|
||||
// These types are defined here to permit the syscall package to reference them.
|
||||
package oserror
|
||||
|
||||
// llgo:skipall
|
||||
import "errors"
|
||||
|
||||
// llgo:skipall
|
||||
type _oserror struct{}
|
||||
|
||||
var (
|
||||
ErrInvalid = errors.New("invalid argument")
|
||||
ErrPermission = errors.New("permission denied")
|
||||
|
||||
45
runtime/internal/lib/internal/poll/poll.go
Normal file
45
runtime/internal/lib/internal/poll/poll.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package poll
|
||||
|
||||
func runtime_Semacquire(sema *uint32) {
|
||||
panic("todo: poll.runtime_Semacquire")
|
||||
}
|
||||
|
||||
func runtime_Semrelease(sema *uint32) {
|
||||
panic("todo: poll.runtime_Semrelease")
|
||||
}
|
||||
|
||||
func runtime_pollServerInit() {
|
||||
panic("todo: poll.runtime_pollServerInit")
|
||||
}
|
||||
|
||||
func runtime_pollOpen(fd uintptr) (uintptr, int) {
|
||||
panic("todo: poll.runtime_pollOpen")
|
||||
}
|
||||
|
||||
func runtime_pollClose(ctx uintptr) {
|
||||
panic("todo: poll.runtime_pollClose")
|
||||
}
|
||||
|
||||
func runtime_pollWait(ctx uintptr, mode int) int {
|
||||
panic("todo: poll.runtime_pollWait")
|
||||
}
|
||||
|
||||
func runtime_pollWaitCanceled(ctx uintptr, mode int) {
|
||||
panic("todo: poll.runtime_pollWaitCanceled")
|
||||
}
|
||||
|
||||
func runtime_pollReset(ctx uintptr, mode int) int {
|
||||
panic("todo: poll.runtime_pollReset")
|
||||
}
|
||||
|
||||
func runtime_pollSetDeadline(ctx uintptr, d int64, mode int) {
|
||||
panic("todo: poll.runtime_pollSetDeadline")
|
||||
}
|
||||
|
||||
func runtime_pollUnblock(ctx uintptr) {
|
||||
panic("todo: poll.runtime_pollUnblock")
|
||||
}
|
||||
|
||||
func runtime_isPollServerDescriptor(fd uintptr) bool {
|
||||
panic("todo: poll.runtime_isPollServerDescriptor")
|
||||
}
|
||||
@@ -6,9 +6,11 @@
|
||||
|
||||
package execenv
|
||||
|
||||
// llgo:skipall
|
||||
import "syscall"
|
||||
|
||||
// llgo:skipall
|
||||
type _execenv struct{}
|
||||
|
||||
// Default will return the default environment
|
||||
// variables based on the process attributes
|
||||
// provided.
|
||||
|
||||
@@ -6,13 +6,15 @@
|
||||
|
||||
package execenv
|
||||
|
||||
// llgo:skipall
|
||||
import (
|
||||
"internal/syscall/windows"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// llgo:skipall
|
||||
type _execenv struct{}
|
||||
|
||||
// Default will return the default environment
|
||||
// variables based on the process attributes
|
||||
// provided.
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
#include <errno.h>
|
||||
#include <stdint.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
struct fcntl_ret
|
||||
{
|
||||
int32_t r1; // Return value
|
||||
int32_t err; // Error code
|
||||
};
|
||||
|
||||
// llgo_fcntl implements the fcntl system call wrapper for Go
|
||||
// fd: file descriptor
|
||||
// cmd: fcntl command
|
||||
// arg: command argument
|
||||
struct fcntl_ret llgo_fcntl2(int32_t fd, int32_t cmd, int32_t arg)
|
||||
{
|
||||
struct fcntl_ret ret = {0};
|
||||
int result = fcntl(fd, cmd, arg);
|
||||
|
||||
if (result == -1)
|
||||
{
|
||||
ret.err = errno;
|
||||
ret.r1 = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
ret.err = 0;
|
||||
ret.r1 = result;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -2,14 +2,13 @@
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
//go:build js && wasm
|
||||
|
||||
package unix
|
||||
|
||||
func IsNonblock(fd int) (nonblocking bool, err error) {
|
||||
return false, nil
|
||||
}
|
||||
const (
|
||||
AT_EACCESS = 0x10
|
||||
AT_FDCWD = -0x2
|
||||
AT_REMOVEDIR = 0x80
|
||||
AT_SYMLINK_NOFOLLOW = 0x0020
|
||||
|
||||
func HasNonblockFlag(flag int) bool {
|
||||
return false
|
||||
}
|
||||
UTIME_OMIT = -0x2
|
||||
)
|
||||
@@ -0,0 +1,19 @@
|
||||
// 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.
|
||||
|
||||
package unix
|
||||
|
||||
import "syscall"
|
||||
|
||||
const unlinkatTrap uintptr = syscall.SYS_UNLINKAT
|
||||
const openatTrap uintptr = syscall.SYS_OPENAT
|
||||
|
||||
const (
|
||||
AT_EACCESS = 0x200
|
||||
AT_FDCWD = -0x64
|
||||
AT_REMOVEDIR = 0x200
|
||||
AT_SYMLINK_NOFOLLOW = 0x100
|
||||
|
||||
UTIME_OMIT = 0x3ffffffe
|
||||
)
|
||||
18
runtime/internal/lib/internal/syscall/unix/constants.go
Normal file
18
runtime/internal/lib/internal/syscall/unix/constants.go
Normal file
@@ -0,0 +1,18 @@
|
||||
// Copyright 2022 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 unix
|
||||
|
||||
package unix
|
||||
|
||||
const (
|
||||
R_OK = 0x4
|
||||
W_OK = 0x2
|
||||
X_OK = 0x1
|
||||
|
||||
// NoFollowErrno is the error returned from open/openat called with
|
||||
// O_NOFOLLOW flag, when the trailing component (basename) of the path
|
||||
// is a symbolic link.
|
||||
NoFollowErrno = noFollowErrno
|
||||
)
|
||||
23
runtime/internal/lib/internal/syscall/unix/fcntl_unix.go
Normal file
23
runtime/internal/lib/internal/syscall/unix/fcntl_unix.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package unix
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
_ "unsafe"
|
||||
)
|
||||
|
||||
// llgo:skip fcntl
|
||||
const (
|
||||
LLGoPackage = "link"
|
||||
LLGoFiles = "_unix/fcntl_unix.c"
|
||||
)
|
||||
|
||||
//go:linkname fcntl C.llgo_fcntl2
|
||||
func fcntl(fd int32, cmd int32, arg int32) (int32, int32)
|
||||
|
||||
func Fcntl(fd int, cmd int, arg int) (int, error) {
|
||||
val, errno := fcntl(int32(fd), int32(cmd), int32(arg))
|
||||
if val == -1 {
|
||||
return int(val), syscall.Errno(errno)
|
||||
}
|
||||
return int(val), nil
|
||||
}
|
||||
14
runtime/internal/lib/internal/syscall/unix/nofollow_bsd.go
Normal file
14
runtime/internal/lib/internal/syscall/unix/nofollow_bsd.go
Normal file
@@ -0,0 +1,14 @@
|
||||
// Copyright 2024 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 dragonfly || freebsd
|
||||
|
||||
package unix
|
||||
|
||||
import "syscall"
|
||||
|
||||
// References:
|
||||
// - https://man.freebsd.org/cgi/man.cgi?open(2)
|
||||
// - https://man.dragonflybsd.org/?command=open§ion=2
|
||||
const noFollowErrno = syscall.EMLINK
|
||||
@@ -0,0 +1,10 @@
|
||||
// Copyright 2024 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 unix
|
||||
|
||||
import "syscall"
|
||||
|
||||
// Reference: https://man.netbsd.org/open.2
|
||||
const noFollowErrno = syscall.EFTYPE
|
||||
22
runtime/internal/lib/internal/syscall/unix/nofollow_posix.go
Normal file
22
runtime/internal/lib/internal/syscall/unix/nofollow_posix.go
Normal file
@@ -0,0 +1,22 @@
|
||||
// Copyright 2024 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 unix && !dragonfly && !freebsd && !netbsd
|
||||
|
||||
package unix
|
||||
|
||||
import "syscall"
|
||||
|
||||
// POSIX.1-2008 says it's ELOOP. Most platforms follow:
|
||||
//
|
||||
// - aix: O_NOFOLLOW not documented (https://www.ibm.com/docs/ssw_aix_73/o_bostechref/open.html), assuming ELOOP
|
||||
// - android: see linux
|
||||
// - darwin: https://github.com/apple/darwin-xnu/blob/main/bsd/man/man2/open.2
|
||||
// - hurd: who knows if it works at all (https://www.gnu.org/software/hurd/open_issues/open_symlink.html)
|
||||
// - illumos: https://illumos.org/man/2/open
|
||||
// - ios: see darwin
|
||||
// - linux: https://man7.org/linux/man-pages/man2/openat.2.html
|
||||
// - openbsd: https://man.openbsd.org/open.2
|
||||
// - solaris: https://docs.oracle.com/cd/E23824_01/html/821-1463/open-2.html
|
||||
const noFollowErrno = syscall.ELOOP
|
||||
@@ -1,23 +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.
|
||||
|
||||
//go:build unix
|
||||
|
||||
package unix
|
||||
|
||||
import "github.com/goplus/llgo/runtime/internal/clite/syscall"
|
||||
|
||||
/* TODO(xsw):
|
||||
func IsNonblock(fd int) (nonblocking bool, err error) {
|
||||
flag, e1 := Fcntl(fd, syscall.F_GETFL, 0)
|
||||
if e1 != nil {
|
||||
return false, e1
|
||||
}
|
||||
return flag&syscall.O_NONBLOCK != 0, nil
|
||||
}
|
||||
*/
|
||||
|
||||
func HasNonblockFlag(flag int) bool {
|
||||
return flag&syscall.O_NONBLOCK != 0
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
// Copyright 2023 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
//go:build wasip1
|
||||
|
||||
package unix
|
||||
|
||||
import "github.com/goplus/llgo/runtime/internal/clite/syscall"
|
||||
|
||||
/* TODO(xsw):
|
||||
import (
|
||||
"syscall"
|
||||
_ "unsafe" // for go:linkname
|
||||
)
|
||||
|
||||
func IsNonblock(fd int) (nonblocking bool, err error) {
|
||||
flags, e1 := fd_fdstat_get_flags(fd)
|
||||
if e1 != nil {
|
||||
return false, e1
|
||||
}
|
||||
return flags&syscall.FDFLAG_NONBLOCK != 0, nil
|
||||
}
|
||||
*/
|
||||
|
||||
func HasNonblockFlag(flag int) bool {
|
||||
return flag&syscall.FDFLAG_NONBLOCK != 0
|
||||
}
|
||||
|
||||
/* TODO(xsw):
|
||||
// This helper is implemented in the syscall package. It means we don't have
|
||||
// to redefine the fd_fdstat_get host import or the fdstat struct it
|
||||
// populates.
|
||||
//
|
||||
//-go:linkname fd_fdstat_get_flags syscall.fd_fdstat_get_flags
|
||||
func fd_fdstat_get_flags(fd int) (uint32, error)
|
||||
*/
|
||||
@@ -17,8 +17,10 @@
|
||||
package unix
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
_ "unsafe"
|
||||
)
|
||||
|
||||
// llgo:skipall
|
||||
type _unix struct{}
|
||||
func HasNonblockFlag(flag int) bool {
|
||||
return flag&syscall.O_NONBLOCK != 0
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user