@@ -54,117 +54,6 @@ void handle_sigint(int)
54
54
g->was_interrupted = true ;
55
55
}
56
56
57
- static int sh_busy (int , char **)
58
- {
59
- struct sigaction sa;
60
- sa.sa_handler = did_receive_signal;
61
- sa.sa_flags = 0 ;
62
- sa.sa_mask = 0 ;
63
- sa.sa_restorer = nullptr ;
64
- int rc = sigaction (SIGUSR1, &sa, nullptr );
65
- assert (rc == 0 );
66
- printf (" listening for signal SIGUSR1 while looping in userspace...\n " );
67
- for (;;) {
68
- for (volatile int i = 0 ; i < 100000 ; ++i)
69
- ;
70
- if (g_got_signal)
71
- break ;
72
- }
73
- g_got_signal = false ;
74
- return 0 ;
75
- }
76
-
77
- static int sh_fork (int , char **)
78
- {
79
- pid_t pid = fork ();
80
- printf (" getpid()=%d, fork()=%d\n " , getpid (), pid);
81
- return 0 ;
82
- }
83
-
84
- static int sh_fe (int , char **)
85
- {
86
- pid_t pid = fork ();
87
- if (!pid) {
88
- int rc = execvp (" /bin/ps" , nullptr );
89
- if (rc < 0 ) {
90
- perror (" execvp" );
91
- exit (1 );
92
- }
93
- }
94
- return 0 ;
95
- }
96
-
97
- static int sh_fef (int , char **)
98
- {
99
- pid_t pid = fork ();
100
- if (!pid) {
101
- int rc = execvp (" /bin/psx" , nullptr );
102
- if (rc < 0 ) {
103
- perror (" execvp" );
104
- exit (1 );
105
- }
106
- }
107
- return 0 ;
108
- }
109
-
110
- static int sh_wt (int , char **)
111
- {
112
- const char * rodata_ptr = " foo" ;
113
- printf (" Writing to rodata=%p...\n " , rodata_ptr);
114
- *const_cast <char *>(rodata_ptr) = 0 ;
115
-
116
- char * text_ptr = (char *)sh_fef;
117
- printf (" Writing to text=%p...\n " , text_ptr);
118
- *text_ptr = 0 ;
119
- return 0 ;
120
- }
121
-
122
- static int sh_mf (int , char **)
123
- {
124
- int rc;
125
- int fd = open (" /Banner.txt" , O_RDONLY);
126
- if (fd < 0 ) {
127
- perror (" open(/Banner.txt)" );
128
- return 1 ;
129
- }
130
- printf (" opened /Banner.txt, calling mmap...\n " );
131
- byte* data = (byte*)mmap (nullptr , getpagesize (), PROT_READ, MAP_PRIVATE, fd, 0 );
132
- if (data == MAP_FAILED) {
133
- perror (" mmap()" );
134
- goto close_it;
135
- }
136
- printf (" mapped file @ %p\n " , data);
137
- printf (" contents: %b %b %b %b\n " , data[0 ], data[1 ], data[2 ], data[3 ]);
138
-
139
- rc = munmap (data, getpagesize ());
140
- printf (" munmap() returned %d\n " , rc);
141
-
142
- close_it:
143
- rc = close (fd);
144
- printf (" close() returned %d\n " , rc);
145
- return 0 ;
146
- }
147
-
148
- static int sh_mp (int , char **)
149
- {
150
- int fd = open (" /kernel.map" , O_RDONLY);
151
- if (fd < 0 ) {
152
- perror (" open(/kernel.map)" );
153
- return 1 ;
154
- }
155
- printf (" opened /kernel.map, calling mmap...\n " );
156
- byte* data = (byte*)mmap (nullptr , getpagesize () * 10 , PROT_READ, MAP_PRIVATE, fd, 0 );
157
- if (data == MAP_FAILED) {
158
- perror (" mmap()" );
159
- return 1 ;
160
- }
161
- printf (" mapped file @ %p\n " , data);
162
- 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 ]);
163
-
164
- printf (" leaving it open :)\n " );
165
- return 0 ;
166
- }
167
-
168
57
static int sh_exit (int , char **)
169
58
{
170
59
printf (" Good-bye!\n " );
@@ -227,34 +116,6 @@ static bool handle_builtin(int argc, char** argv, int& retval)
227
116
retval = sh_exit (argc, argv);
228
117
return true ;
229
118
}
230
- if (!strcmp (argv[0 ], " fe" )) {
231
- retval = sh_fe (argc, argv);
232
- return true ;
233
- }
234
- if (!strcmp (argv[0 ], " fef" )) {
235
- retval = sh_fef (argc, argv);
236
- return true ;
237
- }
238
- if (!strcmp (argv[0 ], " busy" )) {
239
- retval = sh_busy (argc, argv);
240
- return true ;
241
- }
242
- if (!strcmp (argv[0 ], " wt" )) {
243
- retval = sh_wt (argc, argv);
244
- return true ;
245
- }
246
- if (!strcmp (argv[0 ], " mf" )) {
247
- retval = sh_mf (argc, argv);
248
- return true ;
249
- }
250
- if (!strcmp (argv[0 ], " mp" )) {
251
- retval = sh_mp (argc, argv);
252
- return true ;
253
- }
254
- if (!strcmp (argv[0 ], " fork" )) {
255
- retval = sh_fork (argc, argv);
256
- return true ;
257
- }
258
119
return false ;
259
120
}
260
121
0 commit comments