Fixed ioperm calls in hwEnableIO

This commit is contained in:
brian 2019-05-02 16:25:50 -05:00 committed by Brian Haslett
parent bb46e78540
commit a0f738a673

View File

@ -116,16 +116,36 @@ hwDisableIO(void)
static Bool static Bool
hwEnableIO(void) hwEnableIO(void)
{ {
if (ioperm(0, 1024, 1) || iopl(3)) { short i;
ErrorF("xf86EnableIOPorts: failed to set IOPL for I/O (%s)\n", size_t n=0;
int begin, end;
char *buf=NULL, target[4];
FILE *fp;
if (ioperm(0, 1024, 1)) {
ErrorF("xf86EnableIO: failed to enable I/O ports 0000-03ff (%s)\n",
strerror(errno)); strerror(errno));
return FALSE; return FALSE;
} }
#if !defined(__alpha__) #if !defined(__alpha__)
/* XXX: this is actually not trapping anything because of iopl(3) /* trap access to the keyboard controller(s) and timer chip(s) */
* above */ fp = fopen("/proc/ioports", "r");
ioperm(0x40, 4, 0); /* trap access to the timer chip */ while (getline(&buf, &n, fp) != -1) {
ioperm(0x60, 4, 0); /* trap access to the keyboard controller */ if ((strstr(buf, "keyboard") != NULL) || (strstr(buf, "timer") != NULL)) {
for (i=0; i<4; i++)
target[i] = buf[i+2];
begin = atoi(target);
for (i=0; i<4; i++)
target[i] = buf[i+7];
end = atoi(target);
ioperm(begin, end-begin+1, 0);
}
}
free(buf);
fclose(fp);
#endif #endif
return TRUE; return TRUE;