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

« back to all changes in this revision

Viewing changes to hw/vfb/InitOutput.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:
77
77
 
78
78
typedef struct
79
79
{
80
 
    int scrnum;
81
80
    int width;
82
81
    int paddedBytesWidth;
83
82
    int paddedWidth;
105
104
} vfbScreenInfo, *vfbScreenInfoPtr;
106
105
 
107
106
static int vfbNumScreens;
108
 
static vfbScreenInfo vfbScreens[MAXSCREENS];
 
107
static vfbScreenInfo *vfbScreens;
 
108
static vfbScreenInfo defaultScreenInfo = {
 
109
    .width  = VFB_DEFAULT_WIDTH,
 
110
    .height = VFB_DEFAULT_HEIGHT,
 
111
    .depth  = VFB_DEFAULT_DEPTH,
 
112
    .blackPixel = VFB_DEFAULT_BLACKPIXEL,
 
113
    .whitePixel = VFB_DEFAULT_WHITEPIXEL,
 
114
    .lineBias = VFB_DEFAULT_LINEBIAS,
 
115
};
109
116
static Bool vfbPixmapDepths[33];
110
117
#ifdef HAS_MMAP
111
118
static char *pfbdir = NULL;
113
120
typedef enum { NORMAL_MEMORY_FB, SHARED_MEMORY_FB, MMAPPED_FILE_FB } fbMemType;
114
121
static fbMemType fbmemtype = NORMAL_MEMORY_FB;
115
122
static char needswap = 0;
116
 
static int lastScreen = -1;
117
123
static Bool Render = TRUE;
118
124
 
119
125
#define swapcopy16(_dst, _src) \
134
140
        vfbPixmapDepths[i] = FALSE;
135
141
}
136
142
 
137
 
static void
138
 
vfbInitializeDefaultScreens(void)
139
 
{
140
 
    int i;
141
 
 
142
 
    for (i = 0; i < MAXSCREENS; i++)
143
 
    {
144
 
        vfbScreens[i].scrnum = i;
145
 
        vfbScreens[i].width  = VFB_DEFAULT_WIDTH;
146
 
        vfbScreens[i].height = VFB_DEFAULT_HEIGHT;
147
 
        vfbScreens[i].depth  = VFB_DEFAULT_DEPTH;
148
 
        vfbScreens[i].blackPixel = VFB_DEFAULT_BLACKPIXEL;
149
 
        vfbScreens[i].whitePixel = VFB_DEFAULT_WHITEPIXEL;
150
 
        vfbScreens[i].lineBias = VFB_DEFAULT_LINEBIAS;
151
 
        vfbScreens[i].pfbMemory = NULL;
152
 
    }
153
 
    vfbNumScreens = 1;
154
 
}
155
 
 
156
143
static int
157
144
vfbBitsPerPixel(int depth)
158
145
{
207
194
    case NORMAL_MEMORY_FB:
208
195
        for (i = 0; i < vfbNumScreens; i++)
209
196
        {
210
 
            Xfree(vfbScreens[i].pXWDHeader);
 
197
            free(vfbScreens[i].pXWDHeader);
211
198
        }
212
199
        break;
213
200
    }
