forked from nervosnetwork/ckb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0e653fb
commit 38d73a9
Showing
11 changed files
with
117 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#include "spawn_utils.h" | ||
|
||
// 2.4 M bytes | ||
static uint64_t g_data[300 * 1024]; | ||
|
||
int main() { | ||
int err = 0; | ||
uint64_t fds[2] = {0}; | ||
uint64_t pid = 0; | ||
uint64_t current_pid = ckb_process_id(); | ||
size_t argc = 1; | ||
const char* argv[2] = {"", 0}; | ||
int8_t exit_code = 0; | ||
|
||
printf("current pid = %d", current_pid); | ||
for (size_t i = 0; i < sizeof(g_data) / sizeof(uint64_t); i++) { | ||
g_data[i] = current_pid; | ||
} | ||
|
||
if (current_pid == 7) { | ||
// wait forever | ||
ckb_wait(0, &exit_code); | ||
} else { | ||
err = full_spawn(0, argc, argv, fds, &pid); | ||
CHECK(err); | ||
if (current_pid == 0) { | ||
uint8_t buf[1] = {0}; | ||
while (true) { | ||
size_t len = 1; | ||
ckb_read(fds[CKB_STDIN], buf, &len); | ||
} | ||
} else if (current_pid == 1) { | ||
uint64_t inherited_fds[3]; | ||
size_t fds_len = 3; | ||
err = ckb_inherited_file_descriptors(inherited_fds, &fds_len); | ||
CHECK(err); | ||
uint8_t buf[1] = {0}; | ||
while (true) { | ||
size_t len = 1; | ||
ckb_write(inherited_fds[CKB_STDOUT], buf, &len); | ||
ckb_read(fds[CKB_STDIN], buf, &len); | ||
} | ||
} else if (current_pid == 2) { | ||
uint64_t inherited_fds[3]; | ||
size_t fds_len = 3; | ||
err = ckb_inherited_file_descriptors(inherited_fds, &fds_len); | ||
CHECK(err); | ||
uint8_t buf[1] = {0}; | ||
while (true) { | ||
size_t len = 1; | ||
ckb_write(inherited_fds[CKB_STDOUT], buf, &len); | ||
} | ||
} else { | ||
// wait forever | ||
ckb_wait(0, &exit_code); | ||
} | ||
} | ||
// avoid g_data to be optimized | ||
for (size_t i = 0; i < sizeof(g_data) / sizeof(uint64_t); i++) { | ||
err += (int8_t)g_data[i]; | ||
} | ||
|
||
exit: | ||
return err; | ||
} |
Binary file not shown.