Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test shared memory before use #200

Open
wants to merge 1 commit into
base: devel
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 50 additions & 27 deletions module/rdpClientCon.c
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,53 @@ rdpClientConProcessMsgVersion(rdpPtr dev, rdpClientCon *clientCon,
return 0;
}

/**************************************************************************//**
* Allocate shared memory
*
* This memory is shared with the xup driver in xrdp which avoids a lot#
* of unnecessary copying
*
* @param clientCon Client connection
* @param bytes Size of area to attach
*
* Errors are always fatal, as if we can't allocate the moment we can't
* communicate effectively with xrdp
*/
static void
AllocSharedMemory(rdpClientCon *clientCon, int bytes)
{
if (clientCon->shmemptr != 0)
{
shmdt(clientCon->shmemptr);
}
clientCon->shmemid = shmget(IPC_PRIVATE, bytes, IPC_CREAT | 0777);

if (clientCon->shmemid == -1)
{
if (errno == ENOSYS)
{
/* This can happen in FreeBSD jails unless shm is enabled */
FatalError("Shared memory needs to be enabled on this platform");
}
else
{
LLOGLN(0, ("AllocSharedMemory: Can't allocate %d bytes of memory [%s]",
bytes, strerror(errno)));
FatalError("System error creating shared memory area");
}
}
clientCon->shmemptr = shmat(clientCon->shmemid, 0, 0);
shmctl(clientCon->shmemid, IPC_RMID, NULL);
if (clientCon->shmemptr == (void *)-1)
{
LLOGLN(0, ("AllocSharedMemory: Can't attach to shared memory [%s]",
strerror(errno)));
FatalError("System error attaching shared memory area");
}
LLOGLN(0, ("AllocSharedMemory: shmemid %d shmemptr %p",
clientCon->shmemid, clientCon->shmemptr));
}

/******************************************************************************/
/*
this from miScreenInit
Expand Down Expand Up @@ -727,17 +774,9 @@ rdpClientConProcessScreenSizeMsg(rdpPtr dev, rdpClientCon *clientCon,

clientCon->cap_stride_bytes = clientCon->rdp_width * clientCon->rdp_Bpp;

if (clientCon->shmemptr != 0)
{
shmdt(clientCon->shmemptr);
}
bytes = clientCon->rdp_width * clientCon->rdp_height *
clientCon->rdp_Bpp;
clientCon->shmemid = shmget(IPC_PRIVATE, bytes, IPC_CREAT | 0777);
clientCon->shmemptr = shmat(clientCon->shmemid, 0, 0);
shmctl(clientCon->shmemid, IPC_RMID, NULL);
LLOGLN(0, ("rdpClientConProcessScreenSizeMsg: shmemid %d shmemptr %p",
clientCon->shmemid, clientCon->shmemptr));
AllocSharedMemory(clientCon, bytes);
clientCon->shmem_lineBytes = clientCon->rdp_Bpp * clientCon->rdp_width;

if (clientCon->shmRegion != 0)
Expand Down Expand Up @@ -868,17 +907,9 @@ rdpClientConProcessMsgClientInfo(rdpPtr dev, rdpClientCon *clientCon)
clientCon->cap_height = RDPALIGN(clientCon->rdp_height, 64);
LLOGLN(0, (" cap_width %d cap_height %d",
clientCon->cap_width, clientCon->cap_height));
if (clientCon->shmemptr != 0)
{
shmdt(clientCon->shmemptr);
}
bytes = clientCon->cap_width * clientCon->cap_height *
clientCon->rdp_Bpp;
clientCon->shmemid = shmget(IPC_PRIVATE, bytes, IPC_CREAT | 0777);
clientCon->shmemptr = shmat(clientCon->shmemid, 0, 0);
shmctl(clientCon->shmemid, IPC_RMID, NULL);
LLOGLN(0, ("rdpClientConProcessMsgClientInfo: shmemid %d shmemptr %p "
"bytes %d", clientCon->shmemid, clientCon->shmemptr, bytes));
AllocSharedMemory(clientCon, bytes);
clientCon->shmem_lineBytes = clientCon->rdp_Bpp * clientCon->cap_width;
clientCon->cap_stride_bytes = clientCon->cap_width * 4;
shmemstatus = SHM_RFX_ACTIVE;
Expand All @@ -890,16 +921,8 @@ rdpClientConProcessMsgClientInfo(rdpPtr dev, rdpClientCon *clientCon)
clientCon->cap_height = clientCon->rdp_height;
LLOGLN(0, (" cap_width %d cap_height %d",
clientCon->cap_width, clientCon->cap_height));
if (clientCon->shmemptr != 0)
{
shmdt(clientCon->shmemptr);
}
bytes = clientCon->cap_width * clientCon->cap_height * 2;
clientCon->shmemid = shmget(IPC_PRIVATE, bytes, IPC_CREAT | 0777);
clientCon->shmemptr = shmat(clientCon->shmemid, 0, 0);
shmctl(clientCon->shmemid, IPC_RMID, NULL);
LLOGLN(0, ("rdpClientConProcessMsgClientInfo: shmemid %d shmemptr %p "
"bytes %d", clientCon->shmemid, clientCon->shmemptr, bytes));
AllocSharedMemory(clientCon, bytes);
clientCon->shmem_lineBytes = clientCon->rdp_Bpp * clientCon->cap_width;
clientCon->cap_stride_bytes = clientCon->cap_width * 4;
shmemstatus = SHM_H264_ACTIVE;
Expand Down