248
235
{
249
236
    ErrorF("-screen scrn WxHxD     set screen's width, height, depth\n");
250
237
    ErrorF("-pixdepths list-of-int support given pixmap depths\n");
251
 
#ifdef RENDER
252
238
    ErrorF("+/-render              turn on/off RENDER extension support"
253
239
           "(default on)\n");
254
 
#endif
255
240
    ErrorF("-linebias n            adjust thin line pixelization\n");
256
241
    ErrorF("-blackpixel n          pixel value for black\n");
257
242
    ErrorF("-whitepixel n          pixel value for white\n");
269
254
ddxProcessArgument(int argc, char *argv[], int i)
270
255
{
271
256
    static Bool firstTime = TRUE;
 
257
    static int lastScreen = -1;
 
258
    vfbScreenInfo *currentScreen;
272
259
 
273
260
    if (firstTime)
274
261
    {
275
 
        vfbInitializeDefaultScreens();
276
262
        vfbInitializePixmapDepths();
277
263
        firstTime = FALSE;
278
264
    }
279
265
 
 
266
    if (lastScreen == -1)
 
267
        currentScreen = &defaultScreenInfo;
 
268
    else
 
269
        currentScreen = &vfbScreens[lastScreen];
 
270
 
280
271
#define CHECK_FOR_REQUIRED_ARGUMENTS(num) \
281
272
    if (((i + num) >= argc) || (!argv[i + num])) {                      \
282
273
      ErrorF("Required argument to %s not specified\n", argv[i]);       \
289
280
        int screenNum;
290
281
        CHECK_FOR_REQUIRED_ARGUMENTS(2);
291
282
        screenNum = atoi(argv[i+1]);
292
 
        if (screenNum < 0 || screenNum >= MAXSCREENS)
 
283
        if (screenNum < 0)
293
284
        {
294
285
            ErrorF("Invalid screen number %d\n", screenNum);
295
286
            UseMsg();
296
287
            FatalError("Invalid screen number %d passed to -screen\n",
297
288
                       screenNum);
298
289
        }
 
290
 
 
291
        if (vfbNumScreens <= screenNum)
 
292
        {
 
293
            vfbScreens = realloc(vfbScreens, sizeof(*vfbScreens) * (screenNum + 1));
 
294
            if (!vfbScreens)
 
295
                FatalError("Not enough memory for screen %d\n", screenNum);
 
296
            for (; vfbNumScreens <= screenNum; ++vfbNumScreens)
 
297
                vfbScreens[vfbNumScreens] = defaultScreenInfo;
 
298
        }
 
299
 
299
300
        if (3 != sscanf(argv[i+2], "%dx%dx%d",
300
301
                        &vfbScreens[screenNum].width,
301
302
                        &vfbScreens[screenNum].height,
307
308
                   argv[i+2], screenNum);
308
309
        }
309
310
 
310
 
        if (screenNum >= vfbNumScreens)
311
 
            vfbNumScreens = screenNum + 1;
312
311
        lastScreen = screenNum;
313
312
        return 3;
314
313
    }
350
349
 
351
350
    if (strcmp (argv[i], "-blackpixel") == 0)   /* -blackpixel n */
352
351
    {
353
 
        Pixel pix;
354
352
        CHECK_FOR_REQUIRED_ARGUMENTS(1);
355
 
        pix = atoi(argv[++i]);
356
 
        if (-1 == lastScreen)
357
 
        {
358
 
            int i;
359
 
            for (i = 0; i < MAXSCREENS; i++)
360
 
            {
361
 
                vfbScreens[i].blackPixel = pix;
362
 
            }
363
 
        }
364
 
        else
365
 
        {
366
 
            vfbScreens[lastScreen].blackPixel = pix;
367
 
        }
 
353
        currentScreen->blackPixel = atoi(argv[++i]);
368
354
        return 2;
369
355
    }
370
356
 
371
357
    if (strcmp (argv[i], "-whitepixel") == 0)   /* -whitepixel n */
372
358
    {
373
 
        Pixel pix;
374
359
        CHECK_FOR_REQUIRED_ARGUMENTS(1);
375
 
        pix = atoi(argv[++i]);
376
 
        if (-1 == lastScreen)
377
 
        {
378
 
            int i;
379
 
            for (i = 0; i < MAXSCREENS; i++)
380
 
            {
381
 
                vfbScreens[i].whitePixel = pix;
382
 
            }
383
 
        }
384
 
        else
385
 
        {
386
 
            vfbScreens[lastScreen].whitePixel = pix;
387
 
        }
 
360
        currentScreen->whitePixel = atoi(argv[++i]);
388
361
        return 2;
389
362
    }
390
363
 
391
364
    if (strcmp (argv[i], "-linebias") == 0)     /* -linebias n */
392
365
    {
393
 
        unsigned int linebias;
394
366
        CHECK_FOR_REQUIRED_ARGUMENTS(1);
395
 
        linebias = atoi(argv[++i]);
396
 
        if (-1 == lastScreen)
397
 
        {
398
 
            int i;
399
 
            for (i = 0; i < MAXSCREENS; i++)
400
 
            {
401
 
                vfbScreens[i].lineBias = linebias;
402
 
            }
403
 
        }
404
 
        else
405
 
        {
406
 
            vfbScreens[lastScreen].lineBias = linebias;
407
 
        }
 
367
        currentScreen->lineBias = atoi(argv[++i]);
408
368
        return 2;
409
369
    }
410
370
 
429
389
    return 0;
430
390
}
431
391
 
432
 
static ColormapPtr InstalledMaps[MAXSCREENS];
 
392
static DevPrivateKeyRec cmapScrPrivateKeyRec;
 
393
#define cmapScrPrivateKey (&cmapScrPrivateKeyRec)
 
394
 
 
395
#define GetInstalledColormap(s) ((ColormapPtr) dixLookupPrivate(&(s)->devPrivates, cmapScrPrivateKey))
 
396
#define SetInstalledColormap(s,c) (dixSetPrivate(&(s)->devPrivates, cmapScrPrivateKey, c))
433
397
 
434
398
static int
435
399
vfbListInstalledColormaps(ScreenPtr pScreen, Colormap *pmaps)
436
400
{
437
401
    /* By the time we are processing requests, we can guarantee that there
438
402
     * is always a colormap installed */
439
 
    *pmaps = InstalledMaps[pScreen->myNum]->mid;
440
 
    return (1);
 
403
    *pmaps = GetInstalledColormap(pScreen)->mid;
 
404
    return 1;
441
405
}
442
406
 
443
407
 
444
408
static void
445
409
vfbInstallColormap(ColormapPtr pmap)
446
410
{
447
 
    int index = pmap->pScreen->myNum;
448
 
    ColormapPtr oldpmap = InstalledMaps[index];
 
411
    ColormapPtr oldpmap = GetInstalledColormap(pmap->pScreen);
449
412
 
450
413
    if (pmap != oldpmap)
451
414
    {
461
424
        if(oldpmap != (ColormapPtr)None)
462
425
            WalkTree(pmap->pScreen, TellLostMap, (char *)&oldpmap->mid);
463
426
        /* Install pmap */
464
 
        InstalledMaps[index] = pmap;
 
427
        SetInstalledColormap(pmap->pScreen, pmap);
465
428
        WalkTree(pmap->pScreen, TellGainedMap, (char *)&pmap->mid);
466
429
 
467
430
        entries = pmap->pVisual->ColormapEntries;
476
439
        swapcopy32(pXWDHeader->bits_per_rgb, pVisual->bitsPerRGBValue);
477
440
        swapcopy32(pXWDHeader->colormap_entries, pVisual->ColormapEntries);
478
441
 
479
 
        ppix = (Pixel *)xalloc(entries * sizeof(Pixel));
480
 
        prgb = (xrgb *)xalloc(entries * sizeof(xrgb));
481
 
        defs = (xColorItem *)xalloc(entries * sizeof(xColorItem));
 
442
        ppix = (Pixel *)malloc(entries * sizeof(Pixel));
 
443
        prgb = (xrgb *)malloc(entries * sizeof(xrgb));
 
444
        defs = (xColorItem *)malloc(entries * sizeof(xColorItem));
482
445
 
483
446
        for (i = 0; i < entries; i++)  ppix[i] = i;
484
447
        /* XXX truecolor */
485
 
        QueryColors(pmap, entries, ppix, prgb);
 
448
        QueryColors(pmap, entries, ppix, prgb, serverClient);
486
449
 
487
450
        for (i = 0; i < entries; i++) { /* convert xrgbs to xColorItems */
488
451
            defs[i].pixel = ppix[i] & 0xff; /* change pixel to index */
493
456
        }
494
457
        (*pmap->pScreen->StoreColors)(pmap, entries, defs);
495
458
 
496
 
        xfree(ppix);
497
 
        xfree(prgb);
498
 
        xfree(defs);
 
459
        free(ppix);
 
460
        free(prgb);
 
461
        free(defs);
499
462
    }
500
463
}
501
464
 
502
465
static void
503
466
vfbUninstallColormap(ColormapPtr pmap)
504
467
{
505
 
    ColormapPtr curpmap = InstalledMaps[pmap->pScreen->myNum];
 
468
    ColormapPtr curpmap = GetInstalledColormap(pmap->pScreen);
506
469
 
507
470
    if(pmap == curpmap)
508
471
    {
523
486
    XWDColor *pXWDCmap;
524
487
    int i;
525
488
 
526
 
    if (pmap != InstalledMaps[pmap->pScreen->myNum])
 
489
    if (pmap != GetInstalledColormap(pmap->pScreen))
527
490
    {
528
491
        return;
529
492
    }
597
560
    char dummyBuffer[DUMMY_BUFFER_SIZE];
598
561
    int currentFileSize, writeThisTime;
599
562
 
600
 
    sprintf(pvfb->mmap_file, "%s/Xvfb_screen%d", pfbdir, pvfb->scrnum);
 
563
    sprintf(pvfb->mmap_file, "%s/Xvfb_screen%d", pfbdir, (int) (pvfb - vfbScreens));
601
564
    if (-1 == (pvfb->mmap_fd = open(pvfb->mmap_file, O_CREAT|O_RDWR, 0666)))
602
565
    {
603
566
        perror("open");
607
570
 
608
571
    /* Extend the file to be the proper size */
609
572
 
610
 
    bzero(dummyBuffer, DUMMY_BUFFER_SIZE);
 
573
    memset(dummyBuffer, 0, DUMMY_BUFFER_SIZE);
611
574
    for (currentFileSize = 0;
612
575
         currentFileSize < pvfb->sizeInBytes;
613
576
         currentFileSize += writeThisTime)
670
633
        return;
671
634
    }
672
635
 
673
 
    ErrorF("screen %d shmid %d\n", pvfb->scrnum, pvfb->shmid);
 
636
    ErrorF("screen %d shmid %d\n", (int) (pvfb - vfbScreens), pvfb->shmid);
674
637
}
675
638
#endif /* HAS_SHM */
676
639
 
719
682
#endif
720
683
 
721
684
    case NORMAL_MEMORY_FB:
722
 
        pvfb->pXWDHeader = (XWDFileHeader *)Xalloc(pvfb->sizeInBytes);
 
685
        pvfb->pXWDHeader = (XWDFileHeader *)malloc(pvfb->sizeInBytes);
723
686
        break;
724
687
    }
725
688
 
832
795
 
833
796
    /*
834
797
     * XXX probably lots of stuff to clean.  For now,
835
 
     * clear InstalledMaps[] so that server reset works correctly.
 
798
     * clear installed colormaps so that server reset works correctly.
836
799
     */
837
 
    for (i = 0; i < MAXSCREENS; i++)
838
 
        InstalledMaps[i] = NULL;
 
800
    for (i = 0; i < screenInfo.numScreens; i++)
 
801
        SetInstalledColormap(screenInfo.screens[i], NULL);
839
802
 
840
803
    return pScreen->CloseScreen(index, pScreen);
841
804
}
848
811
    int ret;
849
812
    char *pbits;
850
813
    
 
814
    if (!dixRegisterPrivateKey(&cmapScrPrivateKeyRec, PRIVATE_SCREEN, 0))
 
815
        return FALSE;
 
816
 
851
817
    if (dpix == 0)
852
818
      dpix = 100;
853
819
 
904
870
 
905
871
    ret = fbScreenInit(pScreen, pbits, pvfb->width, pvfb->height,
906
872
                       dpix, dpiy, pvfb->paddedWidth,pvfb->bitsPerPixel);
907
 
#ifdef RENDER
908
873
    if (ret && Render) 
909
874
        fbPictureInit (pScreen, 0, 0);
910
 
#endif
911
875
 
912
876
    if (!ret) return FALSE;
913
877
 
996
960
 
997
961
    /* initialize screens */
998
962
 
 
963
    if (vfbNumScreens < 1)
 
964
    {
 
965
        vfbScreens = &defaultScreenInfo;
 
966
        vfbNumScreens = 1;
 
967
    }
999
968
    for (i = 0; i < vfbNumScreens; i++)
1000
969
    {
1001
970
        if (-1 == AddScreen(vfbScreenInit, argc, argv))