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

Allow a zero timeout for g_obj_wait() #2904

Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ FreeBSD_task:
SSL: libressl
matrix:
freebsd_instance:
image_family: freebsd-12-4
image_family: freebsd-13-2
prepare_script:
- pkg install -y $SSL git autoconf automake libtool pkgconf opus jpeg-turbo fdk-aac pixman libX11 libXfixes libXrandr nasm fusefs-libs check imlib2 freetype2 cmocka
- git submodule update --init --recursive
Expand Down
2 changes: 1 addition & 1 deletion common/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,6 @@ libcommon_la_SOURCES = \
$(PIXMAN_SOURCES)

libcommon_la_LIBADD = \
-lpthread \
-lpthread -lrt \
$(OPENSSL_LIBS) \
$(DLOPEN_LIBS)
32 changes: 21 additions & 11 deletions common/ms-rdpbcgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,29 @@

/* TS_UD_HEADER: type ((2.2.1.3.1) */
/* TODO: to be renamed */
#define SEC_TAG_CLI_INFO 0xc001 /* CS_CORE? */
#define SEC_TAG_CLI_CRYPT 0xc002 /* CS_SECURITY? */
#define SEC_TAG_CLI_CHANNELS 0xc003 /* CS_CHANNELS? */
#define SEC_TAG_CLI_4 0xc004 /* CS_CLUSTER? */
#define SEC_TAG_CLI_MONITOR 0xc005 /* CS_MONITOR */
#define SEC_TAG_CLI_MONITOR_EX 0xc008 /* CS_MONITOR_EX */
#define SEC_TAG_CLI_INFO 0xc001 /* CS_CORE? */
#define SEC_TAG_CLI_CRYPT 0xc002 /* CS_SECURITY? */
#define SEC_TAG_CLI_CHANNELS 0xc003 /* CS_CHANNELS? */
#define SEC_TAG_CLI_4 0xc004 /* CS_CLUSTER? */
#define SEC_TAG_CLI_MONITOR 0xc005 /* CS_MONITOR */
#define SEC_TAG_CLI_MONITOR_EX 0xc008 /* CS_MONITOR_EX */

/* Client Core Data: colorDepth, postBeta2ColorDepth (2.2.1.3.2) */
#define RNS_UD_COLOR_4BPP 0xCA00
#define RNS_UD_COLOR_8BPP 0xCA01
#define RNS_UD_COLOR_16BPP_555 0xCA02
#define RNS_UD_COLOR_16BPP_565 0xCA03
#define RNS_UD_COLOR_24BPP 0xCA04
#define RNS_UD_COLOR_4BPP 0xCA00
#define RNS_UD_COLOR_8BPP 0xCA01
#define RNS_UD_COLOR_16BPP_555 0xCA02
#define RNS_UD_COLOR_16BPP_565 0xCA03
#define RNS_UD_COLOR_24BPP 0xCA04

/* Client Core Data: supportedColorDepths (2.2.1.3.2) */
#define RNS_UD_24BPP_SUPPORT 0x0001
#define RNS_UD_16BPP_SUPPORT 0x0002
#define RNS_UD_15BPP_SUPPORT 0x0004
#define RNS_UD_32BPP_SUPPORT 0x0008

/* Client Core Data: earlyCapabilityFlags (2.2.1.3.2) */
#define RNS_UD_CS_WANT_32BPP_SESSION 0x0002
#define RNS_UD_CS_SUPPORT_DYNVC_GFX_PROTOCOL 0x0100

/* Client Core Data: connectionType (2.2.1.3.2) */
#define CONNECTION_TYPE_MODEM 0x01
Expand Down
4 changes: 2 additions & 2 deletions common/os_calls.c
Original file line number Diff line number Diff line change
Expand Up @@ -1979,7 +1979,7 @@ g_obj_wait(tintptr *read_objs, int rcount, tintptr *write_objs, int wcount,
handles[j++] = (HANDLE)(write_objs[i]);
}

