Adds MIT-SHM AttachFd and CreateSegment requests

Submitted by Keith Packard on Oct. 31, 2013, 8:12 p.m.

Details

Message ID 1383250347-12979-1-git-send-email-keithp@keithp.com
State Accepted
Commit be1483563532b5dcaef6847c206d0a6f772c8bd4
Headers show

Not browsing as part of any series.

Commit Message

Keith Packard Oct. 31, 2013, 8:12 p.m.
Passes shared memory segments by file descriptor, AttachFd passes from
client to server, CreateSegment passes from server to client.

Signed-off-by: Keith Packard <keithp@keithp.com>
---
 shm.h      |  2 +-
 shmproto.h | 42 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 43 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/shm.h b/shm.h
index e076402..be49f5e 100644
--- a/shm.h
+++ b/shm.h
@@ -32,7 +32,7 @@  in this Software without prior written authorization from The Open Group.
 #define SHMNAME "MIT-SHM"
 
 #define SHM_MAJOR_VERSION	1	/* current version numbers */
-#define SHM_MINOR_VERSION	1
+#define SHM_MINOR_VERSION	2
 
 #define ShmCompletion			0
 #define ShmNumberEvents			(ShmCompletion + 1)
diff --git a/shmproto.h b/shmproto.h
index e5de377..8136aa9 100644
--- a/shmproto.h
+++ b/shmproto.h
@@ -43,6 +43,8 @@  in this Software without prior written authorization from The Open Group.
 #define X_ShmPutImage			3
 #define X_ShmGetImage			4
 #define X_ShmCreatePixmap		5
+#define X_ShmAttachFd                   6
+#define X_ShmCreateSegment              7
 
 typedef struct _ShmQueryVersion {
     CARD8	reqType;		/* always ShmReqCode */
@@ -178,6 +180,46 @@  typedef struct _ShmCompletion {
 } xShmCompletionEvent;
 #define sz_xShmCompletionEvent	32
 
+/* Version 1.2 additions */
+typedef struct _ShmAttachFd {
+    CARD8	reqType;	/* always ShmReqCode */
+    CARD8	shmReqType;	/* always X_ShmAttachFd */
+    CARD16	length B16;
+    ShmSeg	shmseg B32;
+    BOOL	readOnly;
+    BYTE	pad0;
+    CARD16	pad1 B16;
+} xShmAttachFdReq;
+/* File descriptor is passed with this request */
+#define sz_xShmAttachFdReq	12
+
+typedef struct _ShmCreateSegment {
+    CARD8	reqType;	/* always ShmReqCode */
+    CARD8	shmReqType;	/* always X_ShmAttachFd */
+    CARD16	length B16;
+    ShmSeg	shmseg B32;
+    CARD32      size B32;
+    BOOL	readOnly;
+    BYTE	pad0;
+    CARD16	pad1 B16;
+} xShmCreateSegmentReq;
+#define sz_xShmCreateSegmentReq 16
+
+typedef struct {
+    CARD8	type;			/* must be X_Reply */
+    CARD8	nfd;			/* must be 1	*/
+    CARD16	sequenceNumber  B16;	/* last sequence number */
+    CARD32	length  B32;		/* 0 */
+    CARD32	pad2	B32;		/* unused */
+    CARD32	pad3	B32;		/* unused */
+    CARD32	pad4	B32;		/* unused */
+    CARD32	pad5	B32;		/* unused */
+    CARD32	pad6	B32;		/* unused */
+    CARD32	pad7	B32;		/* unused */
+} xShmCreateSegmentReply;
+/* File descriptor is passed with this reply */
+#define sz_xShmCreateSegmentReply	32
+
 #undef ShmSeg
 #undef Drawable
 #undef VisualID

Comments

On Thu, 2013-10-31 at 13:12 -0700, Keith Packard wrote:
> Passes shared memory segments by file descriptor, AttachFd passes from
> client to server, CreateSegment passes from server to client.

I was hoping for a patch to shmproto.txt, but there isn't one, le sigh.
We should really fix the MIT-SHM docs, Jon's reverse-engineered spec pdf
is full of enough handwave to be embarassing for us.

Failing that: I'm just a little cautious of calling this 1.2 without
some escape hatch for a 1.3.  ShmQueryVersion currently has a bool for
shm pixmaps precisely because they might not be supported.  Supposing
someone comes up with a comparable API for, say, win32, they'd be a bit
stuck, since the 1.3 idea of "pass a file descriptor" might not be a
thing the OS provides.  Even if we don't cotton to non-unix
environments, we might find that one or the other is just too wacky to
try to support in the future.

So maybe something like:

---
#define ShmCapCreatePixmaps (1<<0)
#define ShmCapAttachFd      (1<<1)
#define ShmCapCreateSegment (1<<2)

#define X_ShmQueryCapabilities 8

typedef struct _ShmQueryCapabilities {
    CARD8 reqType;
    CARD8 shmReqType;
    CARD16 length;
} xShmQueryCapabilitiesReq;
#define sz_xShmQueryCapabilitiesReq 4

typedef struct {
    CARD8 type;
    CARD8 pad0;
    CARD16 sequenceNumber;
    CARD32 length;
    CARD32 caps0;
    CARD32 caps1;
    CARD32 caps2;
    CARD32 caps3;
    CARD32 caps4;
    CARD32 caps5;
} xShmQueryCapabilitiesReply;
#define sz_xShmQueryCapabilitiesReply 32
---

Where the cap bits start filling in from caps0.

Other than that:

Reviewed-by: Adam Jackson <ajax@redhat.com>

- ajax