From 19edee8704eed334ea8ed5b798edc9bb8bf1491d Mon Sep 17 00:00:00 2001 From: q66 Date: Thu, 23 Jan 2020 19:25:56 +0100 Subject: [PATCH] Fix segfault from trying to access nonexistent VGA BIOS ROM on non-x86 platforms On non-x86 platforms such as PowerPC Macs with r128 chipsets, the VGA BIOS ROM doesn't exist, and the driver segfaults when trying to access it. Fix this by only accessing the VGA BIOS on x86/x86_64. Signed-off-by: Avraham Hollander --- src/r128_driver.c | 24 ++++++++++++++++++------ src/r128_output.c | 1 + 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/r128_driver.c b/src/r128_driver.c index fc42bfa..f416425 100644 --- a/src/r128_driver.c +++ b/src/r128_driver.c @@ -94,7 +94,12 @@ #include "xf86RandR12.h" #include "xf86cmap.h" #include "xf86xv.h" + /* VBE and int10 are only available on x86. */ +#if defined(__i386__) || defined(__x86_64__) #include "vbe.h" +#else +typedef void *xf86Int10InfoPtr; +#endif /* fbdevhw & vgahw */ #ifdef WITH_VGAHW @@ -419,11 +424,15 @@ static Bool R128GetBIOSParameters(ScrnInfoPtr pScrn, xf86Int10InfoPtr pInt10) return FALSE; } + /* VBE and int10 are only available on x86. */ +#if defined(__i386__) || defined(__x86_64__) if (pInt10) { info->BIOSAddr = pInt10->BIOSseg << 4; (void)memcpy(info->VBIOS, xf86int10Addr(pInt10, info->BIOSAddr), R128_VBIOS_SIZE); - } else { + } else +#endif + { #ifdef XSERVER_LIBPCIACCESS if (pci_device_read_rom(info->PciInfo, info->VBIOS)) { xf86DrvMsg(pScrn->scrnIndex, X_WARNING, @@ -1011,7 +1020,8 @@ static Bool R128PreInitConfig(ScrnInfoPtr pScrn) static Bool R128PreInitDDC(ScrnInfoPtr pScrn, xf86Int10InfoPtr pInt10) { -#if !defined(__powerpc__) && !defined(__alpha__) && !defined(__sparc__) +/* VBE and int10 are only available on x86. */ +#if defined(__i386__) || defined(__x86_64__) R128InfoPtr info = R128PTR(pScrn); vbeInfoPtr pVbe; #endif @@ -1019,8 +1029,7 @@ static Bool R128PreInitDDC(ScrnInfoPtr pScrn, xf86Int10InfoPtr pInt10) if (!xf86LoadSubModule(pScrn, "ddc")) return FALSE; if (!xf86LoadSubModule(pScrn, "i2c")) return FALSE; -#if defined(__powerpc__) || defined(__alpha__) || defined(__sparc__) - /* Int10 is broken on PPC and some Alphas */ +#if !defined(__i386__) && !defined(__x86_64__) return TRUE; #else if (xf86LoadSubModule(pScrn, "vbe")) { @@ -1056,9 +1065,9 @@ static Bool R128PreInitCursor(ScrnInfoPtr pScrn) static Bool R128PreInitInt10(ScrnInfoPtr pScrn, xf86Int10InfoPtr *ppInt10) { +/* VBE and int10 are only available on x86. */ +#if defined(__i386__) || defined(__x86_64__) R128InfoPtr info = R128PTR(pScrn); -#if !defined(__powerpc__) && !defined(__alpha__) - /* int10 is broken on some Alphas and powerpc */ if (xf86LoadSubModule(pScrn, "int10")) { xf86DrvMsg(pScrn->scrnIndex,X_INFO,"initializing int10\n"); *ppInt10 = xf86InitInt10(info->pEnt->index); @@ -1402,9 +1411,12 @@ static Bool R128LegacyMS(ScrnInfoPtr pScrn) ret = TRUE; freeInt10: /* Free int10 info */ +/* VBE and int10 are only available on x86. */ +#if defined(__i386__) || defined(__x86_64__) if (pInt10) { xf86FreeInt10(pInt10); } +#endif exit: return ret; diff --git a/src/r128_output.c b/src/r128_output.c index 6543971..2c00979 100644 --- a/src/r128_output.c +++ b/src/r128_output.c @@ -483,6 +483,7 @@ R128GetConnectorInfoFromBIOS(ScrnInfoPtr pScrn, R128OutputType *otypes) } else { otypes[0] = OUTPUT_VGA; } + return; } bios_header = R128_BIOS16(0x48);