[PATCH 3/7] Xext: Enable MIT-SHM FD-passing request definitions only when possible
Keith Packard
keithp at keithp.com
Thu Nov 7 12:15:56 PST 2013
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 at keithp.com>
---
Xext/shm.c | 14 +++++++++++++-
Xext/shmint.h | 17 ++++++++++++++++-
include/protocol-versions.h | 4 ++++
3 files changed, 33 insertions(+), 2 deletions(-)
diff --git a/Xext/shm.c b/Xext/shm.c
index 1a70260..109a381 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 db35fbb..7b3ea9b 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);
diff --git a/include/protocol-versions.h b/include/protocol-versions.h
index 5ceaeb0..95df8ce 100644
--- a/include/protocol-versions.h
+++ b/include/protocol-versions.h
@@ -93,7 +93,11 @@
/* SHM */
#define SERVER_SHM_MAJOR_VERSION 1
+#if XTRANS_SEND_FDS
+#define SERVER_SHM_MINOR_VERSION 2
+#else
#define SERVER_SHM_MINOR_VERSION 1
+#endif
/* Sync */
#define SERVER_SYNC_MAJOR_VERSION 3
--
1.8.4.2
More information about the xorg-devel
mailing list