Skip to content

Commit

Permalink
Remove ckb2023 feature
Browse files Browse the repository at this point in the history
  • Loading branch information
mohanson committed Sep 11, 2024
1 parent 1a4135e commit ff279d5
Show file tree
Hide file tree
Showing 18 changed files with 138 additions and 35 deletions.
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ exclude = ["docs"]

[package.metadata.docs.rs]
# All features except simulator and rustc-dep-of-std.
features = ["allocator", "ckb-types", "libc", "calc-hash", "build-with-clang", "dlopen-c", "ckb2023"]
features = ["allocator", "ckb-types", "libc", "calc-hash", "build-with-clang", "dlopen-c"]
rustdoc-args = ["--cfg", "docsrs"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand All @@ -23,7 +23,6 @@ native-simulator = ["ckb-x64-simulator"]
dlopen-c = ["libc"]
build-with-clang = []
libc = []
ckb2023 = []
# work with `target-feature=-a` Cargo flag
dummy-atomic = []
log = ["dep:log", "dummy-atomic"]
Expand Down
2 changes: 1 addition & 1 deletion c/ckb-c-stdlib
10 changes: 10 additions & 0 deletions contracts/ckb-std-tests/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ pub enum Error {
ItemMissing,
LengthNotEnough,
Encoding,
WaitFailure,
InvalidFd,
OtherEndClosed,
MaxVmsSpawned,
MaxFdsCreated,
// Add customized errors here...
}

Expand All @@ -18,6 +23,11 @@ impl From<SysError> for Error {
ItemMissing => Self::ItemMissing,
LengthNotEnough(_) => Self::LengthNotEnough,
Encoding => Self::Encoding,
WaitFailure => Self::WaitFailure,
InvalidFd => Self::InvalidFd,
OtherEndClosed => Self::OtherEndClosed,
MaxVmsSpawned => Self::MaxVmsSpawned,
MaxFdsCreated => Self::MaxFdsCreated,
Unknown(err_code) => panic!("unexpected sys error {}", err_code),
}
}
Expand Down
10 changes: 10 additions & 0 deletions contracts/exec-callee/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ pub enum Error {
ItemMissing,
LengthNotEnough,
Encoding,
WaitFailure,
InvalidFd,
OtherEndClosed,
MaxVmsSpawned,
MaxFdsCreated,
// Add customized errors here...
}

Expand All @@ -18,6 +23,11 @@ impl From<SysError> for Error {
ItemMissing => Self::ItemMissing,
LengthNotEnough(_) => Self::LengthNotEnough,
Encoding => Self::Encoding,
WaitFailure => Self::WaitFailure,
InvalidFd => Self::InvalidFd,
OtherEndClosed => Self::OtherEndClosed,
MaxVmsSpawned => Self::MaxVmsSpawned,
MaxFdsCreated => Self::MaxFdsCreated,
Unknown(err_code) => panic!("unexpected sys error {}", err_code),
}
}
Expand Down
10 changes: 10 additions & 0 deletions contracts/exec-caller-by-code-hash/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ pub enum Error {
ItemMissing,
LengthNotEnough,
Encoding,
WaitFailure,
InvalidFd,
OtherEndClosed,
MaxVmsSpawned,
MaxFdsCreated,
// Add customized errors here...
}

Expand All @@ -18,6 +23,11 @@ impl From<SysError> for Error {
ItemMissing => Self::ItemMissing,
LengthNotEnough(_) => Self::LengthNotEnough,
Encoding => Self::Encoding,
WaitFailure => Self::WaitFailure,
InvalidFd => Self::InvalidFd,
OtherEndClosed => Self::OtherEndClosed,
MaxVmsSpawned => Self::MaxVmsSpawned,
MaxFdsCreated => Self::MaxFdsCreated,
Unknown(err_code) => panic!("unexpected sys error {}", err_code),
}
}
Expand Down
10 changes: 10 additions & 0 deletions contracts/exec-caller/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ pub enum Error {
ItemMissing,
LengthNotEnough,
Encoding,
WaitFailure,
InvalidFd,
OtherEndClosed,
MaxVmsSpawned,
MaxFdsCreated,
// Add customized errors here...
}