if (mstimeout < 1)
if (mstimeout < 0)
{
mstimeout = INFINITE;
}
Expand Down Expand Up @@ -2016,7 +2016,7 @@ g_obj_wait(tintptr *read_objs, int rcount, tintptr *write_objs, int wcount,
}
else
{
if (mstimeout < 1)
if (mstimeout < 0)
{
mstimeout = -1;
}
Expand Down
5 changes: 4 additions & 1 deletion common/os_calls.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,13 @@ int g_delete_wait_obj(tintptr obj);
* @param rcount Number of elements in read_objs
* @param write_objs Array of write objects
* @param rcount Number of elements in write_objs
* @param mstimeout Timeout in milliseconds. <= 0 means an infinite timeout.
* @param mstimeout Timeout in milliseconds. < 0 means an infinite timeout.
*
* @return 0 for success. The objects will need to be polled to
* find out what is readable or writeable.
*
* An mstimeout of zero will return immediately, although
* error conditions may be checked for.
*/
int g_obj_wait(tintptr *read_objs, int rcount, tintptr *write_objs,
int wcount, int mstimeout);
Expand Down
9 changes: 9 additions & 0 deletions common/xrdp_client_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,15 @@ struct xrdp_client_info
unsigned int session_physical_height; /* in mm */

int large_pointer_support_flags;
int gfx;
};

enum xrdp_encoder_flags
{
NONE = 0,
ENCODE_COMPLETE = 1 << 0,
GFX_PROGRESSIVE_RFX = 1 << 1,
GFX_H264 = 1 << 2
};

/* yyyymmdd of last incompatible change to xrdp_client_info */
Expand Down
46 changes: 46 additions & 0 deletions common/xrdp_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,4 +291,50 @@
#define XR_RDP_SCAN_LSHIFT 42
#define XR_RDP_SCAN_ALT 56

// Since we're not guaranteed to have pixman, copy these directives.
#define XRDP_PIXMAN_TYPE_ARGB 2
#define XRDP_PIXMAN_TYPE_ABGR 3
#define XRDP_PIXMAN_FORMAT(bpp,type,a,r,g,b) (((bpp) << 24) | \
((type) << 16) | \
((a) << 12) | \
((r) << 8) | \
((g) << 4) | \
((b)))

#define XRDP_a8b8g8r8 \
XRDP_PIXMAN_FORMAT(32, XRDP_PIXMAN_TYPE_ABGR, 8, 8, 8, 8)

#define XRDP_a8r8g8b8 \
XRDP_PIXMAN_FORMAT(32, XRDP_PIXMAN_TYPE_ARGB, 8, 8, 8, 8)

#define XRDP_r5g6b5 \
XRDP_PIXMAN_FORMAT(16, XRDP_PIXMAN_TYPE_ARGB, 0, 5, 6, 5)

#define XRDP_a1r5g5b5 \
XRDP_PIXMAN_FORMAT(16, XRDP_PIXMAN_TYPE_ARGB, 1, 5, 5, 5)

#define XRDP_r3g3b2 \
XRDP_PIXMAN_FORMAT(8, XRDP_PIXMAN_TYPE_ARGB, 0, 3, 3, 2)

// The last used constant in pixman is 63, so use 64+
#define XRDP_nv12 \
XRDP_PIXMAN_FORMAT(12, 64, 0, 0, 0, 0)

#define XRDP_i420 \
XRDP_PIXMAN_FORMAT(12, 65, 0, 0, 0, 0)

#define XRDP_nv12_709fr \
XRDP_PIXMAN_FORMAT(12, 66, 0, 0, 0, 0)

#define XRDP_yuv444_709fr \
XRDP_PIXMAN_FORMAT(32, 67, 0, 0, 0, 0)

// https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-rdpegfx/8131c1bc-1af8-4907-a05a-f72f4581160f
#define XRDP_yuv444_v1_stream_709fr \
XRDP_PIXMAN_FORMAT(32, 68, 0, 0, 0, 0)

// https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-rdpegfx/781406c3-5e24-4f2b-b6ff-42b76bf64f6d
#define XRDP_yuv444_v2_stream_709fr \
XRDP_PIXMAN_FORMAT(32, 69, 0, 0, 0, 0)

