19
19
#include <sys/auxv.h>
20
20
#include <sys/syscall.h>
21
21
#include <sys/wait.h>
22
+ #include "../kselftest.h"
22
23
23
24
#define PAGE_SIZE 4096
24
25
@@ -29,24 +30,24 @@ static int try_to_remap(void *vdso_addr, unsigned long size)
29
30
/* Searching for memory location where to remap */
30
31
dest_addr = mmap (0 , size , PROT_NONE , MAP_PRIVATE |MAP_ANONYMOUS , -1 , 0 );
31
32
if (dest_addr == MAP_FAILED ) {
32
- printf ( "[ WARN]\tmmap failed (%d): %m\n" , errno );
33
+ ksft_print_msg ( " WARN: mmap failed (%d): %m\n" , errno );
33
34
return 0 ;
34
35
}
35
36
36
- printf ( "[NOTE]\tMoving vDSO: [%p, %#lx] -> [%p, %#lx]\n" ,
37
- vdso_addr , (unsigned long )vdso_addr + size ,
38
- dest_addr , (unsigned long )dest_addr + size );
37
+ ksft_print_msg ( "Moving vDSO: [%p, %#lx] -> [%p, %#lx]\n" ,
38
+ vdso_addr , (unsigned long )vdso_addr + size ,
39
+ dest_addr , (unsigned long )dest_addr + size );
39
40
fflush (stdout );
40
41
41
42
new_addr = mremap (vdso_addr , size , size ,
42
43
MREMAP_FIXED |MREMAP_MAYMOVE , dest_addr );
43
44
if ((unsigned long )new_addr == (unsigned long )-1 ) {
44
45
munmap (dest_addr , size );
45
46
if (errno == EINVAL ) {
46
- printf ( "[NOTE]\tvDSO partial move failed, will try with bigger size\n" );
47
+ ksft_print_msg ( "vDSO partial move failed, will try with bigger size\n" );
47
48
return -1 ; /* Retry with larger */
48
49
}
49
- printf ("[FAIL]\tmremap failed (%d): %m\n" , errno );
50
+ ksft_print_msg ("[FAIL]\tmremap failed (%d): %m\n" , errno );
50
51
return 1 ;
51
52
}
52
53
@@ -58,21 +59,22 @@ int main(int argc, char **argv, char **envp)
58
59
{
59
60
pid_t child ;
60
61
62
+ ksft_print_header ();
63
+ ksft_set_plan (1 );
64
+
61
65
child = fork ();
62
- if (child == -1 ) {
63
- printf ("[WARN]\tfailed to fork (%d): %m\n" , errno );
64
- return 1 ;
65
- }
66
+ if (child == -1 )
67
+ ksft_exit_fail_msg ("failed to fork (%d): %m\n" , errno );
66
68
67
69
if (child == 0 ) {
68
70
unsigned long vdso_size = PAGE_SIZE ;
69
71
unsigned long auxval ;
70
72
int ret = -1 ;
71
73
72
74
auxval = getauxval (AT_SYSINFO_EHDR );
73
- printf ( "\tAT_SYSINFO_EHDR is %#lx\n" , auxval );
75
+ ksft_print_msg ( "AT_SYSINFO_EHDR is %#lx\n" , auxval );
74
76
if (!auxval || auxval == - ENOENT ) {
75
- printf ( "[ WARN]\tgetauxval failed\n" );
77
+ ksft_print_msg ( " WARN: getauxval failed\n" );
76
78
return 0 ;
77
79
}
78
80
@@ -92,16 +94,13 @@ int main(int argc, char **argv, char **envp)
92
94
int status ;
93
95
94
96
if (waitpid (child , & status , 0 ) != child ||
95
- !WIFEXITED (status )) {
96
- printf ("[FAIL]\tmremap() of the vDSO does not work on this kernel!\n" );
97
- return 1 ;
98
- } else if (WEXITSTATUS (status ) != 0 ) {
99
- printf ("[FAIL]\tChild failed with %d\n" ,
100
- WEXITSTATUS (status ));
101
- return 1 ;
102
- }
103
- printf ("[OK]\n" );
97
+ !WIFEXITED (status ))
98
+ ksft_test_result_fail ("mremap() of the vDSO does not work on this kernel!\n" );
99
+ else if (WEXITSTATUS (status ) != 0 )
100
+ ksft_test_result_fail ("Child failed with %d\n" , WEXITSTATUS (status ));
101
+ else
102
+ ksft_test_result_pass ("%s\n" , __func__ );
104
103
}
105
104
106
- return 0 ;
105
+ ksft_finished () ;
107
106
}
0 commit comments