• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Check decoding of ioprio_get and ioprio_set syscalls.
3  *
4  * Copyright (c) 2016 Eugene Syromyatnikov <evgsyr@gmail.com>
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. The name of the author may not be used to endorse or promote products
16  *    derived from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #include "tests.h"
31 
32 #include <asm/unistd.h>
33 
34 #if defined(__NR_ioprio_get) && defined(__NR_ioprio_set)
35 
36 # include <stdio.h>
37 # include <unistd.h>
38 
39 enum {
40 	IOPRIO_CLASS_NONE,
41 	IOPRIO_CLASS_RT,
42 	IOPRIO_CLASS_BE,
43 	IOPRIO_CLASS_IDLE
44 };
45 
46 # include "xlat.h"
47 # include "xlat/ioprio_class.h"
48 
49 void
print_ioprio(unsigned long val)50 print_ioprio(unsigned long val)
51 {
52 	printf(" (IOPRIO_PRIO_VALUE(");
53 	printxval(ioprio_class, val >> 13, "IOPRIO_CLASS_???");
54 	printf(", %d))", (int) (val & 0x1fff));
55 }
56 
57 int
main(void)58 main(void)
59 {
60 	static const kernel_ulong_t bogus_which =
61 		(kernel_ulong_t) 0xdeadfacefa57beefULL;
62 	static const kernel_ulong_t bogus_who =
63 		(kernel_ulong_t) 0xbadc0dedda7a1057ULL;
64 	static const kernel_ulong_t bogus_ioprio =
65 		(kernel_ulong_t) 0xdec0ded1facefeedULL;
66 	static const char * const bogus_ioprio_str =
67 		"IOPRIO_PRIO_VALUE(0x7d677 /* IOPRIO_CLASS_??? */, 7917)";
68 
69 	long rc;
70 
71 	rc = syscall(__NR_ioprio_get, bogus_which, bogus_who);
72 	printf("ioprio_get(%#x /* IOPRIO_WHO_??? */, %d) = %s\n",
73 	       (int) bogus_which, (int) bogus_who, sprintrc(rc));
74 
75 	rc = syscall(__NR_ioprio_get, 1, 0);
76 	printf("ioprio_get(IOPRIO_WHO_PROCESS, 0) = %s", sprintrc(rc));
77 
78 	if (rc >= -1)
79 		print_ioprio(rc);
80 
81 	puts("");
82 
83 	rc = syscall(__NR_ioprio_set, 2, 0, 8191);
84 	printf("ioprio_set(IOPRIO_WHO_PGRP, 0, "
85 	       "IOPRIO_PRIO_VALUE(IOPRIO_CLASS_NONE, 8191)) = %s\n",
86 	       sprintrc(rc));
87 
88 	rc = syscall(__NR_ioprio_set, bogus_which, bogus_who, bogus_ioprio);
89 	printf("ioprio_set(%#x /* IOPRIO_WHO_??? */, %d, %s) = %s\n",
90 	       (int) bogus_which, (int) bogus_who, bogus_ioprio_str,
91 	       sprintrc(rc));
92 
93 	puts("+++ exited with 0 +++");
94 
95 	return 0;
96 }
97 
98 #else
99 
100 SKIP_MAIN_UNDEFINED("__NR_ioprio_get && __NR_ioprio_set");
101 
102 #endif
103