~ubuntu-branches/ubuntu/maverick/xorg-server/maverick-security

« back to all changes in this revision

Viewing changes to hw/xfree86/common/xf86Mode.c

  • Committer: Bazaar Package Importer
  • Author(s): Christopher James Halse Rogers
  • Date: 2010-08-05 11:25:14 UTC
  • mfrom: (1.1.35 upstream) (0.1.14 experimental)
  • Revision ID: james.westby@ubuntu.com-20100805112514-q4efdgj3nblevos2
Tags: 2:1.8.99.905-1ubuntu1
* Merge from (unreleased) Debian experimental.  Remaining Ubuntu changes:
  - rules, control:
    + Disable SELinux, libaudit-dev is not in main yet (LP 406226).
      Drop libaudit-dev from build-deps.
  - rules: Enable xcsecurity (LP 247537).
  - local/xvfb-run*: Add correct docs about error codes (LP 328205)
  - rules: Add --with-extra-module-dir to support GL alternatives.
  - control: Xvfb depends on xauth, x11-xkb-utils. (LP 500102)
  - rules, local/64-xorg-xkb.rules: Don't use keyboard-configuration
    until it's available.
  - control: Update some versioned Breaks for Ubuntu versions.
  - debian/patches:
    + 100_rethrow_signals.patch:
      When aborting, re-raise signals for apport
    + 109_fix-swcursor-crash.patch:
      Avoid dereferencing null pointer while reloading cursors during
      resume. (LP 371405)
    + 111_armel-drv-fallbacks.patch:
      Add support for armel driver fallbacks.
    + 121_only_switch_vt_when_active.diff:
      Add a check to prevent the X server from changing the VT when killing
      GDM from the console.
    + 122_xext_fix_card32_overflow_in_xauth.patch:
      Fix server crash when “xauth generate” is called with large timeout.
    + 157_check_null_modes.patch, 162_null_crtc_in_rotation.patch,
      166_nullptr_xinerama_keyrepeat.patch, 167_nullptr_xisbread.patch
      169_mipointer_nullptr_checks.patch,
      172_cwgetbackingpicture_nullptr_check.patch:
      Fix various segfaults in xserver by checking pointers for NULL
      values before dereferencing them.
    + 165_man_xorg_conf_no_device_ident.patch
      Correct man page
    + 168_glibc_trace_to_stderr.patch:
      Report abort traces to stderr instead of terminal
    + 184_virtual_devices_autodetect.patch:
      Use vesa for qemu device, which is not supported by cirrus
    + 187_edid_quirk_hp_nc8430.patch:
      Quirk for another LPL monitor (LP 380009)
    + 188_default_primary_to_first_busid.patch:
      Pick the first device and carry on (LP 459512)
    + 189_xserver_1.5.0_bg_none_root.patch:
      Create a root window with no background.
    + 190_cache-xkbcomp_output_for_fast_start_up.patch:
      Cache keyboard settings.
    + 191-Xorg-add-an-extra-module-path.patch:
      Add support for the alternatives module path.
    + 197_xvfb-randr.patch:
      Adds xrandr support to xvfb. (LP 516123)
    + 198_nohwaccess.patch:
      Adds a -nohwaccess argument to make X not access the hardware
      ports directly.
    + 200_randr-null.patch:
      Clarify a pointer initialization.
* Update changelog entries for 1.8.1.902-1 which became 1.8.99.904-1
* Drop 196_xvfbscreeninit-handling.patch: it's semantically empty, and now 
  doesn't apply.  Merge remaining #include change into 197_xvfb-randr.patch
