From: Richard Palethorpe <rpalethorpe@suse.de>
To: Li Wang <liwang@redhat.com>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH 2/2] setitimer03: convert to new API
Date: Thu, 20 Oct 2022 11:31:21 +0100 [thread overview]
Message-ID: <87czamvkv1.fsf@suse.de> (raw)
In-Reply-To: <CAEemH2e1wkUL_ntOE-7R0UpLDospNTFegEa1TJTC3Jem1v5ucw@mail.gmail.com>
Hello,
Li Wang <liwang@redhat.com> writes:
> On Thu, Oct 20, 2022 at 5:30 PM Li Wang <liwang@redhat.com> wrote:
>
> Richard Palethorpe <rpalethorpe@suse.de> wrote:
>
> > -static struct itimerval *value;
> > +static struct itimerval *value, *ovalue;
> > +
> > +static struct tcase {
> > + int which;
> > + struct itimerval **val;
> > + struct itimerval **oval;
> > + int exp_errno;
>
> There is a whitespace error here (see checkpatch/make check)
>
> yes, thanks.
>
>
>
> > +} tcases[] = {
> > + {ITIMER_REAL, &value, &ovalue, EFAULT},
> > + {ITIMER_VIRTUAL, &value, &ovalue, EFAULT},
> > + {-ITIMER_PROF, &value, &ovalue, EINVAL},
> > +};
>
> Why do we need value and ovalue in the struct?
>
> Becuase it does not allow parsing an invalid pointer address
> from a structure, we have to give a valid address which pointer
> to save an invalid address. Otherwise segement fault will
> be hit in execution.
>
> On the other side, it also does not allow to initializer element
> is not constant in structure. So the two-level pointer is only the
> way I can make all things comprised here.
I'm not sure what you mean and I don't understand why we need this
struct at all. The following works and produces better output:
@@ -20,17 +20,6 @@
static struct itimerval *value, *ovalue;
-static struct tcase {
- int which;
- struct itimerval **val;
- struct itimerval **oval;
- int exp_errno;
-} tcases[] = {
- {ITIMER_REAL, &value, &ovalue, EFAULT},
- {ITIMER_VIRTUAL, &value, &ovalue, EFAULT},
- {-ITIMER_PROF, &value, &ovalue, EINVAL},
-};
-
static int sys_setitimer(int which, void *new_value, void *old_value)
{
return tst_syscall(__NR_setitimer, which, new_value, old_value);
@@ -38,13 +27,17 @@ static int sys_setitimer(int which, void *new_value, void *old_value)
static void verify_setitimer(unsigned int i)
{
- struct tcase *tc = &tcases[i];
-
- if (tc->exp_errno == EFAULT)
- *(tc->oval) = (struct itimerval *)-1;
-
- TST_EXP_FAIL(sys_setitimer(tc->which, *(tc->val), *(tc->oval)),
- tc->exp_errno);
+ switch (i) {
+ case 0:
+ TST_EXP_FAIL(sys_setitimer(ITIMER_REAL, value, (void *)-1), EFAULT);
+ break;
+ case 1:
+ TST_EXP_FAIL(sys_setitimer(ITIMER_VIRTUAL, value, (void *)-1), EFAULT);
+ break;
+ case 2:
+ TST_EXP_FAIL(sys_setitimer(-ITIMER_PROF, value, ovalue), EINVAL);
+ break;
+ }
}
static void setup(void)
@@ -56,7 +49,7 @@ static void setup(void)
}
static struct tst_test test = {
- .tcnt = ARRAY_SIZE(tcases),
+ .tcnt = 3,
.test = verify_setitimer,
.setup = setup,
.bufs = (struct tst_buffers[]) {
This prints
setitimer02.c:32: TPASS: sys_setitimer(ITIMER_REAL, value, (void *)-1) : EFAULT (14)
setitimer02.c:35: TPASS: sys_setitimer(ITIMER_VIRTUAL, value, (void *)-1) : EFAULT (14)
setitimer02.c:38: TPASS: sys_setitimer(-ITIMER_PROF, value, ovalue) : EINVAL (22)
instead of
setitimer02.c:46: TPASS: sys_setitimer(tc->which, *(tc->val), *(tc->oval)) : EFAULT (14)
setitimer02.c:46: TPASS: sys_setitimer(tc->which, *(tc->val), *(tc->oval)) : EFAULT (14)
setitimer02.c:46: TPASS: sys_setitimer(tc->which, *(tc->val), *(tc->oval)) : EINVAL (22)
The same values are passed to the syscall according to strace.
--
Thank you,
Richard.
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2022-10-20 10:40 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-09 6:55 [LTP] [PATCH 1/2] getitimer02: add ITIMER_VIRTUAL timer error check Li Wang
2022-10-09 6:55 ` [LTP] [PATCH 2/2] setitimer03: convert to new API Li Wang
2022-10-20 8:17 ` Richard Palethorpe
2022-10-20 9:30 ` Li Wang
2022-10-20 9:45 ` Li Wang
2022-10-20 10:31 ` Richard Palethorpe [this message]
2022-10-20 11:28 ` Li Wang
2022-10-20 8:11 ` [LTP] [PATCH 1/2] getitimer02: add ITIMER_VIRTUAL timer error check Richard Palethorpe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87czamvkv1.fsf@suse.de \
--to=rpalethorpe@suse.de \
--cc=liwang@redhat.com \
--cc=ltp@lists.linux.it \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox