From aafceeb4881acf38d6edc48936b61f637c469756 Mon Sep 17 00:00:00 2001 From: Jay Sorg Date: Mon, 29 May 2023 22:53:25 -0700 Subject: [PATCH] move to posix shm --- module/rdp.h | 3 +- module/rdpClientCon.c | 65 ++++++++++++++++++++++++++++++------------- module/rdpClientCon.h | 2 +- 3 files changed, 48 insertions(+), 22 deletions(-) diff --git a/module/rdp.h b/module/rdp.h index d10d6a3a..2eb454f4 100644 --- a/module/rdp.h +++ b/module/rdp.h @@ -124,7 +124,8 @@ struct image_data int lineBytes; uint8_t *pixels; uint8_t *shmem_pixels; - int shmem_id; + int shmem_fd; + int shmem_bytes; int shmem_offset; int shmem_lineBytes; }; diff --git a/module/rdpClientCon.c b/module/rdpClientCon.c index 25d2ec2a..d0952e39 100644 --- a/module/rdpClientCon.c +++ b/module/rdpClientCon.c @@ -215,6 +215,7 @@ rdpClientConGotConnection(ScreenPtr pScreen, rdpPtr dev) clientCon->shmemstatus = SHM_UNINITIALIZED; clientCon->updateRetries = 0; clientCon->dev = dev; + clientCon->shmemfd = -1; dev->last_event_time_ms = GetTimeInMillis(); dev->do_dirty_ons = 1; @@ -413,7 +414,9 @@ rdpClientConDisconnect(rdpPtr dev, rdpClientCon *clientCon) free_stream(clientCon->in_s); if (clientCon->shmemptr != NULL) { - shmdt(clientCon->shmemptr); + g_free_unmap_fd(clientCon->shmemptr, + clientCon->shmemfd, + clientCon->shmem_bytes); } free(clientCon); return 0; @@ -687,25 +690,41 @@ rdpClientConProcessMsgVersion(rdpPtr dev, rdpClientCon *clientCon, static void rdpClientConAllocateSharedMemory(rdpClientCon *clientCon, int bytes) { + void *shmemptr; + int shmemfd; + if (clientCon->shmemptr != NULL && clientCon->shmem_bytes == bytes) { - LLOGLN(0, ("rdpClientConAllocateSharedMemory: reusing shmemid %d", - clientCon->shmemid)); + LLOGLN(0, ("rdpClientConAllocateSharedMemory: reusing shmemfd %d", + clientCon->shmemfd)); return; } - - if (clientCon->shmemptr != 0) + if (clientCon->shmemptr != NULL) + { + g_free_unmap_fd(clientCon->shmemptr, + clientCon->shmemfd, + clientCon->shmem_bytes); + clientCon->shmemptr = NULL; + clientCon->shmemfd = -1; + clientCon->shmem_bytes = 0; + } + if (g_alloc_shm_map_fd(&shmemptr, &shmemfd, bytes) == 0) { - shmdt(clientCon->shmemptr); + clientCon->shmemptr = shmemptr; + clientCon->shmemfd = shmemfd; + clientCon->shmem_bytes = bytes; + LLOGLN(0, ("rdpClientConAllocateSharedMemory: shmemfd %d shmemptr %p " + "bytes %d", + clientCon->shmemfd, clientCon->shmemptr, + clientCon->shmem_bytes)); + } + else + { + LLOGLN(0, ("rdpClientConAllocateSharedMemory: g_alloc_shm_map_fd " + "failed")); } - clientCon->shmemid = shmget(IPC_PRIVATE, bytes, IPC_CREAT | 0777); - clientCon->shmemptr = shmat(clientCon->shmemid, 0, 0); - clientCon->shmem_bytes = bytes; - shmctl(clientCon->shmemid, IPC_RMID, NULL); - LLOGLN(0, ("rdpClientConAllocateSharedMemory: shmemid %d shmemptr %p bytes %d", - clientCon->shmemid, clientCon->shmemptr, - clientCon->shmem_bytes)); } + /******************************************************************************/ /* this from miScreenInit @@ -2380,7 +2399,7 @@ rdpClientConCheckDirtyScreen(rdpPtr dev, rdpClientCon *clientCon) /******************************************************************************/ static int -rdpClientConSendPaintRectShmEx(rdpPtr dev, rdpClientCon *clientCon, +rdpClientConSendPaintRectShmFd(rdpPtr dev, rdpClientCon *clientCon, struct image_data *id, RegionPtr dirtyReg, BoxPtr copyRects, int numCopyRects) @@ -2402,15 +2421,15 @@ rdpClientConSendPaintRectShmEx(rdpPtr dev, rdpClientCon *clientCon, num_rects_c = numCopyRects; if ((num_rects_c < 1) || (num_rects_d < 1)) { - LLOGLN(10, ("rdpClientConSendPaintRectShmEx: nothing to send")); + LLOGLN(10, ("rdpClientConSendPaintRectShmFd: nothing to send")); return 0; } size = 2 + 2 + 2 + num_rects_d * 8 + 2 + num_rects_c * 8; - size += 4 + 4 + 4 + 4 + 2 + 2; + size += 4 + 4 + 4 + 4 + 2 + 2 + 2 + 2; rdpClientConPreCheck(dev, clientCon, size); s = clientCon->out_s; - out_uint16_le(s, 61); + out_uint16_le(s, 64); out_uint16_le(s, size); clientCon->count++; @@ -2445,11 +2464,16 @@ rdpClientConSendPaintRectShmEx(rdpPtr dev, rdpClientCon *clientCon, out_uint32_le(s, 0); clientCon->rect_id++; out_uint32_le(s, clientCon->rect_id); - out_uint32_le(s, id->shmem_id); + out_uint32_le(s, id->shmem_bytes); out_uint32_le(s, id->shmem_offset); + out_uint16_le(s, clientCon->cap_left); + out_uint16_le(s, clientCon->cap_top); out_uint16_le(s, clientCon->cap_width); out_uint16_le(s, clientCon->cap_height); + rdpClientConSendPending(clientCon->dev, clientCon); + g_sck_send_fd_set(clientCon->sck, "int", 4, &(id->shmem_fd), 1); + rdpClientConEndUpdate(dev, clientCon); return 0; @@ -2492,7 +2516,7 @@ rdpCapRect(rdpClientCon *clientCon, BoxPtr cap_rect, struct image_data *id) if (rdpCapture(clientCon, cap_dirty, &rects, &num_rects, id)) { LLOGLN(10, ("rdpCapRect: num_rects %d", num_rects)); - rdpClientConSendPaintRectShmEx(clientCon->dev, clientCon, id, + rdpClientConSendPaintRectShmFd(clientCon->dev, clientCon, id, cap_dirty, rects, num_rects); free(rects); } @@ -2739,7 +2763,8 @@ rdpClientConGetScreenImageRect(rdpPtr dev, rdpClientCon *clientCon, id->lineBytes = dev->paddedWidthInBytes; id->pixels = dev->pfbMemory; id->shmem_pixels = clientCon->shmemptr; - id->shmem_id = clientCon->shmemid; + id->shmem_fd = clientCon->shmemfd; + id->shmem_bytes = clientCon->shmem_bytes; id->shmem_offset = 0; id->shmem_lineBytes = clientCon->shmem_lineBytes; } diff --git a/module/rdpClientCon.h b/module/rdpClientCon.h index 604bd227..749932c3 100644 --- a/module/rdpClientCon.h +++ b/module/rdpClientCon.h @@ -104,7 +104,7 @@ struct _rdpClientCon struct xrdp_client_info client_info; uint8_t *shmemptr; - int shmemid; + int shmemfd; int shmem_bytes; int shmem_lineBytes; RegionPtr shmRegion;