提交 1eb34a6e 编写于 作者: B Bucky Kittinger

@DAWN-391 house cleaning

上级 a1a2dcfa
......@@ -421,9 +421,7 @@ struct intrinsic_invoker_impl<Ret, std::tuple<array_ptr<T>, array_ptr<U>, size_t
*/
template<typename Ret>
struct intrinsic_invoker_impl<Ret, std::tuple<array_ptr<char>, int, size_t>, std::tuple<>> {
//using next_step = intrinsic_invoker_impl<void_type, std::tuple<>, std::tuple<I32, I32, I32>>;
using next_step = intrinsic_invoker_impl<Ret, std::tuple<>, std::tuple<I32, I32, I32>>;
//using then_type = void_type(*)(wasm_interface &, array_ptr<char>, int, size_t);
using then_type = Ret(*)(wasm_interface &, array_ptr<char>, int, size_t);
template<then_type Then>
......
......@@ -23,7 +23,6 @@
#include <mutex>
#include <thread>
#include <condition_variable>
//#include <iostream>
......@@ -627,8 +626,8 @@ class context_aware_api {
{}
protected:
wasm_cache::entry& code;
apply_context& context;
wasm_cache::entry& code;
apply_context& context;
};
class system_api : public context_aware_api {
......@@ -822,44 +821,42 @@ class memory_api : public context_aware_api {
return ::memcmp(dest, src, length);
}
char* memset( array_ptr<char> dest, int value, size_t length ) {
return (char *)::memset( dest, value, length );
}
uint32_t sbrk(int num_bytes) {
// TODO: omitted checktime function from previous version of sbrk, may need to be put back in at some point
constexpr uint32_t NBPPL2 = IR::numBytesPerPageLog2;
constexpr uint32_t max_mem = 1024 * 1024;
const auto default_mem = Runtime::getDefaultMemory(code.instance);
const uint32_t num_pages = Runtime::getMemoryNumPages(default_mem);
// limit this min to 32 bit space
const uint32_t min_bytes = (num_pages << NBPPL2) > UINT32_MAX ? UINT32_MAX : num_pages << NBPPL2;
static uint32_t _num_bytes = min_bytes;
const uint32_t prev_num_bytes = _num_bytes;
if (Runtime::getMemoryNumPages(default_mem) != num_pages)
throw eosio::chain::page_memory_error();
// round the absolute value of num_bytes to an alignment boundary
num_bytes = (num_bytes + 7) & ~7;
if ((num_bytes > 0) && (prev_num_bytes > (max_mem - num_bytes))) // test if allocating too much memory (overflowed)
throw eosio::chain::page_memory_error();
else if ((num_bytes < 0) && (prev_num_bytes < (min_bytes - num_bytes))) // test for underflow
throw eosio::chain::page_memory_error();
// update the number of bytes allocated, and compute the number of pages needed
_num_bytes += num_bytes;
const uint32_t num_desired_pages = (_num_bytes + IR::numBytesPerPage - 1) >> NBPPL2;
// grow or shrink the memory to the desired number of pages
if (num_desired_pages > num_pages)
Runtime::growMemory(default_mem, num_desired_pages - num_pages);
else if (num_desired_pages < num_pages)
Runtime::shrinkMemory(default_mem, num_pages - num_desired_pages);
return prev_num_bytes;
}
char* memset( array_ptr<char> dest, int value, size_t length ) {
return (char *)::memset( dest, value, length );
}
uint32_t sbrk(int num_bytes) {
// TODO: omitted checktime function from previous version of sbrk, may need to be put back in at some point
constexpr uint32_t NBPPL2 = IR::numBytesPerPageLog2;
constexpr uint32_t max_mem = 1024 * 1024;
const auto default_mem = Runtime::getDefaultMemory(code.instance);
const uint32_t num_pages = Runtime::getMemoryNumPages(default_mem);
// limit this min to 32 bit space
const uint32_t min_bytes = (num_pages << NBPPL2) > UINT32_MAX ? UINT32_MAX : num_pages << NBPPL2;
static uint32_t _num_bytes = min_bytes;
const uint32_t prev_num_bytes = _num_bytes;
// round the absolute value of num_bytes to an alignment boundary
num_bytes = (num_bytes + 7) & ~7;
if ((num_bytes > 0) && (prev_num_bytes > (max_mem - num_bytes))) // test if allocating too much memory (overflowed)
throw eosio::chain::page_memory_error();
else if ((num_bytes < 0) && (prev_num_bytes < (min_bytes - num_bytes))) // test for underflow
throw eosio::chain::page_memory_error();
// update the number of bytes allocated, and compute the number of pages needed
_num_bytes += num_bytes;
const uint32_t num_desired_pages = (_num_bytes + IR::numBytesPerPage - 1) >> NBPPL2;
// grow or shrink the memory to the desired number of pages
if (num_desired_pages > num_pages)
Runtime::growMemory(default_mem, num_desired_pages - num_pages);
else if (num_desired_pages < num_pages)
Runtime::shrinkMemory(default_mem, num_pages - num_desired_pages);
return prev_num_bytes;
}
};
class transaction_api : public context_aware_api {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册