diff options
Diffstat (limited to 'vendor/codeberg.org')
-rw-r--r-- | vendor/codeberg.org/gruf/go-ffmpreg/embed/ffmpeg/ffmpeg.wasm | bin | 13760061 -> 15504215 bytes | |||
-rw-r--r-- | vendor/codeberg.org/gruf/go-ffmpreg/embed/ffprobe/ffprobe.wasm | bin | 13672019 -> 15415068 bytes | |||
-rw-r--r-- | vendor/codeberg.org/gruf/go-ffmpreg/wasm/funcs.go | 74 | ||||
-rw-r--r-- | vendor/codeberg.org/gruf/go-ffmpreg/wasm/run.go (renamed from vendor/codeberg.org/gruf/go-ffmpreg/wasm/instance.go) | 13 | ||||
-rw-r--r-- | vendor/codeberg.org/gruf/go-ffmpreg/wasm/runtime.go | 67 |
5 files changed, 144 insertions, 10 deletions
diff --git a/vendor/codeberg.org/gruf/go-ffmpreg/embed/ffmpeg/ffmpeg.wasm b/vendor/codeberg.org/gruf/go-ffmpreg/embed/ffmpeg/ffmpeg.wasm Binary files differindex e2083fffd..9d1faa3ed 100644 --- a/vendor/codeberg.org/gruf/go-ffmpreg/embed/ffmpeg/ffmpeg.wasm +++ b/vendor/codeberg.org/gruf/go-ffmpreg/embed/ffmpeg/ffmpeg.wasm diff --git a/vendor/codeberg.org/gruf/go-ffmpreg/embed/ffprobe/ffprobe.wasm b/vendor/codeberg.org/gruf/go-ffmpreg/embed/ffprobe/ffprobe.wasm Binary files differindex b460fa0f9..0094c53f4 100644 --- a/vendor/codeberg.org/gruf/go-ffmpreg/embed/ffprobe/ffprobe.wasm +++ b/vendor/codeberg.org/gruf/go-ffmpreg/embed/ffprobe/ffprobe.wasm diff --git a/vendor/codeberg.org/gruf/go-ffmpreg/wasm/funcs.go b/vendor/codeberg.org/gruf/go-ffmpreg/wasm/funcs.go new file mode 100644 index 000000000..a809ff120 --- /dev/null +++ b/vendor/codeberg.org/gruf/go-ffmpreg/wasm/funcs.go @@ -0,0 +1,74 @@ +package wasm + +import ( + "context" + + "github.com/tetratelabs/wazero/api" + "github.com/tetratelabs/wazero/experimental" +) + +type snapshotskey struct{} + +// 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 { + snapshots := make(map[uint32]experimental.Snapshot, 10) + ctx = experimental.WithSnapshotter(ctx) + ctx = context.WithValue(ctx, snapshotskey{}, snapshots) + return ctx +} + +func getSnapshots(ctx context.Context) map[uint32]experimental.Snapshot { + v, _ := ctx.Value(snapshotskey{}).(map[uint32]experimental.Snapshot) + return v +} + +// setjmp implements the C function: setjmp(env jmp_buf) +func setjmp(ctx context.Context, mod 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) + if snapshots == nil { + panic("setjmp / longjmp not supported") + } + + // Set latest snapshot in map. + snapshots[envptr] = snapshot + + // Set return. + stack[0] = 0 +} + +// longjmp implements the C function: int longjmp(env jmp_buf, value int) +func longjmp(ctx context.Context, mod 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[envptr] + if snapshot == nil { + panic("must first call setjmp") + } + + // 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/instance.go b/vendor/codeberg.org/gruf/go-ffmpreg/wasm/run.go index d2eccd9e9..62ce2bc25 100644 --- a/vendor/codeberg.org/gruf/go-ffmpreg/wasm/instance.go +++ b/vendor/codeberg.org/gruf/go-ffmpreg/wasm/run.go @@ -6,19 +6,9 @@ import ( "unsafe" "github.com/tetratelabs/wazero" - "github.com/tetratelabs/wazero/api" "github.com/tetratelabs/wazero/sys" ) -// 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 - // Args encompasses a common set of // configuration options often passed to // wazero.Runtime on module instantiation. @@ -64,6 +54,9 @@ func Run( 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) diff --git a/vendor/codeberg.org/gruf/go-ffmpreg/wasm/runtime.go b/vendor/codeberg.org/gruf/go-ffmpreg/wasm/runtime.go new file mode 100644 index 000000000..328a26193 --- /dev/null +++ b/vendor/codeberg.org/gruf/go-ffmpreg/wasm/runtime.go @@ -0,0 +1,67 @@ +package wasm + +import ( + "context" + + "github.com/tetratelabs/wazero" + "github.com/tetratelabs/wazero/api" + "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 + +// 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) + + // 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.ValueType{api.ValueTypeI32}, + ).Export("setjmp") + + // Register longjmp host function. + env = env.NewFunctionBuilder(). + WithGoModuleFunction( + api.GoModuleFunc(longjmp), + []api.ValueType{api.ValueTypeI32, api.ValueTypeI32}, + []api.ValueType{}, + ).Export("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 +} |