#endif
25 changes: 19 additions & 6 deletions libxrdp/xrdp_sec.c
Original file line number Diff line number Diff line change
Expand Up @@ -2114,10 +2114,14 @@ xrdp_sec_process_mcs_data_CS_CORE(struct xrdp_sec *self, struct stream *s)
in_uint16_le(s, supportedColorDepths);
LOG_DEVEL(LOG_LEVEL_TRACE, "Received [MS-RDPBCGR] TS_UD_CS_CORE "
"<Optional Field> supportedColorDepths %s",
supportedColorDepths == 0x0001 ? "RNS_UD_24BPP_SUPPORT" :
supportedColorDepths == 0x0002 ? "RNS_UD_16BPP_SUPPORT" :
supportedColorDepths == 0x0004 ? "RNS_UD_15BPP_SUPPORT" :
supportedColorDepths == 0x0008 ? "RNS_UD_32BPP_SUPPORT" :
supportedColorDepths == RNS_UD_24BPP_SUPPORT
? "RNS_UD_24BPP_SUPPORT" :
supportedColorDepths == RNS_UD_16BPP_SUPPORT
? "RNS_UD_16BPP_SUPPORT" :
supportedColorDepths == RNS_UD_15BPP_SUPPORT
? "RNS_UD_15BPP_SUPPORT" :
supportedColorDepths == RNS_UD_32BPP_SUPPORT
? "RNS_UD_32BPP_SUPPORT" :
"unknown");

if (!s_check_rem(s, 2))
Expand All @@ -2129,11 +2133,20 @@ xrdp_sec_process_mcs_data_CS_CORE(struct xrdp_sec *self, struct stream *s)
LOG_DEVEL(LOG_LEVEL_TRACE, "Received [MS-RDPBCGR] TS_UD_CS_CORE "
"<Optional Field> earlyCapabilityFlags 0x%4.4x",
earlyCapabilityFlags);
if ((earlyCapabilityFlags & 0x0002) && (supportedColorDepths & 0x0008))
if ((earlyCapabilityFlags & RNS_UD_CS_WANT_32BPP_SESSION)
&& (supportedColorDepths & RNS_UD_32BPP_SUPPORT))
{
client_info->bpp = 32;
}

if (earlyCapabilityFlags & RNS_UD_CS_SUPPORT_DYNVC_GFX_PROTOCOL)
{
LOG(LOG_LEVEL_INFO, "client supports gfx protocol");
self->rdp_layer->client_info.gfx = 1;
}
else
{
LOG_DEVEL(LOG_LEVEL_INFO, "client DOES NOT support gfx");
}
if (!s_check_rem(s, 64))
{
return 0;
Expand Down
4 changes: 2 additions & 2 deletions sesman/chansrv/chansrv.c
Original file line number Diff line number Diff line change
Expand Up @@ -1787,7 +1787,7 @@ main(int argc, char **argv)
waiters[1] = g_exec_event;
waiters[2] = g_sigchld_event;

if (g_obj_wait(waiters, 3, 0, 0, 0) != 0)
if (g_obj_wait(waiters, 3, 0, 0, -1) != 0)
{
LOG_DEVEL(LOG_LEVEL_ERROR, "main: error, g_obj_wait failed");
break;
Expand All @@ -1814,7 +1814,7 @@ main(int argc, char **argv)
while (g_thread_done_event > 0 && !g_is_wait_obj_set(g_thread_done_event))
{
/* wait for thread to exit */
if (g_obj_wait(&g_thread_done_event, 1, 0, 0, 0) != 0)
if (g_obj_wait(&g_thread_done_event, 1, 0, 0, -1) != 0)
{
LOG_DEVEL(LOG_LEVEL_ERROR, "main: error, g_obj_wait failed");
break;
Expand Down
2 changes: 1 addition & 1 deletion sesman/sesexec/sesexec.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ sesexec_main_loop(void)
continue;
}

if (g_obj_wait(robjs, robjs_count, NULL, 0, 0) != 0)
if (g_obj_wait(robjs, robjs_count, NULL, 0, -1) != 0)
{
/* should not get here */
LOG(LOG_LEVEL_WARNING, "sesexec_main_loop: "
Expand Down
3 changes: 2 additions & 1 deletion xrdp/xrdp.h
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,8 @@ server_set_pointer_large(struct xrdp_mod *mod, int x, int y,
char *data, char *mask, int bpp,
int width, int height);
int
server_paint_rects_ex(struct xrdp_mod *mod, int num_drects, short *drects,
server_paint_rects_ex(struct xrdp_mod *mod,
int num_drects, short *drects,
int num_crects, short *crects,
char *data, int left, int top,
int width, int height,
Expand Down
Loading