Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add spawn syscalls for ckb2023 #41

Merged
merged 4 commits into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ckb_consts.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
#define SYS_ckb_load_cell_data_as_code 2091
#define SYS_ckb_load_cell_data 2092
#define SYS_ckb_debug 2177
#define SYS_ckb_spawn 2101
#define SYS_ckb_get_memory_limit 2102
#define SYS_ckb_set_content 2103

#define CKB_SUCCESS 0
#define CKB_INDEX_OUT_OF_BOUND 1
Expand Down
14 changes: 14 additions & 0 deletions ckb_syscall_apis.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,18 @@ int ckb_dlopen2(const uint8_t* dep_cell_hash, uint8_t hash_type,
size_t* consumed_size);
void* ckb_dlsym(void* handle, const char* symbol);

typedef struct spawn_args_t {
uint64_t memory_limit;
int8_t* exit_code;
uint8_t* content;
uint64_t* content_length;
} spawn_args_t;
int ckb_spawn(size_t index, size_t source, size_t bounds, int argc,
const char* argv[], spawn_args_t* spgs);
int ckb_spawn_cell(const uint8_t* code_hash, uint8_t hash_type, uint32_t offset,
uint32_t length, int argc, const char* argv[],
spawn_args_t* spgs);
int ckb_get_memory_limit();
int ckb_set_content(uint8_t* content, uint64_t* length);

#endif /* CKB_C_STDLIB_CKB_SYSCALL_APIS_H_ */
25 changes: 25 additions & 0 deletions ckb_syscalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,31 @@ int ckb_exec_cell(const uint8_t* code_hash, uint8_t hash_type, uint32_t offset,
argv);
}

int ckb_spawn(size_t index, size_t source, size_t bounds, int argc,
const char* argv[], spawn_args_t* spgs) {
return syscall(SYS_ckb_spawn, index, source, bounds, argc, argv, spgs);
}

int ckb_spawn_cell(const uint8_t* code_hash, uint8_t hash_type, uint32_t offset,
uint32_t length, int argc, const char* argv[],
spawn_args_t* spgs) {
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 ckb_spawn(index, CKB_SOURCE_CELL_DEP, bounds, argc, argv, spgs);
mohanson marked this conversation as resolved.
Show resolved Hide resolved
}

int ckb_get_memory_limit() {
return syscall(SYS_ckb_get_memory_limit, 0, 0, 0, 0, 0, 0);
}

int ckb_set_content(uint8_t* content, uint64_t* length) {
return syscall(SYS_ckb_set_content, content, length, 0, 0, 0, 0);
}

#endif /* CKB_STDLIB_NO_SYSCALL_IMPL */

#endif /* CKB_C_STDLIB_CKB_SYSCALLS_H_ */
21 changes: 11 additions & 10 deletions ckb_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,17 @@ int ckb_since_cmp(uint64_t a, uint64_t b, int *comparable) {
* return 0;
* }
*/
#define CKB_SP_ALIGN \
__asm__("addi t0, sp, 0\n\t" \
"andi sp, sp, 0xfffffffffffffff8\n\t" \
"sd t0, -8(sp)\n\t" \
"sd t0, -16(sp)\n\t" \
"addi sp, sp, -8\n\t" \
"andi sp, sp, 0xfffffffffffffff0" \
: \
: \
: "t0")
#define CKB_SP_ALIGN \
__asm__( \
"addi t0, sp, 0\n" \
"andi sp, sp, 0xfffffffffffffff8\n" \
"sd t0, -8(sp)\n" \
"sd t0, -16(sp)\n" \
"addi sp, sp, -8\n" \
"andi sp, sp, 0xfffffffffffffff0" \
: \
: \
: "t0")
#define CKB_SP_ALIGN_END __asm__("ld sp, 0(sp)")

#endif /* CKB_C_STDLIB_CKB_UTILS_H_ */