* New upstream version will start correctly when no outputs are connected,
  as long as the video driver can dynamically resize the framebuffer
  (true for all KMS drivers) (LP: #337889)
* New upstream version fixes crash on non-admin logout with KDE (LP: #569879)
* Refresh 111_armel-drv-fallbacks.patch to fix the build on armel

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
 */
27
27
 
28
28
/*
 
29
 * LCM() and scanLineWidth() are:
 
30
 *
 
31
 * Copyright 1997 through 2004 by Marc Aurele La France (TSI @ UQV), tsi@xfree86.org
 
32
 *
 
33
 * Permission to use, copy, modify, distribute, and sell this software and its
 
34
 * documentation for any purpose is hereby granted without fee, provided that
 
35
 * the above copyright notice appear in all copies and that both that copyright
 
36
 * notice and this permission notice appear in supporting documentation, and
 
37
 * that the name of Marc Aurele La France not be used in advertising or
 
38
 * publicity pertaining to distribution of the software without specific,
 
39
 * written prior permission.  Marc Aurele La France makes no representations
 
40
 * about the suitability of this software for any purpose.  It is provided
 
41
 * "as-is" without express or implied warranty.
 
42
 *
 
43
 * MARC AURELE LA FRANCE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 
44
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.  IN NO
 
45
 * EVENT SHALL MARC AURELE LA FRANCE BE LIABLE FOR ANY SPECIAL, INDIRECT OR
 
46
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
 
47
 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
 
48
 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 
49
 * PERFORMANCE OF THIS SOFTWARE.
 
50
 *
 
51
 * Copyright 1990,91,92,93 by Thomas Roell, Germany.
 
52
 * Copyright 1991,92,93    by SGCS (Snitily Graphics Consulting Services), USA.
 
53
 *
 
54
 * Permission to use, copy, modify, distribute, and sell this software
 
55
 * and its documentation for any purpose is hereby granted without fee,
 
56
 * provided that the above copyright notice appear in all copies and
 
57
 * that both that copyright notice and this  permission notice appear
 
58
 * in supporting documentation, and that the name of Thomas Roell nor
 
59
 * SGCS be used in advertising or publicity pertaining to distribution
 
60
 * of the software without specific, written prior permission.
 
61
 * Thomas Roell nor SGCS makes no representations about the suitability
 
62
 * of this software for any purpose. It is provided "as is" without
 
63
 * express or implied warranty.
 
64
 *
 
65
 * THOMAS ROELL AND SGCS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
 
66
 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
 
67
 * FITNESS, IN NO EVENT SHALL THOMAS ROELL OR SGCS BE LIABLE FOR ANY
 
68
 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
 
69
 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
 
70
 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
 
71
 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
72
 */
 
73
 
 
74
/*
29
75
 * Authors: Dirk Hohndel <hohndel@XFree86.Org>
30
76
 *          David Dawes <dawes@XFree86.Org>
31
77
 *          Marc La France <tsi@XFree86.Org>
42
88
#include "xf86Modes.h"
43
89
#include "os.h"
44
90
#include "servermd.h"
45
 
#include "mibank.h"
46
91
#include "globals.h"
47
92
#include "xf86.h"
48
93
#include "xf86Priv.h"
1126
1171
    return 1;
1127
1172
}
1128
1173
 
 
1174
/* Least common multiple */
 
1175
static unsigned int
 
1176
LCM(unsigned int x, unsigned int y)
 
1177
{
 
1178
    unsigned int m = x, n = y, o;
 
1179
 
 
1180
    while ((o = m % n))
 
1181
    {
 
1182
        m = n;
 
1183
        n = o;
 
1184
    }
 
1185
 
 
1186
    return (x / n) * y;
 
1187
}
 
1188
 
 
1189
/*
 
1190
 * Given various screen attributes, determine the minimum scanline width such
 
1191
 * that each scanline is server and DDX padded and any pixels with imbedded
 
1192
 * bank boundaries are off-screen.  This function returns -1 if such a width
 
1193
 * cannot exist.
 
1194
 */
 
1195
static int
 
1196
scanLineWidth(
 
1197
    unsigned int     xsize,         /* pixels */
 
1198
    unsigned int     ysize,         /* pixels */
 
1199
    unsigned int     width,         /* pixels */
 
1200
    unsigned long    BankSize,      /* char's */
 
1201
    PixmapFormatRec *pBankFormat,
 
1202
    unsigned int     nWidthUnit     /* bits */
 
1203
)
 
1204
{
 
1205
    unsigned long nBitsPerBank, nBitsPerScanline, nBitsPerScanlinePadUnit;
 
1206
    unsigned long minBitsPerScanline, maxBitsPerScanline;
 
1207
 
 
1208
    /* Sanity checks */
 
1209
 
 
1210
    if (!nWidthUnit || !pBankFormat)
 
1211
        return -1;
 
1212
 
 
1213
    nBitsPerBank = BankSize * 8;
 
1214
    if (nBitsPerBank % pBankFormat->scanlinePad)
 
1215
        return -1;
 
1216
 
 
1217
    if (xsize > width)
 
1218
        width = xsize;
 
1219
    nBitsPerScanlinePadUnit = LCM(pBankFormat->scanlinePad, nWidthUnit);
 
1220
    nBitsPerScanline =
 
1221
        (((width * pBankFormat->bitsPerPixel) + nBitsPerScanlinePadUnit - 1) /
 
1222
         nBitsPerScanlinePadUnit) * nBitsPerScanlinePadUnit;
 
1223
    width = nBitsPerScanline / pBankFormat->bitsPerPixel;
 
1224
 
 
1225
    if (!xsize || !(nBitsPerBank % pBankFormat->bitsPerPixel))
 
1226
        return (int)width;
 
1227
 
 
1228
    /*
 
1229
     * Scanlines will be server-pad aligned at this point.  They will also be
 
1230
     * a multiple of nWidthUnit bits long.  Ensure that pixels with imbedded
 
1231
     * bank boundaries are off-screen.
 
1232
     *
 
1233
     * It seems reasonable to limit total frame buffer size to 1/16 of the
 
1234
     * theoretical maximum address space size.  On a machine with 32-bit
 
1235
     * addresses (to 8-bit quantities) this turns out to be 256MB.  Not only
 
1236
     * does this provide a simple limiting condition for the loops below, but
 
1237
     * it also prevents unsigned long wraparounds.
 
1238
     */
 
1239
    if (!ysize)
 
1240
        return -1;
 
1241
 
 
1242
    minBitsPerScanline = xsize * pBankFormat->bitsPerPixel;
 
1243
    if (minBitsPerScanline > nBitsPerBank)
 
1244
        return -1;
 
1245
 
 
1246
    if (ysize == 1)
 
1247
        return (int)width;
 
1248
 
 
1249
    maxBitsPerScanline =
 
1250
        (((unsigned long)(-1) >> 1) - minBitsPerScanline) / (ysize - 1);
 
1251
    while (nBitsPerScanline <= maxBitsPerScanline)
 
1252
    {
 
1253
        unsigned long BankBase, BankUnit;
 
1254
 
 
1255
        BankUnit = ((nBitsPerBank + nBitsPerScanline - 1) / nBitsPerBank) *
 
1256
            nBitsPerBank;
 
1257
        if (!(BankUnit % nBitsPerScanline))
 
1258
            return (int)width;
 
1259
 
 
1260
        for (BankBase = BankUnit;  ;  BankBase += nBitsPerBank)
 
1261
        {
 
1262
            unsigned long x, y;
 
1263
 
 
1264
            y = BankBase / nBitsPerScanline;
 
1265
            if (y >= ysize)
 
1266
                return (int)width;
 
1267
 
 
1268
            x = BankBase % nBitsPerScanline;
 
1269
            if (!(x % pBankFormat->bitsPerPixel))
 
1270
                continue;
 
1271
 
 
1272
            if (x < minBitsPerScanline)
 
1273
            {
 
1274
                /*
 
1275
                 * Skip ahead certain widths by dividing the excess scanline
 
1276
                 * amongst the y's.
 
1277
                 */
 
1278
                y *= nBitsPerScanlinePadUnit;
 
1279
                nBitsPerScanline +=
 
1280
                    ((x + y - 1) / y) * nBitsPerScanlinePadUnit;
 
1281
                width = nBitsPerScanline / pBankFormat->bitsPerPixel;
 
1282
                break;
 
1283
            }
 
1284
 
 
1285
            if (BankBase != BankUnit)
 
1286
                continue;
 
1287
 
 
1288
            if (!(nBitsPerScanline % x))
 
1289
                return (int)width;
 
1290
 
 
1291
            BankBase = ((nBitsPerScanline - minBitsPerScanline) /
 
1292
                (nBitsPerScanline - x)) * BankUnit;
 
1293
        }
 
1294
    }
 
1295
 
 
1296
    return -1;
 
1297
}
 
1298
 
1129
1299
/*
1130
1300
 * xf86ValidateModes
1131
1301
 *
1312
1482
        memcpy(storeClockRanges, cp, sizeof(ClockRange));
1313
1483
    }
1314
1484
 
1315
 
    /* Determine which pixmap format to pass to miScanLineWidth() */
 
1485
    /* Determine which pixmap format to pass to scanLineWidth() */
1316
1486
    if (scrp->depth > 4)
1317
1487
        BankFormat = &scrp->fbFormat;
1318
1488
    else
1363
1533
            for (i = 0; linePitches[i] != 0; i++) {
1364
1534
                if ((linePitches[i] >= virtualX) &&
1365
1535
                    (linePitches[i] ==
1366
 
                     miScanLineWidth(virtualX, virtualY, linePitches[i],
1367
 
                                     apertureSize, BankFormat, pitchInc))) {
 
1536
                     scanLineWidth(virtualX, virtualY, linePitches[i],
 
1537
                                   apertureSize, BankFormat, pitchInc))) {
1368
1538
                    linePitch = linePitches[i];
1369
1539
                    break;
1370
1540
                }
1371
1541
            }
1372
1542
        } else {
1373
 
            linePitch = miScanLineWidth(virtualX, virtualY, minPitch,
1374
 
                                        apertureSize, BankFormat, pitchInc);
 
1543
            linePitch = scanLineWidth(virtualX, virtualY, minPitch,
 
1544
                                      apertureSize, BankFormat, pitchInc);
1375
1545
        }
