Skip to content

Commit

Permalink
Try #461:
Browse files Browse the repository at this point in the history
  • Loading branch information
bors[bot] committed May 22, 2019
2 parents 32c2ad1 + 43a2448 commit f3177e2
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Blocks of changes will separated by version increments.

## **[Unreleased]**

- [#461](https://github.com/wasmerio/wasmer/pull/461) Prevent passing negative lengths in various places in the runtime C API
- [#459](https://github.com/wasmerio/wasmer/pull/459) Add monotonic and real time clocks for wasi on windows
- [#447](https://github.com/wasmerio/wasmer/pull/447) Add trace macro (`--features trace`) for more verbose debug statements
- [#451](https://github.com/wasmerio/wasmer/pull/451) Add `--mapdir=src:dest` flag to rename host directories in the guest context
Expand Down
16 changes: 8 additions & 8 deletions lib/runtime-c-api/src/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
value::wasmer_value_tag,
wasmer_byte_array, wasmer_result_t,
};
use libc::{c_int, uint32_t};
use libc::{c_uint, uint32_t};
use std::{ffi::c_void, ptr, slice, sync::Arc};
use wasmer_runtime::Module;
use wasmer_runtime_core::{
Expand Down Expand Up @@ -154,19 +154,19 @@ pub extern "C" fn wasmer_import_descriptors_destroy(
#[no_mangle]
pub unsafe extern "C" fn wasmer_import_descriptors_len(
exports: *mut wasmer_import_descriptors_t,
) -> c_int {
) -> c_uint {
if exports.is_null() {
return 0;
}
(*(exports as *mut NamedImportDescriptors)).0.len() as c_int
(*(exports as *mut NamedImportDescriptors)).0.len() as c_uint
}

/// Gets import descriptor by index
#[allow(clippy::cast_ptr_alignment)]
#[no_mangle]
pub unsafe extern "C" fn wasmer_import_descriptors_get(
import_descriptors: *mut wasmer_import_descriptors_t,
idx: c_int,
idx: c_uint,
) -> *mut wasmer_import_descriptor_t {
if import_descriptors.is_null() {
return ptr::null_mut();
Expand Down Expand Up @@ -244,9 +244,9 @@ pub unsafe extern "C" fn wasmer_import_func_params_arity(
pub unsafe extern "C" fn wasmer_import_func_new(
func: extern "C" fn(data: *mut c_void),
params: *const wasmer_value_tag,
params_len: c_int,
params_len: c_uint,
returns: *const wasmer_value_tag,
returns_len: c_int,
returns_len: c_uint,
) -> *mut wasmer_import_func_t {
let params: &[wasmer_value_tag] = slice::from_raw_parts(params, params_len as usize);
let params: Vec<Type> = params.iter().cloned().map(|x| x.into()).collect();
Expand All @@ -272,7 +272,7 @@ pub unsafe extern "C" fn wasmer_import_func_new(
pub unsafe extern "C" fn wasmer_import_func_params(
func: *const wasmer_import_func_t,
params: *mut wasmer_value_tag,
params_len: c_int,
params_len: c_uint,
) -> wasmer_result_t {
let export = &*(func as *const Export);
if let Export::Function { ref signature, .. } = *export {
Expand Down Expand Up @@ -301,7 +301,7 @@ pub unsafe extern "C" fn wasmer_import_func_params(
pub unsafe extern "C" fn wasmer_import_func_returns(
func: *const wasmer_import_func_t,
returns: *mut wasmer_value_tag,
returns_len: c_int,
returns_len: c_uint,
) -> wasmer_result_t {
let export = &*(func as *const Export);
if let Export::Function { ref signature, .. } = *export {
Expand Down
12 changes: 6 additions & 6 deletions lib/runtime-c-api/wasmer.h
Original file line number Diff line number Diff line change
Expand Up @@ -321,12 +321,12 @@ void wasmer_import_descriptors_destroy(wasmer_import_descriptors_t *import_descr
* Gets import descriptor by index
*/
wasmer_import_descriptor_t *wasmer_import_descriptors_get(wasmer_import_descriptors_t *import_descriptors,
int idx);
unsigned int idx);

/**
* Gets the length of the import descriptors
*/
int wasmer_import_descriptors_len(wasmer_import_descriptors_t *exports);
unsigned int wasmer_import_descriptors_len(wasmer_import_descriptors_t *exports);

/**
* Frees memory for the given Func
Expand All @@ -339,9 +339,9 @@ void wasmer_import_func_destroy(wasmer_import_func_t *func);
*/
wasmer_import_func_t *wasmer_import_func_new(void (*func)(void *data),
const wasmer_value_tag *params,
int params_len,
unsigned int params_len,
const wasmer_value_tag *returns,
int returns_len);
unsigned int returns_len);

/**
* Sets the params buffer to the parameter types of the given wasmer_import_func_t
Expand All @@ -351,7 +351,7 @@ wasmer_import_func_t *wasmer_import_func_new(void (*func)(void *data),
*/
wasmer_result_t wasmer_import_func_params(const wasmer_import_func_t *func,
wasmer_value_tag *params,
int params_len);
unsigned int params_len);

/**
* Sets the result parameter to the arity of the params of the wasmer_import_func_t
Expand All @@ -369,7 +369,7 @@ wasmer_result_t wasmer_import_func_params_arity(const wasmer_import_func_t *func
*/
wasmer_result_t wasmer_import_func_returns(const wasmer_import_func_t *func,
wasmer_value_tag *returns,
int returns_len);
unsigned int returns_len);

/**
* Sets the result parameter to the arity of the returns of the wasmer_import_func_t
Expand Down
13 changes: 7 additions & 6 deletions lib/runtime-c-api/wasmer.hh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <cstdarg>
#include <cstdint>
#include <cstdlib>
#include <new>

enum class wasmer_import_export_kind : uint32_t {
WASM_FUNCTION,
Expand Down Expand Up @@ -260,10 +261,10 @@ void wasmer_import_descriptors_destroy(wasmer_import_descriptors_t *import_descr

/// Gets import descriptor by index
wasmer_import_descriptor_t *wasmer_import_descriptors_get(wasmer_import_descriptors_t *import_descriptors,
int idx);
unsigned int idx);

/// Gets the length of the import descriptors
int wasmer_import_descriptors_len(wasmer_import_descriptors_t *exports);
unsigned int wasmer_import_descriptors_len(wasmer_import_descriptors_t *exports);

/// Frees memory for the given Func
void wasmer_import_func_destroy(wasmer_import_func_t *func);
Expand All @@ -272,17 +273,17 @@ void wasmer_import_func_destroy(wasmer_import_func_t *func);
/// The caller owns the object and should call `wasmer_import_func_destroy` to free it.
wasmer_import_func_t *wasmer_import_func_new(void (*func)(void *data),
const wasmer_value_tag *params,
int params_len,
unsigned int params_len,
const wasmer_value_tag *returns,
int returns_len);
unsigned int returns_len);

/// Sets the params buffer to the parameter types of the given wasmer_import_func_t
/// Returns `wasmer_result_t::WASMER_OK` upon success.
/// Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length`
/// and `wasmer_last_error_message` to get an error message.
wasmer_result_t wasmer_import_func_params(const wasmer_import_func_t *func,
wasmer_value_tag *params,
int params_len);
unsigned int params_len);

/// Sets the result parameter to the arity of the params of the wasmer_import_func_t
/// Returns `wasmer_result_t::WASMER_OK` upon success.
Expand All @@ -296,7 +297,7 @@ wasmer_result_t wasmer_import_func_params_arity(const wasmer_import_func_t *func
/// and `wasmer_last_error_message` to get an error message.
wasmer_result_t wasmer_import_func_returns(const wasmer_import_func_t *func,
wasmer_value_tag *returns,
int returns_len);
unsigned int returns_len);

/// Sets the result parameter to the arity of the returns of the wasmer_import_func_t
/// Returns `wasmer_result_t::WASMER_OK` upon success.
Expand Down

0 comments on commit f3177e2

Please sign in to comment.