compiler: build separation runtime with clite
This commit is contained in:
@@ -3,7 +3,7 @@ package main
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/goplus/llgo/compiler/internal/abi"
|
||||
"github.com/goplus/llgo/runtime/abi"
|
||||
)
|
||||
|
||||
type T struct {
|
||||
|
||||
@@ -3,7 +3,7 @@ package main
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/goplus/llgo/compiler/internal/runtime"
|
||||
"github.com/goplus/llgo/runtime/internal/runtime"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -3,7 +3,7 @@ package main
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/goplus/llgo/compiler/internal/runtime"
|
||||
"github.com/goplus/llgo/runtime/internal/runtime"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -3,7 +3,7 @@ package main
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/goplus/llgo/compiler/internal/abi"
|
||||
"github.com/goplus/llgo/runtime/abi"
|
||||
)
|
||||
|
||||
type T string
|
||||
|
||||
@@ -2,7 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/c"
|
||||
"github.com/goplus/llgo/compiler/internal/abi"
|
||||
"github.com/goplus/llgo/runtime/abi"
|
||||
)
|
||||
|
||||
func Basic(kind abi.Kind) *abi.Type {
|
||||
|
||||
@@ -28,6 +28,7 @@ import (
|
||||
|
||||
"golang.org/x/tools/go/ssa"
|
||||
|
||||
"github.com/goplus/llgo/compiler/internal/env"
|
||||
llssa "github.com/goplus/llgo/compiler/ssa"
|
||||
)
|
||||
|
||||
@@ -617,7 +618,7 @@ func pkgKindByPath(pkgPath string) int {
|
||||
func replaceGoName(v string, pos int) string {
|
||||
switch v[:pos] {
|
||||
case "runtime":
|
||||
return "github.com/goplus/llgo/compiler/internal/runtime" + v[pos:]
|
||||
return env.LLGoRuntimePkg + "/internal/runtime" + v[pos:]
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
module github.com/goplus/llgo/compiler
|
||||
|
||||
go 1.23.4
|
||||
go 1.23
|
||||
|
||||
require (
|
||||
github.com/goplus/gogen v1.16.4
|
||||
github.com/goplus/llgo v0.9.9
|
||||
github.com/goplus/llgo/runtime v0.0.0-00010101000000-000000000000
|
||||
github.com/goplus/llvm v0.8.1
|
||||
github.com/goplus/mod v0.13.13
|
||||
github.com/qiniu/x v1.13.10
|
||||
golang.org/x/tools v0.28.0
|
||||
golang.org/x/tools v0.29.0
|
||||
)
|
||||
|
||||
require (
|
||||
@@ -17,3 +18,5 @@ require (
|
||||
)
|
||||
|
||||
replace github.com/goplus/llgo => ../
|
||||
|
||||
replace github.com/goplus/llgo/runtime => ../runtime
|
||||
|
||||
@@ -12,5 +12,5 @@ golang.org/x/mod v0.22.0 h1:D4nJWe9zXqHOmWqj4VMOJhvzj7bEZg4wEYa759z1pH4=
|
||||
golang.org/x/mod v0.22.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
|
||||
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
|
||||
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/tools v0.28.0 h1:WuB6qZ4RPCQo5aP3WdKZS7i595EdWqWR8vqJTlwTVK8=
|
||||
golang.org/x/tools v0.28.0/go.mod h1:dcIOrVd3mfQKTgrDVQHqCPMWy6lnhfhtX3hLXYVLfRw=
|
||||
golang.org/x/tools v0.29.0 h1:Xx0h3TtM9rzQpQuR4dKLrdglAmCEN5Oi+P74JdhdzXE=
|
||||
golang.org/x/tools v0.29.0/go.mod h1:KMQVMRsVxU6nHCFXrBPhDB8XncLNLM0lIy/F14RP588=
|
||||
|
||||
@@ -191,8 +191,8 @@ func Do(args []string, conf *Config) ([]Package, error) {
|
||||
// updates. Since `github.com/goplus/llgo/c/*` contains many application libraries
|
||||
// that may change frequently, a possible solution is to have both depend on a
|
||||
// stable and limited c core API.
|
||||
if !llgoPkgImported(initial) {
|
||||
cfg.Dir = env.LLGoROOT()
|
||||
if !llgoRuntimeImported(initial) {
|
||||
cfg.Dir = env.LLGoRuntimeDir()
|
||||
}
|
||||
altPkgs, err := packages.LoadEx(dedup, sizes, cfg, altPkgPaths...)
|
||||
check(err)
|
||||
@@ -251,10 +251,10 @@ func Do(args []string, conf *Config) ([]Package, error) {
|
||||
return dpkg, nil
|
||||
}
|
||||
|
||||
func llgoPkgImported(pkgs []*packages.Package) bool {
|
||||
func llgoRuntimeImported(pkgs []*packages.Package) bool {
|
||||
for _, pkg := range pkgs {
|
||||
for _, imp := range pkg.Imports {
|
||||
if imp.Module != nil && imp.Module.Path == env.LLGoCompilerPkg {
|
||||
if imp.Module != nil && imp.Module.Path == env.LLGoRuntimePkg {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
16
compiler/internal/env/env.go
vendored
16
compiler/internal/env/env.go
vendored
@@ -7,9 +7,19 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
LLGoCompilerPkg = "github.com/goplus/llgo"
|
||||
LLGoCompilerPkg = "github.com/goplus/llgo"
|
||||
LLGoRuntimePkgName = "runtime"
|
||||
LLGoRuntimePkg = LLGoCompilerPkg + "/" + LLGoRuntimePkgName
|
||||
)
|
||||
|
||||
func LLGoRuntimeDir() string {
|
||||
root := LLGoROOT()
|
||||
if root != "" {
|
||||
return filepath.Join(root, LLGoRuntimePkgName)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func LLGoROOT() string {
|
||||
if root, ok := isLLGoRoot(os.Getenv("LLGO_ROOT")); ok {
|
||||
return root
|
||||
@@ -46,12 +56,12 @@ func isLLGoRoot(root string) (string, bool) {
|
||||
return "", false
|
||||
}
|
||||
// Check for go.mod
|
||||
data, err := os.ReadFile(filepath.Join(root, "go.mod"))
|
||||
data, err := os.ReadFile(filepath.Join(root, LLGoRuntimePkgName, "go.mod"))
|
||||
if err != nil {
|
||||
return "", false
|
||||
}
|
||||
// Check module name
|
||||
if !strings.Contains(string(data), "module "+LLGoCompilerPkg+"\n") {
|
||||
if !strings.Contains(string(data), "module "+LLGoRuntimePkg+"\n") {
|
||||
return "", false
|
||||
}
|
||||
return root, true
|
||||
|
||||
@@ -25,7 +25,8 @@ import (
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"github.com/goplus/llgo/compiler/internal/abi"
|
||||
"github.com/goplus/llgo/compiler/internal/env"
|
||||
"github.com/goplus/llgo/runtime/abi"
|
||||
)
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
@@ -215,7 +216,7 @@ func TypeArgs(typeArgs []types.Type) string {
|
||||
}
|
||||
|
||||
const (
|
||||
PatchPathPrefix = "github.com/goplus/llgo/compiler/internal/lib/"
|
||||
PatchPathPrefix = env.LLGoRuntimePkg + "/internal/lib/"
|
||||
)
|
||||
|
||||
// PathOf returns the package path of the specified package.
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"go/types"
|
||||
"log"
|
||||
|
||||
"github.com/goplus/llgo/compiler/internal/abi"
|
||||
"github.com/goplus/llgo/runtime/abi"
|
||||
)
|
||||
|
||||
// Builds a type representing a Bucket structure for
|
||||
|
||||
@@ -23,6 +23,7 @@ import (
|
||||
"strconv"
|
||||
"unsafe"
|
||||
|
||||
"github.com/goplus/llgo/compiler/internal/env"
|
||||
"github.com/goplus/llgo/compiler/ssa/abi"
|
||||
"github.com/goplus/llvm"
|
||||
"golang.org/x/tools/go/types/typeutil"
|
||||
@@ -30,7 +31,7 @@ import (
|
||||
|
||||
const (
|
||||
PkgPython = "github.com/goplus/llgo/py"
|
||||
PkgRuntime = "github.com/goplus/llgo/compiler/internal/runtime"
|
||||
PkgRuntime = env.LLGoRuntimePkg + "/internal/runtime"
|
||||
)
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
@@ -279,9 +280,16 @@ func (p Program) runtime() *types.Package {
|
||||
}
|
||||
|
||||
func (p Program) rtNamed(name string) *types.Named {
|
||||
t := p.runtime().Scope().Lookup(name).Type().(*types.Named)
|
||||
t, _ = p.gocvt.cvtNamed(t)
|
||||
return t
|
||||
t := p.runtime().Scope().Lookup(name).Type()
|
||||
for {
|
||||
if alias, ok := t.(*types.Alias); ok {
|
||||
t = alias.Rhs()
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
tyNamed, _ := p.gocvt.cvtNamed(t.(*types.Named))
|
||||
return tyNamed
|
||||
}
|
||||
|
||||
func (p Program) rtType(name string) Type {
|
||||
|
||||
5
runtime/go.mod
Normal file
5
runtime/go.mod
Normal file
@@ -0,0 +1,5 @@
|
||||
module github.com/goplus/llgo/runtime
|
||||
|
||||
go 1.20
|
||||
|
||||
require github.com/qiniu/x v1.13.10
|
||||
2
runtime/go.sum
Normal file
2
runtime/go.sum
Normal file
@@ -0,0 +1,2 @@
|
||||
github.com/qiniu/x v1.13.10 h1:J4Z3XugYzAq85SlyAfqlKVrbf05glMbAOh+QncsDQpE=
|
||||
github.com/qiniu/x v1.13.10/go.mod h1:INZ2TSWSJVWO/RuELQROERcslBwVgFG7MkTfEdaQz9E=
|
||||
101
runtime/internal/clite/bdwgc/_test/bdwgc.go
Normal file
101
runtime/internal/clite/bdwgc/_test/bdwgc.go
Normal file
@@ -0,0 +1,101 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
c "github.com/goplus/llgo/runtime/internal/clite"
|
||||
"github.com/goplus/llgo/runtime/internal/clite/bdwgc"
|
||||
"github.com/goplus/llgo/runtime/internal/clite/bdwgc/_test/testing"
|
||||
)
|
||||
|
||||
// ------ Test malloc ------
|
||||
|
||||
func TestMalloc(t *testing.T) {
|
||||
pn := (*int)(bdwgc.Malloc(unsafe.Sizeof(int(0))))
|
||||
*pn = 1 << 30
|
||||
c.Printf(c.Str("value: %d, %x, %p, %p\n"), *pn, *pn, pn, &pn)
|
||||
|
||||
pl := (*int64)(bdwgc.Realloc(c.Pointer(pn), unsafe.Sizeof(int64(0))))
|
||||
*pl = 1 << 60
|
||||
c.Printf(c.Str("value: %lld, %llx, %p, %p\n"), *pl, *pl, pl, &pl)
|
||||
|
||||
bdwgc.Free(c.Pointer(pl))
|
||||
}
|
||||
|
||||
// ------ Test finalizer ------
|
||||
|
||||
const (
|
||||
RETURN_VALUE_FREED = 1 << 31
|
||||
)
|
||||
|
||||
var called uint = 0
|
||||
|
||||
func setReturnValueFreed(pobj c.Pointer, clientData c.Pointer) {
|
||||
called |= RETURN_VALUE_FREED
|
||||
c.Printf(c.Str("called: %x\n"), called)
|
||||
}
|
||||
|
||||
func setLoopValueFreed(pobj c.Pointer, clientData c.Pointer) {
|
||||
pmask := (*uint)(clientData)
|
||||
called |= *pmask
|
||||
c.Printf(c.Str("called: %x\n"), called)
|
||||
}
|
||||
|
||||
func isCalled(mask uint) bool {
|
||||
return called&mask != 0
|
||||
}
|
||||
|
||||
func returnValue() *int {
|
||||
pn := bdwgc.Malloc(unsafe.Sizeof(int(0)))
|
||||
bdwgc.RegisterFinalizer(pn, setReturnValueFreed, nil, nil, nil)
|
||||
return (*int)(pn)
|
||||
}
|
||||
|
||||
func callFunc() {
|
||||
pn := returnValue()
|
||||
*pn = 1 << 30
|
||||
c.Printf(c.Str("value: %d, %x, %p, %p\n"), *pn, *pn, pn, &pn)
|
||||
bdwgc.Gcollect()
|
||||
check(!isCalled(RETURN_VALUE_FREED), c.Str("finalizer should not be called"))
|
||||
}
|
||||
|
||||
func loop() {
|
||||
for i := 0; i < 5; i++ {
|
||||
p := bdwgc.Malloc(unsafe.Sizeof(int(0)))
|
||||
pn := (*int)(p)
|
||||
*pn = i
|
||||
c.Printf(c.Str("value: %d, %x, %p, %p\n"), *pn, *pn, pn, &pn)
|
||||
pflag := (*uint)(c.Malloc(unsafe.Sizeof(uint(0))))
|
||||
*pflag = 1 << i
|
||||
bdwgc.RegisterFinalizer(p, setLoopValueFreed, c.Pointer(pflag), nil, nil)
|
||||
bdwgc.Gcollect()
|
||||
check(!isCalled(1<<i), c.Str("finalizer should not be called"))
|
||||
for j := 0; j < i; j++ {
|
||||
check(isCalled(1<<j), c.Str("finalizers of previous objects should be called"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Clear stack to avoid reference
|
||||
func clearStack() {
|
||||
p := c.Alloca(128)
|
||||
c.Memset(p, 0, 128)
|
||||
}
|
||||
|
||||
func check(b bool, msg *c.Char) {
|
||||
if !b {
|
||||
c.Printf(c.Str("check failed: %s\n"), msg)
|
||||
panic("check failed")
|
||||
}
|
||||
}
|
||||
|
||||
func TestFinalizer(t *testing.T) {
|
||||
bdwgc.Init()
|
||||
|
||||
callFunc()
|
||||
clearStack()
|
||||
bdwgc.Gcollect()
|
||||
check(isCalled(RETURN_VALUE_FREED), c.Str("finalizer should be called"))
|
||||
|
||||
loop()
|
||||
}
|
||||
31
runtime/internal/clite/bdwgc/_test/main.go
Normal file
31
runtime/internal/clite/bdwgc/_test/main.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
c "github.com/goplus/llgo/runtime/internal/clite"
|
||||
"github.com/goplus/llgo/runtime/internal/clite/bdwgc/_test/testing"
|
||||
)
|
||||
|
||||
type TestCase struct {
|
||||
Name string
|
||||
F func(*testing.T)
|
||||
}
|
||||
|
||||
func main() {
|
||||
tests := []TestCase{
|
||||
{"TestMalloc", TestMalloc},
|
||||
{"TestFinalizer", TestFinalizer},
|
||||
}
|
||||
if c.Argc == 1 {
|
||||
for _, test := range tests {
|
||||
c.Printf(c.Str("%s\n"), c.AllocaCStr(test.Name))
|
||||
}
|
||||
return
|
||||
}
|
||||
c.Fprintf(c.Stderr, c.Str("arg: %s\n"), c.Index(c.Argv, 1))
|
||||
idx := int(c.Atoi(c.Index(c.Argv, 1)))
|
||||
if idx < 0 || idx >= len(tests) {
|
||||
c.Printf(c.Str("invalid test index %d"), idx)
|
||||
panic("invalid test index")
|
||||
}
|
||||
tests[idx].F(nil)
|
||||
}
|
||||
4
runtime/internal/clite/bdwgc/_test/testing/testing.go
Normal file
4
runtime/internal/clite/bdwgc/_test/testing/testing.go
Normal file
@@ -0,0 +1,4 @@
|
||||
package testing
|
||||
|
||||
type T struct {
|
||||
}
|
||||
103
runtime/internal/clite/bdwgc/bdwgc.go
Normal file
103
runtime/internal/clite/bdwgc/bdwgc.go
Normal file
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* 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 bdwgc
|
||||
|
||||
import (
|
||||
_ "unsafe"
|
||||
|
||||
c "github.com/goplus/llgo/runtime/internal/clite"
|
||||
)
|
||||
|
||||
const (
|
||||
LLGoPackage = "link: $(pkg-config --libs bdw-gc); -lgc"
|
||||
)
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
//go:linkname Init C.GC_init
|
||||
func Init()
|
||||
|
||||
//go:linkname Malloc C.GC_malloc
|
||||
func Malloc(size uintptr) c.Pointer
|
||||
|
||||
//go:linkname Realloc C.GC_realloc
|
||||
func Realloc(ptr c.Pointer, size uintptr) c.Pointer
|
||||
|
||||
//go:linkname Free C.GC_free
|
||||
func Free(ptr c.Pointer)
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
//go:linkname RegisterFinalizer C.GC_register_finalizer
|
||||
func RegisterFinalizer(
|
||||
obj c.Pointer,
|
||||
fn func(c.Pointer, c.Pointer), cd c.Pointer,
|
||||
oldFn *func(c.Pointer, c.Pointer), oldCd *c.Pointer)
|
||||
|
||||
//go:linkname RegisterFinalizerNoOrder C.GC_register_finalizer_no_order
|
||||
func RegisterFinalizerNoOrder(
|
||||
obj c.Pointer,
|
||||
fn func(c.Pointer, c.Pointer), cd c.Pointer,
|
||||
oldFn *func(c.Pointer, c.Pointer), oldCd *c.Pointer)
|
||||
|
||||
//go:linkname RegisterFinalizerIgnoreSelf C.GC_register_finalizer_ignore_self
|
||||
func RegisterFinalizerIgnoreSelf(
|
||||
obj c.Pointer,
|
||||
fn func(c.Pointer, c.Pointer), cd c.Pointer,
|
||||
oldFn *func(c.Pointer, c.Pointer), oldCd *c.Pointer)
|
||||
|
||||
//go:linkname RegisterFinalizerUnreachable C.GC_register_finalizer_unreachable
|
||||
func RegisterFinalizerUnreachable(
|
||||
obj c.Pointer,
|
||||
fn func(c.Pointer, c.Pointer), cd c.Pointer,
|
||||
oldFn *func(c.Pointer, c.Pointer), oldCd *c.Pointer)
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
//go:linkname Enable C.GC_enable
|
||||
func Enable()
|
||||
|
||||
//go:linkname Disable C.GC_disable
|
||||
func Disable()
|
||||
|
||||
//go:linkname IsDisabled C.GC_is_disabled
|
||||
func IsDisabled() c.Int
|
||||
|
||||
//go:linkname Gcollect C.GC_gcollect
|
||||
func Gcollect()
|
||||
|
||||
//go:linkname GetMemoryUse C.GC_get_memory_use
|
||||
func GetMemoryUse() uintptr
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
//go:linkname EnableIncremental C.GC_enable_incremental
|
||||
func EnableIncremental()
|
||||
|
||||
//go:linkname IsIncrementalMode C.GC_is_incremental_mode
|
||||
func IsIncrementalMode() c.Int
|
||||
|
||||
//go:linkname IncrementalProtectionNeeds C.GC_incremental_protection_needs
|
||||
func IncrementalProtectionNeeds() c.Int
|
||||
|
||||
//go:linkname StartIncrementalCollection C.GC_start_incremental_collection
|
||||
func StartIncrementalCollection()
|
||||
|
||||
//go:linkname CollectALittle C.GC_collect_a_little
|
||||
func CollectALittle()
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
17
runtime/internal/clite/bitcast/_cast/cast.c
Normal file
17
runtime/internal/clite/bitcast/_cast/cast.c
Normal file
@@ -0,0 +1,17 @@
|
||||
typedef union {
|
||||
double d;
|
||||
float f;
|
||||
long v;
|
||||
} castUnion;
|
||||
|
||||
double llgoToFloat64(long v) {
|
||||
castUnion k;
|
||||
k.v = v;
|
||||
return k.d;
|
||||
}
|
||||
|
||||
float llgoToFloat32(long v) {
|
||||
castUnion k;
|
||||
k.v = v;
|
||||
return k.f;
|
||||
}
|
||||
30
runtime/internal/clite/bitcast/bitcast.go
Normal file
30
runtime/internal/clite/bitcast/bitcast.go
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* 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 bitcast
|
||||
|
||||
import _ "unsafe"
|
||||
|
||||
const (
|
||||
LLGoFiles = "_cast/cast.c"
|
||||
LLGoPackage = "link"
|
||||
)
|
||||
|
||||
//go:linkname ToFloat64 C.llgoToFloat64
|
||||
func ToFloat64(v uintptr) float64
|
||||
|
||||
//go:linkname ToFloat32 C.llgoToFloat32
|
||||
func ToFloat32(v uintptr) float32
|
||||
302
runtime/internal/clite/c.go
Normal file
302
runtime/internal/clite/c.go
Normal file
@@ -0,0 +1,302 @@
|
||||
/*
|
||||
* 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 clite
|
||||
|
||||
// typedef unsigned int uint;
|
||||
// typedef unsigned long ulong;
|
||||
// typedef unsigned long long ulonglong;
|
||||
// typedef long long longlong;
|
||||
import "C"
|
||||
import "unsafe"
|
||||
|
||||
const (
|
||||
LLGoPackage = "decl"
|
||||
)
|
||||
|
||||
type (
|
||||
Void = [0]byte
|
||||
Char = int8
|
||||
Float = float32
|
||||
Double = float64
|
||||
Pointer = unsafe.Pointer
|
||||
FilePtr = *FILE
|
||||
)
|
||||
|
||||
type FILE struct {
|
||||
Unused [8]byte
|
||||
}
|
||||
|
||||
type (
|
||||
Int C.int
|
||||
Uint C.uint
|
||||
|
||||
Long C.long
|
||||
Ulong C.ulong
|
||||
|
||||
LongLong C.longlong
|
||||
UlongLong C.ulonglong
|
||||
)
|
||||
|
||||
type integer interface {
|
||||
~int | ~uint | ~uintptr | ~int32 | ~uint32 | ~int64 | ~uint64
|
||||
}
|
||||
|
||||
type SizeT = uintptr
|
||||
|
||||
type IntptrT = uintptr
|
||||
type UintptrT = uintptr
|
||||
type Int8T = int8
|
||||
type Int16T = int16
|
||||
type Int32T = int32
|
||||
type Int64T = int64
|
||||
|
||||
type Uint8T = uint8
|
||||
type Uint16T = uint16
|
||||
type Uint32T = uint32
|
||||
type Uint64T = uint64
|
||||
|
||||
type IntmaxT = LongLong
|
||||
type UintmaxT = UlongLong
|
||||
|
||||
//go:linkname Str llgo.cstr
|
||||
func Str(string) *Char
|
||||
|
||||
//go:linkname Func llgo.funcAddr
|
||||
func Func(any) Pointer
|
||||
|
||||
// llgo:link Advance llgo.advance
|
||||
func Advance[PtrT any, I integer](ptr PtrT, offset I) PtrT { return ptr }
|
||||
|
||||
// llgo:link Index llgo.index
|
||||
func Index[T any, I integer](ptr *T, offset I) T { return *ptr }
|
||||
|
||||
//go:linkname Alloca llgo.alloca
|
||||
func Alloca(size uintptr) Pointer
|
||||
|
||||
//go:linkname AllocaCStr llgo.allocaCStr
|
||||
func AllocaCStr(s string) *Char
|
||||
|
||||
//go:linkname AllocaCStrs llgo.allocaCStrs
|
||||
func AllocaCStrs(strs []string, endWithNil bool) **Char
|
||||
|
||||
// TODO(xsw):
|
||||
// llgo:link AllocaNew llgo.allocaNew
|
||||
func AllocaNew[T any]() *T { return nil }
|
||||
|
||||
//go:linkname Malloc C.malloc
|
||||
func Malloc(size uintptr) Pointer
|
||||
|
||||
//go:linkname Calloc C.calloc
|
||||
func Calloc(num uintptr, size uintptr) Pointer
|
||||
|
||||
//go:linkname Free C.free
|
||||
func Free(ptr Pointer)
|
||||
|
||||
//go:linkname Realloc C.realloc
|
||||
func Realloc(ptr Pointer, size uintptr) Pointer
|
||||
|
||||
//go:linkname Memcpy C.memcpy
|
||||
func Memcpy(dst, src Pointer, n uintptr) Pointer
|
||||
|
||||
//go:linkname Memmove C.memmove
|
||||
func Memmove(dst, src Pointer, n uintptr) Pointer
|
||||
|
||||
//go:linkname Memset C.memset
|
||||
func Memset(s Pointer, c Int, n uintptr) Pointer
|
||||
|
||||
//go:linkname Memchr C.memchr
|
||||
func Memchr(s Pointer, c Int, n uintptr) Pointer
|
||||
|
||||
//go:linkname Memcmp C.memcmp
|
||||
func Memcmp(s1, s2 Pointer, n uintptr) Int
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
//go:linkname Strlen C.strlen
|
||||
func Strlen(s *Char) uintptr
|
||||
|
||||
//go:linkname Strcpy C.strcpy
|
||||
func Strcpy(dst, src *Char) *Char
|
||||
|
||||
//go:linkname Strncpy C.strncpy
|
||||
func Strncpy(dst, src *Char, n uintptr) *Char
|
||||
|
||||
//go:linkname Strcat C.strcat
|
||||
func Strcat(dst, src *Char) *Char
|
||||
|
||||
//go:linkname Strncat C.strncat
|
||||
func Strncat(dst, src *Char, n uintptr) *Char
|
||||
|
||||
//go:linkname Strcmp C.strcmp
|
||||
func Strcmp(s1, s2 *Char) Int
|
||||
|
||||
//go:linkname Strncmp C.strncmp
|
||||
func Strncmp(s1, s2 *Char, n uintptr) Int
|
||||
|
||||
//go:linkname Strchr C.strchr
|
||||
func Strchr(s *Char, c Int) *Char
|
||||
|
||||
//go:linkname Strrchr C.strrchr
|
||||
func Strrchr(s *Char, c Int) *Char
|
||||
|
||||
//go:linkname Strstr C.strstr
|
||||
func Strstr(s1, s2 *Char) *Char
|
||||
|
||||
//go:linkname Strdup C.strdup
|
||||
func Strdup(s *Char) *Char
|
||||
|
||||
//go:linkname Strndup C.strndup
|
||||
func Strndup(s *Char, n uintptr) *Char
|
||||
|
||||
//go:linkname Strtok C.strtok
|
||||
func Strtok(s, delim *Char) *Char
|
||||
|
||||
//go:linkname Strerror C.strerror
|
||||
func Strerror(errnum Int) *Char
|
||||
|
||||
//go:linkname Sprintf C.sprintf
|
||||
func Sprintf(s *Char, format *Char, __llgo_va_list ...any) Int
|
||||
|
||||
//go:linkname Snprintf C.snprintf
|
||||
func Snprintf(s *Char, n uintptr, format *Char, __llgo_va_list ...any) Int
|
||||
|
||||
//go:linkname Vsnprintf C.vsnprintf
|
||||
func Vsnprintf(s *Char, n uintptr, format *Char, ap Pointer) Int
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// GoString converts a C string to a Go string.
|
||||
// TODO(xsw): any => int
|
||||
//
|
||||
//go:linkname GoString llgo.string
|
||||
func GoString(cstr *Char, __llgo_va_list /* n */ ...any) string
|
||||
|
||||
//go:linkname GoStringData llgo.stringData
|
||||
func GoStringData(string) *Char
|
||||
|
||||
//go:linkname GoDeferData llgo.deferData
|
||||
func GoDeferData() Pointer
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
//go:linkname AllocaSigjmpBuf llgo.sigjmpbuf
|
||||
func AllocaSigjmpBuf() Pointer
|
||||
|
||||
//go:linkname Sigsetjmp llgo.sigsetjmp
|
||||
func Sigsetjmp(jb Pointer, savemask Int) Int
|
||||
|
||||
//go:linkname Siglongjmp llgo.siglongjmp
|
||||
func Siglongjmp(jb Pointer, retval Int)
|
||||
|
||||
//go:linkname Unreachable llgo.unreachable
|
||||
func Unreachable()
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
//go:linkname Exit C.exit
|
||||
func Exit(Int)
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
//go:linkname Rand C.rand
|
||||
func Rand() Int
|
||||
|
||||
//go:linkname Qsort C.qsort
|
||||
func Qsort(base Pointer, count, elem uintptr, compar func(a, b Pointer) Int)
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
//go:linkname Atoi C.atoi
|
||||
func Atoi(s *Char) Int
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
//go:linkname Printf C.printf
|
||||
func Printf(format *Char, __llgo_va_list ...any) Int
|
||||
|
||||
//go:linkname Fprintf C.fprintf
|
||||
func Fprintf(fp FilePtr, format *Char, __llgo_va_list ...any) Int
|
||||
|
||||
//go:linkname Fwrite C.fwrite
|
||||
func Fwrite(data Pointer, size, count uintptr, fp FilePtr) uintptr
|
||||
|
||||
//go:linkname Fputc C.fputc
|
||||
func Fputc(c Int, fp FilePtr) Int
|
||||
|
||||
//go:linkname Fputs C.fputs
|
||||
func Fputs(s *Char, fp FilePtr) Int
|
||||
|
||||
//go:linkname Fread C.fread
|
||||
func Fread(data Pointer, size, count uintptr, fp FilePtr) uintptr
|
||||
|
||||
//go:linkname Fflush C.fflush
|
||||
func Fflush(fp FilePtr) Int
|
||||
|
||||
//go:linkname Fopen C.fopen
|
||||
func Fopen(c *Char, mod *Char) FilePtr
|
||||
|
||||
//go:linkname Fclose C.fclose
|
||||
func Fclose(fp FilePtr) Int
|
||||
|
||||
//go:linkname Perror C.perror
|
||||
func Perror(s *Char)
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
//go:linkname Usleep C.usleep
|
||||
func Usleep(useconds Uint) Int
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
type Option struct {
|
||||
Name *Char
|
||||
HasArg Int
|
||||
Flag *Int
|
||||
Val Int
|
||||
}
|
||||
|
||||
//go:linkname Argc __llgo_argc
|
||||
var Argc Int
|
||||
|
||||
//go:linkname Argv __llgo_argv
|
||||
var Argv **Char
|
||||
|
||||
//go:linkname Optarg optarg
|
||||
var Optarg *Char
|
||||
|
||||
//go:linkname Optind optind
|
||||
var Optind Int
|
||||
|
||||
//go:linkname Opterr opterr
|
||||
var Opterr Int
|
||||
|
||||
//go:linkname Optopt optopt
|
||||
var Optopt Int
|
||||
|
||||
//go:linkname Getopt C.getopt
|
||||
func Getopt(argc Int, argv **Char, optstring *Char) Int
|
||||
|
||||
//go:linkname GetoptLong C.getopt_long
|
||||
func GetoptLong(argc Int, argv **Char, optstring *Char, longopts *Option, longindex *Int) Int
|
||||
|
||||
//go:linkname GetoptLongOnly C.getopt_long_only
|
||||
func GetoptLongOnly(argc Int, argv **Char, optstring *Char, longopts *Option, longindex *Int) Int
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
//go:linkname Sysconf C.sysconf
|
||||
func Sysconf(name Int) Long
|
||||
31
runtime/internal/clite/c_default.go
Normal file
31
runtime/internal/clite/c_default.go
Normal file
@@ -0,0 +1,31 @@
|
||||
//go:build !linux
|
||||
// +build !linux
|
||||
|
||||
/*
|
||||
* 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 clite
|
||||
|
||||
import _ "unsafe"
|
||||
|
||||
//go:linkname Stdin __stdinp
|
||||
var Stdin FilePtr
|
||||
|
||||
//go:linkname Stdout __stdoutp
|
||||
var Stdout FilePtr
|
||||
|
||||
//go:linkname Stderr __stderrp
|
||||
var Stderr FilePtr
|
||||
31
runtime/internal/clite/c_linux.go
Normal file
31
runtime/internal/clite/c_linux.go
Normal file
@@ -0,0 +1,31 @@
|
||||
//go:build linux
|
||||
// +build linux
|
||||
|
||||
/*
|
||||
* 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 clite
|
||||
|
||||
import _ "unsafe"
|
||||
|
||||
//go:linkname Stdin stdin
|
||||
var Stdin FilePtr
|
||||
|
||||
//go:linkname Stdout stdout
|
||||
var Stdout FilePtr
|
||||
|
||||
//go:linkname Stderr stderr
|
||||
var Stderr FilePtr
|
||||
27
runtime/internal/clite/debug/_demo/funcinfo/main.go
Normal file
27
runtime/internal/clite/debug/_demo/funcinfo/main.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
c "github.com/goplus/llgo/runtime/internal/clite"
|
||||
"github.com/goplus/llgo/runtime/internal/clite/debug"
|
||||
)
|
||||
|
||||
type T struct {
|
||||
n int
|
||||
}
|
||||
|
||||
func (t *T) Demo() {
|
||||
println(t.n)
|
||||
addr := debug.Address()
|
||||
c.Printf(c.Str("addr:0x%x\n"), addr)
|
||||
var info debug.Info
|
||||
r := debug.Addrinfo(addr, &info)
|
||||
if r == 0 {
|
||||
panic("not found info")
|
||||
}
|
||||
c.Printf(c.Str("func file:%s name:%s base:0x%x addr:0x%x\n"), info.Fname, info.Sname, info.Fbase, info.Saddr)
|
||||
}
|
||||
|
||||
func main() {
|
||||
t := &T{100}
|
||||
t.Demo()
|
||||
}
|
||||
26
runtime/internal/clite/debug/_demo/stacktrace/main.go
Normal file
26
runtime/internal/clite/debug/_demo/stacktrace/main.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/goplus/llgo/runtime/internal/clite/debug"
|
||||
)
|
||||
|
||||
type T struct {
|
||||
n int
|
||||
}
|
||||
|
||||
func (t *T) Demo() {
|
||||
println(t.n)
|
||||
debug.StackTrace(0, func(fr *debug.Frame) bool {
|
||||
var info debug.Info
|
||||
debug.Addrinfo(unsafe.Pointer(fr.PC), &info)
|
||||
println("[", fr.PC, "]", fr.Name, "+", fr.Offset, ", SP =", fr.SP)
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
func main() {
|
||||
t := &T{100}
|
||||
t.Demo()
|
||||
}
|
||||
39
runtime/internal/clite/debug/_wrap/debug.c
Normal file
39
runtime/internal/clite/debug/_wrap/debug.c
Normal file
@@ -0,0 +1,39 @@
|
||||
#if defined(__linux__)
|
||||
#define UNW_LOCAL_ONLY
|
||||
#define _GNU_SOURCE
|
||||
#include <features.h>
|
||||
#endif
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <libunwind.h>
|
||||
|
||||
void *llgo_address() {
|
||||
return __builtin_return_address(0);
|
||||
}
|
||||
|
||||
int llgo_addrinfo(void *addr, Dl_info *info) {
|
||||
return dladdr(addr, info);
|
||||
}
|
||||
|
||||
void llgo_stacktrace(int skip, void *ctx, int (*fn)(void *ctx, void *pc, void *offset, void *sp, char *name)) {
|
||||
unw_cursor_t cursor;
|
||||
unw_context_t context;
|
||||
unw_word_t offset, pc, sp;
|
||||
char fname[256];
|
||||
unw_getcontext(&context);
|
||||
unw_init_local(&cursor, &context);
|
||||
int depth = 0;
|
||||
while (unw_step(&cursor) > 0) {
|
||||
if (depth < skip) {
|
||||
depth++;
|
||||
continue;
|
||||
}
|
||||
if (unw_get_reg(&cursor, UNW_REG_IP, &pc) == 0) {
|
||||
unw_get_proc_name(&cursor, fname, sizeof(fname), &offset);
|
||||
unw_get_reg(&cursor, UNW_REG_SP, &sp);
|
||||
if (fn(ctx, (void*)pc, (void*)offset, (void*)sp, fname) == 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
49
runtime/internal/clite/debug/debug.go
Normal file
49
runtime/internal/clite/debug/debug.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package debug
|
||||
|
||||
/*
|
||||
#cgo linux LDFLAGS: -lunwind
|
||||
*/
|
||||
import "C"
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
c "github.com/goplus/llgo/runtime/internal/clite"
|
||||
)
|
||||
|
||||
const (
|
||||
LLGoPackage = "link"
|
||||
LLGoFiles = "_wrap/debug.c"
|
||||
)
|
||||
|
||||
type Info struct {
|
||||
Fname *c.Char
|
||||
Fbase c.Pointer
|
||||
Sname *c.Char
|
||||
Saddr c.Pointer
|
||||
}
|
||||
|
||||
//go:linkname Address C.llgo_address
|
||||
func Address() unsafe.Pointer
|
||||
|
||||
//go:linkname Addrinfo C.llgo_addrinfo
|
||||
func Addrinfo(addr unsafe.Pointer, info *Info) c.Int
|
||||
|
||||
//go:linkname stacktrace C.llgo_stacktrace
|
||||
func stacktrace(skip c.Int, ctx unsafe.Pointer, fn func(ctx, pc, offset, sp unsafe.Pointer, name *c.Char) c.Int)
|
||||
|
||||
type Frame struct {
|
||||
PC uintptr
|
||||
Offset uintptr
|
||||
SP unsafe.Pointer
|
||||
Name string
|
||||
}
|
||||
|
||||
func StackTrace(skip int, fn func(fr *Frame) bool) {
|
||||
stacktrace(c.Int(1+skip), unsafe.Pointer(&fn), func(ctx, pc, offset, sp unsafe.Pointer, name *c.Char) c.Int {
|
||||
fn := *(*func(fr *Frame) bool)(ctx)
|
||||
if !fn(&Frame{uintptr(pc), uintptr(offset), sp, c.GoString(name)}) {
|
||||
return 0
|
||||
}
|
||||
return 1
|
||||
})
|
||||
}
|
||||
25
runtime/internal/clite/ffi/_demo/_wrap/wrap.c
Normal file
25
runtime/internal/clite/ffi/_demo/_wrap/wrap.c
Normal file
@@ -0,0 +1,25 @@
|
||||
#include <stdio.h>
|
||||
|
||||
struct array
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
int z;
|
||||
int k;
|
||||
};
|
||||
|
||||
int demo1(struct array a)
|
||||
{
|
||||
printf("c.demo1: %d %d %d %d\n",a.x,a.y,a.z,a.k);
|
||||
return a.x+a.y+a.z+a.k;
|
||||
}
|
||||
|
||||
int demo2( int (*fn)(struct array)) {
|
||||
printf("c.demo2: %p\n",fn);
|
||||
struct array a;
|
||||
a.x = 1;
|
||||
a.y = 2;
|
||||
a.z = 3;
|
||||
a.k = 4;
|
||||
return (*fn)(a);
|
||||
}
|
||||
65
runtime/internal/clite/ffi/_demo/cfunc/main.go
Normal file
65
runtime/internal/clite/ffi/_demo/cfunc/main.go
Normal file
@@ -0,0 +1,65 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
c "github.com/goplus/llgo/runtime/internal/clite"
|
||||
"github.com/goplus/llgo/runtime/internal/clite/ffi"
|
||||
)
|
||||
|
||||
const (
|
||||
LLGoPackage = "link"
|
||||
LLGoFiles = "../_wrap/wrap.c"
|
||||
)
|
||||
|
||||
//llgo:type C
|
||||
type Callback func(array) c.Int
|
||||
|
||||
//go:linkname demo1 C.demo1
|
||||
func demo1(array) c.Int
|
||||
|
||||
//go:linkname demo2 C.demo2
|
||||
func demo2(fn Callback) c.Int
|
||||
|
||||
//llgo:type C
|
||||
type array struct {
|
||||
x c.Int
|
||||
y c.Int
|
||||
z c.Int
|
||||
k c.Int
|
||||
}
|
||||
|
||||
var (
|
||||
typeInt32 = &ffi.Type{4, 4, ffi.Sint32, nil}
|
||||
typePointer = &ffi.Type{unsafe.Sizeof(0), uint16(unsafe.Alignof(0)), ffi.Pointer, nil}
|
||||
)
|
||||
|
||||
func main() {
|
||||
cdemo1()
|
||||
cdemo2()
|
||||
}
|
||||
|
||||
func cdemo1() {
|
||||
var cif ffi.Cif
|
||||
tarray := &ffi.Type{0, 0, ffi.Struct, &[]*ffi.Type{typeInt32, typeInt32, typeInt32, typeInt32, nil}[0]}
|
||||
status := ffi.PrepCif(&cif, ffi.DefaultAbi, 1, typeInt32, &[]*ffi.Type{tarray}[0])
|
||||
if status != ffi.OK {
|
||||
panic(status)
|
||||
}
|
||||
ar := array{1, 2, 3, 4}
|
||||
var ret int32
|
||||
ffi.Call(&cif, c.Func(demo1), unsafe.Pointer(&ret), &[]unsafe.Pointer{unsafe.Pointer(&ar)}[0])
|
||||
c.Printf(c.Str("ret: %d\n"), ret)
|
||||
}
|
||||
|
||||
func cdemo2() {
|
||||
var cif ffi.Cif
|
||||
status := ffi.PrepCif(&cif, ffi.DefaultAbi, 1, typeInt32, &[]*ffi.Type{typePointer}[0])
|
||||
if status != ffi.OK {
|
||||
panic(status)
|
||||
}
|
||||
var ret int32
|
||||
fn := c.Func(demo1)
|
||||
ffi.Call(&cif, c.Func(demo2), unsafe.Pointer(&ret), &[]unsafe.Pointer{unsafe.Pointer(&fn)}[0])
|
||||
c.Printf(c.Str("ret: %d\n"), ret)
|
||||
}
|
||||
93
runtime/internal/clite/ffi/_demo/closure/main.go
Normal file
93
runtime/internal/clite/ffi/_demo/closure/main.go
Normal file
@@ -0,0 +1,93 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
c "github.com/goplus/llgo/runtime/internal/clite"
|
||||
"github.com/goplus/llgo/runtime/internal/clite/ffi"
|
||||
)
|
||||
|
||||
const (
|
||||
LLGoPackage = "link"
|
||||
LLGoFiles = "../_wrap/wrap.c"
|
||||
)
|
||||
|
||||
//llgo:type C
|
||||
type Callback func(array) c.Int
|
||||
|
||||
//go:linkname demo1 C.demo1
|
||||
func demo1(array) c.Int
|
||||
|
||||
//go:linkname demo2 C.demo2
|
||||
func demo2(fn Callback) c.Int
|
||||
|
||||
//llgo:type C
|
||||
type array struct {
|
||||
x c.Int
|
||||
y c.Int
|
||||
z c.Int
|
||||
k c.Int
|
||||
}
|
||||
|
||||
func demo(a array) c.Int {
|
||||
c.Printf(c.Str("go.demo %d %d %d %d\n"), a.x, a.y, a.z, a.k)
|
||||
return a.x + a.y + a.z + a.k
|
||||
}
|
||||
|
||||
var (
|
||||
typeInt32 = &ffi.Type{4, 4, ffi.Sint32, nil}
|
||||
typePointer = &ffi.Type{unsafe.Sizeof(0), uint16(unsafe.Alignof(0)), ffi.Pointer, nil}
|
||||
)
|
||||
|
||||
func main() {
|
||||
gofn()
|
||||
c.Printf(c.Str("\n"))
|
||||
goclosure()
|
||||
}
|
||||
|
||||
func gofn() {
|
||||
var cif ffi.Cif
|
||||
status := ffi.PrepCif(&cif, ffi.DefaultAbi, 1, typeInt32, &[]*ffi.Type{typePointer}[0])
|
||||
if status != ffi.OK {
|
||||
panic(status)
|
||||
}
|
||||
var fncode unsafe.Pointer
|
||||
closure := ffi.ClosureAlloc(&fncode)
|
||||
defer ffi.ClosureFree(closure)
|
||||
status = ffi.PreClosureLoc(closure, &cif, func(cif *ffi.Cif, ret unsafe.Pointer, args *unsafe.Pointer, userdata unsafe.Pointer) {
|
||||
ar := *(*array)(ffi.Index(args, 0))
|
||||
*(*c.Int)(ret) = demo(ar)
|
||||
}, nil, fncode)
|
||||
if status != ffi.OK {
|
||||
panic(status)
|
||||
}
|
||||
var ret int32
|
||||
ffi.Call(&cif, c.Func(demo2), unsafe.Pointer(&ret), &[]unsafe.Pointer{unsafe.Pointer(&fncode)}[0])
|
||||
c.Printf(c.Str("ret: %d\n"), ret)
|
||||
}
|
||||
|
||||
func goclosure() {
|
||||
var cif ffi.Cif
|
||||
status := ffi.PrepCif(&cif, ffi.DefaultAbi, 1, typeInt32, &[]*ffi.Type{typePointer}[0])
|
||||
if status != ffi.OK {
|
||||
panic(status)
|
||||
}
|
||||
fn := func(ar array) c.Int {
|
||||
c.Printf(c.Str("call closure %d\n"), cif.NArgs)
|
||||
return demo(ar)
|
||||
}
|
||||
var fncode unsafe.Pointer
|
||||
closure := ffi.ClosureAlloc(&fncode)
|
||||
defer ffi.ClosureFree(closure)
|
||||
status = ffi.PreClosureLoc(closure, &cif, func(cif *ffi.Cif, ret unsafe.Pointer, args *unsafe.Pointer, userdata unsafe.Pointer) {
|
||||
ar := *(*array)(ffi.Index(args, 0))
|
||||
fn := *(*func(array) c.Int)(userdata)
|
||||
*(*c.Int)(ret) = fn(ar)
|
||||
}, unsafe.Pointer(&fn), fncode)
|
||||
if status != ffi.OK {
|
||||
panic(status)
|
||||
}
|
||||
var ret int32
|
||||
ffi.Call(&cif, c.Func(demo2), unsafe.Pointer(&ret), &[]unsafe.Pointer{unsafe.Pointer(&fncode)}[0])
|
||||
c.Printf(c.Str("ret: %d\n"), ret)
|
||||
}
|
||||
26
runtime/internal/clite/ffi/_demo/printf/main.go
Normal file
26
runtime/internal/clite/ffi/_demo/printf/main.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
c "github.com/goplus/llgo/runtime/internal/clite"
|
||||
"github.com/goplus/llgo/runtime/internal/clite/ffi"
|
||||
)
|
||||
|
||||
var (
|
||||
typeInt32 = &ffi.Type{4, 4, ffi.Sint32, nil}
|
||||
typePointer = &ffi.Type{unsafe.Sizeof(0), uint16(unsafe.Alignof(0)), ffi.Pointer, nil}
|
||||
)
|
||||
|
||||
func main() {
|
||||
var cif ffi.Cif
|
||||
status := ffi.PrepCifVar(&cif, ffi.DefaultAbi, 1, 2, typeInt32, &[]*ffi.Type{typePointer, typeInt32}[0])
|
||||
if status != ffi.OK {
|
||||
panic(status)
|
||||
}
|
||||
var ret int32
|
||||
text := c.Str("hello world: %d\n")
|
||||
var n int32 = 100
|
||||
ffi.Call(&cif, c.Func(c.Printf), unsafe.Pointer(&ret), &[]unsafe.Pointer{unsafe.Pointer(&text), unsafe.Pointer(&n)}[0])
|
||||
c.Printf(c.Str("ret: %d\n"), ret)
|
||||
}
|
||||
5
runtime/internal/clite/ffi/_wrap/libffi.c
Normal file
5
runtime/internal/clite/ffi/_wrap/libffi.c
Normal file
@@ -0,0 +1,5 @@
|
||||
#include <ffi.h>
|
||||
|
||||
void *llog_ffi_closure_alloc(void **code) {
|
||||
return ffi_closure_alloc(sizeof(ffi_closure), code);
|
||||
}
|
||||
7
runtime/internal/clite/ffi/abi.go
Normal file
7
runtime/internal/clite/ffi/abi.go
Normal file
@@ -0,0 +1,7 @@
|
||||
//go:build ((freebsd || linux || darwin) && arm64) || (windows && (amd64 || arm64))
|
||||
|
||||
package ffi
|
||||
|
||||
const (
|
||||
DefaultAbi = 1
|
||||
)
|
||||
7
runtime/internal/clite/ffi/abi_amd64.go
Normal file
7
runtime/internal/clite/ffi/abi_amd64.go
Normal file
@@ -0,0 +1,7 @@
|
||||
//go:build freebsd || linux || darwin
|
||||
|
||||
package ffi
|
||||
|
||||
const (
|
||||
DefaultAbi = 2
|
||||
)
|
||||
132
runtime/internal/clite/ffi/ffi.go
Normal file
132
runtime/internal/clite/ffi/ffi.go
Normal file
@@ -0,0 +1,132 @@
|
||||
package ffi
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
c "github.com/goplus/llgo/runtime/internal/clite"
|
||||
)
|
||||
|
||||
const (
|
||||
LLGoPackage = "link: $(pkg-config --libs libffi); -lffi"
|
||||
LLGoFiles = "$(pkg-config --cflags libffi): _wrap/libffi.c"
|
||||
)
|
||||
|
||||
const (
|
||||
Void = iota
|
||||
Int
|
||||
Float
|
||||
Double
|
||||
LongDouble
|
||||
Uint8
|
||||
Sint8
|
||||
Uint16
|
||||
Sint16
|
||||
Uint32
|
||||
Sint32
|
||||
Uint64
|
||||
Sint64
|
||||
Struct
|
||||
Pointer
|
||||
Complex
|
||||
)
|
||||
|
||||
const (
|
||||
OK = iota
|
||||
BAD_TYPEDEF
|
||||
BAD_ABI
|
||||
BAD_ARGTYPE
|
||||
)
|
||||
|
||||
type Type struct {
|
||||
Size uintptr
|
||||
Alignment uint16
|
||||
Type uint16
|
||||
Elements **Type
|
||||
}
|
||||
|
||||
/*typedef struct {
|
||||
ffi_abi abi;
|
||||
unsigned nargs;
|
||||
ffi_type **arg_types;
|
||||
ffi_type *rtype;
|
||||
unsigned bytes;
|
||||
unsigned flags;
|
||||
#ifdef FFI_EXTRA_CIF_FIELDS
|
||||
FFI_EXTRA_CIF_FIELDS;
|
||||
#endif
|
||||
} ffi_cif;
|
||||
*/
|
||||
|
||||
type Cif struct {
|
||||
Abi c.Uint
|
||||
NArgs c.Uint
|
||||
ArgTypes **Type
|
||||
RType *Type
|
||||
Bytes c.Uint
|
||||
Flags c.Uint
|
||||
//Extra c.Uint
|
||||
}
|
||||
|
||||
/*
|
||||
ffi_status
|
||||
ffi_prep_cif(ffi_cif *cif,
|
||||
ffi_abi abi,
|
||||
unsigned int nargs,
|
||||
ffi_type *rtype,
|
||||
ffi_type **atypes);
|
||||
*/
|
||||
//go:linkname PrepCif C.ffi_prep_cif
|
||||
func PrepCif(cif *Cif, abi c.Uint, nargs c.Uint, rtype *Type, atype **Type) c.Uint
|
||||
|
||||
/*
|
||||
ffi_status ffi_prep_cif_var(ffi_cif *cif,
|
||||
ffi_abi abi,
|
||||
unsigned int nfixedargs,
|
||||
unsigned int ntotalargs,
|
||||
ffi_type *rtype,
|
||||
ffi_type **atypes);
|
||||
*/
|
||||
//go:linkname PrepCifVar C.ffi_prep_cif_var
|
||||
func PrepCifVar(cif *Cif, abi c.Uint, nfixedargs c.Uint, ntotalargs c.Uint, rtype *Type, atype **Type) c.Uint
|
||||
|
||||
/*
|
||||
void ffi_call(ffi_cif *cif,
|
||||
void (*fn)(void),
|
||||
void *rvalue,
|
||||
void **avalue);
|
||||
*/
|
||||
//go:linkname Call C.ffi_call
|
||||
func Call(cif *Cif, fn unsafe.Pointer, rvalue unsafe.Pointer, avalue *unsafe.Pointer)
|
||||
|
||||
// void *ffi_closure_alloc (size_t size, void **code);
|
||||
//
|
||||
//go:linkname ClosureAlloc C.llog_ffi_closure_alloc
|
||||
func ClosureAlloc(code *unsafe.Pointer) unsafe.Pointer
|
||||
|
||||
// void ffi_closure_free (void *);
|
||||
//
|
||||
//go:linkname ClosureFree C.ffi_closure_free
|
||||
func ClosureFree(unsafe.Pointer)
|
||||
|
||||
/*
|
||||
ffi_status
|
||||
ffi_prep_closure_loc (ffi_closure*,
|
||||
ffi_cif *,
|
||||
void (*fun)(ffi_cif*,void*,void**,void*),
|
||||
void *user_data,
|
||||
void *codeloc);
|
||||
*/
|
||||
|
||||
//llgo:type C
|
||||
type ClosureFunc func(cif *Cif, ret unsafe.Pointer, args *unsafe.Pointer, userdata unsafe.Pointer)
|
||||
|
||||
//go:linkname PreClosureLoc C.ffi_prep_closure_loc
|
||||
func PreClosureLoc(closure unsafe.Pointer, cif *Cif, fn ClosureFunc, userdata unsafe.Pointer, codeloc unsafe.Pointer) c.Uint
|
||||
|
||||
func add(ptr unsafe.Pointer, offset uintptr) unsafe.Pointer {
|
||||
return unsafe.Pointer(uintptr(ptr) + offset)
|
||||
}
|
||||
|
||||
func Index(args *unsafe.Pointer, i uintptr) unsafe.Pointer {
|
||||
return (*(*unsafe.Pointer)(add(unsafe.Pointer(args), i*unsafe.Sizeof(0))))
|
||||
}
|
||||
151
runtime/internal/clite/math/cmplx/complex.go
Normal file
151
runtime/internal/clite/math/cmplx/complex.go
Normal file
@@ -0,0 +1,151 @@
|
||||
/*
|
||||
* 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 cmplx
|
||||
|
||||
import (
|
||||
_ "unsafe"
|
||||
)
|
||||
|
||||
const (
|
||||
LLGoPackage = "decl"
|
||||
)
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
//go:linkname Abs C.cabs
|
||||
func Abs(z complex128) float64
|
||||
|
||||
//go:linkname Acos C.cacos
|
||||
func Acos(z complex128) complex128
|
||||
|
||||
//go:linkname Acosh C.cacosh
|
||||
func Acosh(z complex128) complex128
|
||||
|
||||
//go:linkname Asin C.casin
|
||||
func Asin(z complex128) complex128
|
||||
|
||||
//go:linkname Asinh C.casinh
|
||||
func Asinh(z complex128) complex128
|
||||
|
||||
//go:linkname Atan C.catan
|
||||
func Atan(z complex128) complex128
|
||||
|
||||
//go:linkname Atanh C.catanh
|
||||
func Atanh(z complex128) complex128
|
||||
|
||||
//go:linkname Cos C.ccos
|
||||
func Cos(z complex128) complex128
|
||||
|
||||
//go:linkname Cosh C.ccosh
|
||||
func Cosh(z complex128) complex128
|
||||
|
||||
//go:linkname Exp C.cexp
|
||||
func Exp(z complex128) complex128
|
||||
|
||||
//go:linkname Log C.clog
|
||||
func Log(z complex128) complex128
|
||||
|
||||
//go:linkname Log10 C.clog10
|
||||
func Log10(z complex128) complex128
|
||||
|
||||
//go:linkname Arg C.carg
|
||||
func Arg(z complex128) float64
|
||||
|
||||
//go:linkname Phase C.carg
|
||||
func Phase(z complex128) float64
|
||||
|
||||
//go:linkname Pow C.cpow
|
||||
func Pow(x, y complex128) complex128
|
||||
|
||||
//go:linkname Sin C.csin
|
||||
func Sin(z complex128) complex128
|
||||
|
||||
//go:linkname Sinh C.csinh
|
||||
func Sinh(z complex128) complex128
|
||||
|
||||
//go:linkname Sqrt C.csqrt
|
||||
func Sqrt(z complex128) complex128
|
||||
|
||||
//go:linkname Tan C.ctan
|
||||
func Tan(z complex128) complex128
|
||||
|
||||
//go:linkname Tanh C.ctanh
|
||||
func Tanh(z complex128) complex128
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
//go:linkname Absf C.cabsf
|
||||
func Absf(z complex64) float32
|
||||
|
||||
//go:linkname Acosf C.cacosf
|
||||
func Acosf(z complex64) complex64
|
||||
|
||||
//go:linkname Acoshf C.cacoshf
|
||||
func Acoshf(z complex64) complex64
|
||||
|
||||
//go:linkname Asinf C.casinf
|
||||
func Asinf(z complex64) complex64
|
||||
|
||||
//go:linkname Asinhf C.casinhf
|
||||
func Asinhf(z complex64) complex64
|
||||
|
||||
//go:linkname Atanf C.catanf
|
||||
func Atanf(z complex64) complex64
|
||||
|
||||
//go:linkname Atanhf C.catanhf
|
||||
func Atanhf(z complex64) complex64
|
||||
|
||||
//go:linkname Cosf C.ccosf
|
||||
func Cosf(z complex64) complex64
|
||||
|
||||
//go:linkname Coshf C.ccoshf
|
||||
func Coshf(z complex64) complex64
|
||||
|
||||
//go:linkname Expf C.cexpf
|
||||
func Expf(z complex64) complex64
|
||||
|
||||
//go:linkname Logf C.clogf
|
||||
func Logf(z complex64) complex64
|
||||
|
||||
//go:linkname Log10f C.clog10f
|
||||
func Log10f(z complex64) complex64
|
||||
|
||||
//go:linkname Argf C.cargf
|
||||
func Argf(z complex64) float32
|
||||
|
||||
//go:linkname Phasef C.cargf
|
||||
func Phasef(z complex64) float32
|
||||
|
||||
//go:linkname Powf C.cpowf
|
||||
func Powf(x, y complex64) complex64
|
||||
|
||||
//go:linkname Sinf C.csinf
|
||||
func Sinf(z complex64) complex64
|
||||
|
||||
//go:linkname Sinhf C.csinhf
|
||||
func Sinhf(z complex64) complex64
|
||||
|
||||
//go:linkname Sqrtf C.csqrtf
|
||||
func Sqrtf(z complex64) complex64
|
||||
|
||||
//go:linkname Tanf C.ctanf
|
||||
func Tanf(z complex64) complex64
|
||||
|
||||
//go:linkname Tanhf C.ctanhf
|
||||
func Tanhf(z complex64) complex64
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
333
runtime/internal/clite/math/math.go
Normal file
333
runtime/internal/clite/math/math.go
Normal file
@@ -0,0 +1,333 @@
|
||||
/*
|
||||
* 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 math
|
||||
|
||||
import (
|
||||
_ "unsafe"
|
||||
|
||||
c "github.com/goplus/llgo/runtime/internal/clite"
|
||||
)
|
||||
|
||||
const (
|
||||
LLGoPackage = "decl"
|
||||
)
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
//go:linkname Acos C.acos
|
||||
func Acos(x float64) float64
|
||||
|
||||
//go:linkname Acosh C.acosh
|
||||
func Acosh(x float64) float64
|
||||
|
||||
//go:linkname Asin C.asin
|
||||
func Asin(x float64) float64
|
||||
|
||||
//go:linkname Asinh C.asinh
|
||||
func Asinh(x float64) float64
|
||||
|
||||
//go:linkname Atan C.atan
|
||||
func Atan(x float64) float64
|
||||
|
||||
//go:linkname Atan2 C.atan2
|
||||
func Atan2(y, x float64) float64
|
||||
|
||||
//go:linkname Atanh C.atanh
|
||||
func Atanh(x float64) float64
|
||||
|
||||
//go:linkname Cbrt C.cbrt
|
||||
func Cbrt(x float64) float64
|
||||
|
||||
//go:linkname Ceil C.ceil
|
||||
func Ceil(x float64) float64
|
||||
|
||||
//go:linkname Cos C.cos
|
||||
func Cos(x float64) float64
|
||||
|
||||
//go:linkname Cosh C.cosh
|
||||
func Cosh(x float64) float64
|
||||
|
||||
//go:linkname Copysign C.copysign
|
||||
func Copysign(x, y float64) float64
|
||||
|
||||
//go:linkname Erf C.erf
|
||||
func Erf(x float64) float64
|
||||
|
||||
//go:linkname Erfc C.erfc
|
||||
func Erfc(x float64) float64
|
||||
|
||||
//go:linkname Exp C.exp
|
||||
func Exp(x float64) float64
|
||||
|
||||
//go:linkname Exp2 C.exp2
|
||||
func Exp2(x float64) float64
|
||||
|
||||
//go:linkname Expm1 C.expm1
|
||||
func Expm1(x float64) float64
|
||||
|
||||
//go:linkname Fdim C.fdim
|
||||
func Fdim(x, y float64) float64
|
||||
|
||||
//go:linkname Floor C.floor
|
||||
func Floor(x float64) float64
|
||||
|
||||
//go:linkname Fma C.fma
|
||||
func Fma(x, y, z float64) float64
|
||||
|
||||
//go:linkname Fmax C.fmax
|
||||
func Fmax(x, y float64) float64
|
||||
|
||||
//go:linkname Fmin C.fmin
|
||||
func Fmin(x, y float64) float64
|
||||
|
||||
//go:linkname Fmod C.fmod
|
||||
func Fmod(x, y float64) float64
|
||||
|
||||
//go:linkname Frexp C.frexp
|
||||
func Frexp(x float64, exp *c.Int) float64
|
||||
|
||||
//go:linkname Gamma C.gamma
|
||||
func Gamma(x float64) float64
|
||||
|
||||
//go:linkname Hypot C.hypot
|
||||
func Hypot(x, y float64) float64
|
||||
|
||||
//go:linkname Ilogb C.ilogb
|
||||
func Ilogb(x float64) c.Int
|
||||
|
||||
//go:linkname J0 C.j0
|
||||
func J0(x float64) float64
|
||||
|
||||
//go:linkname J1 C.j1
|
||||
func J1(x float64) float64
|
||||
|
||||
//go:linkname Jn C.jn
|
||||
func Jn(n c.Int, x float64) float64
|
||||
|
||||
//go:linkname Ldexp C.ldexp
|
||||
func Ldexp(x float64, exp c.Int) float64
|
||||
|
||||
//go:linkname Lgamma C.lgamma
|
||||
func Lgamma(x float64) float64
|
||||
|
||||
//go:linkname Log C.log
|
||||
func Log(x float64) float64
|
||||
|
||||
//go:linkname Log10 C.log10
|
||||
func Log10(x float64) float64
|
||||
|
||||
//go:linkname Log1p C.log1p
|
||||
func Log1p(x float64) float64
|
||||
|
||||
//go:linkname Log2 C.log2
|
||||
func Log2(x float64) float64
|
||||
|
||||
//go:linkname Logb C.logb
|
||||
func Logb(x float64) float64
|
||||
|
||||
//go:linkname Modf C.modf
|
||||
func Modf(x float64, ipart *float64) float64
|
||||
|
||||
//go:linkname Nan C.nan
|
||||
func Nan(tag *c.Char) float64
|
||||
|
||||
//go:linkname Nextafter C.nextafter
|
||||
func Nextafter(x, y float64) float64
|
||||
|
||||
//go:linkname Pow C.pow
|
||||
func Pow(x, y float64) float64
|
||||
|
||||
//go:linkname Remainder C.remainder
|
||||
func Remainder(x, y float64) float64
|
||||
|
||||
//go:linkname Round C.round
|
||||
func Round(x float64) float64
|
||||
|
||||
//go:linkname Sin C.sin
|
||||
func Sin(x float64) float64
|
||||
|
||||
//go:linkname Sinh C.sinh
|
||||
func Sinh(x float64) float64
|
||||
|
||||
//go:linkname Sqrt C.sqrt
|
||||
func Sqrt(x float64) float64
|
||||
|
||||
//go:linkname Tan C.tan
|
||||
func Tan(x float64) float64
|
||||
|
||||
//go:linkname Tanh C.tanh
|
||||
func Tanh(x float64) float64
|
||||
|
||||
//go:linkname Tgamma C.tgamma
|
||||
func Tgamma(x float64) float64
|
||||
|
||||
//go:linkname Trunc C.trunc
|
||||
func Trunc(x float64) float64
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
//go:linkname Acosf C.acosf
|
||||
func Acosf(x float32) float32
|
||||
|
||||
//go:linkname Acoshf C.acoshf
|
||||
func Acoshf(x float32) float32
|
||||
|
||||
//go:linkname Asinf C.asinf
|
||||
func Asinf(x float32) float32
|
||||
|
||||
//go:linkname Asinhf C.asinhf
|
||||
func Asinhf(x float32) float32
|
||||
|
||||
//go:linkname Atanf C.atanf
|
||||
func Atanf(x float32) float32
|
||||
|
||||
//go:linkname Atan2f C.atan2f
|
||||
func Atan2f(y, x float32) float32
|
||||
|
||||
//go:linkname Atanhf C.atanhf
|
||||
func Atanhf(x float32) float32
|
||||
|
||||
//go:linkname Cbrtf C.cbrtf
|
||||
func Cbrtf(x float32) float32
|
||||
|
||||
//go:linkname Ceilf C.ceilf
|
||||
func Ceilf(x float32) float32
|
||||
|
||||
//go:linkname Cosf C.cosf
|
||||
func Cosf(x float32) float32
|
||||
|
||||
//go:linkname Coshf C.coshf
|
||||
func Coshf(x float32) float32
|
||||
|
||||
//go:linkname Copysignf C.copysignf
|
||||
func Copysignf(x, y float32) float32
|
||||
|
||||
//go:linkname Erff C.erff
|
||||
func Erff(x float32) float32
|
||||
|
||||
//go:linkname Erfcf C.erfcf
|
||||
func Erfcf(x float32) float32
|
||||
|
||||
//go:linkname Expf C.expf
|
||||
func Expf(x float32) float32
|
||||
|
||||
//go:linkname Exp2f C.exp2f
|
||||
func Exp2f(x float32) float32
|
||||
|
||||
//go:linkname Expm1f C.expm1f
|
||||
func Expm1f(x float32) float32
|
||||
|
||||
//go:linkname Fdimf C.fdimf
|
||||
func Fdimf(x, y float32) float32
|
||||
|
||||
//go:linkname Floorf C.floorf
|
||||
func Floorf(x float32) float32
|
||||
|
||||
//go:linkname Fmaf C.fmaf
|
||||
func Fmaf(x, y, z float32) float32
|
||||
|
||||
//go:linkname Fmaxf C.fmaxf
|
||||
func Fmaxf(x, y float32) float32
|
||||
|
||||
//go:linkname Fminf C.fminf
|
||||
func Fminf(x, y float32) float32
|
||||
|
||||
//go:linkname Fmodf C.fmodf
|
||||
func Fmodf(x, y float32) float32
|
||||
|
||||
//go:linkname Frexpf C.frexpf
|
||||
func Frexpf(x float32, exp *c.Int) float32
|
||||
|
||||
//go:linkname Gammaf C.gammaf
|
||||
func Gammaf(x float32) float32
|
||||
|
||||
//go:linkname Hypotf C.hypotf
|
||||
func Hypotf(x, y float32) float32
|
||||
|
||||
//go:linkname Ilogbf C.ilogbf
|
||||
func Ilogbf(x float32) c.Int
|
||||
|
||||
//go:linkname J0f C.j0f
|
||||
func J0f(x float32) float32
|
||||
|
||||
//go:linkname J1f C.j1f
|
||||
func J1f(x float32) float32
|
||||
|
||||
//go:linkname Jnf C.jnf
|
||||
func Jnf(n c.Int, x float32) float32
|
||||
|
||||
//go:linkname Ldexpf C.ldexpf
|
||||
func Ldexpf(x float32, exp c.Int) float32
|
||||
|
||||
//go:linkname Lgammaf C.lgammaf
|
||||
func Lgammaf(x float32) float32
|
||||
|
||||
//go:linkname Logf C.logf
|
||||
func Logf(x float32) float32
|
||||
|
||||
//go:linkname Log10f C.log10f
|
||||
func Log10f(x float32) float32
|
||||
|
||||
//go:linkname Log1pf C.log1pf
|
||||
func Log1pf(x float32) float32
|
||||
|
||||
//go:linkname Log2f C.log2f
|
||||
func Log2f(x float32) float32
|
||||
|
||||
//go:linkname Logbf C.logbf
|
||||
func Logbf(x float32) float32
|
||||
|
||||
//go:linkname Modff C.modff
|
||||
func Modff(x float32, ipart *float32) float32
|
||||
|
||||
//go:linkname Nanf C.nanf
|
||||
func Nanf(tag *c.Char) float32
|
||||
|
||||
//go:linkname Nextafterf C.nextafterf
|
||||
func Nextafterf(x, y float32) float32
|
||||
|
||||
//go:linkname Powf C.powf
|
||||
func Powf(x, y float32) float32
|
||||
|
||||
//go:linkname Remainderf C.remainderf
|
||||
func Remainderf(x, y float32) float32
|
||||
|
||||
//go:linkname Roundf C.roundf
|
||||
func Roundf(x float32) float32
|
||||
|
||||
//go:linkname Sinf C.sinf
|
||||
func Sinf(x float32) float32
|
||||
|
||||
//go:linkname Sinhf C.sinhf
|
||||
func Sinhf(x float32) float32
|
||||
|
||||
//go:linkname Sqrtf C.sqrtf
|
||||
func Sqrtf(x float32) float32
|
||||
|
||||
//go:linkname Tanf C.tanf
|
||||
func Tanf(x float32) float32
|
||||
|
||||
//go:linkname Tanhf C.tanhf
|
||||
func Tanhf(x float32) float32
|
||||
|
||||
//go:linkname Tgammaf C.tgammaf
|
||||
func Tgammaf(x float32) float32
|
||||
|
||||
//go:linkname Truncf C.truncf
|
||||
func Truncf(x float32) float32
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
54
runtime/internal/clite/math/rand/rand.go
Normal file
54
runtime/internal/clite/math/rand/rand.go
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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 rand
|
||||
|
||||
import (
|
||||
_ "unsafe"
|
||||
|
||||
c "github.com/goplus/llgo/runtime/internal/clite"
|
||||
)
|
||||
|
||||
const (
|
||||
LLGoPackage = "decl"
|
||||
)
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
//go:linkname Rand C.rand
|
||||
func Rand() c.Int
|
||||
|
||||
//go:linkname RandR C.rand_r
|
||||
func RandR(*c.Uint) c.Int
|
||||
|
||||
//go:linkname Srand C.srand
|
||||
func Srand(c.Uint)
|
||||
|
||||
//go:linkname Sranddev C.sranddev
|
||||
func Sranddev()
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
//go:linkname Random C.random
|
||||
func Random() c.Long
|
||||
|
||||
//go:linkname Srandom C.srandom
|
||||
func Srandom(c.Uint)
|
||||
|
||||
//go:linkname Srandomdev C.srandomdev
|
||||
func Srandomdev()
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
5
runtime/internal/clite/openssl/_wrap/openssl.c
Normal file
5
runtime/internal/clite/openssl/_wrap/openssl.c
Normal file
@@ -0,0 +1,5 @@
|
||||
#include <openssl/crypto.h>
|
||||
|
||||
void opensslFree(void *ptr) {
|
||||
OPENSSL_free(ptr);
|
||||
}
|
||||
61
runtime/internal/clite/openssl/bio.go
Normal file
61
runtime/internal/clite/openssl/bio.go
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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 openssl
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
c "github.com/goplus/llgo/runtime/internal/clite"
|
||||
)
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
type BIO struct {
|
||||
Unused [0]byte
|
||||
}
|
||||
|
||||
// BIO *BIO_new_mem_buf(const void *buf, int len);
|
||||
//
|
||||
//go:linkname BIONewMemBuf C.BIO_new_mem_buf
|
||||
func BIONewMemBuf(buf unsafe.Pointer, len c.Int) *BIO
|
||||
|
||||
// int BIO_free(BIO *a);
|
||||
//
|
||||
// llgo:link (*BIO).Free C.BIO_free
|
||||
func (*BIO) Free() c.Int { return 0 }
|
||||
|
||||
// int BIO_up_ref(BIO *a);
|
||||
//
|
||||
// llgo:link (*BIO).UpRef C.BIO_up_ref
|
||||
func (*BIO) UpRef() c.Int { return 0 }
|
||||
|
||||
// int BIO_read_ex(BIO *b, void *data, size_t dlen, size_t *readbytes);
|
||||
//
|
||||
// llgo:link (*BIO).ReadEx C.BIO_read_ex
|
||||
func (*BIO) ReadEx(data unsafe.Pointer, dlen uintptr, readbytes *uintptr) c.Int { return 0 }
|
||||
|
||||
// int BIO_write(BIO *b, const void *data, int dlen);
|
||||
//
|
||||
// llgo:link (*BIO).Write C.BIO_write
|
||||
func (*BIO) Write(data unsafe.Pointer, dlen c.Int) c.Int { return 0 }
|
||||
|
||||
// int BIO_write_ex(BIO *b, const void *data, size_t dlen, size_t *written);
|
||||
//
|
||||
// llgo:link (*BIO).WriteEx C.BIO_write_ex
|
||||
func (*BIO) WriteEx(data unsafe.Pointer, dlen uintptr, written *uintptr) c.Int { return 0 }
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
409
runtime/internal/clite/openssl/bn.go
Normal file
409
runtime/internal/clite/openssl/bn.go
Normal file
@@ -0,0 +1,409 @@
|
||||
/*
|
||||
* 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 openssl
|
||||
|
||||
import (
|
||||
_ "unsafe"
|
||||
|
||||
c "github.com/goplus/llgo/runtime/internal/clite"
|
||||
)
|
||||
|
||||
type BN_ULONG = uint64
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
type BN_CTX struct {
|
||||
Unused [0]byte
|
||||
}
|
||||
|
||||
// BN_CTX *BN_CTX_new(void);
|
||||
//
|
||||
//go:linkname BN_CTXNew C.BN_CTX_new
|
||||
func BN_CTXNew() *BN_CTX
|
||||
|
||||
// BN_CTX *BN_CTX_secure_new(void);
|
||||
//
|
||||
//go:linkname BN_CTXSecureNew C.BN_CTX_secure_new
|
||||
func BN_CTXSecureNew() *BN_CTX
|
||||
|
||||
// BN_CTX *BN_CTX_new_ex(OSSL_LIB_CTX *ctx);
|
||||
// BN_CTX *BN_CTX_secure_new_ex(OSSL_LIB_CTX *ctx);
|
||||
|
||||
// void BN_CTX_free(BN_CTX *c);
|
||||
//
|
||||
// llgo:link (*BN_CTX).Free C.BN_CTX_free
|
||||
func (*BN_CTX) Free() {}
|
||||
|
||||
// void BN_CTX_start(BN_CTX *ctx);
|
||||
//
|
||||
// llgo:link (*BN_CTX).Start C.BN_CTX_start
|
||||
func (*BN_CTX) Start() {}
|
||||
|
||||
// BIGNUM *BN_CTX_get(BN_CTX *ctx);
|
||||
//
|
||||
// llgo:link (*BN_CTX).Get C.BN_CTX_get
|
||||
func (*BN_CTX) Get() *BIGNUM { return nil }
|
||||
|
||||
// void BN_CTX_end(BN_CTX *ctx);
|
||||
//
|
||||
// llgo:link (*BN_CTX).End C.BN_CTX_end
|
||||
func (*BN_CTX) End() {}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
type BIGNUM struct {
|
||||
Unused [0]byte
|
||||
}
|
||||
|
||||
// BIGNUM *BN_new(void);
|
||||
//
|
||||
//go:linkname BNNew C.BN_new
|
||||
func BNNew() *BIGNUM
|
||||
|
||||
// BIGNUM *BN_secure_new(void);
|
||||
//
|
||||
//go:linkname BNSecureNew C.BN_secure_new
|
||||
func BNSecureNew() *BIGNUM
|
||||
|
||||
// void BN_free(BIGNUM *a);
|
||||
//
|
||||
// llgo:link (*BIGNUM).Free C.BN_free
|
||||
func (*BIGNUM) Free() {}
|
||||
|
||||
// void BN_clear_free(BIGNUM *a);
|
||||
//
|
||||
// llgo:link (*BIGNUM).ClearFree C.BN_clear_free
|
||||
func (*BIGNUM) ClearFree() {}
|
||||
|
||||
// void BN_clear(BIGNUM *a);
|
||||
//
|
||||
// llgo:link (*BIGNUM).Clear C.BN_clear
|
||||
func (*BIGNUM) Clear() {}
|
||||
|
||||
// BIGNUM *BN_dup(const BIGNUM *a);
|
||||
//
|
||||
// llgo:link (*BIGNUM).Dup C.BN_dup
|
||||
func (*BIGNUM) Dup() *BIGNUM { return nil }
|
||||
|
||||
// BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b);
|
||||
//
|
||||
// llgo:link (*BIGNUM).Copy C.BN_copy
|
||||
func (*BIGNUM) Copy(b *BIGNUM) *BIGNUM { return nil }
|
||||
|
||||
// void BN_swap(BIGNUM *a, BIGNUM *b);
|
||||
//
|
||||
// llgo:link (*BIGNUM).Swap C.BN_swap
|
||||
func (*BIGNUM) Swap(b *BIGNUM) {}
|
||||
|
||||
// int BN_is_zero(const BIGNUM *a);
|
||||
//
|
||||
// llgo:link (*BIGNUM).IsZero C.BN_is_zero
|
||||
func (*BIGNUM) IsZero() c.Int { return 0 }
|
||||
|
||||
// void BN_zero_ex(BIGNUM *a);
|
||||
//
|
||||
// llgo:link (*BIGNUM).SetZero C.BN_zero_ex
|
||||
func (*BIGNUM) SetZero() {}
|
||||
|
||||
// int BN_is_one(const BIGNUM *a);
|
||||
//
|
||||
// llgo:link (*BIGNUM).IsOne C.BN_is_one
|
||||
func (*BIGNUM) IsOne() c.Int { return 0 }
|
||||
|
||||
// int BN_is_odd(const BIGNUM *a);
|
||||
//
|
||||
// llgo:link (*BIGNUM).IsOdd C.BN_is_odd
|
||||
func (*BIGNUM) IsOdd() c.Int { return 0 }
|
||||
|
||||
// int BN_abs_is_word(const BIGNUM *a, const BN_ULONG w);
|
||||
//
|
||||
// llgo:link (*BIGNUM).AbsIsWord C.BN_abs_is_word
|
||||
func (*BIGNUM) AbsIsWord(w BN_ULONG) c.Int { return 0 }
|
||||
|
||||
// int BN_is_word(const BIGNUM *a, const BN_ULONG w);
|
||||
//
|
||||
// llgo:link (*BIGNUM).IsWord C.BN_is_word
|
||||
func (*BIGNUM) IsWord(w BN_ULONG) c.Int { return 0 }
|
||||
|
||||
// int BN_set_word(BIGNUM *a, BN_ULONG w);
|
||||
//
|
||||
// llgo:link (*BIGNUM).SetWord C.BN_set_word
|
||||
func (*BIGNUM) SetWord(w BN_ULONG) c.Int { return 0 }
|
||||
|
||||
// BN_ULONG BN_get_word(const BIGNUM *a);
|
||||
//
|
||||
// llgo:link (*BIGNUM).GetWord C.BN_get_word
|
||||
func (*BIGNUM) GetWord() BN_ULONG { return 0 }
|
||||
|
||||
// BN_ULONG BN_mod_word(const BIGNUM *a, BN_ULONG w);
|
||||
//
|
||||
// llgo:link (*BIGNUM).ModWord C.BN_mod_word
|
||||
func (*BIGNUM) ModWord(w BN_ULONG) BN_ULONG { return 0 }
|
||||
|
||||
// BN_ULONG BN_div_word(BIGNUM *a, BN_ULONG w);
|
||||
//
|
||||
// llgo:link (*BIGNUM).DivWord C.BN_div_word
|
||||
func (*BIGNUM) DivWord(w BN_ULONG) BN_ULONG { return 0 }
|
||||
|
||||
// int BN_mul_word(BIGNUM *a, BN_ULONG w);
|
||||
//
|
||||
// llgo:link (*BIGNUM).MulWord C.BN_mul_word
|
||||
func (*BIGNUM) MulWord(w BN_ULONG) c.Int { return 0 }
|
||||
|
||||
// int BN_add_word(BIGNUM *a, BN_ULONG w);
|
||||
//
|
||||
// llgo:link (*BIGNUM).AddWord C.BN_add_word
|
||||
func (*BIGNUM) AddWord(w BN_ULONG) c.Int { return 0 }
|
||||
|
||||
// int BN_sub_word(BIGNUM *a, BN_ULONG w);
|
||||
//
|
||||
// llgo:link (*BIGNUM).SubWord C.BN_sub_word
|
||||
func (*BIGNUM) SubWord(w BN_ULONG) c.Int { return 0 }
|
||||
|
||||
// char *BN_bn2hex(const BIGNUM *a);
|
||||
//
|
||||
// llgo:link (*BIGNUM).Bn2hex C.BN_bn2hex
|
||||
func (*BIGNUM) Bn2hex() *c.Char { return nil }
|
||||
|
||||
// char *BN_bn2dec(const BIGNUM *a);
|
||||
//
|
||||
// llgo:link (*BIGNUM).Bn2dec C.BN_bn2dec
|
||||
func (*BIGNUM) Bn2dec() *c.Char { return nil }
|
||||
|
||||
// llgo:link (*BIGNUM).CStr C.BN_bn2dec
|
||||
func (*BIGNUM) CStr() *c.Char { return nil }
|
||||
|
||||
// int BN_hex2bn(BIGNUM **a, const char *str);
|
||||
//
|
||||
//go:linkname BNHex2bn C.BN_hex2bn
|
||||
func BNHex2bn(a **BIGNUM, str *c.Char) c.Int
|
||||
|
||||
// int BN_dec2bn(BIGNUM **a, const char *str);
|
||||
//
|
||||
//go:linkname BNDec2bn C.BN_dec2bn
|
||||
func BNDec2bn(a **BIGNUM, str *c.Char) c.Int
|
||||
|
||||
// int BN_asc2bn(BIGNUM **a, const char *str);
|
||||
//
|
||||
//go:linkname BNAsc2bn C.BN_asc2bn
|
||||
func BNAsc2bn(a **BIGNUM, str *c.Char) c.Int
|
||||
|
||||
// BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret);
|
||||
//
|
||||
//go:linkname BNBin2bn C.BN_bin2bn
|
||||
func BNBin2bn(s *byte, len c.Int, ret *BIGNUM) *BIGNUM
|
||||
|
||||
// BIGNUM *BN_signed_bin2bn(const unsigned char *s, int len, BIGNUM *ret);
|
||||
//
|
||||
//go:linkname BNSignedBin2bn C.BN_signed_bin2bn
|
||||
func BNSignedBin2bn(s *byte, len c.Int, ret *BIGNUM) *BIGNUM
|
||||
|
||||
// int BN_bn2bin(const BIGNUM *a, unsigned char *to);
|
||||
//
|
||||
// llgo:link (*BIGNUM).Bn2bin C.BN_bn2bin
|
||||
func (bn *BIGNUM) Bn2bin(to *byte) c.Int { return 0 }
|
||||
|
||||
// int BN_bn2binpad(const BIGNUM *a, unsigned char *to, int tolen);
|
||||
//
|
||||
// llgo:link (*BIGNUM).Bn2binpad C.BN_bn2binpad
|
||||
func (bn *BIGNUM) Bn2binpad(to *byte, tolen c.Int) c.Int { return 0 }
|
||||
|
||||
// int BN_signed_bn2bin(const BIGNUM *a, unsigned char *to, int tolen);
|
||||
//
|
||||
// llgo:link (*BIGNUM).SignedBn2bin C.BN_signed_bn2bin
|
||||
func (bn *BIGNUM) SignedBn2bin(to *byte, tolen c.Int) c.Int { return 0 }
|
||||
|
||||
// BIGNUM *BN_lebin2bn(const unsigned char *s, int len, BIGNUM *ret);
|
||||
//
|
||||
//go:linkname BNLebin2bn C.BN_lebin2bn
|
||||
func BNLebin2bn(s *byte, len c.Int, ret *BIGNUM) *BIGNUM
|
||||
|
||||
// BIGNUM *BN_signed_lebin2bn(const unsigned char *s, int len, BIGNUM *ret);
|
||||
//
|
||||
//go:linkname BNSignedLebin2bn C.BN_signed_lebin2bn
|
||||
func BNSignedLebin2bn(s *byte, len c.Int, ret *BIGNUM) *BIGNUM
|
||||
|
||||
// int BN_bn2lebinpad(const BIGNUM *a, unsigned char *to, int tolen);
|
||||
//
|
||||
// llgo:link (*BIGNUM).Bn2lebinpad C.BN_bn2lebinpad
|
||||
func (bn *BIGNUM) Bn2lebinpad(to *byte, tolen c.Int) c.Int { return 0 }
|
||||
|
||||
// int BN_signed_bn2lebin(const BIGNUM *a, unsigned char *to, int tolen);
|
||||
//
|
||||
// llgo:link (*BIGNUM).SignedBn2lebin C.BN_signed_bn2lebin
|
||||
func (bn *BIGNUM) SignedBn2lebin(to *byte, tolen c.Int) c.Int { return 0 }
|
||||
|
||||
// BIGNUM *BN_native2bn(const unsigned char *s, int len, BIGNUM *ret);
|
||||
//
|
||||
//go:linkname BNNative2bn C.BN_native2bn
|
||||
func BNNative2bn(s *byte, len c.Int, ret *BIGNUM) *BIGNUM
|
||||
|
||||
// BIGNUM *BN_signed_native2bn(const unsigned char *s, int len, BIGNUM *ret);
|
||||
//
|
||||
//go:linkname BNSignedNative2bn C.BN_signed_native2bn
|
||||
func BNSignedNative2bn(s *byte, len c.Int, ret *BIGNUM) *BIGNUM
|
||||
|
||||
// int BN_bn2nativepad(const BIGNUM *a, unsigned char *to, int tolen);
|
||||
//
|
||||
// llgo:link (*BIGNUM).Bn2nativepad C.BN_bn2nativepad
|
||||
func (bn *BIGNUM) Bn2nativepad(to *byte, tolen c.Int) c.Int { return 0 }
|
||||
|
||||
// int BN_signed_bn2native(const BIGNUM *a, unsigned char *to, int tolen);
|
||||
//
|
||||
// llgo:link (*BIGNUM).SignedBn2native C.BN_signed_bn2native
|
||||
func (bn *BIGNUM) SignedBn2native(to *byte, tolen c.Int) c.Int { return 0 }
|
||||
|
||||
// BIGNUM *BN_mpi2bn(const unsigned char *s, int len, BIGNUM *ret);
|
||||
//
|
||||
//go:linkname BNMpi2bn C.BN_mpi2bn
|
||||
func BNMpi2bn(s *byte, len c.Int, ret *BIGNUM) *BIGNUM
|
||||
|
||||
// int BN_bn2mpi(const BIGNUM *a, unsigned char *to);
|
||||
//
|
||||
// llgo:link (*BIGNUM).Bn2mpi C.BN_bn2mpi
|
||||
func (bn *BIGNUM) Bn2mpi(to *byte) c.Int { return 0 }
|
||||
|
||||
// int BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
|
||||
//
|
||||
// llgo:link (*BIGNUM).Sub C.BN_sub
|
||||
func (*BIGNUM) Sub(a, b *BIGNUM) c.Int { return 0 }
|
||||
|
||||
// int BN_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
|
||||
//
|
||||
// llgo:link (*BIGNUM).Add C.BN_add
|
||||
func (*BIGNUM) Add(a, b *BIGNUM) c.Int { return 0 }
|
||||
|
||||
// int BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
|
||||
//
|
||||
// llgo:link (*BIGNUM).Usub C.BN_usub
|
||||
func (*BIGNUM) Usub(a, b *BIGNUM) c.Int { return 0 }
|
||||
|
||||
// int BN_uadd(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
|
||||
//
|
||||
// llgo:link (*BIGNUM).Uadd C.BN_uadd
|
||||
func (*BIGNUM) Uadd(a, b *BIGNUM) c.Int { return 0 }
|
||||
|
||||
// int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);
|
||||
//
|
||||
// llgo:link (*BIGNUM).Mul C.BN_mul
|
||||
func (*BIGNUM) Mul(r, a, b *BIGNUM, ctx *BN_CTX) c.Int { return 0 }
|
||||
|
||||
// int BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx);
|
||||
//
|
||||
// llgo:link (*BIGNUM).Sqr C.BN_sqr
|
||||
func (*BIGNUM) Sqr(r, a *BIGNUM, ctx *BN_CTX) c.Int { return 0 }
|
||||
|
||||
/** BN_set_negative sets sign of a BIGNUM
|
||||
* \param b pointer to the BIGNUM object
|
||||
* \param n 0 if the BIGNUM b should be positive and a value != 0 otherwise
|
||||
*/
|
||||
// void BN_set_negative(BIGNUM *b, int n);
|
||||
//
|
||||
// llgo:link (*BIGNUM).SetNegative C.BN_set_negative
|
||||
func (*BIGNUM) SetNegative(n c.Int) {}
|
||||
|
||||
/** BN_is_negative returns 1 if the BIGNUM is negative
|
||||
* \param b pointer to the BIGNUM object
|
||||
* \return 1 if a < 0 and 0 otherwise
|
||||
*/
|
||||
// int BN_is_negative(const BIGNUM *b);
|
||||
//
|
||||
// llgo:link (*BIGNUM).IsNegative C.BN_is_negative
|
||||
func (*BIGNUM) IsNegative() c.Int { return 0 }
|
||||
|
||||
// int BN_div(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx);
|
||||
//
|
||||
// llgo:link (*BIGNUM).Div C.BN_div
|
||||
func (*BIGNUM) Div(rem, m, d *BIGNUM, ctx *BN_CTX) c.Int { return 0 }
|
||||
|
||||
// int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx);
|
||||
//
|
||||
// llgo:link (*BIGNUM).Nnmod C.BN_nnmod
|
||||
func (*BIGNUM) Nnmod(r, m, d *BIGNUM, ctx *BN_CTX) c.Int { return 0 }
|
||||
|
||||
// int BN_cmp(const BIGNUM *a, const BIGNUM *b);
|
||||
//
|
||||
// llgo:link (*BIGNUM).Cmp C.BN_cmp
|
||||
func (*BIGNUM) Cmp(b *BIGNUM) c.Int { return 0 }
|
||||
|
||||
// int BN_ucmp(const BIGNUM *a, const BIGNUM *b);
|
||||
//
|
||||
// llgo:link (*BIGNUM).Ucmp C.BN_ucmp
|
||||
func (*BIGNUM) Ucmp(b *BIGNUM) c.Int { return 0 }
|
||||
|
||||
// int BN_is_bit_set(const BIGNUM *a, int n);
|
||||
//
|
||||
// llgo:link (*BIGNUM).IsBitSet C.BN_is_bit_set
|
||||
func (*BIGNUM) IsBitSet(n c.Int) c.Int { return 0 }
|
||||
|
||||
// int BN_set_bit(BIGNUM *a, int n);
|
||||
//
|
||||
// llgo:link (*BIGNUM).SetBit C.BN_set_bit
|
||||
func (*BIGNUM) SetBit(n c.Int) c.Int { return 0 }
|
||||
|
||||
// int BN_clear_bit(BIGNUM *a, int n);
|
||||
//
|
||||
// llgo:link (*BIGNUM).ClearBit C.BN_clear_bit
|
||||
func (*BIGNUM) ClearBit(n c.Int) c.Int { return 0 }
|
||||
|
||||
// int BN_lshift(BIGNUM *r, const BIGNUM *a, int n);
|
||||
//
|
||||
// llgo:link (*BIGNUM).Lshift C.BN_lshift
|
||||
func (*BIGNUM) Lshift(a *BIGNUM, n c.Int) c.Int { return 0 }
|
||||
|
||||
// int BN_lshift1(BIGNUM *r, const BIGNUM *a);
|
||||
//
|
||||
// llgo:link (*BIGNUM).Lshift1 C.BN_lshift1
|
||||
func (*BIGNUM) Lshift1(a *BIGNUM) c.Int { return 0 }
|
||||
|
||||
// int BN_rshift(BIGNUM *r, const BIGNUM *a, int n);
|
||||
//
|
||||
// llgo:link (*BIGNUM).Rshift C.BN_rshift
|
||||
func (*BIGNUM) Rshift(a *BIGNUM, n c.Int) c.Int { return 0 }
|
||||
|
||||
// int BN_rshift1(BIGNUM *r, const BIGNUM *a);
|
||||
//
|
||||
// llgo:link (*BIGNUM).Rshift1 C.BN_rshift1
|
||||
func (*BIGNUM) Rshift1(a *BIGNUM) c.Int { return 0 }
|
||||
|
||||
// int BN_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx);
|
||||
//
|
||||
// llgo:link (*BIGNUM).Exp C.BN_exp
|
||||
func (*BIGNUM) Exp(a, p *BIGNUM, ctx *BN_CTX) c.Int { return 0 }
|
||||
|
||||
// int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx);
|
||||
//
|
||||
// llgo:link (*BIGNUM).ModExp C.BN_mod_exp
|
||||
func (*BIGNUM) ModExp(a, p, m *BIGNUM, ctx *BN_CTX) c.Int { return 0 }
|
||||
|
||||
// int BN_gcd(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);
|
||||
//
|
||||
// llgo:link (*BIGNUM).Gcd C.BN_gcd
|
||||
func (*BIGNUM) Gcd(a, b *BIGNUM, ctx *BN_CTX) c.Int { return 0 }
|
||||
|
||||
// int BN_are_coprime(const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);
|
||||
//
|
||||
// llgo:link (*BIGNUM).AreCoprime C.BN_are_coprime
|
||||
func (*BIGNUM) AreCoprime(b *BIGNUM, ctx *BN_CTX) c.Int { return 0 }
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
type BN_GENCB struct {
|
||||
Unused [0]byte
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
156
runtime/internal/clite/openssl/err.go
Normal file
156
runtime/internal/clite/openssl/err.go
Normal file
@@ -0,0 +1,156 @@
|
||||
/*
|
||||
* 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 openssl
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
c "github.com/goplus/llgo/runtime/internal/clite"
|
||||
)
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
/*-
|
||||
* The error code packs differently depending on if it records a system
|
||||
* error or an OpenSSL error.
|
||||
*
|
||||
* A system error packs like this (we follow POSIX and only allow positive
|
||||
* numbers that fit in an |int|):
|
||||
*
|
||||
* +-+-------------------------------------------------------------+
|
||||
* |1| system error number |
|
||||
* +-+-------------------------------------------------------------+
|
||||
*
|
||||
* An OpenSSL error packs like this:
|
||||
*
|
||||
* <---------------------------- 32 bits -------------------------->
|
||||
* <--- 8 bits ---><------------------ 23 bits ----------------->
|
||||
* +-+---------------+---------------------------------------------+
|
||||
* |0| library | reason |
|
||||
* +-+---------------+---------------------------------------------+
|
||||
*
|
||||
* A few of the reason bits are reserved as flags with special meaning:
|
||||
*
|
||||
* <5 bits-<>--------- 19 bits ----------------->
|
||||
* +-------+-+-----------------------------------+
|
||||
* | rflags| | reason |
|
||||
* +-------+-+-----------------------------------+
|
||||
* ^
|
||||
* |
|
||||
* ERR_RFLAG_FATAL = ERR_R_FATAL
|
||||
*
|
||||
* The reason flags are part of the overall reason code for practical
|
||||
* reasons, as they provide an easy way to place different types of
|
||||
* reason codes in different numeric ranges.
|
||||
*
|
||||
* The currently known reason flags are:
|
||||
*
|
||||
* ERR_RFLAG_FATAL Flags that the reason code is considered fatal.
|
||||
* For backward compatibility reasons, this flag
|
||||
* is also the code for ERR_R_FATAL (that reason
|
||||
* code served the dual purpose of flag and reason
|
||||
* code in one in pre-3.0 OpenSSL).
|
||||
* ERR_RFLAG_COMMON Flags that the reason code is common to all
|
||||
* libraries. All ERR_R_ macros must use this flag,
|
||||
* and no other _R_ macro is allowed to use it.
|
||||
*/
|
||||
type Errno c.Ulong
|
||||
|
||||
// ERR_get_error returns the earliest error code from the thread's error queue and
|
||||
// removes the entry. This function can be called repeatedly until there are no more
|
||||
// error codes to return.
|
||||
//
|
||||
// unsigned long ERR_get_error(void);
|
||||
//
|
||||
//go:linkname ERRGetError C.ERR_get_error
|
||||
func ERRGetError() Errno
|
||||
|
||||
// ERR_get_error_all() is the same as ERR_get_error(), but on success it additionally
|
||||
// stores the filename, line number and function where the error occurred in *file,
|
||||
// *line and *func, and also extra text and flags in *data, *flags. If any of those
|
||||
// parameters are NULL, it will not be changed.
|
||||
//
|
||||
// unsigned long ERR_get_error_all(
|
||||
// const char **file, int *line, const char **func, const char **data, int *flags);
|
||||
//
|
||||
//go:linkname ERRGetErrorAll C.ERR_get_error_all
|
||||
func ERRGetErrorAll(
|
||||
file **c.Char, line *c.Int, function **c.Char, data **c.Char, flags *c.Int) Errno
|
||||
|
||||
// unsigned long ERR_peek_error(void);
|
||||
//
|
||||
//go:linkname ERRPeekError C.ERR_peek_error
|
||||
func ERRPeekError() Errno
|
||||
|
||||
// unsigned long ERR_peek_error_all(
|
||||
// const char **file, int *line, const char **func, const char **data, int *flags);
|
||||
//
|
||||
//go:linkname ERRPeekErrorAll C.ERR_peek_error_all
|
||||
func ERRPeekErrorAll(
|
||||
file **c.Char, line *c.Int, function **c.Char, data **c.Char, flags *c.Int) Errno
|
||||
|
||||
// unsigned long ERR_peek_last_error(void);
|
||||
//
|
||||
//go:linkname ERRPeekLastError C.ERR_peek_last_error
|
||||
func ERRPeekLastError() Errno
|
||||
|
||||
// unsigned long ERR_peek_last_error_all(
|
||||
// const char **file, int *line, const char **func, const char **data, int *flags);
|
||||
//
|
||||
//go:linkname ERRPeekLastErrorAll C.ERR_peek_last_error_all
|
||||
func ERRPeekLastErrorAll(
|
||||
file **c.Char, line *c.Int, function **c.Char, data **c.Char, flags *c.Int) Errno
|
||||
|
||||
// void ERR_clear_error(void);
|
||||
//
|
||||
//go:linkname ERRClearError C.ERR_clear_error
|
||||
func ERRClearError()
|
||||
|
||||
// ERR_error_string() generates a human-readable string representing the error code e,
|
||||
// and places it at buf. buf must be at least 256 bytes long.
|
||||
//
|
||||
// char *ERR_error_string(unsigned long e, char *buf);
|
||||
//
|
||||
//go:linkname ERRErrorString C.ERR_error_string
|
||||
func ERRErrorString(e Errno, buf *c.Char) *c.Char
|
||||
|
||||
// ERR_lib_error_string() and ERR_reason_error_string() return the library name and
|
||||
// reason string respectively.
|
||||
//
|
||||
// const char *ERR_lib_error_string(unsigned long e);
|
||||
//
|
||||
//go:linkname ERRLibErrorString C.ERR_lib_error_string
|
||||
func ERRLibErrorString(e Errno) *c.Char
|
||||
|
||||
// const char *ERR_reason_error_string(unsigned long e);
|
||||
//
|
||||
//go:linkname ERRReasonErrorString C.ERR_reason_error_string
|
||||
func ERRReasonErrorString(e Errno) *c.Char
|
||||
|
||||
// void ERR_print_errors_cb(int (*cb) (const char *str, size_t len, void *u), void *u);
|
||||
//
|
||||
// [pid]:error:[error code]:[library name]:[function name]:[reason string]:[filename]:[line]:[optional text message]
|
||||
//
|
||||
//go:linkname ERRPrintErrorsCb C.ERR_print_errors_cb
|
||||
func ERRPrintErrorsCb(cb func(str *c.Char, len uintptr, u unsafe.Pointer) c.Int, u unsafe.Pointer)
|
||||
|
||||
// void ERR_print_errors_fp(FILE *fp);
|
||||
//
|
||||
//go:linkname ERRPrintErrorsFp C.ERR_print_errors_fp
|
||||
func ERRPrintErrorsFp(fp c.FilePtr)
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
133
runtime/internal/clite/openssl/hmac.go
Normal file
133
runtime/internal/clite/openssl/hmac.go
Normal file
@@ -0,0 +1,133 @@
|
||||
package openssl
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
c "github.com/goplus/llgo/runtime/internal/clite"
|
||||
)
|
||||
|
||||
const (
|
||||
EVP_MAX_MD_SIZE = 64 /* longest known is SHA512 */
|
||||
)
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
type EVP_MD struct {
|
||||
Unused [0]byte
|
||||
}
|
||||
|
||||
// const EVP_MD *EVP_sha1(void)
|
||||
//
|
||||
//go:linkname EVP_sha1 C.EVP_sha1
|
||||
func EVP_sha1() *EVP_MD
|
||||
|
||||
// const EVP_MD *EVP_sha224(void)
|
||||
//
|
||||
//go:linkname EVP_sha224 C.EVP_sha224
|
||||
func EVP_sha224() *EVP_MD
|
||||
|
||||
// func EVP_sha256() *EVP_MD
|
||||
//
|
||||
//go:linkname EVP_sha256 C.EVP_sha256
|
||||
func EVP_sha256() *EVP_MD
|
||||
|
||||
// const EVP_MD *EVP_sha512_224(void)
|
||||
//
|
||||
//go:linkname EVP_sha512_224 C.EVP_sha512_224
|
||||
func EVP_sha512_224() *EVP_MD
|
||||
|
||||
// const EVP_MD *EVP_sha512_256(void)
|
||||
//
|
||||
//go:linkname EVP_sha512_256 C.EVP_sha512_256
|
||||
func EVP_sha512_256() *EVP_MD
|
||||
|
||||
// const EVP_MD *EVP_sha384(void)
|
||||
//
|
||||
//go:linkname EVP_sha384 C.EVP_sha384
|
||||
func EVP_sha384() *EVP_MD
|
||||
|
||||
// const EVP_MD *EVP_sha512(void)
|
||||
//
|
||||
//go:linkname EVP_sha512 C.EVP_sha512
|
||||
func EVP_sha512() *EVP_MD
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
type HMAC_CTX struct {
|
||||
Unused [0]byte
|
||||
}
|
||||
|
||||
// OSSL_DEPRECATEDIN_3_0 HMAC_CTX *HMAC_CTX_new(void);
|
||||
//
|
||||
//go:linkname NewHMAC_CTX C.HMAC_CTX_new
|
||||
func NewHMAC_CTX() *HMAC_CTX
|
||||
|
||||
// OSSL_DEPRECATEDIN_3_0 void HMAC_CTX_free(HMAC_CTX *ctx);
|
||||
//
|
||||
// llgo:link (*HMAC_CTX).Free C.HMAC_CTX_free
|
||||
func (ctx *HMAC_CTX) Free() {}
|
||||
|
||||
// OSSL_DEPRECATEDIN_3_0 size_t HMAC_size(const HMAC_CTX *e);
|
||||
//
|
||||
// llgo:link (*HMAC_CTX).Size C.HMAC_size
|
||||
func (ctx *HMAC_CTX) Size() uintptr { return 0 }
|
||||
|
||||
// OSSL_DEPRECATEDIN_3_0 int HMAC_CTX_reset(HMAC_CTX *ctx);
|
||||
//
|
||||
// llgo:link (*HMAC_CTX).Reset C.HMAC_CTX_reset
|
||||
func (ctx *HMAC_CTX) Reset() c.Int { return 0 }
|
||||
|
||||
// OSSL_DEPRECATEDIN_1_1_0 __owur int HMAC_Init(HMAC_CTX *ctx,
|
||||
// const void *key, int len,
|
||||
// const EVP_MD *md);
|
||||
//
|
||||
// llgo:link (*HMAC_CTX).Init C.HMAC_Init
|
||||
func (ctx *HMAC_CTX) Init(key unsafe.Pointer, len c.Int, md *EVP_MD) c.Int { return 0 }
|
||||
|
||||
func (ctx *HMAC_CTX) InitBytes(key []byte, md *EVP_MD) c.Int {
|
||||
return ctx.Init(unsafe.Pointer(unsafe.SliceData(key)), c.Int(len(key)), md)
|
||||
}
|
||||
|
||||
func (ctx *HMAC_CTX) InitString(key string, md *EVP_MD) c.Int {
|
||||
return ctx.Init(unsafe.Pointer(unsafe.StringData(key)), c.Int(len(key)), md)
|
||||
}
|
||||
|
||||
// OSSL_DEPRECATEDIN_3_0 int HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int len,
|
||||
// const EVP_MD *md, ENGINE *impl);
|
||||
//
|
||||
// llgo:link (*HMAC_CTX).InitEx C.HMAC_Init_ex
|
||||
func (ctx *HMAC_CTX) InitEx(key unsafe.Pointer, len c.Int, md *EVP_MD, impl unsafe.Pointer) c.Int {
|
||||
return 0
|
||||
}
|
||||
|
||||
// OSSL_DEPRECATEDIN_3_0 int HMAC_Update(HMAC_CTX *ctx, const unsigned char *data,
|
||||
// size_t len);
|
||||
//
|
||||
// llgo:link (*HMAC_CTX).Update C.HMAC_Update
|
||||
func (ctx *HMAC_CTX) Update(data unsafe.Pointer, len uintptr) c.Int { return 0 }
|
||||
|
||||
func (ctx *HMAC_CTX) UpdateBytes(data []byte) c.Int {
|
||||
return ctx.Update(unsafe.Pointer(unsafe.SliceData(data)), uintptr(len(data)))
|
||||
}
|
||||
|
||||
func (ctx *HMAC_CTX) UpdateString(data string) c.Int {
|
||||
return ctx.Update(unsafe.Pointer(unsafe.StringData(data)), uintptr(len(data)))
|
||||
}
|
||||
|
||||
// OSSL_DEPRECATEDIN_3_0 int HMAC_Final(HMAC_CTX *ctx, unsigned char *md,
|
||||
// unsigned int *len);
|
||||
//
|
||||
// llgo:link (*HMAC_CTX).Final C.HMAC_Final
|
||||
func (ctx *HMAC_CTX) Final(md *byte, len *c.Uint) c.Int { return 0 }
|
||||
|
||||
// OSSL_DEPRECATEDIN_3_0 __owur int HMAC_CTX_copy(HMAC_CTX *dctx, HMAC_CTX *sctx);
|
||||
//
|
||||
// llgo:link (*HMAC_CTX).Copy C.HMAC_CTX_copy
|
||||
func (ctx *HMAC_CTX) Copy(sctx *HMAC_CTX) c.Int { return 0 }
|
||||
|
||||
// OSSL_DEPRECATEDIN_3_0 void HMAC_CTX_set_flags(HMAC_CTX *ctx, unsigned long flags);
|
||||
//
|
||||
// llgo:link (*HMAC_CTX).SetFlags C.HMAC_CTX_set_flags
|
||||
func (ctx *HMAC_CTX) SetFlags(flags c.Ulong) {}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
85
runtime/internal/clite/openssl/md5.go
Normal file
85
runtime/internal/clite/openssl/md5.go
Normal file
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* 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 openssl
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
c "github.com/goplus/llgo/runtime/internal/clite"
|
||||
)
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
const (
|
||||
MD5_CBLOCK = 64
|
||||
MD5_LBLOCK = MD5_CBLOCK / 4
|
||||
)
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
type MD5_LONG = c.Uint
|
||||
|
||||
type MD5_CTX struct {
|
||||
A, B, C, D MD5_LONG
|
||||
Nl, Nh MD5_LONG
|
||||
Data [MD5_LBLOCK]MD5_LONG
|
||||
Num c.Uint
|
||||
}
|
||||
|
||||
// OSSL_DEPRECATEDIN_3_0 int MD5_Init(MD5_CTX *c);
|
||||
//
|
||||
// llgo:link (*MD5_CTX).Init C.MD5_Init
|
||||
func (c *MD5_CTX) Init() c.Int { return 0 }
|
||||
|
||||
// OSSL_DEPRECATEDIN_3_0 int MD5_Update(MD5_CTX *c, const void *data, size_t len);
|
||||
//
|
||||
// llgo:link (*MD5_CTX).Update C.MD5_Update
|
||||
func (c *MD5_CTX) Update(data unsafe.Pointer, n uintptr) c.Int { return 0 }
|
||||
|
||||
func (c *MD5_CTX) UpdateBytes(data []byte) c.Int {
|
||||
return c.Update(unsafe.Pointer(unsafe.SliceData(data)), uintptr(len(data)))
|
||||
}
|
||||
|
||||
func (c *MD5_CTX) UpdateString(data string) c.Int {
|
||||
return c.Update(unsafe.Pointer(unsafe.StringData(data)), uintptr(len(data)))
|
||||
}
|
||||
|
||||
// OSSL_DEPRECATEDIN_3_0 int MD5_Final(unsigned char *md, MD5_CTX *c);
|
||||
//
|
||||
//go:linkname md5Final C.MD5_Final
|
||||
func md5Final(md *byte, c *MD5_CTX) c.Int
|
||||
|
||||
func (c *MD5_CTX) Final(md *byte) c.Int {
|
||||
return md5Final(md, c)
|
||||
}
|
||||
|
||||
// OSSL_DEPRECATEDIN_3_0 unsigned char *MD5(const unsigned char *d, size_t n, unsigned char *md);
|
||||
//
|
||||
//go:linkname MD5 C.MD5
|
||||
func MD5(data unsafe.Pointer, n uintptr, md *byte) *byte
|
||||
|
||||
func MD5Bytes(data []byte, md *byte) *byte {
|
||||
return MD5(unsafe.Pointer(unsafe.SliceData(data)), uintptr(len(data)), md)
|
||||
}
|
||||
|
||||
func MD5String(data string, md *byte) *byte {
|
||||
return MD5(unsafe.Pointer(unsafe.StringData(data)), uintptr(len(data)), md)
|
||||
}
|
||||
|
||||
// OSSL_DEPRECATEDIN_3_0 void MD5_Transform(MD5_CTX *c, const unsigned char *b);
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
38
runtime/internal/clite/openssl/openssl.go
Normal file
38
runtime/internal/clite/openssl/openssl.go
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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 openssl
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
c "github.com/goplus/llgo/runtime/internal/clite"
|
||||
)
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
const (
|
||||
LLGoFiles = "$(pkg-config --cflags openssl): _wrap/openssl.c"
|
||||
LLGoPackage = "link: $(pkg-config --libs openssl); -lssl -lcrypto"
|
||||
)
|
||||
|
||||
//go:linkname Free C.opensslFree
|
||||
func Free(ptr unsafe.Pointer)
|
||||
|
||||
//go:linkname FreeCStr C.opensslFree
|
||||
func FreeCStr(ptr *c.Char)
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
37
runtime/internal/clite/openssl/pem.go
Normal file
37
runtime/internal/clite/openssl/pem.go
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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 openssl
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
c "github.com/goplus/llgo/runtime/internal/clite"
|
||||
)
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// typedef int (*pem_password_cb)(char *buf, int size, int rwflag, void *userdata);
|
||||
//
|
||||
// llgo:type C
|
||||
type PemPasswordCb func(buf *c.Char, size, rwflag c.Int, userdata unsafe.Pointer) c.Int
|
||||
|
||||
// RSA *PEM_read_bio_RSAPrivateKey(BIO *bp, RSA **x, pem_password_cb *cb, void *u);
|
||||
//
|
||||
//go:linkname PEMReadBioRSAPrivateKey C.PEM_read_bio_RSAPrivateKey
|
||||
func PEMReadBioRSAPrivateKey(bp *BIO, x **RSA, cb PemPasswordCb, u unsafe.Pointer) *RSA
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
80
runtime/internal/clite/openssl/rand.go
Normal file
80
runtime/internal/clite/openssl/rand.go
Normal file
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* 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 openssl
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
c "github.com/goplus/llgo/runtime/internal/clite"
|
||||
)
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// int RAND_bytes(unsigned char *buf, int num);
|
||||
//
|
||||
//go:linkname RANDBufferWithLen C.RAND_bytes
|
||||
func RANDBufferWithLen(buf *byte, num c.Int) c.Int
|
||||
|
||||
func RANDBytes(buf []byte) c.Int {
|
||||
return RANDBufferWithLen(unsafe.SliceData(buf), c.Int(len(buf)))
|
||||
}
|
||||
|
||||
// int RAND_priv_bytes(unsigned char *buf, int num);
|
||||
//
|
||||
//go:linkname RANDPrivBufferWithLen C.RAND_priv_bytes
|
||||
func RANDPrivBufferWithLen(buf *byte, num c.Int) c.Int
|
||||
|
||||
func RANDPrivBytes(buf []byte) c.Int {
|
||||
return RANDPrivBufferWithLen(unsafe.SliceData(buf), c.Int(len(buf)))
|
||||
}
|
||||
|
||||
// void RAND_seed(const void *buf, int num);
|
||||
//
|
||||
//go:linkname RANDSeed C.RAND_seed
|
||||
func RANDSeed(buf unsafe.Pointer, num c.Int)
|
||||
|
||||
// void RAND_keep_random_devices_open(int keep);
|
||||
//
|
||||
//go:linkname RANDKeepRandomDevicesOpen C.RAND_keep_random_devices_open
|
||||
func RANDKeepRandomDevicesOpen(keep c.Int)
|
||||
|
||||
// int RAND_load_file(const char *file, long max_bytes);
|
||||
//
|
||||
//go:linkname RANDLoadFile C.RAND_load_file
|
||||
func RANDLoadFile(file *c.Char, maxBytes c.Long) c.Int
|
||||
|
||||
// int RAND_write_file(const char *file);
|
||||
//
|
||||
//go:linkname RANDWriteFile C.RAND_write_file
|
||||
func RANDWriteFile(file *c.Char) c.Int
|
||||
|
||||
// const char *RAND_file_name(char *file, size_t num);
|
||||
//
|
||||
//go:linkname RANDFileName C.RAND_file_name
|
||||
func RANDFileName(file *c.Char, num uintptr) *c.Char
|
||||
|
||||
// int RAND_status(void);
|
||||
//
|
||||
//go:linkname RANDStatus C.RAND_status
|
||||
func RANDStatus() c.Int
|
||||
|
||||
// int RAND_poll(void);
|
||||
//
|
||||
//go:linkname RANDPoll C.RAND_poll
|
||||
func RANDPoll() c.Int
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
305
runtime/internal/clite/openssl/rsa.go
Normal file
305
runtime/internal/clite/openssl/rsa.go
Normal file
@@ -0,0 +1,305 @@
|
||||
/*
|
||||
* 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 openssl
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
c "github.com/goplus/llgo/runtime/internal/clite"
|
||||
)
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
type RSA_METHOD struct {
|
||||
Unused [0]byte
|
||||
}
|
||||
|
||||
// OSSL_DEPRECATEDIN_3_0 RSA_METHOD *RSA_meth_new(const char *name, int flags);
|
||||
//
|
||||
//go:linkname RSAMethNew C.RSA_meth_new
|
||||
func RSAMethNew(name *byte, flags c.Int) *RSA_METHOD
|
||||
|
||||
// OSSL_DEPRECATEDIN_3_0 void RSA_meth_free(RSA_METHOD *meth);
|
||||
//
|
||||
// llgo:link (*RSA_METHOD).Free C.RSA_meth_free
|
||||
func (*RSA_METHOD) Free() {}
|
||||
|
||||
// OSSL_DEPRECATEDIN_3_0
|
||||
// int RSA_meth_set_init(RSA_METHOD *rsa, int (*init) (RSA *rsa));
|
||||
//
|
||||
// llgo:link (*RSA_METHOD).SetInit C.RSA_meth_set_init
|
||||
func (*RSA_METHOD) SetInit(init func(rsa *RSA) c.Int) c.Int { return 0 }
|
||||
|
||||
// OSSL_DEPRECATEDIN_3_0
|
||||
// int RSA_meth_set_finish(RSA_METHOD *rsa, int (*finish) (RSA *rsa));
|
||||
//
|
||||
// llgo:link (*RSA_METHOD).SetFinish C.RSA_meth_set_finish
|
||||
func (*RSA_METHOD) SetFinish(finish func(rsa *RSA) c.Int) c.Int { return 0 }
|
||||
|
||||
/*
|
||||
OSSL_DEPRECATEDIN_3_0
|
||||
int RSA_meth_set_mod_exp(RSA_METHOD *rsa,
|
||||
int (*mod_exp) (BIGNUM *r0, const BIGNUM *i, RSA *rsa,
|
||||
BN_CTX *ctx));
|
||||
*/
|
||||
// llgo:link (*RSA_METHOD).SetModExp C.RSA_meth_set_mod_exp
|
||||
func (*RSA_METHOD) SetModExp(modExp func(
|
||||
r0 *BIGNUM, i *BIGNUM, rsa *RSA, ctx *BN_CTX) c.Int) c.Int {
|
||||
return 0
|
||||
}
|
||||
|
||||
/*
|
||||
OSSL_DEPRECATEDIN_3_0
|
||||
int RSA_meth_set_bn_mod_exp(RSA_METHOD *rsa,
|
||||
int (*bn_mod_exp) (BIGNUM *r,
|
||||
const BIGNUM *a,
|
||||
const BIGNUM *p,
|
||||
const BIGNUM *m,
|
||||
BN_CTX *ctx,
|
||||
BN_MONT_CTX *m_ctx));
|
||||
//-llgo:link (*RSA_METHOD).SetBnModExp C.RSA_meth_set_bn_mod_exp
|
||||
func (*RSA_METHOD) SetBnModExp(bnModExp func(
|
||||
r *BIGNUM, a *BIGNUM, p *BIGNUM, m *BIGNUM, ctx *BN_CTX, mCtx *BN_MONT_CTX) c.Int) c.Int {
|
||||
return 0
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
OSSL_DEPRECATEDIN_3_0
|
||||
int RSA_meth_set_pub_enc(RSA_METHOD *rsa,
|
||||
int (*pub_enc) (int flen, const unsigned char *from,
|
||||
unsigned char *to, RSA *rsa,
|
||||
int padding));
|
||||
*/
|
||||
// llgo:link (*RSA_METHOD).SetPubEnc C.RSA_meth_set_pub_enc
|
||||
func (*RSA_METHOD) SetPubEnc(pubEnc func(
|
||||
flen c.Int, from *byte, to *byte, rsa *RSA, padding c.Int) c.Int) c.Int {
|
||||
return 0
|
||||
}
|
||||
|
||||
/*
|
||||
OSSL_DEPRECATEDIN_3_0
|
||||
int RSA_meth_set_pub_dec(RSA_METHOD *rsa,
|
||||
int (*pub_dec) (int flen, const unsigned char *from,
|
||||
unsigned char *to, RSA *rsa,
|
||||
int padding));
|
||||
*/
|
||||
// llgo:link (*RSA_METHOD).SetPubDec C.RSA_meth_set_pub_dec
|
||||
func (*RSA_METHOD) SetPubDec(pubDec func(
|
||||
flen c.Int, from *byte, to *byte, rsa *RSA, padding c.Int) c.Int) c.Int {
|
||||
return 0
|
||||
}
|
||||
|
||||
/*
|
||||
OSSL_DEPRECATEDIN_3_0
|
||||
int RSA_meth_set_priv_enc(RSA_METHOD *rsa,
|
||||
int (*priv_enc) (int flen, const unsigned char *from,
|
||||
unsigned char *to, RSA *rsa,
|
||||
int padding));
|
||||
*/
|
||||
// llgo:link (*RSA_METHOD).SetPrivEnc C.RSA_meth_set_priv_enc
|
||||
func (*RSA_METHOD) SetPrivEnc(privEnc func(
|
||||
flen c.Int, from *byte, to *byte, rsa *RSA, padding c.Int) c.Int) c.Int {
|
||||
return 0
|
||||
}
|
||||
|
||||
/*
|
||||
OSSL_DEPRECATEDIN_3_0
|
||||
int RSA_meth_set_priv_dec(RSA_METHOD *rsa,
|
||||
int (*priv_dec) (int flen, const unsigned char *from,
|
||||
unsigned char *to, RSA *rsa,
|
||||
int padding));
|
||||
*/
|
||||
// llgo:link (*RSA_METHOD).SetPrivDec C.RSA_meth_set_priv_dec
|
||||
func (*RSA_METHOD) SetPrivDec(privDec func(
|
||||
flen c.Int, from *byte, to *byte, rsa *RSA, padding c.Int) c.Int) c.Int {
|
||||
return 0
|
||||
}
|
||||
|
||||
/*
|
||||
OSSL_DEPRECATEDIN_3_0
|
||||
int RSA_meth_set_sign(RSA_METHOD *rsa,
|
||||
int (*sign) (int type, const unsigned char *m,
|
||||
unsigned int m_length,
|
||||
unsigned char *sigret, unsigned int *siglen,
|
||||
const RSA *rsa));
|
||||
*/
|
||||
// llgo:link (*RSA_METHOD).SetSign C.RSA_meth_set_sign
|
||||
func (*RSA_METHOD) SetSign(sign func(
|
||||
typ c.Int, msg *byte, mlen c.Uint,
|
||||
sigret *byte, siglen *c.Uint, rsa *RSA) c.Int) c.Int {
|
||||
return 0
|
||||
}
|
||||
|
||||
/*
|
||||
OSSL_DEPRECATEDIN_3_0
|
||||
int RSA_meth_set_verify(RSA_METHOD *rsa,
|
||||
int (*verify) (int dtype, const unsigned char *m,
|
||||
unsigned int m_length,
|
||||
const unsigned char *sigbuf,
|
||||
unsigned int siglen, const RSA *rsa));
|
||||
*/
|
||||
// llgo:link (*RSA_METHOD).SetVerify C.RSA_meth_set_verify
|
||||
func (*RSA_METHOD) SetVerify(verify func(
|
||||
dtype c.Int, msg *byte, mlen c.Uint,
|
||||
sigbuf *byte, siglen c.Uint, rsa *RSA) c.Int) c.Int {
|
||||
return 0
|
||||
}
|
||||
|
||||
/*
|
||||
OSSL_DEPRECATEDIN_3_0
|
||||
int RSA_meth_set_keygen(RSA_METHOD *rsa,
|
||||
int (*keygen) (RSA *rsa, int bits, BIGNUM *e,
|
||||
BN_GENCB *cb));
|
||||
|
||||
OSSL_DEPRECATEDIN_3_0
|
||||
int RSA_meth_set_multi_prime_keygen(RSA_METHOD *meth,
|
||||
int (*keygen) (RSA *rsa, int bits,
|
||||
int primes, BIGNUM *e,
|
||||
BN_GENCB *cb));
|
||||
*/
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
type RSA struct {
|
||||
Unused [0]byte
|
||||
}
|
||||
|
||||
// OSSL_DEPRECATEDIN_3_0 RSA *RSA_new(void);
|
||||
//
|
||||
//go:linkname RSANew C.RSA_new
|
||||
func RSANew() *RSA
|
||||
|
||||
// OSSL_DEPRECATEDIN_3_0 RSA *RSA_new_method(ENGINE *engine);
|
||||
|
||||
// OSSL_DEPRECATEDIN_3_0 void RSA_free(RSA *r);
|
||||
//
|
||||
// llgo:link (*RSA).Free C.RSA_free
|
||||
func (*RSA) Free() {}
|
||||
|
||||
// "up" the RSA object's reference count
|
||||
// OSSL_DEPRECATEDIN_3_0 int RSA_up_ref(RSA *r);
|
||||
//
|
||||
// llgo:link (*RSA).UpRef C.RSA_up_ref
|
||||
func (*RSA) UpRef() c.Int { return 0 }
|
||||
|
||||
// OSSL_DEPRECATEDIN_3_0 int RSA_bits(const RSA *rsa);
|
||||
//
|
||||
// llgo:link (*RSA).Bits C.RSA_bits
|
||||
func (*RSA) Bits() c.Int { return 0 }
|
||||
|
||||
// OSSL_DEPRECATEDIN_3_0 int RSA_size(const RSA *rsa);
|
||||
//
|
||||
// llgo:link (*RSA).Size C.RSA_size
|
||||
func (*RSA) Size() c.Int { return 0 }
|
||||
|
||||
// OSSL_DEPRECATEDIN_3_0 int RSA_security_bits(const RSA *rsa);
|
||||
//
|
||||
// llgo:link (*RSA).SecurityBits C.RSA_security_bits
|
||||
func (*RSA) SecurityBits() c.Int { return 0 }
|
||||
|
||||
// OSSL_DEPRECATEDIN_3_0 int RSA_flags(const RSA *r);
|
||||
//
|
||||
// llgo:link (*RSA).Flags C.RSA_flags
|
||||
func (*RSA) Flags() c.Int { return 0 }
|
||||
|
||||
// OSSL_DEPRECATEDIN_3_0 void RSA_set_flags(RSA *r, int flags);
|
||||
//
|
||||
// llgo:link (*RSA).SetFlags C.RSA_set_flags
|
||||
func (*RSA) SetFlags(flags c.Int) {}
|
||||
|
||||
// OSSL_DEPRECATEDIN_3_0 void RSA_clear_flags(RSA *r, int flags);
|
||||
//
|
||||
// llgo:link (*RSA).ClearFlags C.RSA_clear_flags
|
||||
func (*RSA) ClearFlags(flags c.Int) {}
|
||||
|
||||
// OSSL_DEPRECATEDIN_3_0 int RSA_test_flags(const RSA *r, int flags);
|
||||
//
|
||||
// llgo:link (*RSA).TestFlags C.RSA_test_flags
|
||||
func (*RSA) TestFlags(flags c.Int) c.Int { return 0 }
|
||||
|
||||
// OSSL_DEPRECATEDIN_3_0 int RSA_get_version(RSA *r);
|
||||
//
|
||||
// llgo:link (*RSA).GetVersion C.RSA_get_version
|
||||
func (*RSA) GetVersion() c.Int { return 0 }
|
||||
|
||||
// OSSL_DEPRECATEDIN_3_0 int RSA_set_ex_data(RSA *r, int idx, void *arg);
|
||||
//
|
||||
// llgo:link (*RSA).SetExData C.RSA_set_ex_data
|
||||
func (*RSA) SetExData(idx c.Int, arg unsafe.Pointer) c.Int { return 0 }
|
||||
|
||||
// OSSL_DEPRECATEDIN_3_0 void *RSA_get_ex_data(const RSA *r, int idx);
|
||||
//
|
||||
// llgo:link (*RSA).GetExData C.RSA_get_ex_data
|
||||
func (*RSA) GetExData(idx c.Int) unsafe.Pointer { return nil }
|
||||
|
||||
// OSSL_DEPRECATEDIN_3_0 int RSA_set_method(RSA *rsa, const RSA_METHOD *meth);
|
||||
//
|
||||
// llgo:link (*RSA).SetMethod C.RSA_set_method
|
||||
func (*RSA) SetMethod(meth *RSA_METHOD) c.Int { return 0 }
|
||||
|
||||
// OSSL_DEPRECATEDIN_3_0 int RSA_generate_key_ex(RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb);
|
||||
//
|
||||
// llgo:link (*RSA).GenerateKeyEx C.RSA_generate_key_ex
|
||||
func (*RSA) GenerateKeyEx(bits c.Int, e *BIGNUM, cb *BN_GENCB) c.Int { return 0 }
|
||||
|
||||
// OSSL_DEPRECATEDIN_3_0 int RSA_generate_multi_prime_key(RSA *rsa, int bits, int primes, BIGNUM *e, BN_GENCB *cb);
|
||||
//
|
||||
// llgo:link (*RSA).GenerateMultiPrimeKey C.RSA_generate_multi_prime_key
|
||||
func (*RSA) GenerateMultiPrimeKey(bits, primes c.Int, e *BIGNUM, cb *BN_GENCB) c.Int { return 0 }
|
||||
|
||||
/*
|
||||
// next 4 return -1 on error
|
||||
|
||||
OSSL_DEPRECATEDIN_3_0
|
||||
int RSA_public_encrypt(int flen, const unsigned char *from, unsigned char *to,
|
||||
RSA *rsa, int padding);
|
||||
OSSL_DEPRECATEDIN_3_0
|
||||
int RSA_private_encrypt(int flen, const unsigned char *from, unsigned char *to,
|
||||
RSA *rsa, int padding);
|
||||
OSSL_DEPRECATEDIN_3_0
|
||||
int RSA_public_decrypt(int flen, const unsigned char *from, unsigned char *to,
|
||||
RSA *rsa, int padding);
|
||||
OSSL_DEPRECATEDIN_3_0
|
||||
int RSA_private_decrypt(int flen, const unsigned char *from, unsigned char *to,
|
||||
RSA *rsa, int padding);
|
||||
*/
|
||||
//go:linkname RSAPublicEncrypt C.RSA_public_encrypt
|
||||
func RSAPublicEncrypt(flen c.Int, from *byte, to *byte, rsa *RSA, padding c.Int) c.Int
|
||||
|
||||
//go:linkname RSAPrivateEncrypt C.RSA_private_encrypt
|
||||
func RSAPrivateEncrypt(flen c.Int, from *byte, to *byte, rsa *RSA, padding c.Int) c.Int
|
||||
|
||||
//go:linkname RSAPublicDecrypt C.RSA_public_decrypt
|
||||
func RSAPublicDecrypt(flen c.Int, from *byte, to *byte, rsa *RSA, padding c.Int) c.Int
|
||||
|
||||
//go:linkname RSAPrivateDecrypt C.RSA_private_decrypt
|
||||
func RSAPrivateDecrypt(flen c.Int, from *byte, to *byte, rsa *RSA, padding c.Int) c.Int
|
||||
|
||||
// OSSL_DEPRECATEDIN_3_0 int RSA_sign(
|
||||
// int type, const unsigned char *m, unsigned int m_length,
|
||||
// unsigned char *sigret, unsigned int *siglen, RSA *rsa);
|
||||
//
|
||||
//go:linkname RSASign C.RSA_sign
|
||||
func RSASign(typ c.Int, msg *byte, mlen c.Uint, sigret *byte, siglen *c.Uint, rsa *RSA) c.Int
|
||||
|
||||
// OSSL_DEPRECATEDIN_3_0 int RSA_verify(int type, const unsigned char *m,
|
||||
// unsigned int m_length,
|
||||
// const unsigned char *sigbuf,
|
||||
// unsigned int siglen, RSA *rsa);
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
94
runtime/internal/clite/openssl/sha1.go
Normal file
94
runtime/internal/clite/openssl/sha1.go
Normal file
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* 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 openssl
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
c "github.com/goplus/llgo/runtime/internal/clite"
|
||||
)
|
||||
|
||||
const (
|
||||
SHA_DIGEST_LENGTH = 20
|
||||
SHA_LBLOCK = 16
|
||||
SHA_CBLOCK = (SHA_LBLOCK * 4)
|
||||
SHA_LAST_BLOCK = (SHA_CBLOCK - 8)
|
||||
|
||||
SHA256_CBLOCK = (SHA_LBLOCK * 4)
|
||||
SHA256_192_DIGEST_LENGTH = 24
|
||||
SHA224_DIGEST_LENGTH = 28
|
||||
SHA256_DIGEST_LENGTH = 32
|
||||
SHA384_DIGEST_LENGTH = 48
|
||||
SHA512_DIGEST_LENGTH = 64
|
||||
SHA512_CBLOCK = (SHA_LBLOCK * 8)
|
||||
)
|
||||
|
||||
type SHA_LONG64 = c.UlongLong
|
||||
|
||||
type SHA_LONG = c.Uint
|
||||
|
||||
type SHA_CTX struct {
|
||||
H0, H1, H2, H3, H4 SHA_LONG
|
||||
Nl, Nh SHA_LONG
|
||||
Data [SHA_LBLOCK]SHA_LONG
|
||||
Num c.Uint
|
||||
}
|
||||
|
||||
// OSSL_DEPRECATEDIN_3_0 int SHA1_Init(SHA_CTX *c);
|
||||
//
|
||||
// llgo:link (*SHA_CTX).Init C.SHA1_Init
|
||||
func (c *SHA_CTX) Init() c.Int { return 0 }
|
||||
|
||||
// OSSL_DEPRECATEDIN_3_0 int SHA1_Update(SHA_CTX *c, const void *data, size_t len);
|
||||
//
|
||||
// llgo:link (*SHA_CTX).Update C.SHA1_Update
|
||||
func (c *SHA_CTX) Update(data unsafe.Pointer, n uintptr) c.Int { return 0 }
|
||||
|
||||
func (c *SHA_CTX) UpdateBytes(data []byte) c.Int {
|
||||
return c.Update(unsafe.Pointer(unsafe.SliceData(data)), uintptr(len(data)))
|
||||
}
|
||||
|
||||
func (c *SHA_CTX) UpdateString(data string) c.Int {
|
||||
return c.Update(unsafe.Pointer(unsafe.StringData(data)), uintptr(len(data)))
|
||||
}
|
||||
|
||||
// OSSL_DEPRECATEDIN_3_0 int SHA1_Final(unsigned char *md, SHA_CTX *c);
|
||||
//
|
||||
//go:linkname sha1Final C.SHA1_Final
|
||||
func sha1Final(md *byte, c *SHA_CTX) c.Int
|
||||
|
||||
func (c *SHA_CTX) Final(md *byte) c.Int {
|
||||
return sha1Final(md, c)
|
||||
}
|
||||
|
||||
// OSSL_DEPRECATEDIN_3_0 void SHA1_Transform(SHA_CTX *c, const unsigned char *data);
|
||||
//
|
||||
// llgo:link (*SHA_CTX).Transform C.SHA1_Transform
|
||||
func (c *SHA_CTX) Transform(data *byte) {}
|
||||
|
||||
// unsigned char *SHA1(const unsigned char *d, size_t n, unsigned char *md);
|
||||
//
|
||||
//go:linkname SHA1 C.SHA1
|
||||
func SHA1(data unsafe.Pointer, n uintptr, md *byte) *byte
|
||||
|
||||
func SHA1Bytes(data []byte, md *byte) *byte {
|
||||
return SHA1(unsafe.Pointer(unsafe.SliceData(data)), uintptr(len(data)), md)
|
||||
}
|
||||
|
||||
func SHA1String(data string, md *byte) *byte {
|
||||
return SHA1(unsafe.Pointer(unsafe.StringData(data)), uintptr(len(data)), md)
|
||||
}
|
||||
117
runtime/internal/clite/openssl/sha256.go
Normal file
117
runtime/internal/clite/openssl/sha256.go
Normal file
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* 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 openssl
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
c "github.com/goplus/llgo/runtime/internal/clite"
|
||||
)
|
||||
|
||||
type SHA256_CTX struct {
|
||||
H [8]SHA_LONG
|
||||
Nl, Nh SHA_LONG
|
||||
Data [SHA_LBLOCK]SHA_LONG
|
||||
Num, MdLen c.Uint
|
||||
}
|
||||
|
||||
type SHA224_CTX SHA256_CTX
|
||||
|
||||
// OSSL_DEPRECATEDIN_3_0 int SHA224_Init(SHA256_CTX *c);
|
||||
//
|
||||
// llgo:link (*SHA224_CTX).Init C.SHA224_Init
|
||||
func (c *SHA224_CTX) Init() c.Int { return 0 }
|
||||
|
||||
// OSSL_DEPRECATEDIN_3_0 int SHA224_Update(SHA256_CTX *c, const void *data, size_t len);
|
||||
//
|
||||
// llgo:link (*SHA224_CTX).Update C.SHA224_Update
|
||||
func (c *SHA224_CTX) Update(data unsafe.Pointer, n uintptr) c.Int { return 0 }
|
||||
|
||||
func (c *SHA224_CTX) UpdateBytes(data []byte) c.Int {
|
||||
return c.Update(unsafe.Pointer(unsafe.SliceData(data)), uintptr(len(data)))
|
||||
}
|
||||
|
||||
func (c *SHA224_CTX) UpdateString(data string) c.Int {
|
||||
return c.Update(unsafe.Pointer(unsafe.StringData(data)), uintptr(len(data)))
|
||||
}
|
||||
|
||||
// OSSL_DEPRECATEDIN_3_0 int SHA224_Final(unsigned char *md, SHA256_CTX *c);
|
||||
//
|
||||
//go:linkname sha224Final C.SHA224_Final
|
||||
func sha224Final(md *byte, c *SHA224_CTX) c.Int
|
||||
|
||||
func (c *SHA224_CTX) Final(md *byte) c.Int {
|
||||
return sha224Final(md, c)
|
||||
}
|
||||
|
||||
// OSSL_DEPRECATEDIN_3_0 int SHA256_Init(SHA256_CTX *c);
|
||||
//
|
||||
// llgo:link (*SHA256_CTX).Init C.SHA256_Init
|
||||
func (c *SHA256_CTX) Init() c.Int { return 0 }
|
||||
|
||||
// OSSL_DEPRECATEDIN_3_0 int SHA256_Update(SHA256_CTX *c, const void *data, size_t len);
|
||||
//
|
||||
// llgo:link (*SHA256_CTX).Update C.SHA256_Update
|
||||
func (c *SHA256_CTX) Update(data unsafe.Pointer, n uintptr) c.Int { return 0 }
|
||||
|
||||
func (c *SHA256_CTX) UpdateBytes(data []byte) c.Int {
|
||||
return c.Update(unsafe.Pointer(unsafe.SliceData(data)), uintptr(len(data)))
|
||||
}
|
||||
|
||||
func (c *SHA256_CTX) UpdateString(data string) c.Int {
|
||||
return c.Update(unsafe.Pointer(unsafe.StringData(data)), uintptr(len(data)))
|
||||
}
|
||||
|
||||
// OSSL_DEPRECATEDIN_3_0 int SHA256_Final(unsigned char *md, SHA256_CTX *c);
|
||||
//
|
||||
//go:linkname sha256Final C.SHA256_Final
|
||||
func sha256Final(md *byte, c *SHA256_CTX) c.Int
|
||||
|
||||
func (c *SHA256_CTX) Final(md *byte) c.Int {
|
||||
return sha256Final(md, c)
|
||||
}
|
||||
|
||||
// OSSL_DEPRECATEDIN_3_0 void SHA256_Transform(SHA256_CTX *c, const unsigned char *data);
|
||||
//
|
||||
// llgo:link (*SHA256_CTX).Transform C.SHA256_Transform
|
||||
func (c *SHA256_CTX) Transform(data *byte) {}
|
||||
|
||||
// unsigned char *SHA224(const unsigned char *d, size_t n, unsigned char *md);
|
||||
//
|
||||
//go:linkname SHA224 C.SHA224
|
||||
func SHA224(data unsafe.Pointer, n uintptr, md *byte) *byte
|
||||
|
||||
func SHA224Bytes(data []byte, md *byte) *byte {
|
||||
return SHA224(unsafe.Pointer(unsafe.SliceData(data)), uintptr(len(data)), md)
|
||||
}
|
||||
|
||||
func SHA224String(data string, md *byte) *byte {
|
||||
return SHA224(unsafe.Pointer(unsafe.StringData(data)), uintptr(len(data)), md)
|
||||
}
|
||||
|
||||
// unsigned char *SHA256(const unsigned char *d, size_t n, unsigned char *md);
|
||||
//
|
||||
//go:linkname SHA256 C.SHA256
|
||||
func SHA256(data unsafe.Pointer, n uintptr, md *byte) *byte
|
||||
|
||||
func SHA256Bytes(data []byte, md *byte) *byte {
|
||||
return SHA256(unsafe.Pointer(unsafe.SliceData(data)), uintptr(len(data)), md)
|
||||
}
|
||||
|
||||
func SHA256String(data string, md *byte) *byte {
|
||||
return SHA256(unsafe.Pointer(unsafe.StringData(data)), uintptr(len(data)), md)
|
||||
}
|
||||
115
runtime/internal/clite/openssl/sha512.go
Normal file
115
runtime/internal/clite/openssl/sha512.go
Normal file
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* 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 openssl
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
c "github.com/goplus/llgo/runtime/internal/clite"
|
||||
)
|
||||
|
||||
type SHA512_CTX struct {
|
||||
H [8]SHA_LONG64
|
||||
N1, Nh SHA_LONG64
|
||||
D [SHA_LBLOCK]SHA_LONG64
|
||||
Num, MdLen c.Uint
|
||||
}
|
||||
|
||||
type SHA384_CTX SHA512_CTX
|
||||
|
||||
// OSSL_DEPRECATEDIN_3_0 int SHA384_Init(SHA512_CTX *c);
|
||||
//
|
||||
// llgo:link (*SHA384_CTX).Init C.SHA384_Init
|
||||
func (c *SHA384_CTX) Init() c.Int { return 0 }
|
||||
|
||||
// OSSL_DEPRECATEDIN_3_0 int SHA384_Update(SHA512_CTX *c, const void *data, size_t len);
|
||||
//
|
||||
// llgo:link (*SHA384_CTX).Update C.SHA384_Update
|
||||
func (c *SHA384_CTX) Update(data unsafe.Pointer, n uintptr) c.Int { return 0 }
|
||||
|
||||
func (c *SHA384_CTX) UpdateBytes(data []byte) c.Int {
|
||||
return c.Update(unsafe.Pointer(unsafe.SliceData(data)), uintptr(len(data)))
|
||||
}
|
||||
|
||||
func (c *SHA384_CTX) UpdateString(data string) c.Int {
|
||||
return c.Update(unsafe.Pointer(unsafe.StringData(data)), uintptr(len(data)))
|
||||
}
|
||||
|
||||
// OSSL_DEPRECATEDIN_3_0 int SHA384_Final(unsigned char *md, SHA512_CTX *c);
|
||||
//
|
||||
//go:linkname sha384Final C.SHA384_Final
|
||||
func sha384Final(md *byte, c *SHA384_CTX) c.Int
|
||||
|
||||
func (c *SHA384_CTX) Final(md *byte) c.Int {
|
||||
return sha384Final(md, c)
|
||||
}
|
||||
|
||||
// OSSL_DEPRECATEDIN_3_0 int SHA512_Init(SHA512_CTX *c);
|
||||
//
|
||||
// llgo:link (*SHA512_CTX).Init C.SHA512_Init
|
||||
func (c *SHA512_CTX) Init() c.Int { return 0 }
|
||||
|
||||
// OSSL_DEPRECATEDIN_3_0 int SHA512_Update(SHA512_CTX *c, const void *data, size_t len);
|
||||
//
|
||||
// llgo:link (*SHA512_CTX).Update C.SHA512_Update
|
||||
func (c *SHA512_CTX) Update(data unsafe.Pointer, n uintptr) c.Int { return 0 }
|
||||
func (c *SHA512_CTX) UpdateBytes(data []byte) c.Int {
|
||||
return c.Update(unsafe.Pointer(unsafe.SliceData(data)), uintptr(len(data)))
|
||||
}
|
||||
func (c *SHA512_CTX) UpdateString(data string) c.Int {
|
||||
return c.Update(unsafe.Pointer(unsafe.StringData(data)), uintptr(len(data)))
|
||||
}
|
||||
|
||||
// OSSL_DEPRECATEDIN_3_0 int SHA512_Final(unsigned char *md, SHA512_CTX *c);
|
||||
//
|
||||
//go:linkname sha512Final C.SHA512_Final
|
||||
func sha512Final(md *byte, c *SHA512_CTX) c.Int
|
||||
|
||||
func (c *SHA512_CTX) Final(md *byte) c.Int {
|
||||
return sha512Final(md, c)
|
||||
}
|
||||
|
||||
// OSSL_DEPRECATEDIN_3_0 void SHA512_Transform(SHA512_CTX *c, const unsigned char *data);
|
||||
//
|
||||
// llgo:link (*SHA512_CTX).Transform C.SHA512_Transform
|
||||
func (c *SHA512_CTX) Transform(data *byte) {}
|
||||
|
||||
// unsigned char *SHA384(const unsigned char *d, size_t n, unsigned char *md);
|
||||
//
|
||||
//go:linkname SHA384 C.SHA384
|
||||
func SHA384(data unsafe.Pointer, n uintptr, md *byte) *byte
|
||||
|
||||
func SHA384Bytes(data []byte, md *byte) *byte {
|
||||
return SHA384(unsafe.Pointer(unsafe.SliceData(data)), uintptr(len(data)), md)
|
||||
}
|
||||
|
||||
func SHA384String(data string, md *byte) *byte {
|
||||
return SHA384(unsafe.Pointer(unsafe.StringData(data)), uintptr(len(data)), md)
|
||||
}
|
||||
|
||||
// unsigned char *SHA512(const unsigned char *d, size_t n, unsigned char *md);
|
||||
//
|
||||
//go:linkname SHA512 C.SHA512
|
||||
func SHA512(data unsafe.Pointer, n uintptr, md *byte) *byte
|
||||
|
||||
func SHA512Bytes(data []byte, md *byte) *byte {
|
||||
return SHA512(unsafe.Pointer(unsafe.SliceData(data)), uintptr(len(data)), md)
|
||||
}
|
||||
|
||||
func SHA512String(data string, md *byte) *byte {
|
||||
return SHA512(unsafe.Pointer(unsafe.StringData(data)), uintptr(len(data)), md)
|
||||
}
|
||||
12
runtime/internal/clite/os/_os/os.c
Normal file
12
runtime/internal/clite/os/_os/os.c
Normal file
@@ -0,0 +1,12 @@
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
|
||||
int llgoClearenv() {
|
||||
extern char **environ;
|
||||
if (environ != NULL) {
|
||||
*environ = NULL;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int llgoErrno() { return errno; }
|
||||
359
runtime/internal/clite/os/os.go
Normal file
359
runtime/internal/clite/os/os.go
Normal file
@@ -0,0 +1,359 @@
|
||||
/*
|
||||
* 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
|
||||
|
||||
// #include <sys/stat.h>
|
||||
// #include <limits.h>
|
||||
import "C"
|
||||
|
||||
import (
|
||||
_ "unsafe"
|
||||
|
||||
c "github.com/goplus/llgo/runtime/internal/clite"
|
||||
"github.com/goplus/llgo/runtime/internal/clite/syscall"
|
||||
)
|
||||
|
||||
const (
|
||||
PATH_MAX = C.PATH_MAX
|
||||
)
|
||||
|
||||
const (
|
||||
/* get file status flags */
|
||||
F_GETFL = 3
|
||||
/* set file status flags */
|
||||
F_SETFL = 4
|
||||
|
||||
/* open for reading only */
|
||||
O_RDONLY = 0x0000
|
||||
/* open for writing only */
|
||||
O_WRONLY = 0x0001
|
||||
/* open for reading and writing */
|
||||
O_RDWR = 0x0002
|
||||
/* mask for above modes */
|
||||
O_ACCMODE = 0x0003
|
||||
|
||||
/* no delay */
|
||||
O_NONBLOCK = 0x00000004
|
||||
/* create if nonexistant */
|
||||
O_CREAT = 0x00000200
|
||||
/* truncate to zero length */
|
||||
O_TRUNC = 0x00000400
|
||||
)
|
||||
|
||||
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
|
||||
)
|
||||
|
||||
//go:linkname Errno C.llgoErrno
|
||||
func Errno() c.Int
|
||||
|
||||
//go:linkname Umask C.umask
|
||||
func Umask(cmask ModeT) ModeT
|
||||
|
||||
//go:linkname Mkdir C.mkdir
|
||||
func Mkdir(path *c.Char, mode ModeT) c.Int
|
||||
|
||||
//go:linkname Rmdir C.rmdir
|
||||
func Rmdir(path *c.Char) c.Int
|
||||
|
||||
//go:linkname Link C.link
|
||||
func Link(oldpath *c.Char, newpath *c.Char) c.Int
|
||||
|
||||
//go:linkname Symlink C.symlink
|
||||
func Symlink(target *c.Char, linkpath *c.Char) c.Int
|
||||
|
||||
//go:linkname Readlink C.readlink
|
||||
func Readlink(path *c.Char, buf c.Pointer, bufsize uintptr) int
|
||||
|
||||
//go:linkname Unlink C.unlink
|
||||
func Unlink(path *c.Char) c.Int
|
||||
|
||||
//go:linkname Remove C.remove
|
||||
func Remove(path *c.Char) c.Int
|
||||
|
||||
//go:linkname Rename C.rename
|
||||
func Rename(oldpath *c.Char, newpath *c.Char) c.Int
|
||||
|
||||
//go:linkname Stat C.stat
|
||||
func Stat(path *c.Char, buf *StatT) c.Int
|
||||
|
||||
//go:linkname Lstat C.lstat
|
||||
func Lstat(path *c.Char, buf *StatT) c.Int
|
||||
|
||||
//go:linkname Truncate C.truncate
|
||||
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
|
||||
func Getcwd(buffer c.Pointer, size uintptr) *c.Char
|
||||
|
||||
//go:linkname Chdir C.chdir
|
||||
func Chdir(path *c.Char) c.Int
|
||||
|
||||
//go:linkname Chroot C.chroot
|
||||
func Chroot(path *c.Char) c.Int
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
//go:linkname Environ environ
|
||||
var Environ **c.Char
|
||||
|
||||
//go:linkname Getenv C.getenv
|
||||
func Getenv(name *c.Char) *c.Char
|
||||
|
||||
//go:linkname Setenv C.setenv
|
||||
func Setenv(name *c.Char, value *c.Char, overwrite c.Int) c.Int
|
||||
|
||||
//go:linkname Putenv C.putenv
|
||||
func Putenv(env *c.Char) c.Int
|
||||
|
||||
//go:linkname Unsetenv C.unsetenv
|
||||
func Unsetenv(name *c.Char) c.Int
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
//go:linkname Fchdir C.fchdir
|
||||
func Fchdir(dirfd c.Int) c.Int
|
||||
|
||||
//go:linkname Faccessat C.faccessat
|
||||
func Faccessat(dirfd c.Int, path *c.Char, mode c.Int, flags c.Int) c.Int
|
||||
|
||||
//go:linkname Fchmodat C.fchmodat
|
||||
func Fchmodat(dirfd c.Int, path *c.Char, mode ModeT, flags c.Int) c.Int
|
||||
|
||||
//go:linkname Fchownat C.fchownat
|
||||
func Fchownat(dirfd c.Int, path *c.Char, owner UidT, group GidT, flags c.Int) c.Int
|
||||
|
||||
//go:linkname Fstatat C.fstatat
|
||||
func Fstatat(dirfd c.Int, path *c.Char, buf *StatT, flags c.Int) c.Int
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
//go:linkname Open C.open
|
||||
func Open(path *c.Char, flags c.Int, __llgo_va_list ...any) c.Int
|
||||
|
||||
//go:linkname Openat C.openat
|
||||
func Openat(dirfd c.Int, path *c.Char, flags c.Int, mode ModeT) c.Int
|
||||
|
||||
//go:linkname Creat C.creat
|
||||
func Creat(path *c.Char, mode ModeT) c.Int
|
||||
|
||||
//go:linkname Fcntl C.fcntl
|
||||
func Fcntl(a c.Int, b c.Int, __llgo_va_list ...any) c.Int
|
||||
|
||||
//go:linkname Dup C.dup
|
||||
func Dup(fd c.Int) c.Int
|
||||
|
||||
//go:linkname Dup2 C.dup2
|
||||
func Dup2(oldfd c.Int, newfd 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
|
||||
|
||||
//go:linkname Mknod C.mknod
|
||||
func Mknod(path *c.Char, mode ModeT, dev DevT) c.Int
|
||||
|
||||
//go:linkname Close C.close
|
||||
func Close(fd c.Int) c.Int
|
||||
|
||||
//go:linkname Read C.read
|
||||
func Read(fd c.Int, buf c.Pointer, count uintptr) int
|
||||
|
||||
//go:linkname Write C.write
|
||||
func Write(fd c.Int, buf c.Pointer, count uintptr) int
|
||||
|
||||
//go:linkname Lseek C.lseek
|
||||
func Lseek(fd c.Int, offset OffT, whence c.Int) OffT
|
||||
|
||||
//go:linkname Fsync C.fsync
|
||||
func Fsync(fd c.Int) c.Int
|
||||
|
||||
//go:linkname Ftruncate C.ftruncate
|
||||
func Ftruncate(fd c.Int, length OffT) c.Int
|
||||
|
||||
//go:linkname Fchmod C.fchmod
|
||||
func Fchmod(fd c.Int, mode ModeT) c.Int
|
||||
|
||||
//go:linkname Fchown C.fchown
|
||||
func Fchown(fd c.Int, owner UidT, group GidT) c.Int
|
||||
|
||||
//go:linkname Fstat C.fstat
|
||||
func Fstat(fd c.Int, buf *StatT) c.Int
|
||||
|
||||
//go:linkname Isatty C.isatty
|
||||
func Isatty(fd c.Int) c.Int
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// Execl(const char *path, const char *arg0, ..., /*, (char *)0, */)
|
||||
//
|
||||
// Execl requires the full path of the program to be provided.
|
||||
//
|
||||
//go:linkname Execl C.execl
|
||||
func Execl(path *c.Char, arg0 *c.Char, __llgo_va_list ...any) c.Int
|
||||
|
||||
// Execle(const char *path, const char *arg0, ..., /* (char *)0, char *const envp[] */)
|
||||
//
|
||||
//go:linkname Execle C.execle
|
||||
func Execle(path *c.Char, arg0 *c.Char, __llgo_va_list ...any) c.Int
|
||||
|
||||
// Execlp(const char *file, const char *arg0, ..., /*, (char *)0, */)
|
||||
//
|
||||
// Execlp only needs to provide the program name and it will search for the program in the
|
||||
// paths specified in the PATH environment variable.
|
||||
//
|
||||
//go:linkname Execlp C.execlp
|
||||
func Execlp(file *c.Char, arg0 *c.Char, __llgo_va_list ...any) c.Int
|
||||
|
||||
//go:linkname Execv C.execv
|
||||
func Execv(path *c.Char, argv **c.Char) c.Int
|
||||
|
||||
//go:linkname Execve C.execve
|
||||
func Execve(path *c.Char, argv **c.Char, envp **c.Char) c.Int
|
||||
|
||||
//go:linkname Execvp C.execvp
|
||||
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
|
||||
|
||||
//go:linkname Getppid C.getppid
|
||||
func Getppid() PidT
|
||||
|
||||
//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.
|
||||
//
|
||||
//go:linkname Wait C.wait
|
||||
func Wait(statLoc *c.Int) PidT
|
||||
|
||||
// If wait3(), wait4(), or waitpid() returns due to a stopped or terminated child
|
||||
// process, the process ID of the child is returned to the calling process. If
|
||||
// there are no children not previously awaited, -1 is returned with errno set to
|
||||
// [ECHILD]. Otherwise, if WNOHANG is specified and there are no stopped or exited
|
||||
// children, 0 is returned. If an error is detected or a caught signal aborts the
|
||||
// call, a value of -1 is returned and errno is set to indicate the error.
|
||||
//
|
||||
//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
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
//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
|
||||
// is returned and the global variable errno is set to indicate the error.
|
||||
//
|
||||
//go:linkname Sysctl C.sysctl
|
||||
func Sysctl(
|
||||
name *c.Int, namelen c.Uint,
|
||||
oldp c.Pointer, oldlenp *uintptr,
|
||||
newp c.Pointer, newlen uintptr) c.Int
|
||||
|
||||
//go:linkname Sysctlbyname C.sysctlbyname
|
||||
func Sysctlbyname(
|
||||
name *c.Char, oldp c.Pointer, oldlenp *uintptr,
|
||||
newp c.Pointer, newlen uintptr) c.Int
|
||||
|
||||
// The sysctlnametomib() function accepts an ASCII representation of the
|
||||
// name, looks up the integer name vector, and returns the numeric repre-
|
||||
// sentation in the mib array pointed to by mibp. The number of elements
|
||||
// in the mib array is given by the location specified by sizep before the
|
||||
// call, and that location gives the number of entries copied after a suc-
|
||||
// cessful call. The resulting mib and size may be used in subsequent
|
||||
// sysctl() calls to get the data associated with the requested ASCII
|
||||
// name. This interface is intended for use by applications that want to
|
||||
// repeatedly request the same variable (the sysctl() function runs in
|
||||
// about a third the time as the same request made via the sysctlbyname()
|
||||
// function). The sysctlnametomib() function is also useful for fetching
|
||||
// mib prefixes and then adding a final component.
|
||||
//
|
||||
//go:linkname Sysctlnametomib C.sysctlnametomib
|
||||
func Sysctlnametomib(name *c.Char, mibp *c.Int, sizep *uintptr) c.Int
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
29
runtime/internal/clite/os/os_linux.go
Normal file
29
runtime/internal/clite/os/os_linux.go
Normal file
@@ -0,0 +1,29 @@
|
||||
//go:build linux
|
||||
|
||||
/*
|
||||
* 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 "C"
|
||||
|
||||
const (
|
||||
LLGoFiles = "_os/os.c"
|
||||
LLGoPackage = "link"
|
||||
)
|
||||
|
||||
//go:linkname Clearenv C.clearenv
|
||||
func Clearenv()
|
||||
29
runtime/internal/clite/os/os_other.go
Normal file
29
runtime/internal/clite/os/os_other.go
Normal file
@@ -0,0 +1,29 @@
|
||||
//go:build !linux
|
||||
|
||||
/*
|
||||
* 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 "C"
|
||||
|
||||
const (
|
||||
LLGoFiles = "_os/os.c"
|
||||
LLGoPackage = "link"
|
||||
)
|
||||
|
||||
//go:linkname Clearenv C.llgoClearenv
|
||||
func Clearenv()
|
||||
109
runtime/internal/clite/pthread/pthread.go
Normal file
109
runtime/internal/clite/pthread/pthread.go
Normal file
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* 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 pthread
|
||||
|
||||
import (
|
||||
_ "unsafe"
|
||||
|
||||
c "github.com/goplus/llgo/runtime/internal/clite"
|
||||
)
|
||||
|
||||
func __noop__() c.Int {
|
||||
return 0
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
type aThread struct {
|
||||
Unused [8]byte
|
||||
}
|
||||
|
||||
//llgo:type C
|
||||
type RoutineFunc func(c.Pointer) c.Pointer
|
||||
|
||||
// Thread represents a POSIX thread.
|
||||
type Thread = *aThread
|
||||
|
||||
// The pthread_exit() function terminates the calling thread and
|
||||
// returns a value via retval that (if the thread is joinable) is
|
||||
// available to another thread in the same process that calls
|
||||
// pthread_join(3).
|
||||
//
|
||||
// See https://man7.org/linux/man-pages/man3/pthread_exit.3.html
|
||||
//
|
||||
//go:linkname Exit C.pthread_exit
|
||||
func Exit(retval c.Pointer)
|
||||
|
||||
// The pthread_cancel() function sends a cancelation request to the
|
||||
// thread thread.
|
||||
//
|
||||
// See https://man7.org/linux/man-pages/man3/pthread_cancel.3.html
|
||||
//
|
||||
//go:linkname Cancel C.pthread_cancel
|
||||
func Cancel(thread Thread) c.Int
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// Attr represents a POSIX thread attributes.
|
||||
type Attr struct {
|
||||
Detached byte
|
||||
SsSp *c.Char
|
||||
SsSize uintptr
|
||||
}
|
||||
|
||||
// llgo:link (*Attr).Init C.pthread_attr_init
|
||||
func (attr *Attr) Init() c.Int { return 0 }
|
||||
|
||||
// llgo:link (*Attr).Destroy C.pthread_attr_destroy
|
||||
func (attr *Attr) Destroy() c.Int { return 0 }
|
||||
|
||||
// llgo:link (*Attr).GetDetached C.pthread_attr_getdetachstate
|
||||
func (attr *Attr) GetDetached(detached *c.Int) c.Int { return 0 }
|
||||
|
||||
// llgo:link (*Attr).SetDetached C.pthread_attr_setdetachstate
|
||||
func (attr *Attr) SetDetached(detached c.Int) c.Int { return 0 }
|
||||
|
||||
// llgo:link (*Attr).GetStackSize C.pthread_attr_getstacksize
|
||||
func (attr *Attr) GetStackSize(stackSize *uintptr) c.Int { return 0 }
|
||||
|
||||
// llgo:link (*Attr).SetStackSize C.pthread_attr_setstacksize
|
||||
func (attr *Attr) SetStackSize(stackSize uintptr) c.Int { return 0 }
|
||||
|
||||
// llgo:link (*Attr).GetStackAddr C.pthread_attr_getstackaddr
|
||||
func (attr *Attr) GetStackAddr(stackAddr *c.Pointer) c.Int { return 0 }
|
||||
|
||||
// llgo:link (*Attr).SetStackAddr C.pthread_attr_setstackaddr
|
||||
func (attr *Attr) SetStackAddr(stackAddr c.Pointer) c.Int { return 0 }
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Thread Local Storage
|
||||
|
||||
type Key c.Uint
|
||||
|
||||
// llgo:link (*Key).Create C.pthread_key_create
|
||||
func (key *Key) Create(destructor func(c.Pointer)) c.Int { return 0 }
|
||||
|
||||
// llgo:link Key.Delete C.pthread_key_delete
|
||||
func (key Key) Delete() c.Int { return 0 }
|
||||
|
||||
// llgo:link Key.Get C.pthread_getspecific
|
||||
func (key Key) Get() c.Pointer { return nil }
|
||||
|
||||
// llgo:link Key.Set C.pthread_setspecific
|
||||
func (key Key) Set(value c.Pointer) c.Int { return __noop__() }
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
80
runtime/internal/clite/pthread/pthread_gc.go
Normal file
80
runtime/internal/clite/pthread/pthread_gc.go
Normal file
@@ -0,0 +1,80 @@
|
||||
//go:build !nogc
|
||||
// +build !nogc
|
||||
|
||||
/*
|
||||
* 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 pthread
|
||||
|
||||
import (
|
||||
_ "unsafe"
|
||||
|
||||
c "github.com/goplus/llgo/runtime/internal/clite"
|
||||
)
|
||||
|
||||
const (
|
||||
LLGoPackage = "link: $(pkg-config --libs bdw-gc); -lgc"
|
||||
)
|
||||
|
||||
// The pthread_create() function starts a new thread in the calling
|
||||
// process. The new thread starts execution by invoking
|
||||
// start_routine(); arg is passed as the sole argument of
|
||||
// start_routine().
|
||||
//
|
||||
// The new thread terminates in one of the following ways:
|
||||
//
|
||||
// - It calls pthread_exit(3), specifying an exit status value that
|
||||
// is available to another thread in the same process that calls
|
||||
// pthread_join(3).
|
||||
//
|
||||
// - It returns from start_routine(). This is equivalent to
|
||||
// calling pthread_exit(3) with the value supplied in the return
|
||||
// statement.
|
||||
//
|
||||
// - It is canceled (see pthread_cancel(3)).
|
||||
//
|
||||
// - Any of the threads in the process calls exit(3), or the main
|
||||
// thread performs a return from main(). This causes the
|
||||
// termination of all threads in the process.
|
||||
//
|
||||
// On success, pthread_create() returns 0; on error, it returns an
|
||||
// error number, and the contents of *thread are undefined.
|
||||
//
|
||||
// See https://man7.org/linux/man-pages/man3/pthread_create.3.html
|
||||
//
|
||||
//go:linkname Create C.GC_pthread_create
|
||||
func Create(pthread *Thread, attr *Attr, routine RoutineFunc, arg c.Pointer) c.Int
|
||||
|
||||
// The pthread_join() function waits for the thread specified by
|
||||
// thread to terminate. If that thread has already terminated, then
|
||||
// pthread_join() returns immediately. The thread specified by
|
||||
// thread must be joinable.
|
||||
//
|
||||
// If retval is not NULL, then pthread_join() copies the exit status
|
||||
// of the target thread (i.e., the value that the target thread
|
||||
// supplied to pthread_exit(3)) into the location pointed to by
|
||||
// retval. If the target thread was canceled, then PTHREAD_CANCELED
|
||||
// is placed in the location pointed to by retval.
|
||||
//
|
||||
// If multiple threads simultaneously try to join with the same
|
||||
// thread, the results are undefined. If the thread calling
|
||||
// pthread_join() is canceled, then the target thread will remain
|
||||
// joinable (i.e., it will not be detached).
|
||||
//
|
||||
// See https://man7.org/linux/man-pages/man3/pthread_join.3.html
|
||||
//
|
||||
//go:linkname Join C.GC_pthread_join
|
||||
func Join(thread Thread, retval *c.Pointer) c.Int
|
||||
80
runtime/internal/clite/pthread/pthread_nogc.go
Normal file
80
runtime/internal/clite/pthread/pthread_nogc.go
Normal file
@@ -0,0 +1,80 @@
|
||||
//go:build nogc
|
||||
// +build nogc
|
||||
|
||||
/*
|
||||
* 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 pthread
|
||||
|
||||
import (
|
||||
_ "unsafe"
|
||||
|
||||
c "github.com/goplus/llgo/runtime/internal/clite"
|
||||
)
|
||||
|
||||
const (
|
||||
LLGoPackage = "decl"
|
||||
)
|
||||
|
||||
// The pthread_create() function starts a new thread in the calling
|
||||
// process. The new thread starts execution by invoking
|
||||
// start_routine(); arg is passed as the sole argument of
|
||||
// start_routine().
|
||||
//
|
||||
// The new thread terminates in one of the following ways:
|
||||
//
|
||||
// - It calls pthread_exit(3), specifying an exit status value that
|
||||
// is available to another thread in the same process that calls
|
||||
// pthread_join(3).
|
||||
//
|
||||
// - It returns from start_routine(). This is equivalent to
|
||||
// calling pthread_exit(3) with the value supplied in the return
|
||||
// statement.
|
||||
//
|
||||
// - It is canceled (see pthread_cancel(3)).
|
||||
//
|
||||
// - Any of the threads in the process calls exit(3), or the main
|
||||
// thread performs a return from main(). This causes the
|
||||
// termination of all threads in the process.
|
||||
//
|
||||
// On success, pthread_create() returns 0; on error, it returns an
|
||||
// error number, and the contents of *thread are undefined.
|
||||
//
|
||||
// See https://man7.org/linux/man-pages/man3/pthread_create.3.html
|
||||
//
|
||||
//go:linkname Create C.pthread_create
|
||||
func Create(pthread *Thread, attr *Attr, routine RoutineFunc, arg c.Pointer) c.Int
|
||||
|
||||
// The pthread_join() function waits for the thread specified by
|
||||
// thread to terminate. If that thread has already terminated, then
|
||||
// pthread_join() returns immediately. The thread specified by
|
||||
// thread must be joinable.
|
||||
//
|
||||
// If retval is not NULL, then pthread_join() copies the exit status
|
||||
// of the target thread (i.e., the value that the target thread
|
||||
// supplied to pthread_exit(3)) into the location pointed to by
|
||||
// retval. If the target thread was canceled, then PTHREAD_CANCELED
|
||||
// is placed in the location pointed to by retval.
|
||||
//
|
||||
// If multiple threads simultaneously try to join with the same
|
||||
// thread, the results are undefined. If the thread calling
|
||||
// pthread_join() is canceled, then the target thread will remain
|
||||
// joinable (i.e., it will not be detached).
|
||||
//
|
||||
// See https://man7.org/linux/man-pages/man3/pthread_join.3.html
|
||||
//
|
||||
//go:linkname Join C.pthread_join
|
||||
func Join(thread Thread, retval *c.Pointer) c.Int
|
||||
70
runtime/internal/clite/pthread/sync/_sema.go
Normal file
70
runtime/internal/clite/pthread/sync/_sema.go
Normal file
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* 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 sync
|
||||
|
||||
// #include <semaphore.h>
|
||||
import "C"
|
||||
|
||||
import (
|
||||
_ "unsafe"
|
||||
|
||||
c "github.com/goplus/llgo/runtime/internal/clite"
|
||||
)
|
||||
|
||||
// Sem represents a semaphore.
|
||||
type Sem C.sem_t
|
||||
|
||||
// initializes the unnamed semaphore at the address
|
||||
// pointed to by sem. The value argument specifies the initial
|
||||
// value for the semaphore.
|
||||
//
|
||||
// The pshared argument indicates whether this semaphore is to be
|
||||
// shared between the threads of a process, or between processes.
|
||||
//
|
||||
// If pshared has the value 0, then the semaphore is shared between
|
||||
// the threads of a process, and should be located at some address
|
||||
// that is visible to all threads (e.g., a global variable, or a
|
||||
// variable allocated dynamically on the heap).
|
||||
//
|
||||
// If pshared is nonzero, then the semaphore is shared between
|
||||
// processes, and should be located in a region of shared memory
|
||||
// (see shm_open(3), mmap(2), and shmget(2)). (Since a child
|
||||
// created by fork(2) inherits its parent's memory mappings, it can
|
||||
// also access the semaphore.) Any process that can access the
|
||||
// shared memory region can operate on the semaphore using
|
||||
// sem_post(3), sem_wait(3), and so on.
|
||||
//
|
||||
// Initializing a semaphore that has already been initialized
|
||||
// results in undefined behavior.
|
||||
//
|
||||
// llgo:link (*Sem).Init C.sem_init
|
||||
func (*Sem) Init(pshared c.Int, value c.Uint) c.Int { return 0 }
|
||||
|
||||
// llgo:link (*Sem).Destroy C.sem_destroy
|
||||
func (*Sem) Destroy() c.Int { return 0 }
|
||||
|
||||
// llgo:link (*Sem).Post C.sem_post
|
||||
func (*Sem) Post() c.Int { return 0 }
|
||||
|
||||
// llgo:link (*Sem).Wait C.sem_wait
|
||||
func (*Sem) Wait() c.Int { return 0 }
|
||||
|
||||
// llgo:link (*Sem).TryWait C.sem_trywait
|
||||
func (*Sem) TryWait() c.Int { return 0 }
|
||||
|
||||
// llgo:link (*Sem).GetValue C.sem_getvalue
|
||||
func (*Sem) GetValue(sval *c.Int) c.Int { return 0 }
|
||||
19
runtime/internal/clite/pthread/sync/_wrap/pthd.c
Normal file
19
runtime/internal/clite/pthread/sync/_wrap/pthd.c
Normal file
@@ -0,0 +1,19 @@
|
||||
#include <pthread.h>
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
pthread_once_t llgoSyncOnceInitVal = PTHREAD_ONCE_INIT;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// wrap return type to void
|
||||
void wrap_pthread_mutex_lock(pthread_mutex_t *mutex) {
|
||||
pthread_mutex_lock(mutex);
|
||||
}
|
||||
|
||||
// wrap return type to void
|
||||
void wrap_pthread_mutex_unlock(pthread_mutex_t *mutex) {
|
||||
pthread_mutex_unlock(mutex);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
174
runtime/internal/clite/pthread/sync/sync.go
Normal file
174
runtime/internal/clite/pthread/sync/sync.go
Normal file
@@ -0,0 +1,174 @@
|
||||
/*
|
||||
* 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 sync
|
||||
|
||||
// #include <pthread.h>
|
||||
import "C"
|
||||
|
||||
import (
|
||||
_ "unsafe"
|
||||
|
||||
c "github.com/goplus/llgo/runtime/internal/clite"
|
||||
"github.com/goplus/llgo/runtime/internal/clite/time"
|
||||
)
|
||||
|
||||
const (
|
||||
LLGoFiles = "_wrap/pthd.c"
|
||||
LLGoPackage = "link"
|
||||
)
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// Once is an object that will perform exactly one action.
|
||||
type Once C.pthread_once_t
|
||||
|
||||
//go:linkname OnceInit llgoSyncOnceInitVal
|
||||
var OnceInit Once
|
||||
|
||||
// llgo:link (*Once).Do C.pthread_once
|
||||
func (o *Once) Do(f func()) c.Int { return 0 }
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
type MutexType c.Int
|
||||
|
||||
const (
|
||||
MUTEX_NORMAL MutexType = C.PTHREAD_MUTEX_NORMAL
|
||||
MUTEX_ERRORCHECK MutexType = C.PTHREAD_MUTEX_ERRORCHECK
|
||||
MUTEX_RECURSIVE MutexType = C.PTHREAD_MUTEX_RECURSIVE
|
||||
MUTEX_DEFAULT MutexType = C.PTHREAD_MUTEX_DEFAULT
|
||||
)
|
||||
|
||||
// MutexAttr is a mutex attribute object.
|
||||
type MutexAttr C.pthread_mutexattr_t
|
||||
|
||||
// llgo:link (*MutexAttr).Init C.pthread_mutexattr_init
|
||||
func (a *MutexAttr) Init(attr *MutexAttr) c.Int { return 0 }
|
||||
|
||||
// llgo:link (*MutexAttr).Destroy C.pthread_mutexattr_destroy
|
||||
func (a *MutexAttr) Destroy() {}
|
||||
|
||||
// llgo:link (*MutexAttr).SetType C.pthread_mutexattr_settype
|
||||
func (a *MutexAttr) SetType(typ MutexType) c.Int { return 0 }
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// Mutex is a mutual exclusion lock.
|
||||
type Mutex C.pthread_mutex_t
|
||||
|
||||
// llgo:link (*Mutex).Init C.pthread_mutex_init
|
||||
func (m *Mutex) Init(attr *MutexAttr) c.Int { return 0 }
|
||||
|
||||
// llgo:link (*Mutex).Destroy C.pthread_mutex_destroy
|
||||
func (m *Mutex) Destroy() {}
|
||||
|
||||
// llgo:link (*Mutex).TryLock C.pthread_mutex_trylock
|
||||
func (m *Mutex) TryLock() c.Int { return 0 }
|
||||
|
||||
// llgo:link (*Mutex).Lock C.wrap_pthread_mutex_lock
|
||||
func (m *Mutex) Lock() {}
|
||||
|
||||
// llgo:link (*Mutex).Unlock C.wrap_pthread_mutex_unlock
|
||||
func (m *Mutex) Unlock() {}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// RWLockAttr is a read-write lock attribute object.
|
||||
type RWLockAttr C.pthread_rwlockattr_t
|
||||
|
||||
// llgo:link (*RWLockAttr).Init C.pthread_rwlockattr_init
|
||||
func (a *RWLockAttr) Init(attr *RWLockAttr) c.Int { return 0 }
|
||||
|
||||
// llgo:link (*RWLockAttr).Destroy C.pthread_rwlockattr_destroy
|
||||
func (a *RWLockAttr) Destroy() {}
|
||||
|
||||
// llgo:link (*RWLockAttr).SetPShared C.pthread_rwlockattr_setpshared
|
||||
func (a *RWLockAttr) SetPShared(pshared c.Int) c.Int { return 0 }
|
||||
|
||||
// llgo:link (*RWLockAttr).GetPShared C.pthread_rwlockattr_getpshared
|
||||
func (a *RWLockAttr) GetPShared(pshared *c.Int) c.Int { return 0 }
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// RWLock is a read-write lock.
|
||||
type RWLock C.pthread_rwlock_t
|
||||
|
||||
// llgo:link (*RWLock).Init C.pthread_rwlock_init
|
||||
func (rw *RWLock) Init(attr *RWLockAttr) c.Int { return 0 }
|
||||
|
||||
// llgo:link (*RWLock).Destroy C.pthread_rwlock_destroy
|
||||
func (rw *RWLock) Destroy() {}
|
||||
|
||||
// llgo:link (*RWLock).RLock C.pthread_rwlock_rdlock
|
||||
func (rw *RWLock) RLock() {}
|
||||
|
||||
// llgo:link (*RWLock).TryRLock C.pthread_rwlock_tryrdlock
|
||||
func (rw *RWLock) TryRLock() c.Int { return 0 }
|
||||
|
||||
// llgo:link (*RWLock).RUnlock C.pthread_rwlock_unlock
|
||||
func (rw *RWLock) RUnlock() {}
|
||||
|
||||
// llgo:link (*RWLock).Lock C.pthread_rwlock_wrlock
|
||||
func (rw *RWLock) Lock() {}
|
||||
|
||||
// llgo:link (*RWLock).TryLock C.pthread_rwlock_trywrlock
|
||||
func (rw *RWLock) TryLock() c.Int { return 0 }
|
||||
|
||||
// llgo:link (*RWLock).Unlock C.pthread_rwlock_unlock
|
||||
func (rw *RWLock) Unlock() {}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// CondAttr is a condition variable attribute object.
|
||||
type CondAttr C.pthread_condattr_t
|
||||
|
||||
// llgo:link (*CondAttr).Init C.pthread_condattr_init
|
||||
func (a *CondAttr) Init(attr *CondAttr) c.Int { return 0 }
|
||||
|
||||
// llgo:link (*CondAttr).Destroy C.pthread_condattr_destroy
|
||||
func (a *CondAttr) Destroy() {}
|
||||
|
||||
// llgo:link (*CondAttr).SetClock C.pthread_condattr_setclock
|
||||
func (a *CondAttr) SetClock(clock time.ClockidT) c.Int { return 0 }
|
||||
|
||||
// llgo:link (*CondAttr).GetClock C.pthread_condattr_getclock
|
||||
func (a *CondAttr) GetClock(clock *time.ClockidT) c.Int { return 0 }
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// Cond is a condition variable.
|
||||
type Cond C.pthread_cond_t
|
||||
|
||||
// llgo:link (*Cond).Init C.pthread_cond_init
|
||||
func (c *Cond) Init(attr *CondAttr) c.Int { return 0 }
|
||||
|
||||
// llgo:link (*Cond).Destroy C.pthread_cond_destroy
|
||||
func (c *Cond) Destroy() {}
|
||||
|
||||
// llgo:link (*Cond).Signal C.pthread_cond_signal
|
||||
func (c *Cond) Signal() c.Int { return 0 }
|
||||
|
||||
// llgo:link (*Cond).Broadcast C.pthread_cond_broadcast
|
||||
func (c *Cond) Broadcast() c.Int { return 0 }
|
||||
|
||||
// llgo:link (*Cond).Wait C.pthread_cond_wait
|
||||
func (c *Cond) Wait(m *Mutex) c.Int { return 0 }
|
||||
|
||||
// llgo:link (*Cond).TimedWait C.pthread_cond_timedwait
|
||||
func (c *Cond) TimedWait(m *Mutex, abstime *time.Timespec) c.Int { return 0 }
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
32
runtime/internal/clite/signal/signal.go
Normal file
32
runtime/internal/clite/signal/signal.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package signal
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
c "github.com/goplus/llgo/runtime/internal/clite"
|
||||
)
|
||||
import "C"
|
||||
|
||||
const (
|
||||
LLGoPackage = "link"
|
||||
)
|
||||
|
||||
//llgo:type C
|
||||
type SignalHandler func(c.Int)
|
||||
|
||||
//llgo:type C
|
||||
type sigactiont struct {
|
||||
handler SignalHandler
|
||||
tramp unsafe.Pointer
|
||||
mask c.Int
|
||||
flags c.Int
|
||||
}
|
||||
|
||||
//go:linkname sigaction C.sigaction
|
||||
func sigaction(sig c.Int, act, old *sigactiont) c.Int
|
||||
|
||||
func Signal(sig c.Int, hanlder SignalHandler) c.Int {
|
||||
var act sigactiont
|
||||
act.handler = hanlder
|
||||
return sigaction(sig, &act, nil)
|
||||
}
|
||||
71
runtime/internal/clite/sync/atomic/atomic.go
Normal file
71
runtime/internal/clite/sync/atomic/atomic.go
Normal file
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* 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 atomic
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
const (
|
||||
LLGoPackage = "decl"
|
||||
)
|
||||
|
||||
type valtype interface {
|
||||
~int | ~uint | ~uintptr | ~int32 | ~uint32 | ~int64 | ~uint64 | ~unsafe.Pointer
|
||||
}
|
||||
|
||||
// llgo:link Add llgo.atomicAdd
|
||||
func Add[T valtype](ptr *T, v T) T { return v }
|
||||
|
||||
// llgo:link Sub llgo.atomicSub
|
||||
func Sub[T valtype](ptr *T, v T) T { return v }
|
||||
|
||||
// llgo:link And llgo.atomicAnd
|
||||
func And[T valtype](ptr *T, v T) T { return v }
|
||||
|
||||
// llgo:link NotAnd llgo.atomicNand
|
||||
func NotAnd[T valtype](ptr *T, v T) T { return v }
|
||||
|
||||
// llgo:link Or llgo.atomicOr
|
||||
func Or[T valtype](ptr *T, v T) T { return v }
|
||||
|
||||
// llgo:link Xor llgo.atomicXor
|
||||
func Xor[T valtype](ptr *T, v T) T { return v }
|
||||
|
||||
// llgo:link Max llgo.atomicMax
|
||||
func Max[T valtype](ptr *T, v T) T { return v }
|
||||
|
||||
// llgo:link Min llgo.atomicMin
|
||||
func Min[T valtype](ptr *T, v T) T { return v }
|
||||
|
||||
// llgo:link UMax llgo.atomicUMax
|
||||
func UMax[T valtype](ptr *T, v T) T { return v }
|
||||
|
||||
// llgo:link UMin llgo.atomicUMin
|
||||
func UMin[T valtype](ptr *T, v T) T { return v }
|
||||
|
||||
// llgo:link Load llgo.atomicLoad
|
||||
func Load[T valtype](ptr *T) T { return *ptr }
|
||||
|
||||
// llgo:link Store llgo.atomicStore
|
||||
func Store[T valtype](ptr *T, v T) {}
|
||||
|
||||
// llgo:link Exchange llgo.atomicXchg
|
||||
func Exchange[T valtype](ptr *T, v T) T { return v }
|
||||
|
||||
// llgo:link CompareAndExchange llgo.atomicCmpXchg
|
||||
func CompareAndExchange[T valtype](ptr *T, old, new T) (T, bool) { return old, false }
|
||||
32
runtime/internal/clite/syscall/syscall.go
Normal file
32
runtime/internal/clite/syscall/syscall.go
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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 syscall
|
||||
|
||||
const (
|
||||
LLGoPackage = "noinit"
|
||||
)
|
||||
|
||||
type Errno = uintptr
|
||||
|
||||
// A Signal is a number describing a process signal.
|
||||
// It implements the os.Signal interface.
|
||||
type Signal = int
|
||||
|
||||
// Unix returns the time stored in ts as seconds plus nanoseconds.
|
||||
func (ts *Timespec) Unix() (sec int64, nsec int64) {
|
||||
return int64(ts.Sec), int64(ts.Nsec)
|
||||
}
|
||||
10
runtime/internal/clite/syscall/unix/at_sysnum_darwin.go
Normal file
10
runtime/internal/clite/syscall/unix/at_sysnum_darwin.go
Normal file
@@ -0,0 +1,10 @@
|
||||
// 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
|
||||
|
||||
const AT_REMOVEDIR = 0x80
|
||||
const AT_SYMLINK_NOFOLLOW = 0x0020
|
||||
|
||||
const UTIME_OMIT = -0x2
|
||||
10
runtime/internal/clite/syscall/unix/at_sysnum_dragonfly.go
Normal file
10
runtime/internal/clite/syscall/unix/at_sysnum_dragonfly.go
Normal file
@@ -0,0 +1,10 @@
|
||||
// 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
|
||||
|
||||
const AT_REMOVEDIR = 0x2
|
||||
const AT_SYMLINK_NOFOLLOW = 0x1
|
||||
|
||||
const UTIME_OMIT = -0x1
|
||||
12
runtime/internal/clite/syscall/unix/at_sysnum_freebsd.go
Normal file
12
runtime/internal/clite/syscall/unix/at_sysnum_freebsd.go
Normal file
@@ -0,0 +1,12 @@
|
||||
// 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
|
||||
|
||||
const (
|
||||
AT_REMOVEDIR = 0x800
|
||||
AT_SYMLINK_NOFOLLOW = 0x200
|
||||
|
||||
UTIME_OMIT = -0x2
|
||||
)
|
||||
14
runtime/internal/clite/syscall/unix/at_sysnum_linux.go
Normal file
14
runtime/internal/clite/syscall/unix/at_sysnum_linux.go
Normal file
@@ -0,0 +1,14 @@
|
||||
// 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
|
||||
|
||||
const (
|
||||
AT_EACCESS = 0x200
|
||||
AT_FDCWD = -0x64
|
||||
AT_REMOVEDIR = 0x200
|
||||
AT_SYMLINK_NOFOLLOW = 0x100
|
||||
|
||||
UTIME_OMIT = 0x3ffffffe
|
||||
)
|
||||
10
runtime/internal/clite/syscall/unix/at_sysnum_netbsd.go
Normal file
10
runtime/internal/clite/syscall/unix/at_sysnum_netbsd.go
Normal file
@@ -0,0 +1,10 @@
|
||||
// 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
|
||||
|
||||
const AT_REMOVEDIR = 0x800
|
||||
const AT_SYMLINK_NOFOLLOW = 0x200
|
||||
|
||||
const UTIME_OMIT = (1 << 30) - 2
|
||||
10
runtime/internal/clite/syscall/unix/at_sysnum_openbsd.go
Normal file
10
runtime/internal/clite/syscall/unix/at_sysnum_openbsd.go
Normal file
@@ -0,0 +1,10 @@
|
||||
// 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
|
||||
|
||||
const AT_REMOVEDIR = 0x08
|
||||
const AT_SYMLINK_NOFOLLOW = 0x02
|
||||
|
||||
const UTIME_OMIT = -0x1
|
||||
21
runtime/internal/clite/syscall/unix/unix.go
Normal file
21
runtime/internal/clite/syscall/unix/unix.go
Normal file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* 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 unix
|
||||
|
||||
const (
|
||||
LLGoPackage = "decl"
|
||||
)
|
||||
1153
runtime/internal/clite/syscall/zerrors_aix_ppc64.go
Normal file
1153
runtime/internal/clite/syscall/zerrors_aix_ppc64.go
Normal file
File diff suppressed because it is too large
Load Diff
1279
runtime/internal/clite/syscall/zerrors_darwin_amd64.go
Normal file
1279
runtime/internal/clite/syscall/zerrors_darwin_amd64.go
Normal file
File diff suppressed because it is too large
Load Diff
1291
runtime/internal/clite/syscall/zerrors_darwin_arm64.go
Normal file
1291
runtime/internal/clite/syscall/zerrors_darwin_arm64.go
Normal file
File diff suppressed because it is too large
Load Diff
1392
runtime/internal/clite/syscall/zerrors_dragonfly_amd64.go
Normal file
1392
runtime/internal/clite/syscall/zerrors_dragonfly_amd64.go
Normal file
File diff suppressed because it is too large
Load Diff
1580
runtime/internal/clite/syscall/zerrors_freebsd_386.go
Normal file
1580
runtime/internal/clite/syscall/zerrors_freebsd_386.go
Normal file
File diff suppressed because it is too large
Load Diff
1581
runtime/internal/clite/syscall/zerrors_freebsd_amd64.go
Normal file
1581
runtime/internal/clite/syscall/zerrors_freebsd_amd64.go
Normal file
File diff suppressed because it is too large
Load Diff
1580
runtime/internal/clite/syscall/zerrors_freebsd_arm.go
Normal file
1580
runtime/internal/clite/syscall/zerrors_freebsd_arm.go
Normal file
File diff suppressed because it is too large
Load Diff
1581
runtime/internal/clite/syscall/zerrors_freebsd_arm64.go
Normal file
1581
runtime/internal/clite/syscall/zerrors_freebsd_arm64.go
Normal file
File diff suppressed because it is too large
Load Diff
1581
runtime/internal/clite/syscall/zerrors_freebsd_riscv64.go
Normal file
1581
runtime/internal/clite/syscall/zerrors_freebsd_riscv64.go
Normal file
File diff suppressed because it is too large
Load Diff
1355
runtime/internal/clite/syscall/zerrors_linux_386.go
Normal file
1355
runtime/internal/clite/syscall/zerrors_linux_386.go
Normal file
File diff suppressed because it is too large
Load Diff
1356
runtime/internal/clite/syscall/zerrors_linux_amd64.go
Normal file
1356
runtime/internal/clite/syscall/zerrors_linux_amd64.go
Normal file
File diff suppressed because it is too large
Load Diff
1368
runtime/internal/clite/syscall/zerrors_linux_arm.go
Normal file
1368
runtime/internal/clite/syscall/zerrors_linux_arm.go
Normal file
File diff suppressed because it is too large
Load Diff
1632
runtime/internal/clite/syscall/zerrors_linux_arm64.go
Normal file
1632
runtime/internal/clite/syscall/zerrors_linux_arm64.go
Normal file
File diff suppressed because it is too large
Load Diff
1931
runtime/internal/clite/syscall/zerrors_linux_loong64.go
Normal file
1931
runtime/internal/clite/syscall/zerrors_linux_loong64.go
Normal file
File diff suppressed because it is too large
Load Diff
1639
runtime/internal/clite/syscall/zerrors_linux_mips.go
Normal file
1639
runtime/internal/clite/syscall/zerrors_linux_mips.go
Normal file
File diff suppressed because it is too large
Load Diff
1622
runtime/internal/clite/syscall/zerrors_linux_mips64.go
Normal file
1622
runtime/internal/clite/syscall/zerrors_linux_mips64.go
Normal file
File diff suppressed because it is too large
Load Diff
1622
runtime/internal/clite/syscall/zerrors_linux_mips64le.go
Normal file
1622
runtime/internal/clite/syscall/zerrors_linux_mips64le.go
Normal file
File diff suppressed because it is too large
Load Diff
1639
runtime/internal/clite/syscall/zerrors_linux_mipsle.go
Normal file
1639
runtime/internal/clite/syscall/zerrors_linux_mipsle.go
Normal file
File diff suppressed because it is too large
Load Diff
1687
runtime/internal/clite/syscall/zerrors_linux_ppc64.go
Normal file
1687
runtime/internal/clite/syscall/zerrors_linux_ppc64.go
Normal file
File diff suppressed because it is too large
Load Diff
1711
runtime/internal/clite/syscall/zerrors_linux_ppc64le.go
Normal file
1711
runtime/internal/clite/syscall/zerrors_linux_ppc64le.go
Normal file
File diff suppressed because it is too large
Load Diff
1686
runtime/internal/clite/syscall/zerrors_linux_riscv64.go
Normal file
1686
runtime/internal/clite/syscall/zerrors_linux_riscv64.go
Normal file
File diff suppressed because it is too large
Load Diff
1747
runtime/internal/clite/syscall/zerrors_linux_s390x.go
Normal file
1747
runtime/internal/clite/syscall/zerrors_linux_s390x.go
Normal file
File diff suppressed because it is too large
Load Diff
1575
runtime/internal/clite/syscall/zerrors_netbsd_386.go
Normal file
1575
runtime/internal/clite/syscall/zerrors_netbsd_386.go
Normal file
File diff suppressed because it is too large
Load Diff
1565
runtime/internal/clite/syscall/zerrors_netbsd_amd64.go
Normal file
1565
runtime/internal/clite/syscall/zerrors_netbsd_amd64.go
Normal file
File diff suppressed because it is too large
Load Diff
1551
runtime/internal/clite/syscall/zerrors_netbsd_arm.go
Normal file
1551
runtime/internal/clite/syscall/zerrors_netbsd_arm.go
Normal file
File diff suppressed because it is too large
Load Diff
1565
runtime/internal/clite/syscall/zerrors_netbsd_arm64.go
Normal file
1565
runtime/internal/clite/syscall/zerrors_netbsd_arm64.go
Normal file
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user