1376
1546
 
1377
1547
        if ((linePitch < minPitch) || (linePitch > maxPitch)) {
1396
1566
        /* XXX this doesn't take m{in,ax}Pitch into account; oh well */
1397
1567
        inferred_virtual = inferVirtualSize(scrp, availModes, &virtX, &virtY);
1398
1568
        if (inferred_virtual)
1399
 
            linePitch = miScanLineWidth(virtX, virtY, minPitch, apertureSize,
1400
 
                                        BankFormat, pitchInc);
 
1569
            linePitch = scanLineWidth(virtX, virtY, minPitch, apertureSize,
 
1570
                                      BankFormat, pitchInc);
1401
1571
    }
1402
1572
 
1403
1573
    /* Print clock ranges and scaled clocks */
1609
1779
                    if ((linePitches[i] >= newVirtX) &&
1610
1780
                        (linePitches[i] >= linePitch) &&
1611
1781
                        (linePitches[i] ==
1612
 
                         miScanLineWidth(newVirtX, newVirtY, linePitches[i],
1613
 
                                         apertureSize, BankFormat, pitchInc))) {
 
1782
                         scanLineWidth(newVirtX, newVirtY, linePitches[i],
 
1783
                                       apertureSize, BankFormat, pitchInc))) {
1614
1784
                        newLinePitch = linePitches[i];
1615
1785
                        break;
1616
1786
                    }
