Skip to content

Commit

Permalink
Adjusting the spawn syscall (#63)
Browse files Browse the repository at this point in the history
* Adjusting the spawn syscall
  • Loading branch information
mohanson authored Sep 11, 2024
1 parent d7dc1e3 commit be84dcf
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion ckb_consts.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#define SYS_ckb_pipe 2604
#define SYS_ckb_write 2605
#define SYS_ckb_read 2606
#define SYS_ckb_inherited_fd 2607
#define SYS_ckb_inherited_fds 2607
#define SYS_ckb_close 2608

#define CKB_SUCCESS 0
Expand Down
9 changes: 8 additions & 1 deletion ckb_syscall_apis.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ typedef struct spawn_args_t {

int ckb_spawn(size_t index, size_t source, size_t place, size_t bounds,
spawn_args_t* spawn_args);

int ckb_spawn_cell(const uint8_t* code_hash, uint8_t hash_type, uint32_t offset,
uint32_t length, spawn_args_t* spawn_args);

int ckb_wait(uint64_t pid, int8_t* exit_code);

uint64_t ckb_process_id();
Expand All @@ -63,8 +67,11 @@ int ckb_read(uint64_t fd, void* buffer, size_t* length);

int ckb_write(uint64_t fd, const void* buffer, size_t* length);

int ckb_inherited_file_descriptors(uint64_t* fd, size_t* length);
int ckb_inherited_fds(uint64_t* fds, size_t* length);

int ckb_close(uint64_t fd);

int ckb_load_block_extension(void* addr, uint64_t* len, size_t offset,
size_t index, size_t source);

#endif /* CKB_C_STDLIB_CKB_SYSCALL_APIS_H_ */
16 changes: 14 additions & 2 deletions ckb_syscalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,18 @@ int ckb_spawn(size_t index, size_t source, size_t place, size_t bounds,
return syscall(SYS_ckb_spawn, index, source, place, bounds, spawn_args, 0);
}

int ckb_spawn_cell(const uint8_t* code_hash, uint8_t hash_type, uint32_t offset,
uint32_t length, spawn_args_t* spawn_args) {
size_t index = SIZE_MAX;
int ret = ckb_look_for_dep_with_hash2(code_hash, hash_type, &index);
if (ret != CKB_SUCCESS) {
return ret;
}
size_t bounds = ((size_t)offset << 32) | length;
return syscall(SYS_ckb_spawn, index, CKB_SOURCE_CELL_DEP, 0, bounds,
spawn_args, 0);
}

int ckb_wait(uint64_t pid, int8_t* exit_code) {
return syscall(SYS_ckb_wait, pid, exit_code, 0, 0, 0, 0);
}
Expand Down Expand Up @@ -414,9 +426,9 @@ int ckb_load_block_extension(void* addr, uint64_t* len, size_t offset,
0);
}

int ckb_inherited_file_descriptors(uint64_t* fd, size_t* length) {
int ckb_inherited_fds(uint64_t* fds, size_t* length) {
volatile size_t l = *length;
int ret = syscall(SYS_ckb_inherited_fd, fd, &l, 0, 0, 0, 0);
int ret = syscall(SYS_ckb_inherited_fds, fds, &l, 0, 0, 0, 0);
*length = l;
return ret;
}
Expand Down

0 comments on commit be84dcf

Please sign in to comment.