runtime: testing runtime
This commit is contained in:
@@ -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