Using sysarch specific syscalls in assembly?

alexander arundel at h3c.de
Wed Aug 10 13:09:22 GMT 2005


I tried to write a little C app that uses sysarch and i386_set_ioperm to gain
access to certain ports and after a bit of testing I'm pretty sure that there
is a bug or better a timing issue with the sysarch syscall or the
i386_set_ioperm procedure. Please have a look at the following code:

//CODE START

#include <machine/sysarch.h>

int main (void) {

unsigned int port = 0x378;
unsigned char val = 'A';
int number = 4;

static inline void outb (unsigned short int port, unsigned char val) {
        __asm__ volatile ("outb %0,%1\n"::"a" (val), "d" (port) );
}

struct i386_ioperm_args {
        unsigned int start;
        unsigned int length;
        int     enable;
};

struct i386_ioperm_args *args;
struct i386_ioperm_args arg;
args = &arg;

args->start = 0x378;
args->length = 1;
args->enable = 1;

if(sysarch(number,args) == 0) {
/* int i;
   for(i=0; i < 100; i++) {
   printf("DELAY\n");
   }
*/
   outb(0x378,0xF);
   exit(0);
}

else {
   printf("Error during syscall");
   exit(1);
}
}

//eof

//CODE END

On my PC this code will cause a core dump (Bus error: 10). If I however add a
delay (the code that's commented out) the app will end without any errors.

It seems FBSD needs some time to set the I/O permissions for an app. Can
somebody test this code on his computer? Maybe this is a bug in RELENG_6. I'm
running:

FreeBSD 6.0-BETA1 #0: Mon Jul 18 03:00:45 CEST 2005

Thx a bunch.


More information about the freebsd-hackers mailing list