|
@@ -54,117 +54,6 @@ void handle_sigint(int)
|
|
|
g->was_interrupted = true;
|
|
|
}
|
|
|
|
|
|
-static int sh_busy(int, char**)
|
|
|
-{
|
|
|
- struct sigaction sa;
|
|
|
- sa.sa_handler = did_receive_signal;
|
|
|
- sa.sa_flags = 0;
|
|
|
- sa.sa_mask = 0;
|
|
|
- sa.sa_restorer = nullptr;
|
|
|
- int rc = sigaction(SIGUSR1, &sa, nullptr);
|
|
|
- assert(rc == 0);
|
|
|
- printf("listening for signal SIGUSR1 while looping in userspace...\n");
|
|
|
- for (;;) {
|
|
|
- for (volatile int i = 0; i < 100000; ++i)
|
|
|
- ;
|
|
|
- if (g_got_signal)
|
|
|
- break;
|
|
|
- }
|
|
|
- g_got_signal = false;
|
|
|
- return 0;
|
|
|
-}
|
|
|
-
|
|
|
-static int sh_fork(int, char**)
|
|
|
-{
|
|
|
- pid_t pid = fork();
|
|
|
- printf("getpid()=%d, fork()=%d\n", getpid(), pid);
|
|
|
- return 0;
|
|
|
-}
|
|
|
-
|
|
|
-static int sh_fe(int, char**)
|
|
|
-{
|
|
|
- pid_t pid = fork();
|
|
|
- if (!pid) {
|
|
|
- int rc = execvp("/bin/ps", nullptr);
|
|
|
- if (rc < 0) {
|
|
|
- perror("execvp");
|
|
|
- exit(1);
|
|
|
- }
|
|
|
- }
|
|
|
- return 0;
|
|
|
-}
|
|
|
-
|
|
|
-static int sh_fef(int, char**)
|
|
|
-{
|
|
|
- pid_t pid = fork();
|
|
|
- if (!pid) {
|
|
|
- int rc = execvp("/bin/psx", nullptr);
|
|
|
- if (rc < 0) {
|
|
|
- perror("execvp");
|
|
|
- exit(1);
|
|
|
- }
|
|
|
- }
|
|
|
- return 0;
|
|
|
-}
|
|
|
-
|
|
|
-static int sh_wt(int, char**)
|
|
|
-{
|
|
|
- const char* rodata_ptr = "foo";
|
|
|
- printf("Writing to rodata=%p...\n", rodata_ptr);
|
|
|
- *const_cast<char*>(rodata_ptr) = 0;
|
|
|
-
|
|
|
- char* text_ptr = (char*)sh_fef;
|
|
|
- printf("Writing to text=%p...\n", text_ptr);
|
|
|
- *text_ptr = 0;
|
|
|
- return 0;
|
|
|
-}
|
|
|
-
|
|
|
-static int sh_mf(int, char**)
|
|
|
-{
|
|
|
- int rc;
|
|
|
- int fd = open("/Banner.txt", O_RDONLY);
|
|
|
- if (fd < 0) {
|
|
|
- perror("open(/Banner.txt)");
|
|
|
- return 1;
|
|
|
- }
|
|
|
- printf("opened /Banner.txt, calling mmap...\n");
|
|
|
- byte* data = (byte*)mmap(nullptr, getpagesize(), PROT_READ, MAP_PRIVATE, fd, 0);
|
|
|
- if (data == MAP_FAILED) {
|
|
|
- perror("mmap()");
|
|
|
- goto close_it;
|
|
|
- }
|
|
|
- printf("mapped file @ %p\n", data);
|
|
|
- printf("contents: %b %b %b %b\n", data[0], data[1], data[2], data[3]);
|
|
|
-
|
|
|
- rc = munmap(data, getpagesize());
|
|
|
- printf("munmap() returned %d\n", rc);
|
|
|
-
|
|
|
-close_it:
|
|
|
- rc = close(fd);
|
|
|
- printf("close() returned %d\n", rc);
|
|
|
- return 0;
|
|
|
-}
|
|
|
-
|
|
|
-static int sh_mp(int, char**)
|
|
|
-{
|
|
|
- int fd = open("/kernel.map", O_RDONLY);
|
|
|
- if (fd < 0) {
|
|
|
- perror("open(/kernel.map)");
|
|
|
- return 1;
|
|
|
- }
|
|
|
- printf("opened /kernel.map, calling mmap...\n");
|
|
|
- byte* data = (byte*)mmap(nullptr, getpagesize() * 10, PROT_READ, MAP_PRIVATE, fd, 0);
|
|
|
- if (data == MAP_FAILED) {
|
|
|
- perror("mmap()");
|
|
|
- return 1;
|
|
|
- }
|
|
|
- printf("mapped file @ %p\n", data);
|
|
|
- printf("contents: %c%c%c%c%c%c%c%c...\n", data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7]);
|
|
|
-
|
|
|
- printf("leaving it open :)\n");
|
|
|
- return 0;
|
|
|
-}
|
|
|
-
|
|
|
static int sh_exit(int, char**)
|
|
|
{
|
|
|
printf("Good-bye!\n");
|
|
@@ -227,34 +116,6 @@ static bool handle_builtin(int argc, char** argv, int& retval)
|
|
|
retval = sh_exit(argc, argv);
|
|
|
return true;
|
|
|
}
|
|
|
- if (!strcmp(argv[0], "fe")) {
|
|
|
- retval = sh_fe(argc, argv);
|
|
|
- return true;
|
|
|
- }
|
|
|
- if (!strcmp(argv[0], "fef")) {
|
|
|
- retval = sh_fef(argc, argv);
|
|
|
- return true;
|
|
|
- }
|
|
|
- if (!strcmp(argv[0], "busy")) {
|
|
|
- retval = sh_busy(argc, argv);
|
|
|
- return true;
|
|
|
- }
|
|
|
- if (!strcmp(argv[0], "wt")) {
|
|
|
- retval = sh_wt(argc, argv);
|
|
|
- return true;
|
|
|
- }
|
|
|
- if (!strcmp(argv[0], "mf")) {
|
|
|
- retval = sh_mf(argc, argv);
|
|
|
- return true;
|
|
|
- }
|
|
|
- if (!strcmp(argv[0], "mp")) {
|
|
|
- retval = sh_mp(argc, argv);
|
|
|
- return true;
|
|
|
- }
|
|
|
- if (!strcmp(argv[0], "fork")) {
|
|
|
- retval = sh_fork(argc, argv);
|
|
|
- return true;
|
|
|
- }
|
|
|
return false;
|
|
|
}
|
|
|
|