Skip to content

Commit

Permalink
Merge pull request #16 from TheWaWaR/support-ckb2021
Browse files Browse the repository at this point in the history
chore: support ckb2021
  • Loading branch information
TheWaWaR authored Sep 1, 2021
2 parents 98985a2 + 2ce778f commit 3939759
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 24 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ckb-std"
version = "0.7.4"
version = "0.8.0"
authors = ["Nervos network"]
edition = "2018"
license = "MIT"
Expand All @@ -19,6 +19,6 @@ simulator = [ "ckb-x64-simulator" ]
cc = "1.0"

[dependencies]
ckb-types = { package = "ckb-standalone-types", version = "0.0.1-pre.1", default-features = false, optional = true }
ckb-types = { package = "ckb-standalone-types", version = "0.1.1", default-features = false, optional = true }
buddy-alloc = { version = "0.4.1", optional = true }
ckb-x64-simulator = { version = "0.4.0", optional = true }
ckb-x64-simulator = { version = "0.5.0", optional = true }
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
TARGET := riscv64imac-unknown-none-elf
DOCKER_IMAGE := jjy0/ckb-capsule-recipe-rust:2020-9-28
DOCKER_IMAGE := thewawar/ckb-capsule:2021-08-16
CC := riscv64-unknown-elf-gcc

default: integration-in-docker
Expand Down
4 changes: 2 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ fn main() {
cc::Build::new()
.file("src/asm/syscall.S")
.compile("ckb-syscall");
build.
flag("-Wno-nonnull-compare")
build
.flag("-Wno-nonnull-compare")
.flag("-nostartfiles")
.compile("dl-c-impl");
} else {
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nightly-2020-09-28
nightly-2021-08-16
39 changes: 26 additions & 13 deletions src/dynamic_loading_c_impl.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
use crate::error::SysError;
use crate::debug;
use crate::error::SysError;
use core::ffi::c_void;
use core::marker::PhantomData;
use core::mem::{size_of, zeroed};
use core::ffi::c_void;
use core::ptr::null;

#[link(name = "dl-c-impl", kind="static")]
#[link(name = "dl-c-impl", kind = "static")]
extern "C" {
fn ckb_dlopen2(dep_cell_hash: *const u8, hash_type: u8,
aligned_addr: *mut u8, aligned_size: usize, handle: *mut *const c_void,
consumed_size: *mut usize) -> isize;
fn ckb_dlopen2(
dep_cell_hash: *const u8,
hash_type: u8,
aligned_addr: *mut u8,
aligned_size: usize,
handle: *mut *const c_void,
consumed_size: *mut usize,
) -> isize;
fn ckb_dlsym(handle: *const c_void, symbol: *const u8) -> usize;
}

Expand Down Expand Up @@ -91,7 +96,10 @@ impl Library {
}
let ptr = ckb_dlsym(self.handle, s.as_ptr());
if ptr == 0 {
debug!("warning, ckb_dlsym returns 0, handle = {:?}, symbol = {:?}", self.handle, symbol);
debug!(
"warning, ckb_dlsym returns 0, handle = {:?}, symbol = {:?}",
self.handle, symbol
);
None
} else {
Some(Symbol::new(ptr))
Expand All @@ -102,7 +110,6 @@ impl Library {
const RISCV_PGSIZE_SHIFT: usize = 12;
const RISCV_PGSIZE: usize = 1 << RISCV_PGSIZE_SHIFT; // 4096


#[repr(C)]
#[repr(align(4096))]
pub struct CKBDLContext<T>(T);
Expand All @@ -126,14 +133,20 @@ impl<T> CKBDLContext<T> {
}

unsafe {
let mut handle : *const c_void = null();
let mut consumed_size : usize = 0;
let hash_type : u8 = 0;
let mut handle: *const c_void = null();
let mut consumed_size: usize = 0;
let hash_type: u8 = 0;
let mut library = Library::new();
let aligned_size = size;
let aligned_addr = (&mut self.0 as *mut T).cast::<u8>().add(offset);
let code = ckb_dlopen2(dep_cell_data_hash.as_ptr(), hash_type, aligned_addr,
aligned_size, &mut handle as *mut *const c_void, &mut consumed_size as *mut usize);
let code = ckb_dlopen2(
dep_cell_data_hash.as_ptr(),
hash_type,
aligned_addr,
aligned_size,
&mut handle as *mut *const c_void,
&mut consumed_size as *mut usize,
);
if code != 0 {
debug!("warning, ckb_dlopen2 return {:?}", code);
return Err(Error::OpenFailed(code));
Expand Down
3 changes: 1 addition & 2 deletions test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
ckb-tool = "0.3"
ckb-testtool = "0.3"
ckb-testtool = "0.5"
2 changes: 1 addition & 1 deletion test/contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2018"

[dependencies]
ckb-std = { path = "../.." }
blake2b-ref = { version = "0.1", default-features = false }
blake2b-ref = { version = "0.3", default-features = false }

[build-dependencies]
blake2b-rs = "0.1.5"
Expand Down
2 changes: 1 addition & 1 deletion test/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use ckb_testtool::context::Context;
use ckb_tool::ckb_types::{bytes::Bytes, core::TransactionBuilder, packed::*, prelude::*};
use ckb_testtool::ckb_types::{bytes::Bytes, core::TransactionBuilder, packed::*, prelude::*};
use std::fs::File;
use std::io::Read;

Expand Down

0 comments on commit 3939759

Please sign in to comment.