1618
1788
            } else {
1619
1789
                if (linePitch < minPitch)
1620
1790
                    linePitch = minPitch;
1621
 
                newLinePitch = miScanLineWidth(newVirtX, newVirtY, linePitch,
1622
 
                                               apertureSize, BankFormat,
1623
 
                                               pitchInc);
 
1791
                newLinePitch = scanLineWidth(newVirtX, newVirtY, linePitch,
 
1792
                                             apertureSize, BankFormat,
 
1793
                                             pitchInc);
1624
1794
            }
1625
1795
            if ((newLinePitch < minPitch) || (newLinePitch > maxPitch)) {
1626
1796
                p->status = MODE_BAD_WIDTH;
1682
1852
                       virtX, virtY, vx, vy);
1683
1853
            virtX = vx;
1684
1854
            virtY = vy;
1685
 
            linePitch = miScanLineWidth(vx, vy, minPitch, apertureSize,
1686
 
                                        BankFormat, pitchInc);
 
1855
            linePitch = scanLineWidth(vx, vy, minPitch, apertureSize,
 
1856
                                      BankFormat, pitchInc);
1687
1857
        }
1688
1858
    }
1689
1859
 
1748
1918
            mode->next->prev = mode->prev;
1749
1919
    }
1750
1920
 
1751
 
    xfree(mode->name);
1752
 
    xfree(mode);
 
1921
    free(mode->name);
 
1922
    free(mode);
1753
1923
}
1754
1924
 
1755
1925
/*