Skip to content

Commit

Permalink
Use tracing unconditionally in the wasmer crate
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael-F-Bryan committed Aug 3, 2023
1 parent 5aa9ec1 commit bfa9f39
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 71 deletions.
2 changes: 1 addition & 1 deletion lib/api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ derivative = { version = "^2" }
bytes = "1"
# - Optional shared dependencies.
wat = { version = "1.0", optional = true }
tracing = { version = "0.1", optional = true }
tracing = { version = "0.1" }
rustc-demangle = "0.1"

# Dependencies and Development Dependencies for `sys`.
Expand Down
5 changes: 1 addition & 4 deletions lib/api/src/js/externals/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::MemoryType;
use std::marker::PhantomData;
use std::mem::MaybeUninit;
use std::slice;
#[cfg(feature = "tracing")]

use tracing::warn;

use wasm_bindgen::prelude::*;
Expand Down Expand Up @@ -178,7 +178,6 @@ impl<'a> MemoryBuffer<'a> {
.ok_or(MemoryAccessError::Overflow)?;
let view = unsafe { &*(self.base) };
if end > view.length().into() {
#[cfg(feature = "tracing")]
warn!(
"attempted to read ({} bytes) beyond the bounds of the memory view ({} > {})",
buf.len(),
Expand All @@ -202,7 +201,6 @@ impl<'a> MemoryBuffer<'a> {
.ok_or(MemoryAccessError::Overflow)?;
let view = unsafe { &*(self.base) };
if end > view.length().into() {
#[cfg(feature = "tracing")]
warn!(
"attempted to read ({} bytes) beyond the bounds of the memory view ({} > {})",
buf.len(),
Expand All @@ -224,7 +222,6 @@ impl<'a> MemoryBuffer<'a> {
.ok_or(MemoryAccessError::Overflow)?;
let view = unsafe { &mut *(self.base) };
if end > view.length().into() {
#[cfg(feature = "tracing")]
warn!(
"attempted to write ({} bytes) beyond the bounds of the memory view ({} > {})",
data.len(),
Expand Down
21 changes: 7 additions & 14 deletions lib/api/src/js/externals/memory_view.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
use crate::mem_access::MemoryAccessError;
use crate::store::AsStoreRef;
use std::convert::TryInto;
use std::marker::PhantomData;
use std::mem::MaybeUninit;
use std::slice;
#[cfg(feature = "tracing")]
use std::{convert::TryInto, marker::PhantomData, mem::MaybeUninit, slice};

use tracing::warn;
use wasm_bindgen::JsCast;

use wasmer_types::{Bytes, Pages};

use super::memory::{Memory, MemoryBuffer};
use crate::{
js::externals::memory::{Memory, MemoryBuffer},
mem_access::MemoryAccessError,
store::AsStoreRef,
};

/// A WebAssembly `memory` view.
///
Expand Down Expand Up @@ -128,7 +126,6 @@ impl<'a> MemoryView<'a> {
.map_err(|_| MemoryAccessError::Overflow)?;
let end = offset.checked_add(len).ok_or(MemoryAccessError::Overflow)?;
if end > view.length() {
#[cfg(feature = "tracing")]
warn!(
"attempted to read ({} bytes) beyond the bounds of the memory view ({} > {})",
len,
Expand All @@ -149,7 +146,6 @@ impl<'a> MemoryView<'a> {
let view = &self.view;
let offset: u32 = offset.try_into().map_err(|_| MemoryAccessError::Overflow)?;
if offset >= view.length() {
#[cfg(feature = "tracing")]
warn!(
"attempted to read beyond the bounds of the memory view ({} >= {})",
offset,
Expand Down Expand Up @@ -183,7 +179,6 @@ impl<'a> MemoryView<'a> {
.map_err(|_| MemoryAccessError::Overflow)?;
let end = offset.checked_add(len).ok_or(MemoryAccessError::Overflow)?;
if end > view.length() {
#[cfg(feature = "tracing")]
warn!(
"attempted to read ({} bytes) beyond the bounds of the memory view ({} > {})",
len,
Expand Down Expand Up @@ -220,7 +215,6 @@ impl<'a> MemoryView<'a> {
let view = &self.view;
let end = offset.checked_add(len).ok_or(MemoryAccessError::Overflow)?;
if end > view.length() {
#[cfg(feature = "tracing")]
warn!(
"attempted to write ({} bytes) beyond the bounds of the memory view ({} > {})",
len,
Expand All @@ -241,7 +235,6 @@ impl<'a> MemoryView<'a> {
let view = &self.view;
let offset: u32 = offset.try_into().map_err(|_| MemoryAccessError::Overflow)?;
if offset >= view.length() {
#[cfg(feature = "tracing")]
warn!(
"attempted to write beyond the bounds of the memory view ({} >= {})",
offset,
Expand Down
6 changes: 2 additions & 4 deletions lib/api/src/js/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use crate::{AsEngineRef, ExportType, ImportType};
use bytes::Bytes;
use js_sys::{Reflect, Uint8Array, WebAssembly};
use std::path::Path;
#[cfg(feature = "tracing")]
use tracing::{debug, warn};
use wasm_bindgen::JsValue;
use wasmer_types::{
Expand Down Expand Up @@ -155,10 +154,8 @@ impl Module {
#[allow(unused_variables)]
if let wasmer_types::ExternType::Memory(mem_ty) = import_type.ty() {
if resolved_import.is_some() {
#[cfg(feature = "tracing")]
debug!("imported shared memory {:?}", &mem_ty);
} else {
#[cfg(feature = "tracing")]
warn!(
"Error while importing {0:?}.{1:?}: memory. Expected {2:?}",
import_type.module(),
Expand Down Expand Up @@ -195,7 +192,6 @@ impl Module {
}
import_externs.push(import);
} else {
#[cfg(feature = "tracing")]
warn!(
"import not found {}:{}",
import_type.module(),
Expand Down Expand Up @@ -227,6 +223,7 @@ impl Module {
));
}

#[tracing::instrument(level = "debug", skip_all)]
pub unsafe fn deserialize_unchecked(
_engine: &impl AsEngineRef,
_bytes: impl IntoBytes,
Expand All @@ -239,6 +236,7 @@ impl Module {
return Err(DeserializeError::Generic("You need to enable the `js-serializable-module` feature flag to deserialize a `Module`".to_string()));
}

#[tracing::instrument(level = "debug", skip_all)]
pub unsafe fn deserialize(
_engine: &impl AsEngineRef,
_bytes: impl IntoBytes,
Expand Down
20 changes: 9 additions & 11 deletions lib/api/src/js/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@
/// This module should not be needed any longer (with the exception of the memory)
/// once the type reflection is added to the WebAssembly JS API.
/// https://github.com/WebAssembly/js-types/
use crate::js::wasm_bindgen_polyfill::Global as JsGlobal;
use js_sys::Function as JsFunction;
use js_sys::WebAssembly;
use js_sys::WebAssembly::{Memory as JsMemory, Table as JsTable};
use std::{any::Any, fmt};

use js_sys::{
Function as JsFunction,
WebAssembly::{self, Memory as JsMemory, Table as JsTable},
};
use serde::{Deserialize, Serialize};
use std::any::Any;
use std::fmt;
#[cfg(feature = "tracing")]
use tracing::trace;
use wasm_bindgen::{JsCast, JsValue};
use wasmer_types::RawValue;
use wasmer_types::{
FunctionType, GlobalType, MemoryError, MemoryType, Pages, TableType, WASM_PAGE_SIZE,
FunctionType, GlobalType, MemoryError, MemoryType, Pages, RawValue, TableType, WASM_PAGE_SIZE,
};

use crate::js::wasm_bindgen_polyfill::Global as JsGlobal;

/// Represents linear memory that is managed by the javascript runtime
#[derive(Clone, Debug, PartialEq)]
pub struct VMMemory {
Expand Down Expand Up @@ -71,7 +71,6 @@ impl VMMemory {
let src = crate::js::externals::memory_view::MemoryView::new_raw(&self.memory);
let amount = src.data_size() as usize;

#[cfg(feature = "tracing")]
trace!(%amount, "memory copy started");

let mut dst = crate::js::externals::memory_view::MemoryView::new_raw(&new_memory);
Expand Down Expand Up @@ -102,7 +101,6 @@ impl VMMemory {
wasmer_types::MemoryError::Generic(format!("failed to copy the memory - {}", err))
})?;

#[cfg(feature = "tracing")]
trace!("memory copy finished (size={})", dst.size().bytes().0);

Ok(Self {
Expand Down
5 changes: 1 addition & 4 deletions lib/api/src/jsc/externals/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::convert::TryInto;
use std::marker::PhantomData;
use std::mem::{self, MaybeUninit};
use std::slice;
#[cfg(feature = "tracing")]

use tracing::warn;

use wasmer_types::{Pages, WASM_PAGE_SIZE};
Expand Down Expand Up @@ -215,7 +215,6 @@ impl<'a> MemoryBuffer<'a> {
.checked_add(buf.len() as u64)
.ok_or(MemoryAccessError::Overflow)?;
if end > self.len.try_into().unwrap() {
#[cfg(feature = "tracing")]
warn!(
"attempted to read ({} bytes) beyond the bounds of the memory view ({} > {})",
buf.len(),
Expand All @@ -239,7 +238,6 @@ impl<'a> MemoryBuffer<'a> {
.checked_add(buf.len() as u64)
.ok_or(MemoryAccessError::Overflow)?;
if end > self.len.try_into().unwrap() {
#[cfg(feature = "tracing")]
warn!(
"attempted to read ({} bytes) beyond the bounds of the memory view ({} > {})",
buf.len(),
Expand All @@ -261,7 +259,6 @@ impl<'a> MemoryBuffer<'a> {
.checked_add(data.len() as u64)
.ok_or(MemoryAccessError::Overflow)?;
if end > self.len.try_into().unwrap() {
#[cfg(feature = "tracing")]
warn!(
"attempted to write ({} bytes) beyond the bounds of the memory view ({} > {})",
data.len(),
Expand Down
2 changes: 0 additions & 2 deletions lib/api/src/jsc/mem_access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ where
.checked_add(total_len)
.ok_or(MemoryAccessError::Overflow)?;
if end > slice.buffer.0.len as u64 {
#[cfg(feature = "tracing")]
warn!(
"attempted to read ({} bytes) beyond the bounds of the memory view ({} > {})",
total_len, end, slice.buffer.0.len
Expand Down Expand Up @@ -46,7 +45,6 @@ where
.checked_add(total_len)
.ok_or(MemoryAccessError::Overflow)?;
if end > ptr.buffer.0.len as u64 {
#[cfg(feature = "tracing")]
warn!(
"attempted to read ({} bytes) beyond the bounds of the memory view ({} > {})",
total_len, end, ptr.buffer.0.len
Expand Down
2 changes: 0 additions & 2 deletions lib/api/src/jsc/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use crate::{AsEngineRef, ExportType, ImportType};
use bytes::Bytes;
use rusty_jsc::{JSObject, JSString, JSValue};
use std::path::Path;
#[cfg(feature = "tracing")]
use tracing::{debug, warn};
use wasmer_types::{
CompileError, DeserializeError, ExportsIterator, ExternType, FunctionType, GlobalType,
Expand Down Expand Up @@ -154,7 +153,6 @@ impl Module {
.unwrap();
}
} else {
#[cfg(feature = "tracing")]
warn!(
"import not found {}:{}",
import_type.module(),
Expand Down
3 changes: 0 additions & 3 deletions lib/api/src/jsc/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use crate::store::AsStoreRef;
use rusty_jsc::{JSObject, JSObjectCallAsFunctionCallback, JSValue};
use std::any::Any;
use std::fmt;
#[cfg(feature = "tracing")]
use tracing::trace;
use wasmer_types::RawValue;
use wasmer_types::{
Expand Down Expand Up @@ -63,7 +62,6 @@ impl VMMemory {
let new_memory =
crate::jsc::externals::memory::Memory::js_memory_from_type(&store, &self.ty)?;

#[cfg(feature = "tracing")]
trace!("memory copy started");

let src = crate::jsc::externals::memory_view::MemoryView::new_raw(&self.memory, store);
Expand Down Expand Up @@ -96,7 +94,6 @@ impl VMMemory {
wasmer_types::MemoryError::Generic(format!("failed to copy the memory - {}", err))
})?;

#[cfg(feature = "tracing")]
trace!("memory copy finished (size={})", dst.size().bytes().0);

Ok(Self {
Expand Down
29 changes: 14 additions & 15 deletions lib/api/src/sys/externals/memory.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
use super::memory_view::MemoryView;
use crate::store::{AsStoreMut, AsStoreRef};
use crate::sys::engine::NativeEngineExt;
use crate::vm::VMExternMemory;
use crate::MemoryAccessError;
use crate::MemoryType;
use std::convert::TryInto;
use std::marker::PhantomData;
use std::mem;
use std::mem::MaybeUninit;
use std::slice;
#[cfg(feature = "tracing")]
use std::{
convert::TryInto,
marker::PhantomData,
mem::{self, MaybeUninit},
slice,
};

use tracing::warn;
use wasmer_types::Pages;
use wasmer_vm::{LinearMemory, MemoryError, StoreHandle, VMExtern, VMMemory};

use crate::{
store::{AsStoreMut, AsStoreRef},
sys::{engine::NativeEngineExt, externals::memory_view::MemoryView},
vm::VMExternMemory,
MemoryAccessError, MemoryType,
};

#[derive(Debug, Clone)]
pub struct Memory {
pub(crate) handle: StoreHandle<VMMemory>,
Expand Down Expand Up @@ -110,7 +112,6 @@ impl<'a> MemoryBuffer<'a> {
.checked_add(buf.len() as u64)
.ok_or(MemoryAccessError::Overflow)?;
if end > self.len.try_into().unwrap() {
#[cfg(feature = "tracing")]
warn!(
"attempted to read ({} bytes) beyond the bounds of the memory view ({} > {})",
buf.len(),
Expand All @@ -134,7 +135,6 @@ impl<'a> MemoryBuffer<'a> {
.checked_add(buf.len() as u64)
.ok_or(MemoryAccessError::Overflow)?;
if end > self.len.try_into().unwrap() {
#[cfg(feature = "tracing")]
warn!(
"attempted to read ({} bytes) beyond the bounds of the memory view ({} > {})",
buf.len(),
Expand All @@ -156,7 +156,6 @@ impl<'a> MemoryBuffer<'a> {
.checked_add(data.len() as u64)
.ok_or(MemoryAccessError::Overflow)?;
if end > self.len.try_into().unwrap() {
#[cfg(feature = "tracing")]
warn!(
"attempted to write ({} bytes) beyond the bounds of the memory view ({} > {})",
data.len(),
Expand Down
9 changes: 5 additions & 4 deletions lib/api/src/sys/mem_access.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use crate::access::{RefCow, SliceCow, WasmRefAccess, WasmSliceAccess};
use crate::{MemoryAccessError, WasmRef, WasmSlice};
use std::mem;

use crate::{
access::{RefCow, SliceCow, WasmRefAccess, WasmSliceAccess},
MemoryAccessError, WasmRef, WasmSlice,
};

impl<'a, T> WasmSliceAccess<'a, T>
where
T: wasmer_types::ValueType,
Expand All @@ -16,7 +19,6 @@ where
.checked_add(total_len)
.ok_or(MemoryAccessError::Overflow)?;
if end > slice.buffer.0.len as u64 {
#[cfg(feature = "tracing")]
tracing::warn!(
"attempted to read ({} bytes) beyond the bounds of the memory view ({} > {})",
total_len,
Expand Down Expand Up @@ -48,7 +50,6 @@ where
.checked_add(total_len)
.ok_or(MemoryAccessError::Overflow)?;
if end > ptr.buffer.0.len as u64 {
#[cfg(feature = "tracing")]
tracing::warn!(
"attempted to read ({} bytes) beyond the bounds of the memory view ({} > {})",
total_len,
Expand Down
Loading

0 comments on commit bfa9f39

Please sign in to comment.