Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat causes a segmentation fault on a call to inb_p()?
    text
    copied!<p>I am getting a segmentation fault when trying to read a port with inb_p( ). I'm compiling this on a Debian system running 2.6.6 kernel on an Intel D525 dual-core system (Advantech PCM 9389 SBC). Here is a sample program which illustrates the segfault.</p> <p>What is the probable cause? How do I fix this?</p> <p>Currently, I don't have any devices hooked up. Could this cause the segfault? I would have expected to get either a zero or some random byte, but not a segfault.</p> <p>Other things I tried: 1) Declared the input variable as int instead of char. 2) Used iopl() instead of ioperm()</p> <pre><code>/* * ioexample.c: very simple ioexample of port I/O * very simple port i/o * Compile with `gcc -O2 -o ioexample ioexample.c', * and run as root with `./ioexample'. */ #include &lt;stdlib.h&gt; #include &lt;stdio.h&gt; #include &lt;unistd.h&gt; #include &lt;sys/io.h&gt; #define BASEPORT 0x0100 /* iobase for sample system */ #define FLIPC 0x01 #define FLIPST 0x0 #define DIPSWITCH 0x25 int main() { char cinput; cinput = 0xff; setuid(0); printf("begin\n"); /* Get access to the ports */ if (ioperm(BASEPORT+DIPSWITCH, 10, 1)) { perror("ioperm"); exit(EXIT_FAILURE); } printf("read the dipswitch with pause\n"); cinput = inb_p(BASEPORT+DIPSWITCH); // &lt;=====SEGFAULT HERE /* We don't need the ports anymore */ if (ioperm(BASEPORT+DIPSWITCH, 10, 0)) { perror("ioperm"); exit(EXIT_FAILURE); } printf("Dipswitch setting: 0x%X", cinput); exit(EXIT_SUCCESS); } /* end of ioexample.c */ </code></pre> <p>Output:</p> <pre><code>root@debian:/home/howard/sources# ./ioexample begin read the dipswitch with pause Segmentation fault </code></pre> <p>Edit: /proc/ioports did not list anything at address 0x100, so I tried several other port addresses that were listed, with the same result. Then I decided to try an <em>output</em> to a known parallel port location (0x0378), and outb did not cause a segfault. However, trying to read either 0x378 or 0x379 <em>did</em> cause a segfault. I am beginning to suspect that the problem is hardware related.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload