Sha256: 15bb793e8f9924369ee78ed80e22150c5da40ee74aa4245126b2550a8643b4aa

Contents?: true

Size: 1.35 KB

Versions: 15

Compression:

Stored size: 1.35 KB

Contents

use std::alloc::{alloc, dealloc, Layout};
use std::os::raw::{c_int, c_void};

#[no_mangle]
pub extern "C" fn rust_zstd_wasm_shim_malloc(size: usize) -> *mut c_void {
    unsafe {
        let layout = Layout::from_size_align_unchecked(size, 1);
        alloc(layout).cast()
    }
}

#[no_mangle]
pub extern "C" fn rust_zstd_wasm_shim_calloc(
    nmemb: usize,
    size: usize,
) -> *mut c_void {
    unsafe {
        let layout = Layout::from_size_align_unchecked(size * nmemb, 1);
        alloc(layout).cast()
    }
}

#[no_mangle]
pub unsafe extern "C" fn rust_zstd_wasm_shim_free(ptr: *mut c_void) {
    // layout is not actually used
    let layout = Layout::from_size_align_unchecked(1, 1);
    dealloc(ptr.cast(), layout);
}

#[no_mangle]
pub unsafe extern "C" fn rust_zstd_wasm_shim_memcpy(
    dest: *mut c_void,
    src: *const c_void,
    n: usize,
) -> *mut c_void {
    std::ptr::copy_nonoverlapping(src as *const u8, dest as *mut u8, n);
    dest
}

#[no_mangle]
pub unsafe extern "C" fn rust_zstd_wasm_shim_memmove(
    dest: *mut c_void,
    src: *const c_void,
    n: usize,
) -> *mut c_void {
    std::ptr::copy(src as *const u8, dest as *mut u8, n);
    dest
}

#[no_mangle]
pub unsafe extern "C" fn rust_zstd_wasm_shim_memset(
    dest: *mut c_void,
    c: c_int,
    n: usize,
) -> *mut c_void {
    std::ptr::write_bytes(dest as *mut u8, c as u8, n);
    dest
}

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
wasmtime-13.0.0 ./ext/cargo-vendor/zstd-sys-2.0.8+zstd.1.5.5/src/wasm_shim.rs
wasmtime-12.0.1 ./ext/cargo-vendor/zstd-sys-2.0.8+zstd.1.5.5/src/wasm_shim.rs
wasmtime-12.0.0 ./ext/cargo-vendor/zstd-sys-2.0.8+zstd.1.5.5/src/wasm_shim.rs
wasmtime-11.0.0 ./ext/cargo-vendor/zstd-sys-2.0.8+zstd.1.5.5/src/wasm_shim.rs
wasmtime-10.0.1 ./ext/cargo-vendor/zstd-sys-2.0.8+zstd.1.5.5/src/wasm_shim.rs
wasmtime-10.0.0 ./ext/cargo-vendor/zstd-sys-2.0.8+zstd.1.5.5/src/wasm_shim.rs
wasmtime-9.0.4 ./ext/cargo-vendor/zstd-sys-2.0.8+zstd.1.5.5/src/wasm_shim.rs
wasmtime-9.0.1 ./ext/cargo-vendor/zstd-sys-2.0.8+zstd.1.5.5/src/wasm_shim.rs
wasmtime-8.0.0 ./ext/cargo-vendor/zstd-sys-2.0.8+zstd.1.5.5/src/wasm_shim.rs
wasmtime-7.0.0 ./ext/cargo-vendor/zstd-sys-2.0.7+zstd.1.5.4/src/wasm_shim.rs
wasmtime-6.0.1 ./ext/cargo-vendor/zstd-sys-2.0.7+zstd.1.5.4/src/wasm_shim.rs
wasmtime-6.0.0 ./ext/cargo-vendor/zstd-sys-2.0.7+zstd.1.5.4/src/wasm_shim.rs
wasmtime-5.0.0 ./ext/cargo-vendor/zstd-sys-2.0.5+zstd.1.5.2/src/wasm_shim.rs
wasmtime-0.4.1 ./ext/cargo-vendor/zstd-sys-2.0.4+zstd.1.5.2/src/wasm_shim.rs
wasmtime-0.4.0 ./ext/cargo-vendor/zstd-sys-2.0.4+zstd.1.5.2/src/wasm_shim.rs