@@ -213,22 +213,22 @@ static int make_exe(const uint8_t *payload, size_t len)
213
213
214
214
/*
215
215
* 0: vsyscall VMA doesn't exist vsyscall=none
216
- * 1: vsyscall VMA is r- xp vsyscall=emulate
217
- * 2: vsyscall VMA is -- xp vsyscall=xonly
216
+ * 1: vsyscall VMA is -- xp vsyscall=xonly
217
+ * 2: vsyscall VMA is r- xp vsyscall=emulate
218
218
*/
219
- static int g_vsyscall ;
219
+ static volatile int g_vsyscall ;
220
220
static const char * str_vsyscall ;
221
221
222
222
static const char str_vsyscall_0 [] = "" ;
223
223
static const char str_vsyscall_1 [] =
224
- "ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall]\n" ;
225
- static const char str_vsyscall_2 [] =
226
224
"ffffffffff600000-ffffffffff601000 --xp 00000000 00:00 0 [vsyscall]\n" ;
225
+ static const char str_vsyscall_2 [] =
226
+ "ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall]\n" ;
227
227
228
228
#ifdef __x86_64__
229
229
static void sigaction_SIGSEGV (int _ , siginfo_t * __ , void * ___ )
230
230
{
231
- _exit (1 );
231
+ _exit (g_vsyscall );
232
232
}
233
233
234
234
/*
@@ -255,52 +255,28 @@ static void vsyscall(void)
255
255
act .sa_sigaction = sigaction_SIGSEGV ;
256
256
(void )sigaction (SIGSEGV , & act , NULL );
257
257
258
+ g_vsyscall = 0 ;
258
259
/* gettimeofday(NULL, NULL); */
259
260
asm volatile (
260
261
"call %P0"
261
262
:
262
263
: "i" (0xffffffffff600000 ), "D" (NULL ), "S" (NULL )
263
264
: "rax" , "rcx" , "r11"
264
265
);
265
- exit (0 );
266
- }
267
- waitpid (pid , & wstatus , 0 );
268
- if (WIFEXITED (wstatus ) && WEXITSTATUS (wstatus ) == 0 ) {
269
- /* vsyscall page exists and is executable. */
270
- } else {
271
- /* vsyscall page doesn't exist. */
272
- g_vsyscall = 0 ;
273
- return ;
274
- }
275
-
276
- pid = fork ();
277
- if (pid < 0 ) {
278
- fprintf (stderr , "fork, errno %d\n" , errno );
279
- exit (1 );
280
- }
281
- if (pid == 0 ) {
282
- struct rlimit rlim = {0 , 0 };
283
- (void )setrlimit (RLIMIT_CORE , & rlim );
284
-
285
- /* Hide "segfault at ffffffffff600000" messages. */
286
- struct sigaction act ;
287
- memset (& act , 0 , sizeof (struct sigaction ));
288
- act .sa_flags = SA_SIGINFO ;
289
- act .sa_sigaction = sigaction_SIGSEGV ;
290
- (void )sigaction (SIGSEGV , & act , NULL );
291
266
267
+ g_vsyscall = 1 ;
292
268
* (volatile int * )0xffffffffff600000UL ;
293
- exit (0 );
269
+
270
+ g_vsyscall = 2 ;
271
+ exit (g_vsyscall );
294
272
}
295
273
waitpid (pid , & wstatus , 0 );
296
- if (WIFEXITED (wstatus ) && WEXITSTATUS (wstatus ) == 0 ) {
297
- /* vsyscall page is readable and executable. */
298
- g_vsyscall = 1 ;
299
- return ;
274
+ if (WIFEXITED (wstatus )) {
275
+ g_vsyscall = WEXITSTATUS (wstatus );
276
+ } else {
277
+ fprintf (stderr , "error: wstatus %08x\n" , wstatus );
278
+ exit (1 );
300
279
}
301
-
302
- /* vsyscall page is executable but unreadable. */
303
- g_vsyscall = 2 ;
304
280
}
305
281
306
282
int main (void )
0 commit comments