From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH] openposix: mmap/21-1: adjust the test to work with MAP_SHARED_VALIDATE
Date: Mon, 12 Feb 2018 16:17:55 +0100 [thread overview]
Message-ID: <20180212151755.GA23827@rei> (raw)
In-Reply-To: <a6a0ea9a-6552-bdf3-3b31-64e85cb09cbc@oracle.com>
Hi!
> >> +int is_valid(int flag)
> >> +{
> >> + if (flag == MAP_SHARED || flag == MAP_PRIVATE || flag == MAP_FIXED)
> >> + return 1;
> >> +
> >> +#ifdef __linux__
> >> +
> >> +#ifndef MAP_SHARED_VALIDATE
> >> +#define MAP_SHARED_VALIDATE 0x03
> >> +#endif
> >> +
> >> + if (flag == MAP_SHARED_VALIDATE)
> >> + return 1;
> >> +#endif
> >> +
> >> + return 0;
> >> +}
> >
> > Hmm, this probably does not scale up, what about setting the flag to
> > have all its bits set (i.e. passing ~0 to the mmap()) from the start
> > instead?
> >
>
> In main() we search for the first value of 'flag' for which the
> following statement is not true:
>
> flag == MAP_SHARED || flag == MAP_PRIVATE || flag == MAP_FIXED || flag
> == MAP_SHARED_VALIDATE
>
> where the last part is Linux-specific and likely needs an #ifdef.
>
> We are not interested if flag has MAP_SHARED or other bits set, but we
> are interested when flag _equals_ MAP_SHARED or other values.
>
> In order to make the code more readable (IMHO) I decided to move this
> check into a separate function.
>
> I don't fully understand your proposal. Could you, please, elaborate a
> bit more?
We are trying to trigger EINVAL by passing an invalid flags value to
mmap. And given that the flags are likely to be allocated in increasing
manner starting with known flag and increasing it while it's equal to
other known flags will break again sooner or later and we will end up
adding more and more special cases for different systems.
Hence I suggest to use a value that is unlikely to be valid flag (all
bits set) and use that for the testing.
--
Cyril Hrubis
chrubis@suse.cz
next prev parent reply other threads:[~2018-02-12 15:17 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-08 15:55 [LTP] [PATCH] openposix: mmap/21-1: adjust the test to work with MAP_SHARED_VALIDATE Stanislav Kholmanskikh
2018-02-08 16:34 ` Cyril Hrubis
2018-02-12 12:29 ` Stanislav Kholmanskikh
2018-02-12 15:17 ` Cyril Hrubis [this message]
2018-03-01 9:22 ` [LTP] [PATCH] openposix: mmap/21-1: use all bits set as the invalid flag Stanislav Kholmanskikh
2018-03-01 9:50 ` Cyril Hrubis
2018-03-01 10:59 ` Stanislav Kholmanskikh
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=20180212151755.GA23827@rei \
--to=chrubis@suse.cz \
--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