• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) International Business Machines  Corp., 2001
4  * 03/2001 - Written by Wayne Boyer
5  *
6  */
7 
8 /*\
9  * [Description]
10  *
11  * Check that setitimer() call fails:
12  *
13  * 1. EFAULT with invalid itimerval pointer
14  * 2. EINVAL when called with an invalid first argument
15  */
16 
17 #include <errno.h>
18 #include <sys/time.h>
19 #include <stdlib.h>
20 #include "tst_test.h"
21 #include "lapi/syscalls.h"
22 
23 static struct itimerval *value, *ovalue;
24 
sys_setitimer(int which,void * new_value,void * old_value)25 static int sys_setitimer(int which, void *new_value, void *old_value)
26 {
27 	return tst_syscall(__NR_setitimer, which, new_value, old_value);
28 }
29 
verify_setitimer(unsigned int i)30 static void verify_setitimer(unsigned int i)
31 {
32 	switch (i) {
33 	case 0:
34 		TST_EXP_FAIL(sys_setitimer(ITIMER_REAL, value, (void *)-1), EFAULT);
35 		break;
36 	case 1:
37 		TST_EXP_FAIL(sys_setitimer(ITIMER_VIRTUAL, value, (void *)-1), EFAULT);
38 		break;
39 	case 2:
40 		TST_EXP_FAIL(sys_setitimer(-ITIMER_PROF, value, ovalue), EINVAL);
41 		break;
42 	}
43 }
44 
setup(void)45 static void setup(void)
46 {
47 	value->it_value.tv_sec = 30;
48 	value->it_value.tv_usec = 0;
49 	value->it_interval.tv_sec = 0;
50 	value->it_interval.tv_usec = 0;
51 }
52 
53 static struct tst_test test = {
54 	.tcnt = 3,
55 	.test = verify_setitimer,
56 	.setup = setup,
57 	.bufs = (struct tst_buffers[]) {
58 		{&value,  .size = sizeof(struct itimerval)},
59 		{&ovalue, .size = sizeof(struct itimerval)},
60 		{}
61 	}
62 };
63