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.
Showing
4 changed files
with
54 additions
and
1 deletion.
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
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,45 @@ | ||
#include "spawn_utils.h" | ||
|
||
#define MAX_MEMORY (4 * 1024 * 1024) | ||
#define PAGE_SIZE (4 * 1024) | ||
|
||
extern char _end[]; | ||
|
||
void dirty_all_pages() { | ||
uint64_t addr = (uint64_t)_end; | ||
while (addr < MAX_MEMORY) { | ||
uint8_t* ptr = (uint8_t*)addr; | ||
*ptr = 0; | ||
addr += PAGE_SIZE; | ||
} | ||
} | ||
|
||
int main(int argc, const char* argv[]) { | ||
int err = 0; | ||
if (argc > 0) { | ||
// child | ||
dirty_all_pages(); | ||
uint64_t inherited_fds[2]; | ||
size_t inherited_fds_length = 2; | ||
err = ckb_inherited_file_descriptors(inherited_fds, &inherited_fds_length); | ||
uint64_t length = MAX_MEMORY; | ||
// Write a piece of data starting from address 0 with a size of 4M. | ||
// Internally, it is cached before being read out. | ||
err = ckb_write(inherited_fds[CKB_STDOUT], 0, &length); | ||
// should be blocked forever since there is no reading on other end | ||
CHECK(err); | ||
} else { | ||
// parent | ||
for (size_t i = 0; i < 15; i++) { | ||
uint64_t pid = 0; | ||
const char* argv[] = {"", 0}; | ||
uint64_t fds[2] = {0}; | ||
err = full_spawn(0, 1, argv, fds, &pid); | ||
CHECK(err); | ||
} | ||
dirty_all_pages(); | ||
} | ||
|
||
exit: | ||
return err; | ||
} |