コード例 #1
0
ファイル: shm.c プロジェクト: Agnarr/xserver
void
ShmExtensionInit(INITARGS)
{
    ExtensionEntry *extEntry;
    int i;

#ifdef MUST_CHECK_FOR_SHM_SYSCALL
    if (!CheckForShmSyscall())
    {
	ErrorF("MIT-SHM extension disabled due to lack of kernel support\n");
	return;
    }
#endif

    if (!ShmRegisterPrivates())
	return;

    sharedPixmaps = xFalse;
    {
      sharedPixmaps = xTrue;
      for (i = 0; i < screenInfo.numScreens; i++)
      {
	ShmScrPrivateRec *screen_priv = ShmInitScreenPriv(screenInfo.screens[i]);
	if (!screen_priv->shmFuncs)
	    screen_priv->shmFuncs = &miFuncs;
	if (!screen_priv->shmFuncs->CreatePixmap)
	    sharedPixmaps = xFalse;
      }
      if (sharedPixmaps)
	for (i = 0; i < screenInfo.numScreens; i++)
	{
	    ShmScrPrivateRec *screen_priv = ShmGetScreenPriv(screenInfo.screens[i]);
	    screen_priv->destroyPixmap = screenInfo.screens[i]->DestroyPixmap;
	    screenInfo.screens[i]->DestroyPixmap = ShmDestroyPixmap;
	}
    }
    ShmSegType = CreateNewResourceType(ShmDetachSegment, "ShmSeg");
    if (ShmSegType &&
	(extEntry = AddExtension(SHMNAME, ShmNumberEvents, ShmNumberErrors,
				 ProcShmDispatch, SProcShmDispatch,
				 ShmResetProc, StandardMinorOpcode)))
    {
	ShmReqCode = (unsigned char)extEntry->base;
	ShmCompletionCode = extEntry->eventBase;
	BadShmSegCode = extEntry->errorBase;
	SetResourceTypeErrorValue(ShmSegType, BadShmSegCode);
	EventSwapVector[ShmCompletionCode] = (EventSwapPtr) SShmCompletionEvent;
    }
}
コード例 #2
0
void
XFree86BigfontExtensionInit(void)
{
    if (AddExtension(XF86BIGFONTNAME,
		     XF86BigfontNumberEvents,
		     XF86BigfontNumberErrors,
		     ProcXF86BigfontDispatch,
		     SProcXF86BigfontDispatch,
		     XF86BigfontResetProc,
		     StandardMinorOpcode)) {
#ifdef HAS_SHM
#ifdef MUST_CHECK_FOR_SHM_SYSCALL
	/*
	 * Note: Local-clients will not be optimized without shared memory
	 * support. Remote-client optimization does not depend on shared
	 * memory support.  Thus, the extension is still registered even
	 * when shared memory support is not functional.  
	 */
	if (!CheckForShmSyscall()) {
	    ErrorF(XF86BIGFONTNAME " extension local-client optimization disabled due to lack of shared memory support in the kernel\n");
	    return;
	}
#endif

	srand((unsigned int) time(NULL));
	signature = ((unsigned int) (65536.0/(RAND_MAX+1.0) * rand()) << 16)
	           + (unsigned int) (65536.0/(RAND_MAX+1.0) * rand());
	/* fprintf(stderr, "signature = 0x%08X\n", signature); */

	FontShmdescIndex = AllocateFontPrivateIndex();

#if !defined(CSRG_BASED) && !defined(__CYGWIN__)
	pagesize = SHMLBA;
#else
# ifdef _SC_PAGESIZE
	pagesize = sysconf(_SC_PAGESIZE);
# else
	pagesize = getpagesize();
# endif
#endif
#endif
    }
}
コード例 #3
0
ファイル: xf86bigfont.c プロジェクト: dimkr/tinyxserver
void
XFree86BigfontExtensionInit()
{
    ExtensionEntry* extEntry;

    if ((extEntry = AddExtension(XF86BIGFONTNAME,
				 XF86BigfontNumberEvents,
				 XF86BigfontNumberErrors,
				 ProcXF86BigfontDispatch,
				 SProcXF86BigfontDispatch,
				 XF86BigfontResetProc,
				 StandardMinorOpcode))) {
	XF86BigfontReqCode = (unsigned char) extEntry->base;
#ifdef HAS_SHM
#ifdef MUST_CHECK_FOR_SHM_SYSCALL
	if (!CheckForShmSyscall()) {
	    ErrorF(XF86BIGFONTNAME " extension disabled due to lack of shared memory support in the kernel\n");
	    return;
	}
#endif

	srand((unsigned int) time(NULL));
	signature = ((unsigned int) (65536.0/(RAND_MAX+1.0) * rand()) << 16)
	           + (unsigned int) (65536.0/(RAND_MAX+1.0) * rand());
	/* fprintf(stderr, "signature = 0x%08X\n", signature); */

	FontShmdescIndex = AllocateFontPrivateIndex();

#if !defined(CSRG_BASED) && !defined(__CYGWIN__)
	pagesize = SHMLBA;
#else
# ifdef _SC_PAGESIZE
	pagesize = sysconf(_SC_PAGESIZE);
# else
	pagesize = getpagesize();
# endif
#endif
#endif
    }
}
コード例 #4
0
ファイル: xf86bigfont.c プロジェクト: Magister/x11rdp_xorg71
void
XFree86BigfontExtensionInit()
{
#if 0
    ExtensionEntry* extEntry;

    if ((extEntry = AddExtension(XF86BIGFONTNAME,
				 XF86BigfontNumberEvents,
				 XF86BigfontNumberErrors,
				 ProcXF86BigfontDispatch,
				 SProcXF86BigfontDispatch,
				 XF86BigfontResetProc,
				 StandardMinorOpcode))) {
	XF86BigfontReqCode = (unsigned char) extEntry->base;
#else
    if (AddExtension(XF86BIGFONTNAME,
		     XF86BigfontNumberEvents,
		     XF86BigfontNumberErrors,
		     ProcXF86BigfontDispatch,
		     SProcXF86BigfontDispatch,
		     XF86BigfontResetProc,
		     StandardMinorOpcode)) {
#endif
#ifdef HAS_SHM
#ifdef MUST_CHECK_FOR_SHM_SYSCALL
	/*
	 * Note: Local-clients will not be optimized without shared memory
	 * support. Remote-client optimization does not depend on shared
	 * memory support.  Thus, the extension is still registered even
	 * when shared memory support is not functional.  
	 */
	if (!CheckForShmSyscall()) {
	    ErrorF(XF86BIGFONTNAME " extension local-client optimization disabled due to lack of shared memory support in the kernel\n");
	    return;
	}
#endif

	srand((unsigned int) time(NULL));
	signature = ((unsigned int) (65536.0/(RAND_MAX+1.0) * rand()) << 16)
	           + (unsigned int) (65536.0/(RAND_MAX+1.0) * rand());
	/* fprintf(stderr, "signature = 0x%08X\n", signature); */

	FontShmdescIndex = AllocateFontPrivateIndex();

#if !defined(CSRG_BASED) && !defined(__CYGWIN__)
	pagesize = SHMLBA;
#else
# ifdef _SC_PAGESIZE
	pagesize = sysconf(_SC_PAGESIZE);
# else
	pagesize = getpagesize();
# endif
#endif
#endif
    }
}


/* ========== Management of shared memory segments ========== */

#ifdef HAS_SHM

#ifdef __linux__
/* On Linux, shared memory marked as "removed" can still be attached.
   Nice feature, because the kernel will automatically free the associated
   storage when the server and all clients are gone. */
#define EARLY_REMOVE
#endif

typedef struct _ShmDesc {
    struct _ShmDesc *next;
    struct _ShmDesc **prev;
    int shmid;
    char *attach_addr;
} ShmDescRec, *ShmDescPtr;

static ShmDescPtr ShmList = (ShmDescPtr) NULL;

static ShmDescPtr
shmalloc(
    unsigned int size)
{
    ShmDescPtr pDesc;
    int shmid;
    char *addr;

#ifdef MUST_CHECK_FOR_SHM_SYSCALL
    if (pagesize == 0)
	return (ShmDescPtr) NULL;
#endif

    /* On some older Linux systems, the number of shared memory segments
       system-wide is 127. In Linux 2.4, it is 4095.
       Therefore there is a tradeoff to be made between allocating a
       shared memory segment on one hand, and allocating memory and piping
       the glyph metrics on the other hand. If the glyph metrics size is
       small, we prefer the traditional way. */
    if (size < 3500)
	return (ShmDescPtr) NULL;

    pDesc = (ShmDescRec *) xalloc(sizeof(ShmDescRec));
    if (!pDesc)
	return (ShmDescPtr) NULL;

    size = (size + pagesize-1) & -pagesize;
    shmid = shmget(IPC_PRIVATE, size, S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH);
    if (shmid == -1) {
	ErrorF(XF86BIGFONTNAME " extension: shmget() failed, size = %u, errno = %d\n",
	       size, errno);
	xfree(pDesc);
	return (ShmDescPtr) NULL;
    }

    if ((addr = shmat(shmid, 0, 0)) == (char *)-1) {
	ErrorF(XF86BIGFONTNAME " extension: shmat() failed, size = %u, errno = %d\n",
	       size, errno);
	shmctl(shmid, IPC_RMID, (void *) 0);
	xfree(pDesc);
	return (ShmDescPtr) NULL;
    }

#ifdef EARLY_REMOVE
    shmctl(shmid, IPC_RMID, (void *) 0);
#endif

    pDesc->shmid = shmid;
    pDesc->attach_addr = addr;
    if (ShmList) ShmList->prev = &pDesc->next;
    pDesc->next = ShmList;
    pDesc->prev = &ShmList;
    ShmList = pDesc;

    return pDesc;
}