summaryrefslogtreecommitdiff
path: root/vendor/codeberg.org/gruf/go-ffmpreg/wasm
diff options
context:
space:
mode:
authorLibravatar Terin Stock <terinjokes@gmail.com>2025-03-09 17:47:56 +0100
committerLibravatar Terin Stock <terinjokes@gmail.com>2025-12-01 22:08:04 +0100
commitb1af8fd87760b34e3ff2fd3bda38f211815a0473 (patch)
tree9317fad1a7ec298d7a8d2678e4e422953bbc6f33 /vendor/codeberg.org/gruf/go-ffmpreg/wasm
parent[chore] update URLs to forked source (diff)
downloadgotosocial-b1af8fd87760b34e3ff2fd3bda38f211815a0473.tar.xz
[chore] remove vendor
Diffstat (limited to 'vendor/codeberg.org/gruf/go-ffmpreg/wasm')
-rw-r--r--vendor/codeberg.org/gruf/go-ffmpreg/wasm/funcs.go139
-rw-r--r--vendor/codeberg.org/gruf/go-ffmpreg/wasm/run.go88
-rw-r--r--vendor/codeberg.org/gruf/go-ffmpreg/wasm/runtime.go70
3 files changed, 0 insertions, 297 deletions
diff --git a/vendor/codeberg.org/gruf/go-ffmpreg/wasm/funcs.go b/vendor/codeberg.org/gruf/go-ffmpreg/wasm/funcs.go
deleted file mode 100644
index a0a199ca1..000000000
--- a/vendor/codeberg.org/gruf/go-ffmpreg/wasm/funcs.go
+++ /dev/null
@@ -1,139 +0,0 @@
-package wasm
-
-import (
- "context"
-
- "github.com/tetratelabs/wazero/api"
- "github.com/tetratelabs/wazero/experimental"
-)
-
-type snapshotskey struct{}
-
-type snapshotctx struct {
- context.Context
- snaps *snapshots
-}
-
-func (ctx snapshotctx) Value(key any) any {
- if _, ok := key.(snapshotskey); ok {
- return ctx.snaps
- }
- return ctx.Context.Value(key)
-}
-
-const ringsz uint = 8
-
-type snapshots struct {
- r [ringsz]struct {
- eptr uint32
- snap experimental.Snapshot
- }
- n uint
-}
-
-func (s *snapshots) get(envptr uint32) experimental.Snapshot {
- start := (s.n % ringsz)
-
- for i := start; i != ^uint(0); i-- {
- if s.r[i].eptr == envptr {
- snap := s.r[i].snap
- s.r[i].eptr = 0
- s.r[i].snap = nil
- s.n = i - 1
- return snap
- }
- }
-
- for i := ringsz - 1; i > start; i-- {
- if s.r[i].eptr == envptr {
- snap := s.r[i].snap
- s.r[i].eptr = 0
- s.r[i].snap = nil
- s.n = i - 1
- return snap
- }
- }
-
- panic("snapshot not found")
-}
-
-func (s *snapshots) set(envptr uint32, snapshot experimental.Snapshot) {
- start := (s.n % ringsz)
-
- for i := start; i < ringsz; i++ {
- switch s.r[i].eptr {
- case 0, envptr:
- s.r[i].eptr = envptr
- s.r[i].snap = snapshot
- s.n = i
- return
- }
- }
-
- for i := uint(0); i < start; i++ {
- switch s.r[i].eptr {
- case 0, envptr:
- s.r[i].eptr = envptr
- s.r[i].snap = snapshot
- s.n = i
- return
- }
- }
-
- panic("snapshots full")
-}
-
-// withSetjmpLongjmp updates the context to contain wazero/experimental.Snapshotter{} support,
-// and embeds the necessary snapshots map required for later calls to Setjmp() / Longjmp().
-func withSetjmpLongjmp(ctx context.Context) context.Context {
- return snapshotctx{Context: experimental.WithSnapshotter(ctx), snaps: new(snapshots)}
-}
-
-func getSnapshots(ctx context.Context) *snapshots {
- v, _ := ctx.Value(snapshotskey{}).(*snapshots)
- return v
-}
-
-// setjmp implements the C function: setjmp(env jmp_buf)
-func setjmp(ctx context.Context, _ api.Module, stack []uint64) {
-
- // Input arguments.
- envptr := api.DecodeU32(stack[0])
-
- // Take snapshot of current execution environment.
- snapshotter := experimental.GetSnapshotter(ctx)
- snapshot := snapshotter.Snapshot()
-
- // Get stored snapshots map.
- snapshots := getSnapshots(ctx)
-
- // Set latest snapshot in map.
- snapshots.set(envptr, snapshot)
-
- // Set return.
- stack[0] = 0
-}
-
-// longjmp implements the C function: int longjmp(env jmp_buf, value int)
-func longjmp(ctx context.Context, _ api.Module, stack []uint64) {
-
- // Input arguments.
- envptr := api.DecodeU32(stack[0])
- // val := stack[1]
-
- // Get stored snapshots map.
- snapshots := getSnapshots(ctx)
- if snapshots == nil {
- panic("setjmp / longjmp not supported")
- }
-
- // Get snapshot stored in map.
- snapshot := snapshots.get(envptr)
-
- // Set return.
- stack[0] = 0
-
- // Restore execution and
- // return passed value arg.
- snapshot.Restore(stack[1:])
-}
diff --git a/vendor/codeberg.org/gruf/go-ffmpreg/wasm/run.go b/vendor/codeberg.org/gruf/go-ffmpreg/wasm/run.go
deleted file mode 100644
index c247abaf0..000000000
--- a/vendor/codeberg.org/gruf/go-ffmpreg/wasm/run.go
+++ /dev/null
@@ -1,88 +0,0 @@
-package wasm
-
-import (
- "context"
- "io"
- "unsafe"
-
- "github.com/tetratelabs/wazero"
- "github.com/tetratelabs/wazero/sys"
-)
-
-// Args encompasses a common set of
-// configuration options often passed to
-// wazero.Runtime on module instantiation.
-type Args struct {
-
- // Program name, depending on the
- // module being run this may or may
- // not be necessary.
- Name string
-
- // Optional further module configuration function.
- // (e.g. to mount filesystem dir, set env vars, etc).
- Config func(wazero.ModuleConfig) wazero.ModuleConfig
-
- // Standard FDs.
- Stdin io.Reader
- Stdout io.Writer
- Stderr io.Writer
-
- // CLI args.
- Args []string
-}
-
-// Run will run given compiled WebAssembly module
-// within the given runtime, with given arguments.
-// Returns the exit code, or error.
-func Run(
- ctx context.Context,
- runtime wazero.Runtime,
- module wazero.CompiledModule,
- args Args,
-) (rc uint32, err error) {
-
- // Prefix arguments with module name.
- cargs := make([]string, len(args.Args)+1)
- cargs[0] = args.Name
- copy(cargs[1:], args.Args)
-
- // Prepare new module configuration.
- modcfg := wazero.NewModuleConfig()
- modcfg = modcfg.WithArgs(cargs...)
- modcfg = modcfg.WithStdin(args.Stdin)
- modcfg = modcfg.WithStdout(args.Stdout)
- modcfg = modcfg.WithStderr(args.Stderr)
- modcfg = modcfg.WithName("")
-
- if args.Config != nil {
- // Pass through config fn.
- modcfg = args.Config(modcfg)
- }
-
- // Enable setjmp longjmp.
- ctx = withSetjmpLongjmp(ctx)
-
- // Instantiate the module from precompiled wasm module data.
- mod, err := runtime.InstantiateModule(ctx, module, modcfg)
-
- if !isNil(mod) {
- // Ensure closed.
- _ = mod.Close(ctx)
- }
-
- // Try extract exit code.
- switch err := err.(type) {
- case *sys.ExitError:
- return err.ExitCode(), nil
- default:
- return 0, err
- }
-}
-
-// isNil will safely check if 'v' is nil without
-// dealing with weird Go interface nil bullshit.
-func isNil(i interface{}) bool {
- type eface struct{ Type, Data unsafe.Pointer }
- return (*(*eface)(unsafe.Pointer(&i))).Data == nil
-}
diff --git a/vendor/codeberg.org/gruf/go-ffmpreg/wasm/runtime.go b/vendor/codeberg.org/gruf/go-ffmpreg/wasm/runtime.go
deleted file mode 100644
index 048486ee4..000000000
--- a/vendor/codeberg.org/gruf/go-ffmpreg/wasm/runtime.go
+++ /dev/null
@@ -1,70 +0,0 @@
-package wasm
-
-import (
- "context"
-
- "github.com/tetratelabs/wazero"
- "github.com/tetratelabs/wazero/api"
- "github.com/tetratelabs/wazero/experimental"
- "github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1"
-)
-
-// CoreFeatures are the WebAssembly Core specification
-// features our embedded binaries are compiled with.
-const CoreFeatures = api.CoreFeatureSIMD |
- api.CoreFeatureBulkMemoryOperations |
- api.CoreFeatureNonTrappingFloatToIntConversion |
- api.CoreFeatureMutableGlobal |
- api.CoreFeatureReferenceTypes |
- api.CoreFeatureSignExtensionOps |
- experimental.CoreFeaturesTailCall
-
-// NewRuntime returns a new WebAssembly wazero.Runtime compatible with go-ffmpreg.
-func NewRuntime(ctx context.Context, cfg wazero.RuntimeConfig) (wazero.Runtime, error) {
- var err error
-
- if cfg == nil {
- // Ensure runtime config is set.
- cfg = wazero.NewRuntimeConfig()
- }
-
- // Set core features ffmpeg compiled with.
- cfg = cfg.WithCoreFeatures(CoreFeatures)
- cfg = cfg.WithDebugInfoEnabled(false)
-
- // Instantiate runtime with prepared config.
- rt := wazero.NewRuntimeWithConfig(ctx, cfg)
-
- // Prepare default "env" host module.
- env := rt.NewHostModuleBuilder("env")
-
- // Register setjmp host function.
- env = env.NewFunctionBuilder().
- WithGoModuleFunction(
- api.GoModuleFunc(setjmp),
- []api.ValueType{api.ValueTypeI32, api.ValueTypeI32, api.ValueTypeI32},
- []api.ValueType{},
- ).Export("__wasm_setjmp")
-
- // Register longjmp host function.
- env = env.NewFunctionBuilder().
- WithGoModuleFunction(
- api.GoModuleFunc(longjmp),
- []api.ValueType{api.ValueTypeI32, api.ValueTypeI32},
- []api.ValueType{},
- ).Export("__wasm_longjmp")
-
- // Instantiate "env" module.
- _, err = env.Instantiate(ctx)
- if err != nil {
- return nil, err
- }
-
- // Instantiate the wasi snapshot preview 1 in runtime.
- _, err = wasi_snapshot_preview1.Instantiate(ctx, rt)
- if err != nil {
- return nil, err
- }
-
- return rt, nil
-}