summaryrefslogtreecommitdiff
path: root/Xext
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2013-11-03 10:08:15 -0800
committerKeith Packard <keithp@keithp.com>2013-11-11 15:12:50 -0800
commitbee2ec54049377e0033d49abff20d7bd069c62aa (patch)
tree74564b09ff872e6d64820dc773d8e7bbece419d3 /Xext
parentea8acfe3e2f74a46c3f1e91809b4b99af18502b7 (diff)
Xext: Enable MIT-SHM FD-passing request definitions only when possible
Check to see if xtrans FD passing is available and use that to advertise the appropriate version of the SHM extension Signed-off-by: Keith Packard <keithp@keithp.com> Reviewed-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Diffstat (limited to 'Xext')
-rw-r--r--Xext/shm.c14
-rw-r--r--Xext/shmint.h17
2 files changed, 29 insertions, 2 deletions
diff --git a/Xext/shm.c b/Xext/shm.c
index 1a70260fb..109a381a0 100644
--- a/Xext/shm.c
+++ b/Xext/shm.c
@@ -384,7 +384,7 @@ ProcShmAttach(ClientPtr client)
return BadValue;
}
for (shmdesc = Shmsegs; shmdesc; shmdesc = shmdesc->next) {
- if (!shmdesc->is_fd && shmdesc->shmid == stuff->shmid)
+ if (!SHMDESC_IS_FD(shmdesc) && shmdesc->shmid == stuff->shmid)
break;
}
if (shmdesc) {
@@ -396,7 +396,9 @@ ProcShmAttach(ClientPtr client)
shmdesc = malloc(sizeof(ShmDescRec));
if (!shmdesc)
return BadAlloc;
+#ifdef SHM_FD_PASSING
shmdesc->is_fd = FALSE;
+#endif
shmdesc->addr = shmat(stuff->shmid, 0,
stuff->readOnly ? SHM_RDONLY : 0);
if ((shmdesc->addr == ((char *) -1)) || SHMSTAT(stuff->shmid, &buf)) {
@@ -435,9 +437,11 @@ ShmDetachSegment(pointer value, /* must conform to DeleteType */
if (--shmdesc->refcnt)
return TRUE;
+#if SHM_FD_PASSING
if (shmdesc->is_fd)
munmap(shmdesc->addr, shmdesc->size);
else
+#endif
shmdt(shmdesc->addr);
for (prev = &Shmsegs; *prev != shmdesc; prev = &(*prev)->next);
*prev = shmdesc->next;
@@ -1094,6 +1098,7 @@ ProcShmCreatePixmap(ClientPtr client)
return BadAlloc;
}
+#ifdef SHM_FD_PASSING
static int
ProcShmAttachFd(ClientPtr client)
{
@@ -1209,6 +1214,7 @@ ProcShmCreateSegment(ClientPtr client)
WriteToClient(client, sizeof (xShmCreateSegmentReply), &rep);
return Success;
}
+#endif /* SHM_FD_PASSING */
static int
ProcShmDispatch(ClientPtr client)
@@ -1239,10 +1245,12 @@ ProcShmDispatch(ClientPtr client)
return ProcPanoramiXShmCreatePixmap(client);
#endif
return ProcShmCreatePixmap(client);
+#ifdef SHM_FD_PASSING
case X_ShmAttachFd:
return ProcShmAttachFd(client);
case X_ShmCreateSegment:
return ProcShmCreateSegment(client);
+#endif
default:
return BadRequest;
}
@@ -1343,6 +1351,7 @@ SProcShmCreatePixmap(ClientPtr client)
return ProcShmCreatePixmap(client);
}
+#ifdef SHM_FD_PASSING
static int
SProcShmAttachFd(ClientPtr client)
{
@@ -1364,6 +1373,7 @@ SProcShmCreateSegment(ClientPtr client)
swapl(&stuff->size);
return ProcShmCreateSegment(client);
}
+#endif /* SHM_FD_PASSING */
static int
SProcShmDispatch(ClientPtr client)
@@ -1382,10 +1392,12 @@ SProcShmDispatch(ClientPtr client)
return SProcShmGetImage(client);
case X_ShmCreatePixmap:
return SProcShmCreatePixmap(client);
+#ifdef SHM_FD_PASSING
case X_ShmAttachFd:
return SProcShmAttachFd(client);
case X_ShmCreateSegment:
return SProcShmCreateSegment(client);
+#endif
default:
return BadRequest;
}
diff --git a/Xext/shmint.h b/Xext/shmint.h
index db35fbbbe..7b3ea9bab 100644
--- a/Xext/shmint.h
+++ b/Xext/shmint.h
@@ -56,16 +56,31 @@ typedef struct _ShmFuncs {
void (*PutImage) (XSHM_PUT_IMAGE_ARGS);
} ShmFuncs, *ShmFuncsPtr;
+#include <protocol-versions.h>
+
+#if SERVER_SHM_MAJOR_VERSION == 1 && SERVER_SHM_MINOR_VERSION >= 2
+#define SHM_FD_PASSING 1
+#endif
+
typedef struct _ShmDesc {
struct _ShmDesc *next;
int shmid;
int refcnt;
char *addr;
- Bool is_fd;
Bool writable;
unsigned long size;
+#ifdef SHM_FD_PASSING
+ Bool is_fd;
+ XID resource;
+#endif
} ShmDescRec, *ShmDescPtr;
+#ifdef SHM_FD_PASSING
+#define SHMDESC_IS_FD(shmdesc) ((shmdesc)->is_fd)
+#else
+#define SHMDESC_IS_FD(shmdesc) (0)
+#endif
+
extern _X_EXPORT void
ShmRegisterFuncs(ScreenPtr pScreen, ShmFuncsPtr funcs);