Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
YottaChain
YTBP
提交
90ce83bd
Y
YTBP
项目概览
YottaChain
/
YTBP
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Y
YTBP
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
90ce83bd
编写于
2月 13, 2018
作者:
B
Bart Wyatt
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
modularize sbrk
上级
4ed1d1ea
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
81 addition
and
66 deletion
+81
-66
libraries/chain/include/eosio/chain/wasm_interface_private.hpp
...ries/chain/include/eosio/chain/wasm_interface_private.hpp
+2
-3
libraries/chain/include/eosio/chain/webassembly/common.hpp
libraries/chain/include/eosio/chain/webassembly/common.hpp
+1
-3
libraries/chain/include/eosio/chain/webassembly/jit.hpp
libraries/chain/include/eosio/chain/webassembly/jit.hpp
+25
-15
libraries/chain/wasm_interface.cpp
libraries/chain/wasm_interface.cpp
+6
-42
libraries/chain/webassembly/jit.cpp
libraries/chain/webassembly/jit.cpp
+45
-1
libraries/fc/include/fc/optional.hpp
libraries/fc/include/fc/optional.hpp
+2
-2
未找到文件。
libraries/chain/include/eosio/chain/wasm_interface_private.hpp
浏览文件 @
90ce83bd
...
...
@@ -9,13 +9,12 @@ using namespace eosio::chain::webassembly;
namespace
eosio
{
namespace
chain
{
struct
wasm_cache
::
entry
{
entry
(
jit
::
entry
&&
jit
,
uint32_t
default_sbrk_bytes
)
:
jit
(
std
::
forward
<
jit
::
entry
>
(
jit
))
,
default_sbrk_bytes
(
default_sbrk_bytes
)
entry
(
jit
::
entry
&&
jit
)
:
jit
(
std
::
forward
<
jit
::
entry
>
(
jit
))
{
}
jit
::
entry
jit
;
uint32_t
default_sbrk_bytes
;
};
struct
wasm_interface_impl
{
...
...
libraries/chain/include/eosio/chain/webassembly/common.hpp
浏览文件 @
90ce83bd
...
...
@@ -11,15 +11,13 @@ namespace eosio { namespace chain { namespace webassembly { namespace common {
using
wasm_double
=
boost
::
multiprecision
::
cpp_dec_float_50
;
struct
wasm_context
{
wasm_context
(
wasm_cache
::
entry
&
code
,
apply_context
&
ctx
,
uint32_t
sbrk_bytes
)
wasm_context
(
wasm_cache
::
entry
&
code
,
apply_context
&
ctx
)
:
code
(
code
)
,
context
(
ctx
)
,
sbrk_bytes
(
sbrk_bytes
)
{
}
eosio
::
chain
::
wasm_cache
::
entry
&
code
;
apply_context
&
context
;
uint32_t
sbrk_bytes
;
};
class
intrinsics_accessor
{
...
...
libraries/chain/include/eosio/chain/webassembly/jit.hpp
浏览文件 @
90ce83bd
...
...
@@ -13,14 +13,11 @@ using namespace eosio::chain::webassembly::common;
namespace
eosio
{
namespace
chain
{
namespace
webassembly
{
namespace
jit
{
struct
info
;
struct
entry
{
entry
(
ModuleInstance
*
instance
,
Module
*
module
)
:
instance
(
instance
),
module
(
module
)
{
}
class
entry
{
public:
ModuleInstance
*
instance
;
Module
*
module
;
uint32_t
sbrk_bytes
;
void
reset
(
const
info
&
);
...
...
@@ -30,15 +27,25 @@ struct entry {
void
call_apply
(
apply_context
&
);
void
call_error
(
apply_context
&
);
int
sbrk
(
int
num_bytes
);
static
const
entry
&
get
(
wasm_interface
&
wasm
);
static
entry
build
(
const
char
*
wasm_binary
,
size_t
wasm_binary_size
);
private:
entry
(
ModuleInstance
*
instance
,
Module
*
module
,
uint32_t
sbrk_bytes
)
:
instance
(
instance
),
module
(
module
),
sbrk_bytes
(
sbrk_bytes
)
{
}
};
struct
info
{
info
(
const
entry
&
jit
)
{
MemoryInstance
*
current_memory
=
Runtime
::
getDefaultMemory
(
jit
.
instance
);
default_sbrk_bytes
=
jit
.
sbrk_bytes
;
if
(
current_memory
)
{
char
*
mem_ptr
=
&
memoryRef
<
char
>
(
current_memory
,
0
);
...
...
@@ -56,6 +63,9 @@ struct info {
size_t
mem_start
=
0
;
size_t
mem_end
=
1
<<
16
;
vector
<
char
>
mem_image
;
uint32_t
default_sbrk_bytes
=
0
;
};
...
...
libraries/chain/wasm_interface.cpp
浏览文件 @
90ce83bd
...
...
@@ -174,11 +174,7 @@ namespace eosio { namespace chain {
// find or create a new entry
auto
iter
=
_cache
.
emplace
(
code_id
,
code_info
(
std
::
move
(
*
jit_info
))).
first
;
/// TODO: make sbrk bytes generic
MemoryInstance
*
default_mem
=
Runtime
::
getDefaultMemory
(
jit
->
instance
);
uint32_t
default_sbrk_bytes
=
default_mem
?
Runtime
::
getMemoryNumPages
(
default_mem
)
<<
IR
::
numBytesPerPageLog2
:
0
;
iter
->
second
.
instances
.
emplace_back
(
std
::
make_unique
<
wasm_cache
::
entry
>
(
std
::
move
(
*
jit
),
default_sbrk_bytes
));
iter
->
second
.
instances
.
emplace_back
(
std
::
make_unique
<
wasm_cache
::
entry
>
(
std
::
move
(
*
jit
)));
pending_result
=
optional_entry_ref
(
*
iter
->
second
.
instances
.
back
().
get
());
});
}
...
...
@@ -269,7 +265,7 @@ namespace eosio { namespace chain {
*/
struct
scoped_context
{
template
<
typename
...
Args
>
scoped_context
(
optional
<
wasm_context
>
&
context
,
Args
&
...
args
)
scoped_context
(
optional
<
wasm_context
>
&
context
,
Args
&
&
...
args
)
:
context
(
context
)
{
context
.
emplace
(
std
::
forward
<
Args
>
(
args
)...
);
...
...
@@ -295,12 +291,12 @@ namespace eosio { namespace chain {
}
void
wasm_interface
::
apply
(
wasm_cache
::
entry
&
code
,
apply_context
&
context
)
{
auto
context_guard
=
scoped_context
(
my
->
current_context
,
code
,
context
,
code
.
default_sbrk_bytes
);
auto
context_guard
=
scoped_context
(
my
->
current_context
,
code
,
context
);
code
.
jit
.
call_apply
(
context
);
}
void
wasm_interface
::
error
(
wasm_cache
::
entry
&
code
,
apply_context
&
context
)
{
auto
context_guard
=
scoped_context
(
my
->
current_context
,
code
,
context
,
code
.
default_sbrk_bytes
);
auto
context_guard
=
scoped_context
(
my
->
current_context
,
code
,
context
);
code
.
jit
.
call_error
(
context
);
}
...
...
@@ -320,12 +316,10 @@ namespace eosio { namespace chain {
class
context_aware_api
{
public:
context_aware_api
(
wasm_interface
&
wasm
)
:
context
(
intrinsics_accessor
::
get_context
(
wasm
).
context
),
code
(
intrinsics_accessor
::
get_context
(
wasm
).
code
),
sbrk_bytes
(
intrinsics_accessor
::
get_context
(
wasm
).
sbrk_bytes
)
:
context
(
intrinsics_accessor
::
get_context
(
wasm
).
context
),
code
(
intrinsics_accessor
::
get_context
(
wasm
).
code
)
{}
protected:
uint32_t
&
sbrk_bytes
;
wasm_cache
::
entry
&
code
;
apply_context
&
context
;
};
...
...
@@ -839,37 +833,7 @@ class memory_api : public context_aware_api {
}
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
;
MemoryInstance
*
default_mem
=
Runtime
::
getDefaultMemory
(
code
.
jit
.
instance
);
if
(
!
default_mem
)
throw
eosio
::
chain
::
page_memory_error
();
const
uint32_t
num_pages
=
Runtime
::
getMemoryNumPages
(
default_mem
);
const
uint32_t
min_bytes
=
(
num_pages
<<
NBPPL2
)
>
UINT32_MAX
?
UINT32_MAX
:
num_pages
<<
NBPPL2
;
const
uint32_t
prev_num_bytes
=
sbrk_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
sbrk_bytes
+=
num_bytes
;
const
uint32_t
num_desired_pages
=
(
sbrk_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
;
return
code
.
jit
.
sbrk
(
num_bytes
);
}
};
...
...
libraries/chain/webassembly/jit.cpp
浏览文件 @
90ce83bd
...
...
@@ -70,6 +70,40 @@ void entry::call_error(apply_context& context)
call
(
"error"
,
args
,
context
);
}
int
entry
::
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
;
MemoryInstance
*
default_mem
=
Runtime
::
getDefaultMemory
(
instance
);
if
(
!
default_mem
)
throw
eosio
::
chain
::
page_memory_error
();
const
uint32_t
num_pages
=
Runtime
::
getMemoryNumPages
(
default_mem
);
const
uint32_t
min_bytes
=
(
num_pages
<<
NBPPL2
)
>
UINT32_MAX
?
UINT32_MAX
:
num_pages
<<
NBPPL2
;
const
uint32_t
prev_num_bytes
=
sbrk_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
sbrk_bytes
+=
num_bytes
;
const
uint32_t
num_desired_pages
=
(
sbrk_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
;
}
void
entry
::
reset
(
const
info
&
base_info
)
{
if
(
getDefaultMemory
(
instance
))
{
...
...
@@ -78,6 +112,8 @@ void entry::reset(const info& base_info) {
memcpy
(
memstart
,
base_info
.
mem_image
.
data
(),
base_info
.
mem_end
);
}
resetGlobalInstances
(
instance
);
sbrk_bytes
=
base_info
.
default_sbrk_bytes
;
}
...
...
@@ -91,7 +127,15 @@ entry entry::build(const char* wasm_binary, size_t wasm_binary_size) {
LinkResult
link_result
=
linkModule
(
*
module
,
resolver
);
ModuleInstance
*
instance
=
instantiateModule
(
*
module
,
std
::
move
(
link_result
.
resolvedImports
));
FC_ASSERT
(
instance
!=
nullptr
);
return
entry
(
instance
,
module
);
MemoryInstance
*
current_memory
=
Runtime
::
getDefaultMemory
(
instance
);
uint32_t
sbrk_bytes
=
0
;
if
(
current_memory
)
{
sbrk_bytes
=
Runtime
::
getMemoryNumPages
(
current_memory
)
<<
IR
::
numBytesPerPageLog2
;
}
return
entry
(
instance
,
module
,
sbrk_bytes
);
};
}}}}
\ No newline at end of file
libraries/fc/include/fc/optional.hpp
浏览文件 @
90ce83bd
...
...
@@ -93,12 +93,12 @@ namespace fc {
}
template
<
typename
...
Args
>
void
emplace
(
Args
...
args
)
{
void
emplace
(
Args
&&
...
args
)
{
if
(
_valid
)
{
reset
();
}
new
((
char
*
)
ptr
())
T
(
args
...
);
new
((
char
*
)
ptr
())
T
(
fc
::
forward
<
Args
>
(
args
)
...
);
_valid
=
true
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录