mirror of https://github.com/status-im/evmc.git
Merge pull request #101 from ethereum/evmc
EVM-C: Attach result_release function to the result itself
This commit is contained in:
commit
bdbfe79001
|
@ -93,6 +93,6 @@ int main(int argc, char *argv[]) {
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
intf.release_result(&result);
|
result.release(&result);
|
||||||
intf.destroy(jit);
|
intf.destroy(jit);
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,6 +40,10 @@ int evm_set_option(struct evm_instance* evm,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void evm_release_result(struct evm_result const* result)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
static struct evm_result evm_execute(struct evm_instance* instance,
|
static struct evm_result evm_execute(struct evm_instance* instance,
|
||||||
struct evm_env* env,
|
struct evm_env* env,
|
||||||
enum evm_mode mode,
|
enum evm_mode mode,
|
||||||
|
@ -57,16 +61,13 @@ static struct evm_result evm_execute(struct evm_instance* instance,
|
||||||
|
|
||||||
// Execute code and refer to callbacks: instance->query_fn()
|
// Execute code and refer to callbacks: instance->query_fn()
|
||||||
|
|
||||||
|
ret.release = evm_release_result;
|
||||||
ret.code = EVM_FAILURE;
|
ret.code = EVM_FAILURE;
|
||||||
ret.gas_left = 0;
|
ret.gas_left = 0;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void evm_release_result(struct evm_result const* result)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
struct evm_interface examplevm_get_interface()
|
struct evm_interface examplevm_get_interface()
|
||||||
{
|
{
|
||||||
struct evm_interface intf;
|
struct evm_interface intf;
|
||||||
|
@ -75,7 +76,6 @@ struct evm_interface examplevm_get_interface()
|
||||||
intf.create = evm_create;
|
intf.create = evm_create;
|
||||||
intf.destroy = evm_destroy;
|
intf.destroy = evm_destroy;
|
||||||
intf.execute = evm_execute;
|
intf.execute = evm_execute;
|
||||||
intf.release_result = evm_release_result;
|
|
||||||
intf.set_option = evm_set_option;
|
intf.set_option = evm_set_option;
|
||||||
return intf;
|
return intf;
|
||||||
}
|
}
|
|
@ -55,6 +55,18 @@ enum evm_result_code {
|
||||||
EVM_STACK_UNDERFLOW = 6,
|
EVM_STACK_UNDERFLOW = 6,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct evm_result;
|
||||||
|
|
||||||
|
/// Releases resources assigned to an execution result.
|
||||||
|
///
|
||||||
|
/// This function releases memory (and other resources, if any) assigned to the
|
||||||
|
/// specified execution result making the result object invalid.
|
||||||
|
///
|
||||||
|
/// @param result The execution result which resource are to be released. The
|
||||||
|
/// result itself it not modified by this function, but becomes
|
||||||
|
/// invalid and user should discard it as well.
|
||||||
|
typedef void (*evm_release_result_fn)(struct evm_result const* result);
|
||||||
|
|
||||||
/// The EVM code execution result.
|
/// The EVM code execution result.
|
||||||
struct evm_result {
|
struct evm_result {
|
||||||
/// The execution result code.
|
/// The execution result code.
|
||||||
|
@ -65,24 +77,44 @@ struct evm_result {
|
||||||
/// The value is valid only if evm_result::code == ::EVM_SUCCESS.
|
/// The value is valid only if evm_result::code == ::EVM_SUCCESS.
|
||||||
int64_t gas_left;
|
int64_t gas_left;
|
||||||
|
|
||||||
/// The reference to output data. The memory containing the output data
|
union
|
||||||
/// is owned by EVM and is freed with evm_release_result_fn().
|
{
|
||||||
uint8_t const* output_data;
|
struct
|
||||||
|
{
|
||||||
|
/// The reference to output data. The memory containing the output
|
||||||
|
/// data is owned by EVM and is freed with evm_result::release().
|
||||||
|
uint8_t const* output_data;
|
||||||
|
|
||||||
/// The size of the output data.
|
/// The size of the output data.
|
||||||
size_t output_size;
|
size_t output_size;
|
||||||
|
};
|
||||||
|
|
||||||
|
/// The address of the successfully created contract.
|
||||||
|
///
|
||||||
|
/// This field has valid value only if the evm_result comes from a
|
||||||
|
/// successful CREATE opcode execution
|
||||||
|
/// (i.e. evm_call_fn(..., EVM_CREATE, ...)).
|
||||||
|
struct evm_uint160be create_address;
|
||||||
|
};
|
||||||
|
|
||||||
|
/// The pointer to the result release implementation.
|
||||||
|
///
|
||||||
|
/// This function pointer must be set by the VM implementation and works
|
||||||
|
/// similary to C++ virtual destructor. Attaching the releaser to the result
|
||||||
|
/// itself allows VM composition.
|
||||||
|
evm_release_result_fn release;
|
||||||
|
|
||||||
/// @name Optional
|
/// @name Optional
|
||||||
/// The optional information that EVM is not required to provide.
|
/// The optional information that EVM is not required to provide.
|
||||||
/// @{
|
/// @{
|
||||||
|
|
||||||
|
/// The error message explaining the result code.
|
||||||
|
char const* error_message;
|
||||||
|
|
||||||
/// The pointer to EVM-owned memory. For EVM internal use.
|
/// The pointer to EVM-owned memory. For EVM internal use.
|
||||||
/// @see output_data.
|
/// @see output_data.
|
||||||
void* internal_memory;
|
void* internal_memory;
|
||||||
|
|
||||||
/// The error message explaining the result code.
|
|
||||||
char const* error_message;
|
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -370,15 +402,6 @@ typedef struct evm_result (*evm_execute_fn)(struct evm_instance* instance,
|
||||||
size_t input_size,
|
size_t input_size,
|
||||||
struct evm_uint256be value);
|
struct evm_uint256be value);
|
||||||
|
|
||||||
/// Releases resources assigned to an execution result.
|
|
||||||
///
|
|
||||||
/// This function releases memory (and other resources, if any) assigned to the
|
|
||||||
/// specified execution result making the result object invalid.
|
|
||||||
///
|
|
||||||
/// @param result The execution result which resource are to be released. The
|
|
||||||
/// result itself it not modified by this function, but becomes
|
|
||||||
/// invalid and user should discard it as well.
|
|
||||||
typedef void (*evm_release_result_fn)(struct evm_result const* result);
|
|
||||||
|
|
||||||
/// Status of a code in VM. Useful for JIT-like implementations.
|
/// Status of a code in VM. Useful for JIT-like implementations.
|
||||||
enum evm_code_status {
|
enum evm_code_status {
|
||||||
|
@ -427,9 +450,6 @@ struct evm_interface {
|
||||||
/// Pointer to function execuing a code in a VM.
|
/// Pointer to function execuing a code in a VM.
|
||||||
evm_execute_fn execute;
|
evm_execute_fn execute;
|
||||||
|
|
||||||
/// Pointer to function releasing an execution result.
|
|
||||||
evm_release_result_fn release_result;
|
|
||||||
|
|
||||||
/// Optional pointer to function returning a status of a code.
|
/// Optional pointer to function returning a status of a code.
|
||||||
///
|
///
|
||||||
/// If the VM does not support this feature the pointer can be NULL.
|
/// If the VM does not support this feature the pointer can be NULL.
|
||||||
|
|
Loading…
Reference in New Issue