forked from iotaledger/streams
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.rs
117 lines (102 loc) · 3.05 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#![feature(alloc_error_handler)]
#![no_std]
#![no_main]
// Required to use the `alloc` crate and its types, the `abort` intrinsic, and a
// custom panic handler.
#![feature(core_intrinsics, lang_items)]
extern crate alloc;
extern crate wee_alloc;
// Use `wee_alloc` as the global allocator.
#[global_allocator]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
// Need to provide a tiny `panic_fmt` lang-item implementation for `#![no_std]`.
// This implementation will translate panics into traps in the resulting
// WebAssembly.
#[panic_handler]
fn panic(_info: &core::panic::PanicInfo) -> ! {
core::intrinsics::abort()
}
#[alloc_error_handler]
fn alloc_error(_: core::alloc::Layout) -> ! {
core::intrinsics::abort()
}
#[lang = "eh_personality"]
extern "C" fn eh_personality() {}
#[no_mangle]
pub extern "C" fn WinMainCRTStartup() -> () {
WinMain()
}
#[no_mangle]
pub extern "C" fn WinMain() -> () {
minmain()
}
// TODO: fix msvc link error: __chkstk, memcpy, memmove, memset, memcmp symbols not resolved
//
// #[link(name = "libcmt", kind = "static")]
// extern "C" {}
// #[link(name = "libucrt", kind = "static")]
// extern "C" {}
// #[link(name = "libcmt", kind = "static")]
// extern {
// fn memcpy(dest: *mut u8, _src: *const u8, _n: usize) -> *mut u8;
// fn memmove(dest: *mut u8, _src: *const u8, _n: usize) -> *mut u8;
// fn memset(mem: *mut u8, _val: i32, _n: usize) -> *mut u8;
// fn memcmp(_mem1: *const u8, _mem2: *const u8, _n: usize) -> i32;
// }
#[no_mangle]
pub unsafe extern "C" fn __chkstk() {
// Do not check stack; just crash?
}
#[no_mangle]
pub unsafe extern "C" fn memcpy(dest: *mut u8, src: *const u8, n: usize) -> *mut u8 {
if dest != 0 as *mut u8 && src != 0 as *const u8 {
for i in 0..n {
*dest.add(i) = *src.add(i);
}
}
dest
}
#[no_mangle]
pub unsafe extern "C" fn memmove(dest: *mut u8, src: *const u8, n: usize) -> *mut u8 {
if dest != 0 as *mut u8 && src != 0 as *const u8 {
if dest as *const u8 <= src {
for i in 0..n {
*dest.add(i) = *src.add(i);
}
} else {
for i in (0..n).rev() {
*dest.add(i) = *src.add(i);
}
}
}
dest
}
#[no_mangle]
pub unsafe extern "C" fn memset(mem: *mut u8, val: i32, n: usize) -> *mut u8 {
if mem != 0 as *mut u8 {
for i in 0..n {
*mem.add(i) = val as u8;
}
}
mem
}
#[no_mangle]
pub unsafe extern "C" fn memcmp(mem1: *const u8, mem2: *const u8, n: usize) -> i32 {
if mem1 != 0 as *const u8 && mem2 != 0 as *const u8 {
for i in 0..n {
use core::cmp::Ordering;
match (&*mem1.add(i)).cmp(&*mem2.add(i)) {
Ordering::Equal => continue,
Ordering::Less => return -1,
Ordering::Greater => return 1,
}
}
}
0
}
use iota_streams::app_channels::api::tangle::{BucketTransport, test::example, };
fn minmain() {
let transport = BucketTransport::new();
let _r = example(transport);
// assert!(dbg!(r).is_ok());
}