Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
YottaChain
YTBP
提交
458017c3
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,发现更多精彩内容 >>
提交
458017c3
编写于
2月 14, 2018
作者:
B
Bart Wyatt
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
progress on correct memory assumptions
上级
8d321000
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
47 addition
and
112 deletion
+47
-112
libraries/chain/include/eosio/chain/webassembly/binaryen.hpp
libraries/chain/include/eosio/chain/webassembly/binaryen.hpp
+21
-21
libraries/chain/wast_to_wasm.cpp
libraries/chain/wast_to_wasm.cpp
+5
-0
libraries/chain/webassembly/binaryen.cpp
libraries/chain/webassembly/binaryen.cpp
+17
-16
libraries/testing/tester.cpp
libraries/testing/tester.cpp
+2
-42
programs/eosioc/main.cpp
programs/eosioc/main.cpp
+2
-33
未找到文件。
libraries/chain/include/eosio/chain/webassembly/binaryen.hpp
浏览文件 @
458017c3
...
...
@@ -37,13 +37,13 @@ struct interpreter_interface : ModuleInstance::ExternalInterface {
void
init
(
Module
&
wasm
,
ModuleInstance
&
instance
)
override
{
FC_ASSERT
(
wasm
.
memory
.
initial
*
wasm
::
Memory
::
kPageSize
<=
wasm_constraints
::
maximum_linear_memory
);
// initialize the linear memory
memset
(
memory
.
data
,
0
,
wasm
.
memory
.
initial
*
Memory
::
kPageSize
);
for
(
size_t
i
=
0
;
i
<
wasm
.
memory
.
segments
.
size
();
i
++
)
{
const
auto
&
segment
=
wasm
.
memory
.
segments
.
at
(
i
);
char
*
base
=
memory
.
data
+
(
i
*
Memory
::
kPageSize
);
Address
offset
=
ConstantExpressionRunner
<
TrivialGlobalManager
>
(
instance
.
globals
).
visit
(
segment
.
offset
).
value
.
geti32
();
char
*
base
=
memory
.
data
+
offset
;
FC_ASSERT
(
offset
+
segment
.
data
.
size
()
<=
wasm_constraints
::
maximum_linear_memory
);
memcpy
(
base
,
segment
.
data
.
data
(),
segment
.
data
.
size
());
if
(
segment
.
data
.
size
()
<
Memory
::
kPageSize
)
{
memset
(
base
+
segment
.
data
.
size
(),
0
,
Memory
::
kPageSize
-
segment
.
data
.
size
());
}
}
table
.
resize
(
wasm
.
table
.
initial
);
...
...
@@ -54,6 +54,8 @@ struct interpreter_interface : ModuleInstance::ExternalInterface {
table
[
offset
+
i
]
=
segment
.
data
[
i
];
}
}
sbrk_bytes
=
wasm
.
memory
.
initial
*
Memory
::
kPageSize
;
}
Literal
callImport
(
Import
*
import
,
LiteralList
&
args
)
override
...
...
@@ -120,6 +122,11 @@ struct interpreter_interface : ModuleInstance::ExternalInterface {
}
}
void
growMemory
(
Address
,
Address
)
override
{
FC_THROW_EXCEPTION
(
wasm_execution_error
,
"grow memory is not supported"
);
}
int8_t
load8s
(
Address
addr
)
override
{
return
load_memory
<
int8_t
>
(
addr
);
}
uint8_t
load8u
(
Address
addr
)
override
{
return
load_memory
<
uint8_t
>
(
addr
);
}
int16_t
load16s
(
Address
addr
)
override
{
return
load_memory
<
int16_t
>
(
addr
);
}
...
...
@@ -168,28 +175,21 @@ struct info {
info
(
const
entry
&
binaryen
)
{
int
num_segments
=
binaryen
.
module
->
memory
.
segments
.
size
();
default_sbrk_bytes
=
num_segments
*
Memory
::
kPageSize
;
mem_images
.
reserve
(
num_segments
);
for
(
const
auto
&
segment
:
binaryen
.
module
->
memory
.
segments
)
{
const
char
*
start
=
segment
.
data
.
data
();
const
char
*
high_watermark
=
start
+
segment
.
data
.
size
();
while
(
high_watermark
>
start
)
{
if
(
*
high_watermark
)
{
break
;
}
high_watermark
--
;
}
if
(
high_watermark
>
start
)
{
mem_images
.
emplace_back
(
start
,
high_watermark
);
}
else
{
mem_images
.
emplace_back
();
default_sbrk_bytes
=
binaryen
.
interface
->
sbrk_bytes
;
const
char
*
start
=
binaryen
.
interface
->
memory
.
data
;
const
char
*
high_watermark
=
start
+
(
binaryen
.
module
->
memory
.
initial
*
Memory
::
kPageSize
);
while
(
high_watermark
>
start
)
{
if
(
*
high_watermark
)
{
break
;
}
high_watermark
--
;
}
mem_image
.
resize
(
high_watermark
-
start
);
memcpy
(
mem_image
.
data
(),
start
,
high_watermark
-
start
);
}
// a clean image of the memory used to sanitize things on checkin
vector
<
vector
<
char
>>
mem_images
;
vector
<
char
>
mem_image
;
uint32_t
default_sbrk_bytes
;
};
...
...
libraries/chain/wast_to_wasm.cpp
浏览文件 @
458017c3
...
...
@@ -36,6 +36,11 @@ namespace eosio { namespace chain {
FC_ASSERT
(
!
"error parsing wast"
,
"${msg}"
,
(
"msg"
,
ss
.
get
())
);
}
for
(
auto
sectionIt
=
module
.
userSections
.
begin
();
sectionIt
!=
module
.
userSections
.
end
();
++
sectionIt
)
{
if
(
sectionIt
->
name
==
"name"
)
{
module
.
userSections
.
erase
(
sectionIt
);
break
;
}
}
try
{
// Serialize the WebAssembly module.
...
...
libraries/chain/webassembly/binaryen.cpp
浏览文件 @
458017c3
...
...
@@ -46,31 +46,32 @@ int entry::sbrk(int num_bytes) {
}
void
entry
::
reset
(
const
info
&
base_info
)
{
for
(
size_t
i
=
0
;
i
<
base_info
.
mem_images
.
size
();
i
++
)
{
const
auto
&
image
=
base_info
.
mem_images
.
at
(
i
);
char
*
base
=
interface
->
memory
.
data
+
(
i
*
Memory
::
kPageSize
);
memcpy
(
base
,
image
.
data
(),
image
.
size
());
}
if
(
interface
->
sbrk_bytes
>
base_info
.
default_sbrk_bytes
)
{
memset
(
interface
->
memory
.
data
+
base_info
.
default_sbrk_bytes
,
0
,
interface
->
sbrk_bytes
-
base_info
.
default_sbrk_bytes
);
const
auto
&
image
=
base_info
.
mem_image
;
char
*
base
=
interface
->
memory
.
data
;
memcpy
(
base
,
image
.
data
(),
image
.
size
());
if
(
interface
->
sbrk_bytes
>
image
.
size
())
{
memset
(
interface
->
memory
.
data
+
image
.
size
(),
0
,
interface
->
sbrk_bytes
-
image
.
size
());
}
interface
->
sbrk_bytes
=
base_info
.
default_sbrk_bytes
;
}
entry
entry
::
build
(
const
char
*
wasm_binary
,
size_t
wasm_binary_size
)
{
vector
<
char
>
code
(
wasm_binary
,
wasm_binary
+
wasm_binary_size
);
unique_ptr
<
Module
>
module
;
WasmBinaryBuilder
builder
(
*
module
,
code
,
false
);
builder
.
read
();
try
{
vector
<
char
>
code
(
wasm_binary
,
wasm_binary
+
wasm_binary_size
);
unique_ptr
<
Module
>
module
(
new
Module
());
WasmBinaryBuilder
builder
(
*
module
,
code
,
false
);
builder
.
read
();
unique_ptr
<
interpreter_interface
>
interface
;
unique_ptr
<
ModuleInstance
>
instance
(
new
ModuleInstance
(
*
module
.
get
(),
interface
.
get
()));
unique_ptr
<
interpreter_interface
>
interface
(
new
interpreter_interface
())
;
unique_ptr
<
ModuleInstance
>
instance
(
new
ModuleInstance
(
*
module
.
get
(),
interface
.
get
()));
//TODO: validate
//TODO: validate
return
entry
(
move
(
module
),
move
(
interface
),
move
(
instance
));
return
entry
(
move
(
module
),
move
(
interface
),
move
(
instance
));
}
catch
(
const
ParseException
&
e
)
{
FC_THROW_EXCEPTION
(
wasm_execution_error
,
"Error building interpreter: ${s}"
,
(
"s"
,
e
.
text
));
}
};
entry
::
entry
(
unique_ptr
<
Module
>&&
module
,
unique_ptr
<
interpreter_interface
>&&
interface
,
unique_ptr
<
ModuleInstance
>&&
instance
)
...
...
libraries/testing/tester.cpp
浏览文件 @
458017c3
#include <boost/test/unit_test.hpp>
#include <eosio/testing/tester.hpp>
#include <eosio/chain/asset.hpp>
#include <eosio/chain/wast_to_wasm.hpp>
#include <eosio/chain/contracts/types.hpp>
#include <eosio/chain/contracts/eos_contract.hpp>
#include <eosio/chain/contracts/contract_table_objects.hpp>
...
...
@@ -239,48 +240,7 @@ namespace eosio { namespace testing {
}
FC_CAPTURE_AND_RETHROW
(
(
account
)(
perm
)(
auth
)(
parent
)
)
}
void
tester
::
set_code
(
account_name
account
,
const
char
*
wast
)
try
{
const
auto
assemble
=
[](
const
char
*
wast
)
->
vector
<
unsigned
char
>
{
using
namespace
IR
;
using
namespace
WAST
;
using
namespace
WASM
;
using
namespace
Serialization
;
Module
module
;
vector
<
Error
>
parse_errors
;
parseModule
(
wast
,
fc
::
const_strlen
(
wast
),
module
,
parse_errors
);
if
(
!
parse_errors
.
empty
())
{
fc
::
exception
parse_exception
(
FC_LOG_MESSAGE
(
warn
,
"Failed to parse WAST"
),
fc
::
std_exception_code
,
"wast_parse_error"
,
"Failed to parse WAST"
);
for
(
const
auto
&
err
:
parse_errors
)
{
parse_exception
.
append_log
(
FC_LOG_MESSAGE
(
error
,
":${desc}: ${message}"
,
(
"desc"
,
err
.
locus
.
describe
())(
"message"
,
err
.
message
.
c_str
())
)
);
parse_exception
.
append_log
(
FC_LOG_MESSAGE
(
error
,
string
(
err
.
locus
.
column
(
8
),
' '
)
+
"^"
));
}
throw
parse_exception
;
}
try
{
// Serialize the WebAssembly module.
ArrayOutputStream
stream
;
serialize
(
stream
,
module
);
return
stream
.
getBytes
();
}
catch
(
const
FatalSerializationException
&
ex
)
{
fc
::
exception
serialize_exception
(
FC_LOG_MESSAGE
(
warn
,
"Failed to serialize wasm: ${message}"
,
(
"message"
,
ex
.
message
)),
fc
::
std_exception_code
,
"wasm_serialization_error"
,
"Failed to serialize WASM"
);
throw
serialize_exception
;
}
};
auto
wasm
=
assemble
(
wast
);
auto
wasm
=
wast_to_wasm
(
wast
);
signed_transaction
trx
;
trx
.
actions
.
emplace_back
(
vector
<
permission_level
>
{{
account
,
config
::
active_name
}},
...
...
programs/eosioc/main.cpp
浏览文件 @
458017c3
...
...
@@ -73,6 +73,7 @@ Options:
#include <eosio/utilities/key_conversion.hpp>
#include <eosio/chain/config.hpp>
#include <eosio/chain/wast_to_wasm.hpp>
#include <eosio/chain_plugin/chain_plugin.hpp>
#include <boost/range/algorithm/find_if.hpp>
#include <boost/range/algorithm/sort.hpp>
...
...
@@ -172,38 +173,6 @@ inline std::vector<name> sort_names( const std::vector<name>& names ) {
return
results
;
}
vector
<
uint8_t
>
assemble_wast
(
const
std
::
string
&
wast
)
{
IR
::
Module
module
;
std
::
vector
<
WAST
::
Error
>
parseErrors
;
WAST
::
parseModule
(
wast
.
c_str
(),
wast
.
size
(),
module
,
parseErrors
);
if
(
parseErrors
.
size
())
{
// Print any parse errors;
std
::
cerr
<<
localized
(
"Error parsing WebAssembly text file:"
)
<<
std
::
endl
;
for
(
auto
&
error
:
parseErrors
)
{
std
::
cerr
<<
":"
<<
error
.
locus
.
describe
()
<<
": "
<<
error
.
message
.
c_str
()
<<
std
::
endl
;
std
::
cerr
<<
error
.
locus
.
sourceLine
<<
std
::
endl
;
std
::
cerr
<<
std
::
setw
(
error
.
locus
.
column
(
8
))
<<
"^"
<<
std
::
endl
;
}
FC_THROW_EXCEPTION
(
explained_exception
,
"wast parse error"
);
}
try
{
// Serialize the WebAssembly module.
Serialization
::
ArrayOutputStream
stream
;
WASM
::
serialize
(
stream
,
module
);
return
stream
.
getBytes
();
}
catch
(
Serialization
::
FatalSerializationException
exception
)
{
std
::
cerr
<<
localized
(
"Error serializing WebAssembly binary file:"
)
<<
std
::
endl
;
std
::
cerr
<<
exception
.
message
<<
std
::
endl
;
FC_THROW_EXCEPTION
(
explained_exception
,
"wasm serialize error"
);
}
}
auto
tx_expiration
=
fc
::
seconds
(
30
);
bool
tx_force_unique
=
false
;
void
add_standard_transaction_options
(
CLI
::
App
*
cmd
)
{
...
...
@@ -717,7 +686,7 @@ int main( int argc, char** argv ) {
}
else
{
std
::
cout
<<
localized
(
"Assembling WASM..."
)
<<
std
::
endl
;
wasm
=
assemble_wast
(
wast
);
wasm
=
wast_to_wasm
(
wast
);
}
contracts
::
setcode
handler
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录