/* $Id: ioperm.c,v 1.2 2008/09/12 21:14:28 kostik Exp kostik $ */ #include #include #include #include #include #include static const unsigned int port_num = 0x130; unsigned char inb(unsigned int port) { unsigned char data; __asm __volatile("inb %%dx,%0" : "=a" (data) : "d" (port)); return (data); } void sigbus_handler(int signo) { fprintf(stderr, "Got SIGBUS\n"); exit(0); } int main(int argc, char *argv[]) { struct sigaction sa; unsigned int length1; int enable1; if (i386_get_ioperm(port_num, &length1, &enable1) == -1) { fprintf(stderr, "get 1: %s\n", strerror(errno)); return (1); } if (length1 != 0 && enable1 != 0) { fprintf(stderr, "enable1: enabled\n"); return (1); } if (i386_set_ioperm(port_num, 1, 1) == -1) { fprintf(stderr, "set 1: %s\n", strerror(errno)); return (1); } inb(port_num); if (i386_set_ioperm(port_num, 1, 0) == -1) { fprintf(stderr, "set 2: %s\n", strerror(errno)); return (1); } if (i386_get_ioperm(port_num, &length1, &enable1) == -1) { fprintf(stderr, "get 1: %s\n", strerror(errno)); return (1); } if (enable1 != 0) { fprintf(stderr, "enable2: enabled\n"); return (1); } fprintf(stderr, "And now we should get SIGBUS\n"); memset(&sa, 0, sizeof(sa)); sa.sa_handler = sigbus_handler; if (sigaction(SIGBUS, &sa, NULL) == -1) { fprintf(stderr, "sigaction(SIGBUS): %s\n", strerror(errno)); return (1); } inb(port_num); return (0); }