From ff279d506e2008de6920dfe359c7b9daaf24d349 Mon Sep 17 00:00:00 2001 From: mohanson Date: Wed, 11 Sep 2024 11:46:57 +0800 Subject: [PATCH] Remove ckb2023 feature --- Cargo.toml | 3 +- c/ckb-c-stdlib | 2 +- contracts/ckb-std-tests/src/error.rs | 10 ++++ contracts/exec-callee/src/error.rs | 10 ++++ .../exec-caller-by-code-hash/src/error.rs | 10 ++++ contracts/exec-caller/src/error.rs | 10 ++++ contracts/spawn-callee/Cargo.toml | 2 +- contracts/spawn-callee/src/entry.rs | 2 +- .../spawn-caller-by-code-hash/Cargo.toml | 2 +- contracts/spawn-caller/Cargo.toml | 2 +- src/ckb_constants.rs | 11 +--- src/error.rs | 5 -- src/high_level.rs | 1 - src/syscalls/native.rs | 14 +---- src/syscalls/simulator.rs | 59 +++++++++++++++++++ test/simulator/src/exec_callee.rs | 10 ++++ .../simulator/src/exec_caller_by_code_hash.rs | 10 ++++ test/simulator/src/main.rs | 10 ++++ 18 files changed, 138 insertions(+), 35 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6024ee0..845eec2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 @@ -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"] diff --git a/c/ckb-c-stdlib b/c/ckb-c-stdlib index 458af43..be84dcf 160000 --- a/c/ckb-c-stdlib +++ b/c/ckb-c-stdlib @@ -1 +1 @@ -Subproject commit 458af43931d122559c42fdd5bf879509a3e10a21 +Subproject commit be84dcf385ddc2ab52b2650fb959e3769dc75093 diff --git a/contracts/ckb-std-tests/src/error.rs b/contracts/ckb-std-tests/src/error.rs index 13e7def..c84bbe6 100644 --- a/contracts/ckb-std-tests/src/error.rs +++ b/contracts/ckb-std-tests/src/error.rs @@ -7,6 +7,11 @@ pub enum Error { ItemMissing, LengthNotEnough, Encoding, + WaitFailure, + InvalidFd, + OtherEndClosed, + MaxVmsSpawned, + MaxFdsCreated, // Add customized errors here... } @@ -18,6 +23,11 @@ impl From 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), } } diff --git a/contracts/exec-callee/src/error.rs b/contracts/exec-callee/src/error.rs index 13e7def..c84bbe6 100644 --- a/contracts/exec-callee/src/error.rs +++ b/contracts/exec-callee/src/error.rs @@ -7,6 +7,11 @@ pub enum Error { ItemMissing, LengthNotEnough, Encoding, + WaitFailure, + InvalidFd, + OtherEndClosed, + MaxVmsSpawned, + MaxFdsCreated, // Add customized errors here... } @@ -18,6 +23,11 @@ impl From 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), } } diff --git a/contracts/exec-caller-by-code-hash/src/error.rs b/contracts/exec-caller-by-code-hash/src/error.rs index 13e7def..c84bbe6 100644 --- a/contracts/exec-caller-by-code-hash/src/error.rs +++ b/contracts/exec-caller-by-code-hash/src/error.rs @@ -7,6 +7,11 @@ pub enum Error { ItemMissing, LengthNotEnough, Encoding, + WaitFailure, + InvalidFd, + OtherEndClosed, + MaxVmsSpawned, + MaxFdsCreated, // Add customized errors here... } @@ -18,6 +23,11 @@ impl From 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), } } diff --git a/contracts/exec-caller/src/error.rs b/contracts/exec-caller/src/error.rs index 13e7def..c84bbe6 100644 --- a/contracts/exec-caller/src/error.rs +++ b/contracts/exec-caller/src/error.rs @@ -7,6 +7,11 @@ pub enum Error { ItemMissing, LengthNotEnough, Encoding, + WaitFailure, + InvalidFd, + OtherEndClosed, + MaxVmsSpawned, + MaxFdsCreated, // Add customized errors here... } @@ -18,6 +23,11 @@ impl From 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), } } diff --git a/contracts/spawn-callee/Cargo.toml b/contracts/spawn-callee/Cargo.toml index 50f1687..60d771e 100644 --- a/contracts/spawn-callee/Cargo.toml +++ b/contracts/spawn-callee/Cargo.toml @@ -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 = "../../" } diff --git a/contracts/spawn-callee/src/entry.rs b/contracts/spawn-callee/src/entry.rs index 0c13756..7404317 100644 --- a/contracts/spawn-callee/src/entry.rs +++ b/contracts/spawn-callee/src/entry.rs @@ -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()); diff --git a/contracts/spawn-caller-by-code-hash/Cargo.toml b/contracts/spawn-caller-by-code-hash/Cargo.toml index 72782e6..cf5b834 100644 --- a/contracts/spawn-caller-by-code-hash/Cargo.toml +++ b/contracts/spawn-caller-by-code-hash/Cargo.toml @@ -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 = "../../" } diff --git a/contracts/spawn-caller/Cargo.toml b/contracts/spawn-caller/Cargo.toml index 15bade2..af1c69b 100644 --- a/contracts/spawn-caller/Cargo.toml +++ b/contracts/spawn-caller/Cargo.toml @@ -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 = "../../" } diff --git a/src/ckb_constants.rs b/src/ckb_constants.rs index 18c714c..1782c2d 100644 --- a/src/ckb_constants.rs +++ b/src/ckb_constants.rs @@ -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; diff --git a/src/error.rs b/src/error.rs index 35b2c18..65ccd6c 100644 --- a/src/error.rs +++ b/src/error.rs @@ -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 diff --git a/src/high_level.rs b/src/high_level.rs index 6e2cad7..68b50a9 100644 --- a/src/high_level.rs +++ b/src/high_level.rs @@ -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, diff --git a/src/syscalls/native.rs b/src/syscalls/native.rs index 6d6027f..26c3bc9 100644 --- a/src/syscalls/native.rs +++ b/src/syscalls/native.rs @@ -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. @@ -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, @@ -636,7 +634,6 @@ pub fn spawn( /// * `pid` - process id /// /// Returns exit code. -#[cfg(feature = "ckb2023")] pub fn wait(pid: u64) -> Result { let mut code: u64 = 0; let ret = unsafe { syscall(pid, &mut code as *mut u64 as u64, 0, 0, 0, 0, 0, SYS_WAIT) }; @@ -649,7 +646,6 @@ pub fn wait(pid: u64) -> Result { /// 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) } } @@ -657,7 +653,6 @@ pub fn process_id() -> u64 { /// 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) }; @@ -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 { let mut l: u64 = buffer.len() as u64; let ret = unsafe { @@ -698,7 +692,6 @@ pub fn read(fd: u64, buffer: &mut [u8]) -> Result { /// 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 { let mut l: u64 = buffer.len() as u64; let ret = unsafe { @@ -725,8 +718,7 @@ pub fn write(fd: u64, buffer: &[u8]) -> Result { /// 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( @@ -737,7 +729,7 @@ pub fn inherited_file_descriptors(fds: &mut [u64]) { 0, 0, 0, - SYS_INHERITED_FD, + SYS_INHERITED_FDS, ) }; } @@ -745,7 +737,6 @@ pub fn inherited_file_descriptors(fds: &mut [u64]) { /// 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 { @@ -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, diff --git a/src/syscalls/simulator.rs b/src/syscalls/simulator.rs index 8312dd2..40cbfd4 100644 --- a/src/syscalls/simulator.rs +++ b/src/syscalls/simulator.rs @@ -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 { + panic!("This is not supported in the native-simulator!"); +} + +pub fn wait(pid: u64) -> Result { + 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 { + panic!("This is not supported in the native-simulator!"); +} + +pub fn write(fd: u64, buffer: &[u8]) -> Result { + 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 { + panic!("This is not supported in the native-simulator!"); +} diff --git a/test/simulator/src/exec_callee.rs b/test/simulator/src/exec_callee.rs index 4c8aec4..ff011ca 100644 --- a/test/simulator/src/exec_callee.rs +++ b/test/simulator/src/exec_callee.rs @@ -12,6 +12,11 @@ pub mod error { ItemMissing, LengthNotEnough, Encoding, + WaitFailure, + InvalidFd, + OtherEndClosed, + MaxVmsSpawned, + MaxFdsCreated, // Add customized errors here... } @@ -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), } } diff --git a/test/simulator/src/exec_caller_by_code_hash.rs b/test/simulator/src/exec_caller_by_code_hash.rs index a5b1a74..28b899e 100644 --- a/test/simulator/src/exec_caller_by_code_hash.rs +++ b/test/simulator/src/exec_caller_by_code_hash.rs @@ -12,6 +12,11 @@ pub mod error { ItemMissing, LengthNotEnough, Encoding, + WaitFailure, + InvalidFd, + OtherEndClosed, + MaxVmsSpawned, + MaxFdsCreated, // Add customized errors here... } @@ -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), } } diff --git a/test/simulator/src/main.rs b/test/simulator/src/main.rs index 9d5f73a..b91d7a9 100644 --- a/test/simulator/src/main.rs +++ b/test/simulator/src/main.rs @@ -15,6 +15,11 @@ pub mod error { ItemMissing, LengthNotEnough, Encoding, + WaitFailure, + InvalidFd, + OtherEndClosed, + MaxVmsSpawned, + MaxFdsCreated, // Add customized errors here... } @@ -26,6 +31,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), } }