Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename evmc_context to evmc_host_context #426

Merged
merged 1 commit into from
Sep 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bindings/go/evmc/evmc.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ static inline enum evmc_set_option_result set_option(struct evmc_instance* insta

struct extended_context
{
struct evmc_context context;
struct evmc_host_context context;
int64_t index;
};

Expand Down
2 changes: 1 addition & 1 deletion bindings/go/evmc/host.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const struct evmc_host_interface evmc_go_host = {
#pragma GCC diagnostic error "-Wconversion"
static inline void go_exported_functions_type_checks()
{
struct evmc_context* context = NULL;
struct evmc_host_context* context = NULL;
evmc_address* address = NULL;
evmc_bytes32 bytes32;
uint8_t* data = NULL;
Expand Down
2 changes: 1 addition & 1 deletion bindings/go/evmc/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ package evmc

struct extended_context
{
struct evmc_context context;
struct evmc_host_context context;
int64_t index;
};

Expand Down
2 changes: 1 addition & 1 deletion bindings/rust/evmc-declare/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ fn build_execute_fn(names: &VMNameSet) -> proc_macro2::TokenStream {
quote! {
extern "C" fn __evmc_execute(
instance: *mut ::evmc_vm::ffi::evmc_instance,
context: *mut ::evmc_vm::ffi::evmc_context,
context: *mut ::evmc_vm::ffi::evmc_host_context,
revision: ::evmc_vm::ffi::evmc_revision,
msg: *const ::evmc_vm::ffi::evmc_message,
code: *const u8,
Expand Down
4 changes: 2 additions & 2 deletions bindings/rust/evmc-vm/src/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ mod tests {
}

unsafe extern "C" fn get_dummy_tx_context(
_context: *mut evmc_sys::evmc_context,
_context: *mut evmc_sys::evmc_host_context,
) -> evmc_sys::evmc_tx_context {
evmc_sys::evmc_tx_context {
tx_gas_price: Uint256::default(),
Expand Down Expand Up @@ -132,7 +132,7 @@ mod tests {
get_block_hash: None,
emit_log: None,
};
let mut backing_context = ::evmc_sys::evmc_context { host: &host };
let mut backing_context = ::evmc_sys::evmc_host_context { host: &host };

let mut context = ExecutionContext::new(&mut backing_context);
let container = EvmcContainer::<TestVm>::new(instance);
Expand Down
43 changes: 22 additions & 21 deletions bindings/rust/evmc-vm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub type ExecutionTxContext = ffi::evmc_tx_context;
/// EVMC context structure. Exposes the EVMC host functions, message data, and transaction context
/// to the executing VM.
pub struct ExecutionContext<'a> {
context: &'a mut ffi::evmc_context,
context: &'a mut ffi::evmc_host_context,
tx_context: ExecutionTxContext,
}

Expand Down Expand Up @@ -194,11 +194,11 @@ impl ExecutionMessage {
}

impl<'a> ExecutionContext<'a> {
pub fn new(_context: &'a mut ffi::evmc_context) -> Self {
pub fn new(_context: &'a mut ffi::evmc_host_context) -> Self {
assert!(_context.host != std::ptr::null());
let _tx_context = unsafe {
assert!((*(_context.host)).get_tx_context.is_some());
(*(_context.host)).get_tx_context.unwrap()(_context as *mut ffi::evmc_context)
(*(_context.host)).get_tx_context.unwrap()(_context as *mut ffi::evmc_host_context)
};

ExecutionContext {
Expand All @@ -217,7 +217,7 @@ impl<'a> ExecutionContext<'a> {
unsafe {
assert!((*self.context.host).account_exists.is_some());
(*self.context.host).account_exists.unwrap()(
self.context as *mut ffi::evmc_context,
self.context as *mut ffi::evmc_host_context,
address as *const Address,
)
}
Expand All @@ -228,7 +228,7 @@ impl<'a> ExecutionContext<'a> {
unsafe {
assert!((*self.context.host).get_storage.is_some());
(*self.context.host).get_storage.unwrap()(
self.context as *mut ffi::evmc_context,
self.context as *mut ffi::evmc_host_context,
address as *const Address,
key as *const Bytes32,
)
Expand All @@ -245,7 +245,7 @@ impl<'a> ExecutionContext<'a> {
unsafe {
assert!((*self.context.host).set_storage.is_some());
(*self.context.host).set_storage.unwrap()(
self.context as *mut ffi::evmc_context,
self.context as *mut ffi::evmc_host_context,
address as *const Address,
key as *const Bytes32,
value as *const Bytes32,
Expand All @@ -258,7 +258,7 @@ impl<'a> ExecutionContext<'a> {
unsafe {
assert!((*self.context.host).get_balance.is_some());
(*self.context.host).get_balance.unwrap()(
self.context as *mut ffi::evmc_context,
self.context as *mut ffi::evmc_host_context,
address as *const Address,
)
}
Expand All @@ -269,7 +269,7 @@ impl<'a> ExecutionContext<'a> {
unsafe {
assert!((*self.context.host).get_code_size.is_some());
(*self.context.host).get_code_size.unwrap()(
self.context as *mut ffi::evmc_context,
self.context as *mut ffi::evmc_host_context,
address as *const Address,
)
}
Expand All @@ -280,7 +280,7 @@ impl<'a> ExecutionContext<'a> {
unsafe {
assert!((*self.context.host).get_code_size.is_some());
(*self.context.host).get_code_hash.unwrap()(
self.context as *mut ffi::evmc_context,
self.context as *mut ffi::evmc_host_context,
address as *const Address,
)
}
Expand All @@ -291,7 +291,7 @@ impl<'a> ExecutionContext<'a> {
unsafe {
assert!((*self.context.host).copy_code.is_some());
(*self.context.host).copy_code.unwrap()(
self.context as *mut ffi::evmc_context,
self.context as *mut ffi::evmc_host_context,
address as *const Address,
code_offset,
// FIXME: ensure that alignment of the array elements is OK
Expand All @@ -306,7 +306,7 @@ impl<'a> ExecutionContext<'a> {
unsafe {
assert!((*self.context.host).selfdestruct.is_some());
(*self.context.host).selfdestruct.unwrap()(
self.context as *mut ffi::evmc_context,
self.context as *mut ffi::evmc_host_context,
address as *const Address,
beneficiary as *const Address,
)
Expand Down Expand Up @@ -345,7 +345,7 @@ impl<'a> ExecutionContext<'a> {
unsafe {
assert!((*self.context.host).call.is_some());
(*self.context.host).call.unwrap()(
self.context as *mut ffi::evmc_context,
self.context as *mut ffi::evmc_host_context,
&message as *const ffi::evmc_message,
)
.into()
Expand All @@ -357,7 +357,7 @@ impl<'a> ExecutionContext<'a> {
unsafe {
assert!((*self.context.host).get_block_hash.is_some());
(*self.context.host).get_block_hash.unwrap()(
self.context as *mut ffi::evmc_context,
self.context as *mut ffi::evmc_host_context,
num,
)
}
Expand All @@ -368,7 +368,7 @@ impl<'a> ExecutionContext<'a> {
unsafe {
assert!((*self.context.host).emit_log.is_some());
(*self.context.host).emit_log.unwrap()(
self.context as *mut ffi::evmc_context,
self.context as *mut ffi::evmc_host_context,
address as *const Address,
// FIXME: ensure that alignment of the array elements is OK
data.as_ptr(),
Expand Down Expand Up @@ -749,7 +749,7 @@ mod tests {
}

unsafe extern "C" fn get_dummy_tx_context(
_context: *mut ffi::evmc_context,
_context: *mut ffi::evmc_host_context,
) -> ffi::evmc_tx_context {
ffi::evmc_tx_context {
tx_gas_price: Uint256 { bytes: [0u8; 32] },
Expand All @@ -764,14 +764,14 @@ mod tests {
}

unsafe extern "C" fn get_dummy_code_size(
_context: *mut ffi::evmc_context,
_context: *mut ffi::evmc_host_context,
_addr: *const Address,
) -> usize {
105023 as usize
}

unsafe extern "C" fn execute_call(
_context: *mut ffi::evmc_context,
_context: *mut ffi::evmc_host_context,
_msg: *const ffi::evmc_message,
) -> ffi::evmc_result {
// Some dumb validation for testing.
Expand Down Expand Up @@ -801,8 +801,8 @@ mod tests {
}

// Update these when needed for tests
fn get_dummy_context() -> ffi::evmc_context {
ffi::evmc_context {
fn get_dummy_context() -> ffi::evmc_host_context {
ffi::evmc_host_context {
host: Box::into_raw(Box::new(ffi::evmc_host_interface {
account_exists: None,
get_storage: None,
Expand All @@ -822,7 +822,7 @@ mod tests {

// Helper to safely dispose of the dummy context, and not bring up false positives in the
// sanitizers.
fn dummy_context_dispose(context: ffi::evmc_context) {
fn dummy_context_dispose(context: ffi::evmc_host_context) {
unsafe {
Box::from_raw(context.host as *mut ffi::evmc_host_interface);
}
Expand All @@ -838,7 +838,8 @@ mod tests {

let exe_context = ExecutionContext::new(&mut context_raw);
let a = exe_context.get_tx_context();
let b = unsafe { get_dummy_tx_context(&mut context_raw_copy as *mut ffi::evmc_context) };
let b =
unsafe { get_dummy_tx_context(&mut context_raw_copy as *mut ffi::evmc_host_context) };

assert_eq!(a.block_gas_limit, b.block_gas_limit);
assert_eq!(a.block_timestamp, b.block_timestamp);
Expand Down
4 changes: 2 additions & 2 deletions docs/Host_Guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ allows VMs to query and modify Ethereum state during the execution.
The implementation can be done in object-oriented manner.
The ::evmc_host_interface lists the methods any Host must implement.

Moreover, each of the methods has a pointer to ::evmc_context
Moreover, each of the methods has a pointer to ::evmc_host_context
as a parameter. The context is owned entirely by the Host allowing a Host instance
to behave as an object with data.

Expand All @@ -35,7 +35,7 @@ When Host implementation is ready it's time to start using EVMC VMs.
You will need:
- the code to execute,
- the message (::evmc_message) object that describes the execution context,
- the Host instance, passed as ::evmc_context pointer.
- the Host instance, passed as ::evmc_host_context pointer.

5. When execution finishes you will receive ::evmc_result object that describes
the results of the execution.
Expand Down
2 changes: 1 addition & 1 deletion examples/example.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ int main(int argc, char* argv[])
tx_context.block_number = 42;
tx_context.block_timestamp = 66;
tx_context.block_gas_limit = gas * 2;
struct evmc_context* ctx = example_host_create_context(tx_context);
struct evmc_host_context* ctx = example_host_create_context(tx_context);
struct evmc_message msg;
msg.kind = EVMC_CALL;
msg.sender = addr;
Expand Down
4 changes: 2 additions & 2 deletions examples/example_host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,12 @@ class ExampleHost : public evmc::Host

extern "C" {

evmc_context* example_host_create_context(evmc_tx_context tx_context)
evmc_host_context* example_host_create_context(evmc_tx_context tx_context)
{
return new ExampleHost(tx_context);
}

void example_host_destroy_context(evmc_context* context)
void example_host_destroy_context(evmc_host_context* context)
{
delete static_cast<ExampleHost*>(context);
}
Expand Down
4 changes: 2 additions & 2 deletions examples/example_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
extern "C" {
#endif

struct evmc_context* example_host_create_context(struct evmc_tx_context tx_context);
struct evmc_host_context* example_host_create_context(struct evmc_tx_context tx_context);

void example_host_destroy_context(struct evmc_context* context);
void example_host_destroy_context(struct evmc_host_context* context);

#if __cplusplus
}
Expand Down
2 changes: 1 addition & 1 deletion examples/example_precompiles_vm/example_precompiles_vm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ static evmc_result not_implemented()
}

static evmc_result execute(evmc_instance*,
evmc_context*,
evmc_host_context*,
enum evmc_revision rev,
const evmc_message* msg,
const uint8_t*,
Expand Down
2 changes: 1 addition & 1 deletion examples/example_vm/example_vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ static void free_result_output_data(const struct evmc_result* result)

/// The example implementation of the evmc_instance::execute() method.
static struct evmc_result execute(struct evmc_instance* instance,
struct evmc_context* context,
struct evmc_host_context* context,
enum evmc_revision rev,
const struct evmc_message* msg,
const uint8_t* code,
Expand Down
Loading