make runtime compatible with wasm
This commit is contained in:
@@ -16,10 +16,6 @@
|
||||
|
||||
package os
|
||||
|
||||
// #include <sys/stat.h>
|
||||
// #include <limits.h>
|
||||
import "C"
|
||||
|
||||
import (
|
||||
_ "unsafe"
|
||||
|
||||
@@ -27,10 +23,6 @@ import (
|
||||
"github.com/goplus/llgo/runtime/internal/clite/syscall"
|
||||
)
|
||||
|
||||
const (
|
||||
PATH_MAX = C.PATH_MAX
|
||||
)
|
||||
|
||||
const (
|
||||
/* get file status flags */
|
||||
F_GETFL = 3
|
||||
@@ -58,14 +50,6 @@ const (
|
||||
EAGAIN = 35
|
||||
)
|
||||
|
||||
type (
|
||||
ModeT C.mode_t
|
||||
UidT C.uid_t
|
||||
GidT C.gid_t
|
||||
OffT C.off_t
|
||||
DevT C.dev_t
|
||||
)
|
||||
|
||||
type (
|
||||
StatT = syscall.Stat_t
|
||||
)
|
||||
@@ -115,12 +99,6 @@ func Truncate(path *c.Char, length OffT) c.Int
|
||||
//go:linkname Chmod C.chmod
|
||||
func Chmod(path *c.Char, mode ModeT) c.Int
|
||||
|
||||
//go:linkname Chown C.chown
|
||||
func Chown(path *c.Char, owner UidT, group GidT) c.Int
|
||||
|
||||
//go:linkname Lchown C.lchown
|
||||
func Lchown(path *c.Char, owner UidT, group GidT) c.Int
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
//go:linkname Getcwd C.getcwd
|
||||
@@ -189,16 +167,6 @@ func Dup2(oldfd c.Int, newfd c.Int) c.Int
|
||||
//go:linkname Dup3 C.dup3
|
||||
func Dup3(oldfd c.Int, newfd c.Int, flags c.Int) c.Int
|
||||
|
||||
/* TODO(xsw):
|
||||
On Alpha, IA-64, MIPS, SuperH, and SPARC/SPARC64, pipe() has the following prototype:
|
||||
struct fd_pair {
|
||||
long fd[2];
|
||||
};
|
||||
struct fd_pair pipe(void);
|
||||
*/
|
||||
//go:linkname Pipe C.pipe
|
||||
func Pipe(fds *[2]c.Int) c.Int
|
||||
|
||||
//go:linkname Mkfifo C.mkfifo
|
||||
func Mkfifo(path *c.Char, mode ModeT) c.Int
|
||||
|
||||
@@ -270,9 +238,6 @@ func Execvp(file *c.Char, argv **c.Char) c.Int
|
||||
|
||||
type PidT c.Int
|
||||
|
||||
//go:linkname Fork C.fork
|
||||
func Fork() PidT
|
||||
|
||||
//go:linkname Getpid C.getpid
|
||||
func Getpid() PidT
|
||||
|
||||
@@ -293,9 +258,6 @@ func Getppid() PidT
|
||||
//go:linkname Syscall C.syscall
|
||||
func Syscall(sysno c.Long, __llgo_va_list ...any) c.Long
|
||||
|
||||
//go:linkname Kill C.kill
|
||||
func Kill(pid PidT, sig c.Int) c.Int
|
||||
|
||||
// If wait() returns due to a stopped or terminated child process, the process ID
|
||||
// of the child is returned to the calling process. Otherwise, a value of -1 is
|
||||
// returned and errno is set to indicate the error.
|
||||
@@ -313,9 +275,6 @@ func Wait(statLoc *c.Int) PidT
|
||||
//go:linkname Wait3 C.wait3
|
||||
func Wait3(statLoc *c.Int, options c.Int, rusage *syscall.Rusage) PidT
|
||||
|
||||
//go:linkname Wait4 C.wait4
|
||||
func Wait4(pid PidT, statLoc *c.Int, options c.Int, rusage *syscall.Rusage) PidT
|
||||
|
||||
//go:linkname Waitpid C.waitpid
|
||||
func Waitpid(pid PidT, statLoc *c.Int, options c.Int) PidT
|
||||
|
||||
@@ -324,26 +283,6 @@ func Waitpid(pid PidT, statLoc *c.Int, options c.Int) PidT
|
||||
//go:linkname Exit C.exit
|
||||
func Exit(c.Int)
|
||||
|
||||
//go:linkname Getuid C.getuid
|
||||
func Getuid() UidT
|
||||
|
||||
//go:linkname Geteuid C.geteuid
|
||||
func Geteuid() UidT
|
||||
|
||||
//go:linkname Getgid C.getgid
|
||||
func Getgid() GidT
|
||||
|
||||
//go:linkname Getegid C.getegid
|
||||
func Getegid() GidT
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
//go:linkname Getrlimit C.getrlimit
|
||||
func Getrlimit(resource c.Int, rlp *syscall.Rlimit) c.Int
|
||||
|
||||
//go:linkname Setrlimit C.setrlimit
|
||||
func Setrlimit(resource c.Int, rlp *syscall.Rlimit) c.Int
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// Upon successful completion, the value 0 is returned; otherwise the value -1
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
//go:build linux
|
||||
|
||||
/*
|
||||
* Copyright (c) 2024 The GoPlus Authors (goplus.org). All rights reserved.
|
||||
*
|
||||
@@ -18,12 +16,28 @@
|
||||
|
||||
package os
|
||||
|
||||
import "C"
|
||||
import (
|
||||
_ "unsafe"
|
||||
|
||||
c "github.com/goplus/llgo/runtime/internal/clite"
|
||||
)
|
||||
|
||||
const (
|
||||
LLGoFiles = "_os/os.c"
|
||||
LLGoPackage = "link"
|
||||
)
|
||||
|
||||
//go:linkname Clearenv C.clearenv
|
||||
func Clearenv()
|
||||
const (
|
||||
PATH_MAX = 1024
|
||||
)
|
||||
|
||||
type (
|
||||
ModeT uint16
|
||||
UidT uint32
|
||||
GidT uint32
|
||||
OffT int64
|
||||
DevT int32
|
||||
)
|
||||
|
||||
//go:linkname Clearenv C.cliteClearenv
|
||||
func Clearenv() c.Int
|
||||
69
runtime/internal/clite/os/os_nonwasm.go
Normal file
69
runtime/internal/clite/os/os_nonwasm.go
Normal file
@@ -0,0 +1,69 @@
|
||||
//go:build !wasm
|
||||
|
||||
/*
|
||||
* Copyright (c) 2024 The GoPlus Authors (goplus.org). All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package os
|
||||
|
||||
import (
|
||||
_ "unsafe"
|
||||
|
||||
c "github.com/goplus/llgo/runtime/internal/clite"
|
||||
"github.com/goplus/llgo/runtime/internal/clite/syscall"
|
||||
)
|
||||
|
||||
//go:linkname Getuid C.getuid
|
||||
func Getuid() UidT
|
||||
|
||||
//go:linkname Geteuid C.geteuid
|
||||
func Geteuid() UidT
|
||||
|
||||
//go:linkname Getgid C.getgid
|
||||
func Getgid() GidT
|
||||
|
||||
//go:linkname Getegid C.getegid
|
||||
func Getegid() GidT
|
||||
|
||||
//go:linkname Chown C.chown
|
||||
func Chown(path *c.Char, owner UidT, group GidT) c.Int
|
||||
|
||||
//go:linkname Lchown C.lchown
|
||||
func Lchown(path *c.Char, owner UidT, group GidT) c.Int
|
||||
|
||||
//go:linkname Getrlimit C.getrlimit
|
||||
func Getrlimit(resource c.Int, rlp *syscall.Rlimit) c.Int
|
||||
|
||||
//go:linkname Setrlimit C.setrlimit
|
||||
func Setrlimit(resource c.Int, rlp *syscall.Rlimit) c.Int
|
||||
|
||||
//go:linkname Wait4 C.wait4
|
||||
func Wait4(pid PidT, statLoc *c.Int, options c.Int, rusage *syscall.Rusage) PidT
|
||||
|
||||
/* TODO(xsw):
|
||||
On Alpha, IA-64, MIPS, SuperH, and SPARC/SPARC64, pipe() has the following prototype:
|
||||
struct fd_pair {
|
||||
long fd[2];
|
||||
};
|
||||
struct fd_pair pipe(void);
|
||||
*/
|
||||
//go:linkname Pipe C.pipe
|
||||
func Pipe(fds *[2]c.Int) c.Int
|
||||
|
||||
//go:linkname Fork C.fork
|
||||
func Fork() PidT
|
||||
|
||||
//go:linkname Kill C.kill
|
||||
func Kill(pid PidT, sig c.Int) c.Int
|
||||
@@ -1,4 +1,4 @@
|
||||
//go:build !linux
|
||||
//go:build !darwin
|
||||
|
||||
/*
|
||||
* Copyright (c) 2024 The GoPlus Authors (goplus.org). All rights reserved.
|
||||
@@ -18,12 +18,28 @@
|
||||
|
||||
package os
|
||||
|
||||
import "C"
|
||||
import (
|
||||
_ "unsafe"
|
||||
|
||||
c "github.com/goplus/llgo/runtime/internal/clite"
|
||||
)
|
||||
|
||||
const (
|
||||
LLGoFiles = "_os/os.c"
|
||||
LLGoPackage = "link"
|
||||
)
|
||||
|
||||
//go:linkname Clearenv C.cliteClearenv
|
||||
func Clearenv()
|
||||
const (
|
||||
PATH_MAX = 4096
|
||||
)
|
||||
|
||||
type (
|
||||
ModeT uint32
|
||||
UidT uint32
|
||||
GidT uint32
|
||||
OffT int64
|
||||
DevT uint64
|
||||
)
|
||||
|
||||
//go:linkname Clearenv C.clearenv
|
||||
func Clearenv() c.Int
|
||||
|
||||
1
runtime/internal/clite/os/os_wasm.go
Normal file
1
runtime/internal/clite/os/os_wasm.go
Normal file
@@ -0,0 +1 @@
|
||||
package os
|
||||
Reference in New Issue
Block a user