lkml.org 
[lkml]   [1997]   [Jan]   [7]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: what is wrong with this?
On Mon, 6 Jan 1997, Andrew E. Mileski wrote:

> > #include <asm/io.h>
> > void main()
> > {
> > long port;
> > short data;
> >
> > port = 0x8370;
> > data = 0;
> > iopl(3);
> > (*(volatile unsigned short *)(port))=0;
> > }
> >
> > running this as root should not segv. However, it does. Why?
> > tried linux 2.1.14 and 2.1.20...
>
> Try reading the man pages :-)
>
> You cannot access ports > 0x3ff without calling ioperm().
> The iopl() man pages refer you to ioperm() for a reason.
>
> Explanation: A bit map is used to specify what ports a process
> can access. By default, only the first 1024 are mapped since they
> are commonly used. This mapping requires 128 bytes! Now it is a waste
> to lug around any more if they are not being used - it takes 8k to
> map the entire I/O space.

Bzzt. Sorry, but thanks for playing.

Firstly, Todd was doing _memory_ access, not io-port access. Secondly,
you've got iopl() and ioperm() backwards - it's ioperm() that only works
for ports below 0x400, for the reasons you gave. iopl(3) should give you
access to any ports.

The reason the code faults, I imagine, is that it's trying to access
memory that plain doesn't exist. All the privilege in the world won't
protect you from a fault when you try to write to an unmapped page.

P.


\
 
 \ /
  Last update: 2005-03-22 13:38    [W:0.062 / U:1.780 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site