Expand All @@ -18,6 +23,11 @@ impl From<SysError> for Error {
ItemMissing => Self::ItemMissing,
LengthNotEnough(_) => Self::LengthNotEnough,
Encoding => Self::Encoding,
WaitFailure => Self::WaitFailure,
InvalidFd => Self::InvalidFd,
OtherEndClosed => Self::OtherEndClosed,
MaxVmsSpawned => Self::MaxVmsSpawned,
MaxFdsCreated => Self::MaxFdsCreated,
Unknown(err_code) => panic!("unexpected sys error {}", err_code),
}
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/spawn-callee/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
ckb-std = { path = "../../", features = ["ckb2023"] }
ckb-std = { path = "../../" }
2 changes: 1 addition & 1 deletion contracts/spawn-callee/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use core::result::Result;
pub fn main() -> Result<(), Error> {
let argv = ckb_std::env::argv();
let mut std_fds: [u64; 2] = [0; 2];
syscalls::inherited_file_descriptors(&mut std_fds);
syscalls::inherited_fds(&mut std_fds);
let mut out = vec![];
for arg in argv {
out.extend_from_slice(arg.to_bytes());
Expand Down
2 changes: 1 addition & 1 deletion contracts/spawn-caller-by-code-hash/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
ckb-std = { path = "../../", features = ["ckb2023"] }
ckb-std = { path = "../../" }
2 changes: 1 addition & 1 deletion contracts/spawn-caller/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
ckb-std = { path = "../../", features = ["ckb2023"] }
ckb-std = { path = "../../" }
11 changes: 1 addition & 10 deletions src/ckb_constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,14 @@ pub const SYS_LOAD_INPUT_BY_FIELD: u64 = 2083;
pub const SYS_LOAD_CELL_DATA_AS_CODE: u64 = 2091;
pub const SYS_LOAD_CELL_DATA: u64 = 2092;
pub const SYS_DEBUG: u64 = 2177;
#[cfg(feature = "ckb2023")]
pub const SYS_SPAWN: u64 = 2601;
#[cfg(feature = "ckb2023")]
pub const SYS_WAIT: u64 = 2602;
#[cfg(feature = "ckb2023")]
pub const SYS_PROCESS_ID: u64 = 2603;
#[cfg(feature = "ckb2023")]
pub const SYS_PIPE: u64 = 2604;
#[cfg(feature = "ckb2023")]
pub const SYS_WRITE: u64 = 2605;
#[cfg(feature = "ckb2023")]
pub const SYS_READ: u64 = 2606;
#[cfg(feature = "ckb2023")]
pub const SYS_INHERITED_FD: u64 = 2607;
#[cfg(feature = "ckb2023")]
pub const SYS_INHERITED_FDS: u64 = 2607;
pub const SYS_CLOSE: u64 = 2608;
#[cfg(feature = "ckb2023")]
pub const SYS_LOAD_BLOCK_EXTENSION: u64 = 2104;

pub const CKB_SUCCESS: u64 = 0;
Expand Down
5 changes: 0 additions & 5 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,14 @@ pub enum SysError {
Encoding,

/// Failed to wait. Its value is 5.
#[cfg(feature = "ckb2023")]
WaitFailure,
/// Invalid file descriptor. Its value is 6.
#[cfg(feature = "ckb2023")]
InvalidFd,
/// Reading from or writing to file descriptor failed due to other end closed. Its value is 7.
#[cfg(feature = "ckb2023")]
OtherEndClosed,
/// Max vms has been spawned. Its value is 8.
#[cfg(feature = "ckb2023")]
MaxVmsSpawned,
/// Max fds has been spawned. Its value is 9.
#[cfg(feature = "ckb2023")]
MaxFdsCreated,

/// Unknown syscall error number
Expand Down
1 change: 0 additions & 1 deletion src/high_level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,6 @@ pub fn exec_cell(
/// - if you want to pass a piece of bytes data, you may encode it to hexadecimal string or other format:
/// - high_level::encode_hex(&vec![0xff, 0xfe, 0xfd]);
/// * `inherited_fds` - the fd list to be passed to the child process.
#[cfg(feature = "ckb2023")]
pub fn spawn_cell(
code_hash: &[u8],
hash_type: ScriptHashType,
Expand Down
14 changes: 2 additions & 12 deletions src/syscalls/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,6 @@ pub fn exec(index: usize, source: Source, place: usize, bounds: usize, argv: &[&
}
}

#[cfg(feature = "ckb2023")]
#[repr(C)]
pub struct SpawnArgs {
/// argc contains the number of arguments passed to the program.
Expand All @@ -597,7 +596,6 @@ pub struct SpawnArgs {
/// * `spgs` - spawn arguments.
///
/// Returns success or a syscall error.
#[cfg(feature = "ckb2023")]
pub fn spawn(
index: usize,
source: Source,
Expand Down Expand Up @@ -636,7 +634,6 @@ pub fn spawn(
/// * `pid` - process id
///
/// Returns exit code.
#[cfg(feature = "ckb2023")]
pub fn wait(pid: u64) -> Result<i8, SysError> {
let mut code: u64 = 0;
let ret = unsafe { syscall(pid, &mut code as *mut u64 as u64, 0, 0, 0, 0, 0, SYS_WAIT) };
Expand All @@ -649,15 +646,13 @@ pub fn wait(pid: u64) -> Result<i8, SysError> {

/// This syscall is used to get the current process id. Root process ID is 0.
/// Note: available after ckb2023.
#[cfg(feature = "ckb2023")]
pub fn process_id() -> u64 {
unsafe { syscall(0, 0, 0, 0, 0, 0, 0, SYS_PROCESS_ID) }
}

/// This syscall create a pipe with read-write pair of file descriptions. The file descriptor with read permission is
/// located at fds[0], and the corresponding file descriptor with write permission is located at fds[1].
/// Note: available after ckb2023.
#[cfg(feature = "ckb2023")]
pub fn pipe() -> Result<(u64, u64), SysError> {
let mut fds: [u64; 2] = [0, 0];
let ret = unsafe { syscall(fds.as_mut_ptr() as u64, 0, 0, 0, 0, 0, 0, SYS_PIPE) };
Expand All @@ -671,7 +666,6 @@ pub fn pipe() -> Result<(u64, u64), SysError> {
/// This syscall reads data from a pipe via a file descriptor. The syscall Read attempts to read up to value pointed by
/// length bytes from file descriptor fd into the buffer, and the actual length of data read is returned.
/// Note: available after ckb2023.
#[cfg(feature = "ckb2023")]
pub fn read(fd: u64, buffer: &mut [u8]) -> Result<usize, SysError> {
let mut l: u64 = buffer.len() as u64;
let ret = unsafe {
Expand All @@ -698,7 +692,6 @@ pub fn read(fd: u64, buffer: &mut [u8]) -> Result<usize, SysError> {
/// This syscall writes data to a pipe via a file descriptor. The syscall Write writes up to value pointed by length
/// bytes from the buffer, and the actual length of data written is returned.
/// Note: available after ckb2023.
#[cfg(feature = "ckb2023")]
pub fn write(fd: u64, buffer: &[u8]) -> Result<usize, SysError> {
let mut l: u64 = buffer.len() as u64;
let ret = unsafe {
Expand All @@ -725,8 +718,7 @@ pub fn write(fd: u64, buffer: &[u8]) -> Result<usize, SysError> {
/// This syscall retrieves the file descriptors available to the current process, which are passed in from the parent
/// process. These results are copied from the inherited_fds parameter of the Spawn syscall.
/// Note: available after ckb2023.
#[cfg(feature = "ckb2023")]
pub fn inherited_file_descriptors(fds: &mut [u64]) {
pub fn inherited_fds(fds: &mut [u64]) {
let mut l: u64 = fds.len() as u64;
unsafe {
syscall(
Expand All @@ -737,15 +729,14 @@ pub fn inherited_file_descriptors(fds: &mut [u64]) {
0,
0,
0,
SYS_INHERITED_FD,
SYS_INHERITED_FDS,
)
};
}

/// This syscall manually closes a file descriptor. After calling this, any attempt to read/write the file descriptor
/// pointed to the other end would fail.
/// Note: available after ckb2023.
#[cfg(feature = "ckb2023")]
pub fn close(fd: u64) -> Result<(), SysError> {
let ret = unsafe { syscall(fd, 0, 0, 0, 0, 0, 0, SYS_CLOSE) };
match ret {
Expand All @@ -766,7 +757,6 @@ pub fn close(fd: u64) -> Result<(), SysError> {
/// * `source` - source of cell
///
/// Note: available after ckb2023.
#[cfg(feature = "ckb2023")]
pub fn load_block_extension(
buf: &mut [u8],
offset: usize,
Expand Down
59 changes: 59 additions & 0 deletions src/syscalls/simulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,3 +257,62 @@ pub fn exec_cell(
);
Err(SysError::Unknown(ret as u64))
}

#[repr(C)]
pub struct SpawnArgs {
/// argc contains the number of arguments passed to the program.
pub argc: u64,
/// argv is a one-dimensional array of strings.
pub argv: *const *const i8,
/// a pointer used to save the process_id of the child process.
pub process_id: *mut u64,
/// an array representing the file descriptors passed to the child process. It must end with zero.
pub inherited_fds: *const u64,
}

pub fn spawn(
index: usize,
source: Source,
place: usize,
bounds: usize,
spgs: &mut SpawnArgs,
) -> Result<u64, SysError> {
panic!("This is not supported in the native-simulator!");
}

pub fn wait(pid: u64) -> Result<i8, SysError> {
panic!("This is not supported in the native-simulator!");
}

pub fn process_id() -> u64 {
panic!("This is not supported in the native-simulator!");
}

pub fn pipe() -> Result<(u64, u64), SysError> {
panic!("This is not supported in the native-simulator!");
}

pub fn read(fd: u64, buffer: &mut [u8]) -> Result<usize, SysError> {
panic!("This is not supported in the native-simulator!");
}

pub fn write(fd: u64, buffer: &[u8]) -> Result<usize, SysError> {
panic!("This is not supported in the native-simulator!");
}

pub fn inherited_fds(fds: &mut [u64]) {
panic!("This is not supported in the native-simulator!");
}

pub fn close(fd: u64) -> Result<(), SysError> {
panic!("This is not supported in the native-simulator!");
}

pub fn load_block_extension(
buf: &mut [u8],
offset: usize,
index: usize,
source: Source,
) -> Result<usize, SysError> {
panic!("This is not supported in the native-simulator!");
}
10 changes: 10 additions & 0 deletions test/simulator/src/exec_callee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ pub mod error {
ItemMissing,
LengthNotEnough,
Encoding,
WaitFailure,
InvalidFd,
OtherEndClosed,
MaxVmsSpawned,
MaxFdsCreated,
// Add customized errors here...
}

Expand All @@ -23,6 +28,11 @@ pub mod error {
ItemMissing => Self::ItemMissing,
LengthNotEnough(_) => Self::LengthNotEnough,
Encoding => Self::Encoding,
WaitFailure => Self::WaitFailure,
InvalidFd => Self::InvalidFd,
OtherEndClosed => Self::OtherEndClosed,
MaxVmsSpawned => Self::MaxVmsSpawned,
MaxFdsCreated => Self::MaxFdsCreated,
Unknown(err_code) => panic!("unexpected sys error {}", err_code),
}
}
Expand Down
10 changes: 10 additions & 0 deletions test/simulator/src/exec_caller_by_code_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ pub mod error {
ItemMissing,
LengthNotEnough,
Encoding,
WaitFailure,
InvalidFd,
OtherEndClosed,
MaxVmsSpawned,
MaxFdsCreated,
// Add customized errors here...
}

Expand All @@ -23,6 +28,11 @@ pub mod error {
ItemMissing => Self::ItemMissing,
LengthNotEnough(_) => Self::LengthNotEnough,
Encoding => Self::Encoding,
WaitFailure => Self::WaitFailure,
InvalidFd => Self::InvalidFd,
OtherEndClosed => Self::OtherEndClosed,
MaxVmsSpawned => Self::MaxVmsSpawned,
MaxFdsCreated => Self::MaxFdsCreated,
Unknown(err_code) => panic!("unexpected sys error {}", err_code),
}
}
Expand Down
Loading

0 comments on commit ff279d5

Please sign in to comment.