From: Sergey Oskotskiy <sergey.oskotskiy@gmail.com>
To: "Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com>
Cc: linux-man@vger.kernel.org
Subject: Re: typo in ioperm man page
Date: Thu, 26 Dec 2019 10:45:42 +0300 [thread overview]
Message-ID: <CALzkOGjRhD1WCq51iEdsV22fhz=2DZCfetpaSmNDfQ=4y_7O=A@mail.gmail.com> (raw)
In-Reply-To: <8519468f-e9e6-9a7e-8a6c-8ef18cf24213@gmail.com>
Hello Michael,
Thank you for your reply. Sorry if I am wrong about the typo. My
reasoning is as follows:
in the GLIBC source code (for versions 2.27 and 2.30) I see the
following comment before the declaration of the function ioperm(): "If
TURN_ON is TRUE, request for permission to do direct i/o on the port
numbers in the range [FROM,FROM+NUM-1]...". As far as I understand,
port numbers here are individual bytes (not bits) in the I/O address
space.
I ran the following sample program under GLIBC 2.27 (under Ubuntu
18.04, Linux kernel 4.15):
#include <stdio.h>
#include <sys/io.h>
int main(int argc, char* argv[]) {
int i;
i = ioperm(0x378, 1, 1);
printf("ioperm() returned: %d\n", i);
outb(0xFF, 0x378);
printf("1-st outb() completed\n");
outb(0xFF, 0x379);
printf("2-nd outb() completed\n");
return 0;
}
When I run this program (under privileged user), I see the following output:
ioperm() returned: 0
1-st outb() completed
Segmentation fault
So, on the second call to outb() the program receives a segmentation
fault: according to outb man page it means an attempt to access an I/O
port without prior getting permission to access this port by means of
ioperm().
If in the call to ioperm() I change the parameter num (the second
parameter) from 1 to 2:
i = ioperm(0x378, 2, 1);
then the program runs without segmentation fault and gives the following output:
ioperm() returned: 0
1-st outb() completed
2-nd outb() completed
i.e. the second call to outb() also succeeded (because ioperm() now
permits the access to both I/O ports accessed by the program).
It makes me think that the num parameter of ioperm() function
specifies the number of whole bytes (but not bits) in the I/O address
space.
Best regards,
Sergey
On Wed, Dec 25, 2019 at 9:25 PM Michael Kerrisk (man-pages)
<mtk.manpages@gmail.com> wrote:
>
> On 12/25/19 8:51 AM, Sergey Oskotskiy wrote:
> > Hello Michael,
> >
> > I think the ioperm man page
> > (http://man7.org/linux/man-pages/man2/ioperm.2.html) has a typo:
> > it says "ioperm() sets the port access permission bits for the calling
> > thread for num ___bits___ ...".
> > I think it should be "...for num ___bytes___..."
> >
> > With best Christmas wishes,
>
> Sergey,
>
> Can you say more abut *why* you think it's wrong.[1] That would
> help me investigate.
>
> Thanks,
>
> Michael
>
> [1] At first glance, I suspect that the existing text *is*
> correct.
>
> --
> Michael Kerrisk
> Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
> Linux/UNIX System Programming Training: http://man7.org/training/
prev parent reply other threads:[~2019-12-26 7:45 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-25 7:51 typo in ioperm man page Sergey Oskotskiy
2019-12-25 18:25 ` Michael Kerrisk (man-pages)
2019-12-26 7:45 ` Sergey Oskotskiy [this message]
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='CALzkOGjRhD1WCq51iEdsV22fhz=2DZCfetpaSmNDfQ=4y_7O=A@mail.gmail.com' \
--to=sergey.oskotskiy@gmail.com \
--cc=linux-man@vger.kernel.org \
--cc=mtk.manpages@gmail.com \
/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;
as well as URLs for NNTP newsgroup(s).