mirror of https://github.com/FreeRDP/FreeRDP
commit
242f7f2313
|
@ -245,7 +245,6 @@ static Pixmap xf_brush_new(xfContext* xfc, UINT32 width, UINT32 height,
|
|||
image->bitmap_bit_order = LSBFirst;
|
||||
gc = XCreateGC(xfc->display, xfc->drawable, 0, NULL);
|
||||
XPutImage(xfc->display, bitmap, gc, image, 0, 0, 0, 0, width, height);
|
||||
|
||||
image->data = NULL;
|
||||
XDestroyImage(image);
|
||||
|
||||
|
@ -577,7 +576,7 @@ static BOOL xf_gdi_invalidate_poly_region(xfContext* xfc, XPoint* points,
|
|||
static BOOL xf_gdi_polyline(rdpContext* context,
|
||||
const POLYLINE_ORDER* polyline)
|
||||
{
|
||||
int i;
|
||||
UINT32 i;
|
||||
int npoints;
|
||||
XColor color;
|
||||
XPoint* points;
|
||||
|
@ -1011,6 +1010,7 @@ static BOOL xf_gdi_update_screen(xfContext* xfc, const BYTE* pSrcData,
|
|||
bpp = 2;
|
||||
else
|
||||
bpp = 1;
|
||||
|
||||
XSetFunction(xfc->display, xfc->gc, GXcopy);
|
||||
XSetFillStyle(xfc->display, xfc->gc, FillSolid);
|
||||
|
||||
|
@ -1021,15 +1021,14 @@ static BOOL xf_gdi_update_screen(xfContext* xfc, const BYTE* pSrcData,
|
|||
UINT32 width = rects[i].right - rects[i].left;
|
||||
UINT32 height = rects[i].bottom - rects[i].top;
|
||||
const BYTE* src = pSrcData + top * scanline + bpp * left;
|
||||
|
||||
image = XCreateImage(xfc->display, xfc->visual, xfc->depth, ZPixmap, 0,
|
||||
(char*) src, width, height, xfc->scanline_pad, scanline);
|
||||
|
||||
if (!image)
|
||||
break;
|
||||
|
||||
image->byte_order = LSBFirst;
|
||||
image->bitmap_bit_order = LSBFirst;
|
||||
|
||||
XPutImage(xfc->display, xfc->primary, xfc->gc, image, 0, 0, left, top, width, height);
|
||||
image->data = NULL;
|
||||
XDestroyImage(image);
|
||||
|
@ -1059,17 +1058,14 @@ static BOOL xf_gdi_surface_bits(rdpContext* context,
|
|||
cmdRect.top = cmd->destTop;
|
||||
cmdRect.right = cmdRect.left + cmd->bmp.width;
|
||||
cmdRect.bottom = cmdRect.top + cmd->bmp.height;
|
||||
|
||||
|
||||
gdi = context->gdi;
|
||||
|
||||
xf_lock_x11(xfc, FALSE);
|
||||
|
||||
switch (cmd->bmp.codecID)
|
||||
{
|
||||
case RDP_CODEC_ID_REMOTEFX:
|
||||
if (!rfx_process_message(context->codecs->rfx, cmd->bmp.bitmapData,
|
||||
cmd->bmp.bitmapDataLength, cmd->destLeft, cmd->destTop,
|
||||
cmd->bmp.bitmapDataLength, cmd->destLeft, cmd->destTop,
|
||||
gdi->primary_buffer, gdi->dstFormat, gdi->stride,
|
||||
gdi->height, ®ion))
|
||||
goto fail;
|
||||
|
@ -1078,9 +1074,9 @@ static BOOL xf_gdi_surface_bits(rdpContext* context,
|
|||
|
||||
case RDP_CODEC_ID_NSCODEC:
|
||||
if (!nsc_process_message(context->codecs->nsc, cmd->bmp.bpp, cmd->bmp.width,
|
||||
cmd->bmp.height, cmd->bmp.bitmapData, cmd->bmp.bitmapDataLength,
|
||||
cmd->bmp.height, cmd->bmp.bitmapData, cmd->bmp.bitmapDataLength,
|
||||
gdi->primary_buffer, gdi->dstFormat, gdi->stride,
|
||||
0, 0, cmd->bmp.width, cmd->bmp.height, FREERDP_FLIP_VERTICAL))
|
||||
0, 0, cmd->bmp.width, cmd->bmp.height, FREERDP_FLIP_VERTICAL))
|
||||
goto fail;
|
||||
|
||||
region16_union_rect(®ion, ®ion, &cmdRect);
|
||||
|
@ -1091,7 +1087,7 @@ static BOOL xf_gdi_surface_bits(rdpContext* context,
|
|||
format = gdi_get_pixel_format(cmd->bmp.bpp);
|
||||
|
||||
if (!freerdp_image_copy(gdi->primary_buffer, gdi->dstFormat, gdi->stride,
|
||||
cmd->destLeft, cmd->destTop, cmd->bmp.width, cmd->bmp.height,
|
||||
cmd->destLeft, cmd->destTop, cmd->bmp.width, cmd->bmp.height,
|
||||
pSrcData, format, 0, 0, 0,
|
||||
&xfc->context.gdi->palette, FREERDP_FLIP_VERTICAL))
|
||||
goto fail;
|
||||
|
|
|
@ -160,7 +160,7 @@ void xf_keyboard_key_release(xfContext* xfc, BYTE keycode, KeySym keysym)
|
|||
|
||||
void xf_keyboard_release_all_keypress(xfContext* xfc)
|
||||
{
|
||||
int keycode;
|
||||
size_t keycode;
|
||||
DWORD rdp_scancode;
|
||||
|
||||
for (keycode = 0; keycode < ARRAYSIZE(xfc->KeyboardState); keycode++)
|
||||
|
|
|
@ -136,7 +136,7 @@ static BOOL xf_is_monitor_id_active(xfContext* xfc, UINT32 id)
|
|||
|
||||
BOOL xf_detect_monitors(xfContext* xfc, UINT32* pMaxWidth, UINT32* pMaxHeight)
|
||||
{
|
||||
int i;
|
||||
UINT32 i;
|
||||
int nmonitors = 0;
|
||||
int monitor_index = 0;
|
||||
BOOL primaryMonitorFound = FALSE;
|
||||
|
|
|
@ -153,7 +153,7 @@ void xf_SetWindowMinimized(xfContext* xfc, xfWindow* window)
|
|||
|
||||
void xf_SetWindowFullscreen(xfContext* xfc, xfWindow* window, BOOL fullscreen)
|
||||
{
|
||||
int i;
|
||||
UINT32 i;
|
||||
rdpSettings* settings = xfc->context.settings;
|
||||
int startX, startY;
|
||||
UINT32 width = window->width;
|
||||
|
|
|
@ -937,7 +937,7 @@ struct rdp_settings
|
|||
UINT64 padding0384[384 - 323]; /* 323 */
|
||||
|
||||
/* Client Monitor Data */
|
||||
ALIGN64 int MonitorCount; /* 384 */
|
||||
ALIGN64 UINT32 MonitorCount; /* 384 */
|
||||
ALIGN64 UINT32 MonitorDefArraySize; /* 385 */
|
||||
ALIGN64 rdpMonitor* MonitorDefArray; /* 386 */
|
||||
ALIGN64 BOOL SpanMonitors; /* 387 */
|
||||
|
|
|
@ -812,7 +812,7 @@ HttpResponse* http_response_recv(rdpTls* tls)
|
|||
count = 0;
|
||||
line = strtok(buffer, "\r\n");
|
||||
|
||||
while (line && response->lines)
|
||||
while (line && (response->count > count))
|
||||
{
|
||||
response->lines[count] = line;
|
||||
|
||||
|
|
|
@ -1671,7 +1671,7 @@ BOOL gcc_read_client_cluster_data(wStream* s, rdpMcs* mcs, UINT16 blockLength)
|
|||
|
||||
if (blockLength != 8)
|
||||
{
|
||||
if (Stream_GetRemainingLength(s) >= (blockLength - 8))
|
||||
if (Stream_GetRemainingLength(s) >= (size_t)(blockLength - 8))
|
||||
{
|
||||
/* The old Microsoft Mac RDP client can send a pad here */
|
||||
Stream_Seek(s, (blockLength - 8));
|
||||
|
@ -1740,7 +1740,7 @@ BOOL gcc_read_client_monitor_data(wStream* s, rdpMcs* mcs, UINT16 blockLength)
|
|||
monitorCount = settings->MonitorDefArraySize;
|
||||
}
|
||||
|
||||
if (((blockLength - 8) / 20) < monitorCount)
|
||||
if ((UINT32)((blockLength - 8) / 20) < monitorCount)
|
||||
return FALSE;
|
||||
|
||||
settings->MonitorCount = monitorCount;
|
||||
|
|
|
@ -1578,7 +1578,7 @@ static BOOL update_message_process_update_class(rdpUpdateProxy* proxy, wMessage*
|
|||
BOOL rc = FALSE;
|
||||
|
||||
if (!proxy || !msg)
|
||||
return -1;
|
||||
return FALSE;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
|
|
|
@ -313,7 +313,7 @@ fail:
|
|||
|
||||
const char* freerdp_keyboard_get_layout_name_from_id(DWORD keyboardLayoutID)
|
||||
{
|
||||
int i;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < ARRAYSIZE(RDP_KEYBOARD_LAYOUT_TABLE); i++)
|
||||
{
|
||||
|
@ -338,7 +338,7 @@ const char* freerdp_keyboard_get_layout_name_from_id(DWORD keyboardLayoutID)
|
|||
|
||||
DWORD freerdp_keyboard_get_layout_id_from_name(const char* name)
|
||||
{
|
||||
int i;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < ARRAYSIZE(RDP_KEYBOARD_LAYOUT_TABLE); i++)
|
||||
{
|
||||
|
|
|
@ -419,7 +419,7 @@ int detect_keyboard_layout_from_xkbfile(void* display, DWORD* keyboardLayoutId)
|
|||
|
||||
int freerdp_keyboard_load_map_from_xkbfile(void* display, DWORD x11_keycode_to_rdp_scancode[256])
|
||||
{
|
||||
int i, j;
|
||||
size_t i, j;
|
||||
BOOL found;
|
||||
XkbDescPtr xkb;
|
||||
BOOL status = FALSE;
|
||||
|
|
|
@ -631,14 +631,13 @@ static const LOCALE_KEYBOARD_LAYOUTS LOCALE_KEYBOARD_LAYOUTS_TABLE[] =
|
|||
{ XHOSA, { 0x00000409, 0x00000409, 0x0, 0x0, 0x0 } },
|
||||
};
|
||||
|
||||
BOOL freerdp_get_system_language_and_country_codes(char* language, char* country)
|
||||
static BOOL freerdp_get_system_language_and_country_codes(char* language, char* country)
|
||||
{
|
||||
int dot;
|
||||
DWORD nSize;
|
||||
int underscore;
|
||||
char* env_lang = NULL;
|
||||
LPCSTR lang = "LANG";
|
||||
|
||||
/* LANG = <language>_<country>.<encoding> */
|
||||
nSize = GetEnvironmentVariableA(lang, NULL, 0);
|
||||
|
||||
|
@ -650,9 +649,10 @@ BOOL freerdp_get_system_language_and_country_codes(char* language, char* country
|
|||
if (!env_lang)
|
||||
return FALSE;
|
||||
|
||||
if (GetEnvironmentVariableA(lang, env_lang, nSize) != nSize - 1) /* Get locale from environment variable LANG */
|
||||
if (GetEnvironmentVariableA(lang, env_lang,
|
||||
nSize) != nSize - 1) /* Get locale from environment variable LANG */
|
||||
{
|
||||
free (env_lang);
|
||||
free(env_lang);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
@ -688,18 +688,18 @@ BOOL freerdp_get_system_language_and_country_codes(char* language, char* country
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
SYSTEM_LOCALE* freerdp_detect_system_locale()
|
||||
static SYSTEM_LOCALE* freerdp_detect_system_locale(void)
|
||||
{
|
||||
int i;
|
||||
size_t i;
|
||||
char language[4];
|
||||
char country[10];
|
||||
SYSTEM_LOCALE* locale = NULL;
|
||||
|
||||
freerdp_get_system_language_and_country_codes(language, country);
|
||||
|
||||
for (i = 0; i < ARRAYSIZE(SYSTEM_LOCALE_TABLE); i++)
|
||||
{
|
||||
if ((strcmp(language, SYSTEM_LOCALE_TABLE[i].language) == 0) && (strcmp(country, SYSTEM_LOCALE_TABLE[i].country) == 0))
|
||||
if ((strcmp(language, SYSTEM_LOCALE_TABLE[i].language) == 0) &&
|
||||
(strcmp(country, SYSTEM_LOCALE_TABLE[i].country) == 0))
|
||||
{
|
||||
locale = (SYSTEM_LOCALE*) &SYSTEM_LOCALE_TABLE[i];
|
||||
break;
|
||||
|
@ -709,10 +709,9 @@ SYSTEM_LOCALE* freerdp_detect_system_locale()
|
|||
return locale;
|
||||
}
|
||||
|
||||
DWORD freerdp_get_system_locale_id()
|
||||
DWORD freerdp_get_system_locale_id(void)
|
||||
{
|
||||
SYSTEM_LOCALE* locale;
|
||||
|
||||
locale = freerdp_detect_system_locale();
|
||||
|
||||
if (locale != NULL)
|
||||
|
@ -723,7 +722,7 @@ DWORD freerdp_get_system_locale_id()
|
|||
|
||||
const char* freerdp_get_system_locale_name_from_id(DWORD localeId)
|
||||
{
|
||||
int index;
|
||||
size_t index;
|
||||
|
||||
for (index = 0; index < ARRAYSIZE(LOCALE_NAME_TABLE); index++)
|
||||
{
|
||||
|
@ -736,11 +735,10 @@ const char* freerdp_get_system_locale_name_from_id(DWORD localeId)
|
|||
|
||||
int freerdp_detect_keyboard_layout_from_system_locale(DWORD* keyboardLayoutId)
|
||||
{
|
||||
int i, j;
|
||||
size_t i, j;
|
||||
char language[4];
|
||||
char country[10];
|
||||
SYSTEM_LOCALE* locale;
|
||||
|
||||
freerdp_get_system_language_and_country_codes(language, country);
|
||||
|
||||
if ((strcmp(language, "C") == 0) || (strcmp(language, "POSIX") == 0))
|
||||
|
@ -761,7 +759,6 @@ int freerdp_detect_keyboard_layout_from_system_locale(DWORD* keyboardLayoutId)
|
|||
if (LOCALE_KEYBOARD_LAYOUTS_TABLE[i].locale == locale->code)
|
||||
{
|
||||
/* Locale found in list of default keyboard layouts */
|
||||
|
||||
for (j = 0; j < 5; j++)
|
||||
{
|
||||
if (LOCALE_KEYBOARD_LAYOUTS_TABLE[i].keyboardLayouts[j] == ENGLISH_UNITED_STATES)
|
||||
|
|
|
@ -105,7 +105,7 @@ const int fatal_signals[] =
|
|||
|
||||
int freerdp_handle_signals(void)
|
||||
{
|
||||
int signal_index;
|
||||
size_t signal_index;
|
||||
sigset_t orig_set;
|
||||
struct sigaction orig_sigaction;
|
||||
struct sigaction fatal_sigaction;
|
||||
|
|
|
@ -1295,7 +1295,7 @@ static BOOL shadow_client_send_surface_update(rdpShadowClient* client,
|
|||
const RECTANGLE_16* extents;
|
||||
BYTE* pSrcData;
|
||||
int nSrcStep;
|
||||
int index;
|
||||
UINT32 index;
|
||||
UINT32 numRects = 0;
|
||||
const RECTANGLE_16* rects;
|
||||
|
||||
|
|
|
@ -579,11 +579,7 @@ typedef struct _wEventType wEventType;
|
|||
DEFINE_EVENT_UNSUBSCRIBE(_name)
|
||||
|
||||
#define DEFINE_EVENT_ENTRY(_name) \
|
||||
{ #_name, { sizeof( _name ## EventArgs) }, 0, { \
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, \
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, \
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, \
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL } },
|
||||
{ #_name, { sizeof( _name ## EventArgs), NULL }, 0, { NULL } },
|
||||
|
||||
struct _wPubSub
|
||||
{
|
||||
|
|
|
@ -29,101 +29,101 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
#define Data_Read_UINT8_NE(_d, _v) do { _v = \
|
||||
*((BYTE*) _d); } while (0)
|
||||
*((const BYTE*) _d); } while (0)
|
||||
|
||||
#define Data_Read_UINT8(_d, _v) do { _v = \
|
||||
*((BYTE*) _d); } while (0)
|
||||
*((const BYTE*) _d); } while (0)
|
||||
|
||||
#define Data_Read_UINT16_NE(_d, _v) do { _v = \
|
||||
*((UINT16*) _d); } while (0)
|
||||
*((const UINT16*) _d); } while (0)
|
||||
|
||||
#define Data_Read_UINT16(_d, _v) do { _v = \
|
||||
(UINT16)(*((BYTE*) _d)) + \
|
||||
(((UINT16)(*((BYTE*) _d + 1))) << 8); \
|
||||
} while (0)
|
||||
(UINT16)(*((const BYTE*) _d)) + \
|
||||
(UINT16)(((UINT16)(*((const BYTE*) _d + 1))) << 8); \
|
||||
} while (0)
|
||||
|
||||
#define Data_Read_UINT16_BE(_d, _v) do { _v = \
|
||||
(((UINT16)(*(BYTE*) _d)) << 8) + \
|
||||
(UINT16)(*((BYTE*) _d + 1)); \
|
||||
} while (0)
|
||||
(((UINT16)(*(const BYTE*) _d)) << 8) + \
|
||||
(UINT16)(*((const BYTE*) _d + 1)); \
|
||||
} while (0)
|
||||
|
||||
#define Data_Read_UINT32_NE(_d, _v) do { _v = \
|
||||
*((UINT32*) _d); } while (0)
|
||||
*((UINT32*) _d); } while (0)
|
||||
|
||||
#define Data_Read_UINT32(_d, _v) do { _v = \
|
||||
(UINT32)(*((BYTE*) _d)) + \
|
||||
(((UINT32)(*((BYTE*) _d + 1))) << 8) + \
|
||||
(((UINT32)(*((BYTE*) _d + 2))) << 16) + \
|
||||
(((UINT32)(*((BYTE*) _d + 3))) << 24); \
|
||||
} while (0)
|
||||
(UINT32)(*((const BYTE*) _d)) + \
|
||||
(((UINT32)(*((const BYTE*) _d + 1))) << 8) + \
|
||||
(((UINT32)(*((const BYTE*) _d + 2))) << 16) + \
|
||||
(((UINT32)(*((const BYTE*) _d + 3))) << 24); \
|
||||
} while (0)
|
||||
|
||||
#define Data_Read_UINT32_BE(_d, _v) do { _v = \
|
||||
(((UINT32)(*((BYTE*) _d))) << 24) + \
|
||||
(((UINT32)(*((BYTE*) _d + 1))) << 16) + \
|
||||
(((UINT32)(*((BYTE*) _d + 2))) << 8) + \
|
||||
(((UINT32)(*((BYTE*) _d + 3)))); \
|
||||
} while (0)
|
||||
(((UINT32)(*((const BYTE*) _d))) << 24) + \
|
||||
(((UINT32)(*((const BYTE*) _d + 1))) << 16) + \
|
||||
(((UINT32)(*((const BYTE*) _d + 2))) << 8) + \
|
||||
(((UINT32)(*((const BYTE*) _d + 3)))); \
|
||||
} while (0)
|
||||
|
||||
#define Data_Read_UINT64_NE(_d, _v) do { _v = \
|
||||
*((UINT64*) _d); } while (0)
|
||||
*((UINT64*) _d); } while (0)
|
||||
|
||||
#define Data_Read_UINT64(_d, _v) do { _v = \
|
||||
(UINT64)(*((BYTE*) _d)) + \
|
||||
(((UINT64)(*((BYTE*) _d + 1))) << 8) + \
|
||||
(((UINT64)(*((BYTE*) _d + 2))) << 16) + \
|
||||
(((UINT64)(*((BYTE*) _d + 3))) << 24) + \
|
||||
(((UINT64)(*((BYTE*) _d + 4))) << 32) + \
|
||||
(((UINT64)(*((BYTE*) _d + 5))) << 40) + \
|
||||
(((UINT64)(*((BYTE*) _d + 6))) << 48) + \
|
||||
(((UINT64)(*((BYTE*) _d + 7))) << 56); \
|
||||
} while (0)
|
||||
(UINT64)(*((const BYTE*) _d)) + \
|
||||
(((UINT64)(*((const BYTE*) _d + 1))) << 8) + \
|
||||
(((UINT64)(*((const BYTE*) _d + 2))) << 16) + \
|
||||
(((UINT64)(*((const BYTE*) _d + 3))) << 24) + \
|
||||
(((UINT64)(*((const BYTE*) _d + 4))) << 32) + \
|
||||
(((UINT64)(*((const BYTE*) _d + 5))) << 40) + \
|
||||
(((UINT64)(*((const BYTE*) _d + 6))) << 48) + \
|
||||
(((UINT64)(*((const BYTE*) _d + 7))) << 56); \
|
||||
} while (0)
|
||||
|
||||
#define Data_Write_UINT8_NE(_d, _v) do { \
|
||||
*((UINT8*) _d) = v; } while (0)
|
||||
*((UINT8*) _d) = v; } while (0)
|
||||
|
||||
#define Data_Write_UINT8(_d, _v) do { \
|
||||
*_d = (UINT8)(_v); } while (0)
|
||||
*_d = (UINT8)(_v); } while (0)
|
||||
|
||||
#define Data_Write_UINT16_NE(_d, _v) do { \
|
||||
*((UINT16*) _d) = _v; } while (0)
|
||||
*((UINT16*) _d) = _v; } while (0)
|
||||
|
||||
#define Data_Write_UINT16(_d, _v) do { \
|
||||
*((BYTE*) _d) = (_v) & 0xFF; \
|
||||
*((BYTE*) _d + 1) = ((_v) >> 8) & 0xFF; \
|
||||
*((BYTE*) _d) = (_v) & 0xFF; \
|
||||
*((BYTE*) _d + 1) = ((_v) >> 8) & 0xFF; \
|
||||
} while (0)
|
||||
|
||||
#define Data_Write_UINT16_BE(_d, _v) do { \
|
||||
*((BYTE*) _d) = ((_v) >> 8) & 0xFF; \
|
||||
*((BYTE*) _d + 1) = (_v) & 0xFF; \
|
||||
*((BYTE*) _d) = ((_v) >> 8) & 0xFF; \
|
||||
*((BYTE*) _d + 1) = (_v) & 0xFF; \
|
||||
} while (0)
|
||||
|
||||
#define Data_Write_UINT32_NE(_d, _v) do { \
|
||||
*((UINT32*) _d) = _v; } while (0)
|
||||
*((UINT32*) _d) = _v; } while (0)
|
||||
|
||||
#define Data_Write_UINT32(_d, _v) do { \
|
||||
*((BYTE*) _d) = (_v) & 0xFF; \
|
||||
*((BYTE*) _d + 1) = ((_v) >> 8) & 0xFF; \
|
||||
*((BYTE*) _d + 2) = ((_v) >> 16) & 0xFF; \
|
||||
*((BYTE*) _d + 3) = ((_v) >> 24) & 0xFF; \
|
||||
*((BYTE*) _d) = (_v) & 0xFF; \
|
||||
*((BYTE*) _d + 1) = ((_v) >> 8) & 0xFF; \
|
||||
*((BYTE*) _d + 2) = ((_v) >> 16) & 0xFF; \
|
||||
*((BYTE*) _d + 3) = ((_v) >> 24) & 0xFF; \
|
||||
} while (0)
|
||||
|
||||
#define Data_Write_UINT32_BE(_d, _v) do { \
|
||||
Data_Write_UINT16_BE((BYTE*) _d, ((_v) >> 16 & 0xFFFF)); \
|
||||
Data_Write_UINT16_BE((BYTE*) _d + 2, ((_v) & 0xFFFF)); \
|
||||
Data_Write_UINT16_BE((BYTE*) _d, ((_v) >> 16 & 0xFFFF)); \
|
||||
Data_Write_UINT16_BE((BYTE*) _d + 2, ((_v) & 0xFFFF)); \
|
||||
} while (0)
|
||||
|
||||
#define Data_Write_UINT64_NE(_d, _v) do { \
|
||||
*((UINT64*) _d) = _v; } while (0)
|
||||
*((UINT64*) _d) = _v; } while (0)
|
||||
|
||||
#define Data_Write_UINT64(_d, _v) do { \
|
||||
*((BYTE*) _d) = (UINT64)(_v) & 0xFF; \
|
||||
*((BYTE*) _d + 1) = ((UINT64)(_v) >> 8) & 0xFF; \
|
||||
*((BYTE*) _d + 2) = ((UINT64)(_v) >> 16) & 0xFF; \
|
||||
*((BYTE*) _d + 3) = ((UINT64)(_v) >> 24) & 0xFF; \
|
||||
*((BYTE*) _d + 4) = ((UINT64)(_v) >> 32) & 0xFF; \
|
||||
*((BYTE*) _d + 5) = ((UINT64)(_v) >> 40) & 0xFF; \
|
||||
*((BYTE*) _d + 6) = ((UINT64)(_v) >> 48) & 0xFF; \
|
||||
*((BYTE*) _d + 7) = ((UINT64)(_v) >> 56) & 0xFF; \
|
||||
*((BYTE*) _d) = (UINT64)(_v) & 0xFF; \
|
||||
*((BYTE*) _d + 1) = ((UINT64)(_v) >> 8) & 0xFF; \
|
||||
*((BYTE*) _d + 2) = ((UINT64)(_v) >> 16) & 0xFF; \
|
||||
*((BYTE*) _d + 3) = ((UINT64)(_v) >> 24) & 0xFF; \
|
||||
*((BYTE*) _d + 4) = ((UINT64)(_v) >> 32) & 0xFF; \
|
||||
*((BYTE*) _d + 5) = ((UINT64)(_v) >> 40) & 0xFF; \
|
||||
*((BYTE*) _d + 6) = ((UINT64)(_v) >> 48) & 0xFF; \
|
||||
*((BYTE*) _d + 7) = ((UINT64)(_v) >> 56) & 0xFF; \
|
||||
} while (0)
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -129,7 +129,7 @@ static BOOL CommInitialized()
|
|||
}
|
||||
|
||||
|
||||
void CommLog_Print(int level, ...)
|
||||
void CommLog_Print(DWORD level, ...)
|
||||
{
|
||||
if (!CommInitialized())
|
||||
return;
|
||||
|
@ -1204,7 +1204,23 @@ static HANDLE_OPS ops =
|
|||
CommIsHandled,
|
||||
CommCloseHandle,
|
||||
CommGetFd,
|
||||
NULL /* CleanupHandle */
|
||||
NULL, /* CleanupHandle */
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -95,7 +95,7 @@ typedef struct winpr_comm WINPR_COMM;
|
|||
#define FREERDP_PURGE_RXABORT 0x00000002 /* abort pending reception */
|
||||
|
||||
|
||||
void CommLog_Print(int wlog_level, ...);
|
||||
void CommLog_Print(DWORD wlog_level, ...);
|
||||
|
||||
BOOL CommIsHandled(HANDLE handle);
|
||||
BOOL CommCloseHandle(HANDLE handle);
|
||||
|
|
|
@ -56,11 +56,28 @@ static int NoneHandleGetFd(HANDLE handle)
|
|||
return -1;
|
||||
}
|
||||
|
||||
static HANDLE_OPS ops = {
|
||||
NoneHandleIsHandle,
|
||||
NoneHandleCloseHandle,
|
||||
NoneHandleGetFd,
|
||||
NULL /* CleanupHandle */
|
||||
static HANDLE_OPS ops =
|
||||
{
|
||||
NoneHandleIsHandle,
|
||||
NoneHandleCloseHandle,
|
||||
NoneHandleGetFd,
|
||||
NULL, /* CleanupHandle */
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
HANDLE CreateNoneHandle()
|
||||
|
@ -72,7 +89,6 @@ HANDLE CreateNoneHandle()
|
|||
return NULL;
|
||||
|
||||
none->ops = &ops;
|
||||
|
||||
return (HANDLE)none;
|
||||
}
|
||||
|
||||
|
|
|
@ -218,7 +218,7 @@ DWORD GetModuleFileNameA(HMODULE hModule, LPSTR lpFilename, DWORD nSize)
|
|||
{
|
||||
#if defined(__linux__)
|
||||
int status;
|
||||
int length;
|
||||
size_t length;
|
||||
char path[64];
|
||||
|
||||
if (!hModule)
|
||||
|
|
|
@ -457,7 +457,19 @@ static HANDLE_OPS namedOps =
|
|||
NamedPipeRead,
|
||||
NULL,
|
||||
NULL,
|
||||
NamedPipeWrite
|
||||
NamedPipeWrite,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
static BOOL InitWinPRPipeModule()
|
||||
|
|
|
@ -1150,7 +1150,7 @@ WINSCARDAPI LONG WINAPI PCSC_SCardLocateCardsByATRW(SCARDCONTEXT hContext,
|
|||
WINSCARDAPI LONG WINAPI PCSC_SCardGetStatusChange_Internal(SCARDCONTEXT hContext,
|
||||
DWORD dwTimeout, LPSCARD_READERSTATEA rgReaderStates, DWORD cReaders)
|
||||
{
|
||||
int i, j;
|
||||
PCSC_DWORD i, j;
|
||||
int* map;
|
||||
PCSC_DWORD cMappedReaders;
|
||||
PCSC_SCARD_READERSTATE* states;
|
||||
|
|
|
@ -86,19 +86,19 @@ static BOOL LogonUserIsHandled(HANDLE handle)
|
|||
|
||||
static int LogonUserGetFd(HANDLE handle)
|
||||
{
|
||||
WINPR_ACCESS_TOKEN *pLogonUser = (WINPR_ACCESS_TOKEN *)handle;
|
||||
WINPR_ACCESS_TOKEN* pLogonUser = (WINPR_ACCESS_TOKEN*)handle;
|
||||
|
||||
if (!LogonUserIsHandled(handle))
|
||||
return -1;
|
||||
|
||||
/* TODO: File fd not supported */
|
||||
(void)pLogonUser;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
BOOL LogonUserCloseHandle(HANDLE handle) {
|
||||
WINPR_ACCESS_TOKEN *token = (WINPR_ACCESS_TOKEN *) handle;
|
||||
BOOL LogonUserCloseHandle(HANDLE handle)
|
||||
{
|
||||
WINPR_ACCESS_TOKEN* token = (WINPR_ACCESS_TOKEN*) handle;
|
||||
|
||||
if (!handle || !LogonUserIsHandled(handle))
|
||||
return FALSE;
|
||||
|
@ -106,19 +106,35 @@ BOOL LogonUserCloseHandle(HANDLE handle) {
|
|||
free(token->Username);
|
||||
free(token->Domain);
|
||||
free(token);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static HANDLE_OPS ops = {
|
||||
LogonUserIsHandled,
|
||||
LogonUserCloseHandle,
|
||||
LogonUserGetFd,
|
||||
NULL /* CleanupHandle */
|
||||
static HANDLE_OPS ops =
|
||||
{
|
||||
LogonUserIsHandled,
|
||||
LogonUserCloseHandle,
|
||||
LogonUserGetFd,
|
||||
NULL, /* CleanupHandle */
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
BOOL LogonUserA(LPCSTR lpszUsername, LPCSTR lpszDomain, LPCSTR lpszPassword,
|
||||
DWORD dwLogonType, DWORD dwLogonProvider, PHANDLE phToken)
|
||||
DWORD dwLogonType, DWORD dwLogonProvider, PHANDLE phToken)
|
||||
{
|
||||
struct passwd* pw;
|
||||
WINPR_ACCESS_TOKEN* token;
|
||||
|
@ -132,10 +148,9 @@ BOOL LogonUserA(LPCSTR lpszUsername, LPCSTR lpszDomain, LPCSTR lpszPassword,
|
|||
return FALSE;
|
||||
|
||||
WINPR_HANDLE_SET_TYPE_AND_MODE(token, HANDLE_TYPE_ACCESS_TOKEN, WINPR_FD_READ);
|
||||
|
||||
token->ops = &ops;
|
||||
|
||||
token->Username = _strdup(lpszUsername);
|
||||
|
||||
if (!token->Username)
|
||||
{
|
||||
free(token);
|
||||
|
@ -145,6 +160,7 @@ BOOL LogonUserA(LPCSTR lpszUsername, LPCSTR lpszDomain, LPCSTR lpszPassword,
|
|||
if (lpszDomain)
|
||||
{
|
||||
token->Domain = _strdup(lpszDomain);
|
||||
|
||||
if (!token->Domain)
|
||||
{
|
||||
free(token->Username);
|
||||
|
@ -162,26 +178,25 @@ BOOL LogonUserA(LPCSTR lpszUsername, LPCSTR lpszDomain, LPCSTR lpszPassword,
|
|||
}
|
||||
|
||||
*((ULONG_PTR*) phToken) = (ULONG_PTR) token;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL LogonUserW(LPCWSTR lpszUsername, LPCWSTR lpszDomain, LPCWSTR lpszPassword,
|
||||
DWORD dwLogonType, DWORD dwLogonProvider, PHANDLE phToken)
|
||||
DWORD dwLogonType, DWORD dwLogonProvider, PHANDLE phToken)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL LogonUserExA(LPCSTR lpszUsername, LPCSTR lpszDomain, LPCSTR lpszPassword,
|
||||
DWORD dwLogonType, DWORD dwLogonProvider, PHANDLE phToken, PSID* ppLogonSid,
|
||||
PVOID* ppProfileBuffer, LPDWORD pdwProfileLength, PQUOTA_LIMITS pQuotaLimits)
|
||||
DWORD dwLogonType, DWORD dwLogonProvider, PHANDLE phToken, PSID* ppLogonSid,
|
||||
PVOID* ppProfileBuffer, LPDWORD pdwProfileLength, PQUOTA_LIMITS pQuotaLimits)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL LogonUserExW(LPCWSTR lpszUsername, LPCWSTR lpszDomain, LPCWSTR lpszPassword,
|
||||
DWORD dwLogonType, DWORD dwLogonProvider, PHANDLE phToken, PSID* ppLogonSid,
|
||||
PVOID* ppProfileBuffer, LPDWORD pdwProfileLength, PQUOTA_LIMITS pQuotaLimits)
|
||||
DWORD dwLogonType, DWORD dwLogonProvider, PHANDLE phToken, PSID* ppLogonSid,
|
||||
PVOID* ppProfileBuffer, LPDWORD pdwProfileLength, PQUOTA_LIMITS pQuotaLimits)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -194,7 +209,6 @@ BOOL GetUserNameExA(EXTENDED_NAME_FORMAT NameFormat, LPSTR lpNameBuffer, PULONG
|
|||
switch (NameFormat)
|
||||
{
|
||||
case NameSamCompatible:
|
||||
|
||||
login = getlogin();
|
||||
length = strlen(login);
|
||||
|
||||
|
|
|
@ -105,7 +105,23 @@ static HANDLE_OPS ops =
|
|||
EventIsHandled,
|
||||
EventCloseHandle,
|
||||
EventGetFd,
|
||||
NULL /* CleanupHandle */
|
||||
NULL, /* CleanupHandle */
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
HANDLE CreateEventW(LPSECURITY_ATTRIBUTES lpEventAttributes, BOOL bManualReset, BOOL bInitialState,
|
||||
|
|
|
@ -53,7 +53,8 @@ static BOOL MutexIsHandled(HANDLE handle)
|
|||
|
||||
static int MutexGetFd(HANDLE handle)
|
||||
{
|
||||
WINPR_MUTEX *mux = (WINPR_MUTEX *)handle;
|
||||
WINPR_MUTEX* mux = (WINPR_MUTEX*)handle;
|
||||
|
||||
if (!MutexIsHandled(handle))
|
||||
return -1;
|
||||
|
||||
|
@ -77,17 +78,18 @@ BOOL MutexCloseHandle(HANDLE handle)
|
|||
{
|
||||
size_t used = 0, i;
|
||||
void* stack = winpr_backtrace(20);
|
||||
char **msg = NULL;
|
||||
char** msg = NULL;
|
||||
|
||||
if (stack)
|
||||
msg = winpr_backtrace_symbols(stack, &used);
|
||||
|
||||
if (msg)
|
||||
{
|
||||
for(i=0; i<used; i++)
|
||||
for (i = 0; i < used; i++)
|
||||
WLog_ERR(TAG, "%2"PRIdz": %s", i, msg[i]);
|
||||
}
|
||||
free (msg);
|
||||
|
||||
free(msg);
|
||||
winpr_backtrace_free(stack);
|
||||
}
|
||||
#endif
|
||||
|
@ -98,7 +100,6 @@ BOOL MutexCloseHandle(HANDLE handle)
|
|||
}
|
||||
|
||||
free(handle);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -107,14 +108,29 @@ static HANDLE_OPS ops =
|
|||
MutexIsHandled,
|
||||
MutexCloseHandle,
|
||||
MutexGetFd,
|
||||
NULL /* CleanupHandle */
|
||||
NULL, /* CleanupHandle */
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
HANDLE CreateMutexW(LPSECURITY_ATTRIBUTES lpMutexAttributes, BOOL bInitialOwner, LPCWSTR lpName)
|
||||
{
|
||||
HANDLE handle = NULL;
|
||||
WINPR_MUTEX* mutex;
|
||||
|
||||
mutex = (WINPR_MUTEX*) calloc(1, sizeof(WINPR_MUTEX));
|
||||
|
||||
if (mutex)
|
||||
|
@ -123,10 +139,8 @@ HANDLE CreateMutexW(LPSECURITY_ATTRIBUTES lpMutexAttributes, BOOL bInitialOwner,
|
|||
pthread_mutexattr_init(&attr);
|
||||
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
|
||||
pthread_mutex_init(&mutex->mutex, &attr);
|
||||
|
||||
WINPR_HANDLE_SET_TYPE_AND_MODE(mutex, HANDLE_TYPE_MUTEX, WINPR_FD_READ);
|
||||
mutex->ops = &ops;
|
||||
|
||||
handle = (HANDLE) mutex;
|
||||
|
||||
if (bInitialOwner)
|
||||
|
@ -141,22 +155,24 @@ HANDLE CreateMutexA(LPSECURITY_ATTRIBUTES lpMutexAttributes, BOOL bInitialOwner,
|
|||
return CreateMutexW(lpMutexAttributes, bInitialOwner, NULL);
|
||||
}
|
||||
|
||||
HANDLE CreateMutexExA(LPSECURITY_ATTRIBUTES lpMutexAttributes, LPCTSTR lpName, DWORD dwFlags, DWORD dwDesiredAccess)
|
||||
HANDLE CreateMutexExA(LPSECURITY_ATTRIBUTES lpMutexAttributes, LPCTSTR lpName, DWORD dwFlags,
|
||||
DWORD dwDesiredAccess)
|
||||
{
|
||||
return CreateMutexW(lpMutexAttributes, FALSE, NULL);
|
||||
}
|
||||
|
||||
HANDLE CreateMutexExW(LPSECURITY_ATTRIBUTES lpMutexAttributes, LPCWSTR lpName, DWORD dwFlags, DWORD dwDesiredAccess)
|
||||
HANDLE CreateMutexExW(LPSECURITY_ATTRIBUTES lpMutexAttributes, LPCWSTR lpName, DWORD dwFlags,
|
||||
DWORD dwDesiredAccess)
|
||||
{
|
||||
return CreateMutexW(lpMutexAttributes, FALSE, NULL);
|
||||
}
|
||||
|
||||
HANDLE OpenMutexA(DWORD dwDesiredAccess, BOOL bInheritHandle,LPCSTR lpName)
|
||||
HANDLE OpenMutexA(DWORD dwDesiredAccess, BOOL bInheritHandle, LPCSTR lpName)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
HANDLE OpenMutexW(DWORD dwDesiredAccess, BOOL bInheritHandle,LPCWSTR lpName)
|
||||
HANDLE OpenMutexW(DWORD dwDesiredAccess, BOOL bInheritHandle, LPCWSTR lpName)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
@ -173,11 +189,13 @@ BOOL ReleaseMutex(HANDLE hMutex)
|
|||
{
|
||||
WINPR_MUTEX* mutex = (WINPR_MUTEX*) Object;
|
||||
int rc = pthread_mutex_unlock(&mutex->mutex);
|
||||
|
||||
if (rc)
|
||||
{
|
||||
WLog_ERR(TAG, "pthread_mutex_unlock failed with %s [%d]", strerror(rc), rc);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ static BOOL SemaphoreIsHandled(HANDLE handle)
|
|||
|
||||
static int SemaphoreGetFd(HANDLE handle)
|
||||
{
|
||||
WINPR_SEMAPHORE *sem = (WINPR_SEMAPHORE *)handle;
|
||||
WINPR_SEMAPHORE* sem = (WINPR_SEMAPHORE*)handle;
|
||||
|
||||
if (!SemaphoreIsHandled(handle))
|
||||
return -1;
|
||||
|
@ -64,7 +64,7 @@ static int SemaphoreGetFd(HANDLE handle)
|
|||
static DWORD SemaphoreCleanupHandle(HANDLE handle)
|
||||
{
|
||||
int length;
|
||||
WINPR_SEMAPHORE *sem = (WINPR_SEMAPHORE *)handle;
|
||||
WINPR_SEMAPHORE* sem = (WINPR_SEMAPHORE*)handle;
|
||||
|
||||
if (!SemaphoreIsHandled(handle))
|
||||
return WAIT_FAILED;
|
||||
|
@ -80,8 +80,9 @@ static DWORD SemaphoreCleanupHandle(HANDLE handle)
|
|||
return WAIT_OBJECT_0;
|
||||
}
|
||||
|
||||
BOOL SemaphoreCloseHandle(HANDLE handle) {
|
||||
WINPR_SEMAPHORE *semaphore = (WINPR_SEMAPHORE *) handle;
|
||||
BOOL SemaphoreCloseHandle(HANDLE handle)
|
||||
{
|
||||
WINPR_SEMAPHORE* semaphore = (WINPR_SEMAPHORE*) handle;
|
||||
|
||||
if (!SemaphoreIsHandled(handle))
|
||||
return FALSE;
|
||||
|
@ -111,18 +112,35 @@ BOOL SemaphoreCloseHandle(HANDLE handle) {
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
static HANDLE_OPS ops = {
|
||||
SemaphoreIsHandled,
|
||||
SemaphoreCloseHandle,
|
||||
SemaphoreGetFd,
|
||||
SemaphoreCleanupHandle
|
||||
static HANDLE_OPS ops =
|
||||
{
|
||||
SemaphoreIsHandled,
|
||||
SemaphoreCloseHandle,
|
||||
SemaphoreGetFd,
|
||||
SemaphoreCleanupHandle,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
HANDLE CreateSemaphoreW(LPSECURITY_ATTRIBUTES lpSemaphoreAttributes, LONG lInitialCount, LONG lMaximumCount, LPCWSTR lpName)
|
||||
HANDLE CreateSemaphoreW(LPSECURITY_ATTRIBUTES lpSemaphoreAttributes, LONG lInitialCount,
|
||||
LONG lMaximumCount, LPCWSTR lpName)
|
||||
{
|
||||
HANDLE handle;
|
||||
WINPR_SEMAPHORE* semaphore;
|
||||
|
||||
semaphore = (WINPR_SEMAPHORE*) calloc(1, sizeof(WINPR_SEMAPHORE));
|
||||
|
||||
if (!semaphore)
|
||||
|
@ -132,7 +150,6 @@ HANDLE CreateSemaphoreW(LPSECURITY_ATTRIBUTES lpSemaphoreAttributes, LONG lIniti
|
|||
semaphore->pipe_fd[1] = -1;
|
||||
semaphore->sem = (winpr_sem_t*) NULL;
|
||||
semaphore->ops = &ops;
|
||||
|
||||
#ifdef WINPR_PIPE_SEMAPHORE
|
||||
|
||||
if (pipe(semaphore->pipe_fd) < 0)
|
||||
|
@ -157,14 +174,18 @@ HANDLE CreateSemaphoreW(LPSECURITY_ATTRIBUTES lpSemaphoreAttributes, LONG lIniti
|
|||
|
||||
#else
|
||||
semaphore->sem = (winpr_sem_t*) malloc(sizeof(winpr_sem_t));
|
||||
|
||||
if (!semaphore->sem)
|
||||
{
|
||||
WLog_ERR(TAG, "failed to allocate semaphore memory");
|
||||
free(semaphore);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#if defined __APPLE__
|
||||
if (semaphore_create(mach_task_self(), semaphore->sem, SYNC_POLICY_FIFO, lMaximumCount) != KERN_SUCCESS)
|
||||
|
||||
if (semaphore_create(mach_task_self(), semaphore->sem, SYNC_POLICY_FIFO,
|
||||
lMaximumCount) != KERN_SUCCESS)
|
||||
#else
|
||||
if (sem_init(semaphore->sem, 0, lMaximumCount) == -1)
|
||||
#endif
|
||||
|
@ -174,14 +195,15 @@ HANDLE CreateSemaphoreW(LPSECURITY_ATTRIBUTES lpSemaphoreAttributes, LONG lIniti
|
|||
free(semaphore);
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
WINPR_HANDLE_SET_TYPE_AND_MODE(semaphore, HANDLE_TYPE_SEMAPHORE, WINPR_FD_READ);
|
||||
handle = (HANDLE) semaphore;
|
||||
return handle;
|
||||
}
|
||||
|
||||
HANDLE CreateSemaphoreA(LPSECURITY_ATTRIBUTES lpSemaphoreAttributes, LONG lInitialCount, LONG lMaximumCount, LPCSTR lpName)
|
||||
HANDLE CreateSemaphoreA(LPSECURITY_ATTRIBUTES lpSemaphoreAttributes, LONG lInitialCount,
|
||||
LONG lMaximumCount, LPCSTR lpName)
|
||||
{
|
||||
return CreateSemaphoreW(lpSemaphoreAttributes, lInitialCount, lMaximumCount, NULL);
|
||||
}
|
||||
|
|
|
@ -222,6 +222,7 @@ static void WaitableTimerHandler(void* arg)
|
|||
{
|
||||
if (timer->running)
|
||||
dispatch_suspend(timer->source);
|
||||
|
||||
timer->running = FALSE;
|
||||
}
|
||||
}
|
||||
|
@ -241,6 +242,7 @@ static int InitializeWaitableTimer(WINPR_TIMER* timer)
|
|||
free(timer);
|
||||
return -1;
|
||||
}
|
||||
|
||||
#elif defined(__APPLE__)
|
||||
#else
|
||||
WLog_ERR(TAG, "%s: os specific implementation is missing", __FUNCTION__);
|
||||
|
@ -280,7 +282,23 @@ static HANDLE_OPS ops =
|
|||
TimerIsHandled,
|
||||
TimerCloseHandle,
|
||||
TimerGetFd,
|
||||
TimerCleanupHandle
|
||||
TimerCleanupHandle,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -323,8 +341,10 @@ HANDLE CreateWaitableTimerA(LPSECURITY_ATTRIBUTES lpTimerAttributes, BOOL bManua
|
|||
dispatch_set_context(timer->source, timer);
|
||||
dispatch_source_set_event_handler_f(timer->source, WaitableTimerHandler);
|
||||
timer->fd = timer->pipe[0];
|
||||
|
||||
if (fcntl(timer->fd, F_SETFL, O_NONBLOCK) < 0)
|
||||
goto fail;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -491,17 +511,20 @@ BOOL SetWaitableTimer(HANDLE hTimer, const LARGE_INTEGER* lpDueTime, LONG lPerio
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
{ /* Clean out old data from FD */
|
||||
{
|
||||
/* Clean out old data from FD */
|
||||
BYTE buffer[32];
|
||||
|
||||
while (read(timer->fd, buffer, sizeof(buffer)) > 0);
|
||||
}
|
||||
|
||||
{
|
||||
if (timer->running)
|
||||
dispatch_suspend(timer->source);
|
||||
|
||||
dispatch_time_t start = dispatch_time(DISPATCH_TIME_NOW, nanoseconds);
|
||||
uint64_t interval = DISPATCH_TIME_FOREVER;
|
||||
|
||||
if (lPeriod > 0)
|
||||
interval = lPeriod * 1000000;
|
||||
|
||||
|
@ -546,8 +569,10 @@ BOOL CancelWaitableTimer(HANDLE hTimer)
|
|||
|
||||
timer = (WINPR_TIMER*)Object;
|
||||
#if defined(__APPLE__)
|
||||
|
||||
if (timer->running)
|
||||
dispatch_suspend(timer->source);
|
||||
|
||||
timer->running = FALSE;
|
||||
#endif
|
||||
return TRUE;
|
||||
|
|
|
@ -81,10 +81,10 @@
|
|||
#endif
|
||||
|
||||
/* clock_gettime is not implemented on OSX prior to 10.12 */
|
||||
int _mach_clock_gettime(int clk_id, struct timespec *t);
|
||||
int _mach_clock_gettime(int clk_id, struct timespec* t);
|
||||
|
||||
int
|
||||
_mach_clock_gettime(int clk_id, struct timespec *t)
|
||||
int
|
||||
_mach_clock_gettime(int clk_id, struct timespec* t)
|
||||
{
|
||||
UINT64 time;
|
||||
double seconds;
|
||||
|
@ -103,14 +103,17 @@ _mach_clock_gettime(int clk_id, struct timespec *t)
|
|||
#ifdef __CLOCK_AVAILABILITY
|
||||
/* If we compiled with Mac OSX 10.12 or later, then clock_gettime will be declared
|
||||
* * but it may be NULL at runtime. So we need to check before using it. */
|
||||
int _mach_safe_clock_gettime(int clk_id, struct timespec *t);
|
||||
int _mach_safe_clock_gettime(int clk_id, struct timespec* t);
|
||||
|
||||
int
|
||||
_mach_safe_clock_gettime(int clk_id, struct timespec *t) {
|
||||
if( clock_gettime ) {
|
||||
return clock_gettime(clk_id, t);
|
||||
}
|
||||
return _mach_clock_gettime(clk_id, t);
|
||||
_mach_safe_clock_gettime(int clk_id, struct timespec* t)
|
||||
{
|
||||
if (clock_gettime)
|
||||
{
|
||||
return clock_gettime(clk_id, t);
|
||||
}
|
||||
|
||||
return _mach_clock_gettime(clk_id, t);
|
||||
}
|
||||
|
||||
#define clock_gettime _mach_safe_clock_gettime
|
||||
|
@ -121,8 +124,8 @@ _mach_safe_clock_gettime(int clk_id, struct timespec *t) {
|
|||
#endif
|
||||
|
||||
|
||||
static long long ts_difftime(const struct timespec *o,
|
||||
const struct timespec *n)
|
||||
static long long ts_difftime(const struct timespec* o,
|
||||
const struct timespec* n)
|
||||
{
|
||||
long long oldValue = o->tv_sec * 1000000000LL + o->tv_nsec;
|
||||
long long newValue = n->tv_sec * 1000000000LL + n->tv_nsec;
|
||||
|
@ -134,7 +137,7 @@ static long long ts_difftime(const struct timespec *o,
|
|||
#if !defined(HAVE_PTHREAD_MUTEX_TIMEDLOCK)
|
||||
#include <pthread.h>
|
||||
|
||||
static int pthread_mutex_timedlock(pthread_mutex_t *mutex, const struct timespec *timeout)
|
||||
static int pthread_mutex_timedlock(pthread_mutex_t* mutex, const struct timespec* timeout)
|
||||
{
|
||||
struct timespec timenow;
|
||||
struct timespec sleepytime;
|
||||
|
@ -166,8 +169,10 @@ static int pthread_mutex_timedlock(pthread_mutex_t *mutex, const struct timespec
|
|||
static DWORD handle_mode_to_pollevent(ULONG mode)
|
||||
{
|
||||
DWORD event = 0;
|
||||
|
||||
if (mode & WINPR_FD_READ)
|
||||
event |= POLLIN;
|
||||
|
||||
if (mode & WINPR_FD_WRITE)
|
||||
event |= POLLOUT;
|
||||
|
||||
|
@ -175,7 +180,7 @@ static DWORD handle_mode_to_pollevent(ULONG mode)
|
|||
}
|
||||
#endif
|
||||
|
||||
static void ts_add_ms(struct timespec *ts, DWORD dwMilliseconds)
|
||||
static void ts_add_ms(struct timespec* ts, DWORD dwMilliseconds)
|
||||
{
|
||||
ts->tv_sec += dwMilliseconds / 1000L;
|
||||
ts->tv_nsec += (dwMilliseconds % 1000L) * 1000000L;
|
||||
|
@ -212,6 +217,7 @@ static int waitOnFd(int fd, ULONG mode, DWORD dwMilliseconds)
|
|||
|
||||
if (mode & WINPR_FD_READ)
|
||||
prfds = &rfds;
|
||||
|
||||
if (mode & WINPR_FD_WRITE)
|
||||
pwfds = &wfds;
|
||||
|
||||
|
@ -245,8 +251,8 @@ DWORD WaitForSingleObject(HANDLE hHandle, DWORD dwMilliseconds)
|
|||
|
||||
if (Type == HANDLE_TYPE_PROCESS)
|
||||
{
|
||||
WINPR_PROCESS *process;
|
||||
process = (WINPR_PROCESS *) Object;
|
||||
WINPR_PROCESS* process;
|
||||
process = (WINPR_PROCESS*) Object;
|
||||
|
||||
if (process->pid != waitpid(process->pid, &(process->status), 0))
|
||||
{
|
||||
|
@ -260,8 +266,8 @@ DWORD WaitForSingleObject(HANDLE hHandle, DWORD dwMilliseconds)
|
|||
}
|
||||
else if (Type == HANDLE_TYPE_MUTEX)
|
||||
{
|
||||
WINPR_MUTEX *mutex;
|
||||
mutex = (WINPR_MUTEX *) Object;
|
||||
WINPR_MUTEX* mutex;
|
||||
mutex = (WINPR_MUTEX*) Object;
|
||||
|
||||
if (dwMilliseconds != INFINITE)
|
||||
{
|
||||
|
@ -285,6 +291,7 @@ DWORD WaitForSingleObject(HANDLE hHandle, DWORD dwMilliseconds)
|
|||
{
|
||||
int status;
|
||||
int fd = winpr_Handle_getFd(Object);
|
||||
|
||||
if (fd < 0)
|
||||
{
|
||||
WLog_ERR(TAG, "winpr_Handle_getFd did not return a fd!");
|
||||
|
@ -292,7 +299,6 @@ DWORD WaitForSingleObject(HANDLE hHandle, DWORD dwMilliseconds)
|
|||
return WAIT_FAILED;
|
||||
}
|
||||
|
||||
|
||||
status = waitOnFd(fd, Object->Mode, dwMilliseconds);
|
||||
|
||||
if (status < 0)
|
||||
|
@ -319,23 +325,24 @@ DWORD WaitForSingleObjectEx(HANDLE hHandle, DWORD dwMilliseconds, BOOL bAlertabl
|
|||
return WAIT_FAILED;
|
||||
}
|
||||
|
||||
DWORD WaitForMultipleObjects(DWORD nCount, const HANDLE *lpHandles, BOOL bWaitAll, DWORD dwMilliseconds)
|
||||
DWORD WaitForMultipleObjects(DWORD nCount, const HANDLE* lpHandles, BOOL bWaitAll,
|
||||
DWORD dwMilliseconds)
|
||||
{
|
||||
struct timespec starttime;
|
||||
struct timespec timenow;
|
||||
unsigned long long diff;
|
||||
DWORD signalled;
|
||||
DWORD polled;
|
||||
DWORD *poll_map = NULL;
|
||||
BOOL *signalled_idx = NULL;
|
||||
DWORD* poll_map = NULL;
|
||||
BOOL* signalled_idx = NULL;
|
||||
int fd = -1;
|
||||
int index;
|
||||
DWORD index;
|
||||
int status;
|
||||
ULONG Type;
|
||||
BOOL signal_handled = FALSE;
|
||||
WINPR_HANDLE* Object;
|
||||
#ifdef HAVE_POLL_H
|
||||
struct pollfd *pollfds;
|
||||
struct pollfd* pollfds;
|
||||
#else
|
||||
int maxfd;
|
||||
fd_set rfds;
|
||||
|
@ -368,11 +375,11 @@ DWORD WaitForMultipleObjects(DWORD nCount, const HANDLE *lpHandles, BOOL bWaitAl
|
|||
fd_set* prfds = NULL;
|
||||
fd_set* pwfds = NULL;
|
||||
maxfd = 0;
|
||||
|
||||
FD_ZERO(&rfds);
|
||||
FD_ZERO(&wfds);
|
||||
ZeroMemory(&timeout, sizeof(timeout));
|
||||
#endif
|
||||
|
||||
if (bWaitAll && (dwMilliseconds != INFINITE))
|
||||
clock_gettime(CLOCK_MONOTONIC, &starttime);
|
||||
|
||||
|
@ -414,6 +421,7 @@ DWORD WaitForMultipleObjects(DWORD nCount, const HANDLE *lpHandles, BOOL bWaitAl
|
|||
|
||||
if (Object->Mode & WINPR_FD_READ)
|
||||
prfds = &rfds;
|
||||
|
||||
if (Object->Mode & WINPR_FD_WRITE)
|
||||
pwfds = &wfds;
|
||||
|
||||
|
@ -443,7 +451,7 @@ DWORD WaitForMultipleObjects(DWORD nCount, const HANDLE *lpHandles, BOOL bWaitAl
|
|||
do
|
||||
{
|
||||
status = select(maxfd + 1, prfds, pwfds, 0,
|
||||
(dwMilliseconds == INFINITE) ? NULL : &timeout);
|
||||
(dwMilliseconds == INFINITE) ? NULL : &timeout);
|
||||
}
|
||||
while (status < 0 && errno == EINTR);
|
||||
|
||||
|
@ -453,10 +461,10 @@ DWORD WaitForMultipleObjects(DWORD nCount, const HANDLE *lpHandles, BOOL bWaitAl
|
|||
{
|
||||
#ifdef HAVE_POLL_H
|
||||
WLog_ERR(TAG, "poll() handle %d (%"PRIu32") failure [%d] %s", index, nCount, errno,
|
||||
strerror(errno));
|
||||
strerror(errno));
|
||||
#else
|
||||
WLog_ERR(TAG, "select() handle %d (%"PRIu32") failure [%d] %s", index, nCount, errno,
|
||||
strerror(errno));
|
||||
strerror(errno));
|
||||
#endif
|
||||
winpr_log_backtrace(TAG, WLOG_ERROR, 20);
|
||||
SetLastError(ERROR_INTERNAL_ERROR);
|
||||
|
@ -478,6 +486,7 @@ DWORD WaitForMultipleObjects(DWORD nCount, const HANDLE *lpHandles, BOOL bWaitAl
|
|||
}
|
||||
|
||||
signal_handled = FALSE;
|
||||
|
||||
for (index = 0; index < polled; index++)
|
||||
{
|
||||
DWORD idx;
|
||||
|
@ -490,9 +499,9 @@ DWORD WaitForMultipleObjects(DWORD nCount, const HANDLE *lpHandles, BOOL bWaitAl
|
|||
|
||||
if (!winpr_Handle_GetInfo(lpHandles[idx], &Type, &Object))
|
||||
{
|
||||
WLog_ERR(TAG, "invalid hHandle.");
|
||||
SetLastError(ERROR_INVALID_HANDLE);
|
||||
return WAIT_FAILED;
|
||||
WLog_ERR(TAG, "invalid hHandle.");
|
||||
SetLastError(ERROR_INVALID_HANDLE);
|
||||
return WAIT_FAILED;
|
||||
}
|
||||
|
||||
fd = winpr_Handle_getFd(lpHandles[idx]);
|
||||
|
@ -507,14 +516,19 @@ DWORD WaitForMultipleObjects(DWORD nCount, const HANDLE *lpHandles, BOOL bWaitAl
|
|||
#ifdef HAVE_POLL_H
|
||||
signal_set = pollfds[index].revents & pollfds[index].events;
|
||||
#else
|
||||
|
||||
if (Object->Mode & WINPR_FD_READ)
|
||||
signal_set = FD_ISSET(fd, &rfds) ? 1 : 0;
|
||||
|
||||
if (Object->Mode & WINPR_FD_WRITE)
|
||||
signal_set |= FD_ISSET(fd, &wfds) ? 1 : 0;
|
||||
|
||||
#endif
|
||||
|
||||
if (signal_set)
|
||||
{
|
||||
DWORD rc = winpr_Handle_cleanup(lpHandles[idx]);
|
||||
|
||||
if (rc != WAIT_OBJECT_0)
|
||||
return rc;
|
||||
|
||||
|
@ -547,12 +561,14 @@ DWORD WaitForMultipleObjects(DWORD nCount, const HANDLE *lpHandles, BOOL bWaitAl
|
|||
return WAIT_FAILED;
|
||||
}
|
||||
|
||||
DWORD WaitForMultipleObjectsEx(DWORD nCount, const HANDLE *lpHandles, BOOL bWaitAll, DWORD dwMilliseconds, BOOL bAlertable)
|
||||
DWORD WaitForMultipleObjectsEx(DWORD nCount, const HANDLE* lpHandles, BOOL bWaitAll,
|
||||
DWORD dwMilliseconds, BOOL bAlertable)
|
||||
{
|
||||
return WaitForMultipleObjects(nCount, lpHandles, bWaitAll, dwMilliseconds);
|
||||
}
|
||||
|
||||
DWORD SignalObjectAndWait(HANDLE hObjectToSignal, HANDLE hObjectToWaitOn, DWORD dwMilliseconds, BOOL bAlertable)
|
||||
DWORD SignalObjectAndWait(HANDLE hObjectToSignal, HANDLE hObjectToWaitOn, DWORD dwMilliseconds,
|
||||
BOOL bAlertable)
|
||||
{
|
||||
WLog_ERR(TAG, "%s: Not implemented.", __FUNCTION__);
|
||||
SetLastError(ERROR_NOT_SUPPORTED);
|
||||
|
|
|
@ -108,6 +108,7 @@ static char* FindApplicationPath(char* application)
|
|||
return _strdup(application);
|
||||
|
||||
lpSystemPath = (LPSTR) malloc(nSize);
|
||||
|
||||
if (!lpSystemPath)
|
||||
return NULL;
|
||||
|
||||
|
@ -131,12 +132,10 @@ static char* FindApplicationPath(char* application)
|
|||
|
||||
free(filename);
|
||||
filename = NULL;
|
||||
|
||||
path = strtok_s(NULL, ":", &save);
|
||||
}
|
||||
|
||||
free(lpSystemPath);
|
||||
|
||||
return filename;
|
||||
}
|
||||
|
||||
|
@ -144,9 +143,10 @@ static HANDLE CreateProcessHandle(pid_t pid);
|
|||
static BOOL ProcessHandleCloseHandle(HANDLE handle);
|
||||
|
||||
BOOL _CreateProcessExA(HANDLE hToken, DWORD dwLogonFlags,
|
||||
LPCSTR lpApplicationName, LPSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes,
|
||||
LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment,
|
||||
LPCSTR lpCurrentDirectory, LPSTARTUPINFOA lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation)
|
||||
LPCSTR lpApplicationName, LPSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes,
|
||||
LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags,
|
||||
LPVOID lpEnvironment,
|
||||
LPCSTR lpCurrentDirectory, LPSTARTUPINFOA lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation)
|
||||
{
|
||||
pid_t pid;
|
||||
int numArgs;
|
||||
|
@ -161,15 +161,13 @@ BOOL _CreateProcessExA(HANDLE hToken, DWORD dwLogonFlags,
|
|||
sigset_t oldSigMask;
|
||||
sigset_t newSigMask;
|
||||
BOOL restoreSigMask = FALSE;
|
||||
|
||||
numArgs = 0;
|
||||
lpszEnvironmentBlock = NULL;
|
||||
|
||||
pArgs = CommandLineToArgvA(lpCommandLine, &numArgs);
|
||||
|
||||
if (!pArgs)
|
||||
return FALSE;
|
||||
|
||||
|
||||
token = (WINPR_ACCESS_TOKEN*) hToken;
|
||||
|
||||
if (lpEnvironment)
|
||||
|
@ -179,23 +177,25 @@ BOOL _CreateProcessExA(HANDLE hToken, DWORD dwLogonFlags,
|
|||
else
|
||||
{
|
||||
lpszEnvironmentBlock = GetEnvironmentStrings();
|
||||
|
||||
if (!lpszEnvironmentBlock)
|
||||
goto finish;
|
||||
|
||||
envp = EnvironmentBlockToEnvpA(lpszEnvironmentBlock);
|
||||
}
|
||||
|
||||
if (!envp)
|
||||
goto finish;
|
||||
|
||||
filename = FindApplicationPath(pArgs[0]);
|
||||
|
||||
if (NULL == filename)
|
||||
goto finish;
|
||||
|
||||
/* block all signals so that the child can safely reset the caller's handlers */
|
||||
sigfillset(&newSigMask);
|
||||
restoreSigMask = !pthread_sigmask(SIG_SETMASK, &newSigMask, &oldSigMask);
|
||||
|
||||
/* fork and exec */
|
||||
|
||||
pid = fork();
|
||||
|
||||
if (pid < 0)
|
||||
|
@ -214,14 +214,15 @@ BOOL _CreateProcessExA(HANDLE hToken, DWORD dwLogonFlags,
|
|||
int sig;
|
||||
sigset_t set;
|
||||
struct sigaction act;
|
||||
|
||||
/* set default signal handlers */
|
||||
memset(&act, 0, sizeof(act));
|
||||
act.sa_handler = SIG_DFL;
|
||||
act.sa_flags = 0;
|
||||
sigemptyset(&act.sa_mask);
|
||||
|
||||
for (sig = 1; sig < NSIG; sig++)
|
||||
sigaction(sig, &act, NULL);
|
||||
|
||||
/* unblock all signals */
|
||||
sigfillset(&set);
|
||||
pthread_sigmask(SIG_UNBLOCK, &set, NULL);
|
||||
|
@ -229,21 +230,22 @@ BOOL _CreateProcessExA(HANDLE hToken, DWORD dwLogonFlags,
|
|||
if (lpStartupInfo)
|
||||
{
|
||||
int handle_fd;
|
||||
|
||||
handle_fd = winpr_Handle_getFd(lpStartupInfo->hStdOutput);
|
||||
|
||||
if (handle_fd != -1)
|
||||
dup2(handle_fd, STDOUT_FILENO);
|
||||
|
||||
handle_fd = winpr_Handle_getFd(lpStartupInfo->hStdError);
|
||||
|
||||
if (handle_fd != -1)
|
||||
dup2(handle_fd, STDERR_FILENO);
|
||||
|
||||
handle_fd = winpr_Handle_getFd(lpStartupInfo->hStdInput);
|
||||
|
||||
if (handle_fd != -1)
|
||||
dup2(handle_fd, STDIN_FILENO);
|
||||
}
|
||||
|
||||
|
||||
#ifdef __sun
|
||||
closefrom(3);
|
||||
#else
|
||||
|
@ -252,8 +254,10 @@ BOOL _CreateProcessExA(HANDLE hToken, DWORD dwLogonFlags,
|
|||
#else
|
||||
maxfd = sysconf(_SC_OPEN_MAX);
|
||||
#endif
|
||||
for(fd=3; fd<maxfd; fd++)
|
||||
|
||||
for (fd = 3; fd < maxfd; fd++)
|
||||
close(fd);
|
||||
|
||||
#endif // __sun
|
||||
|
||||
if (token)
|
||||
|
@ -261,6 +265,7 @@ BOOL _CreateProcessExA(HANDLE hToken, DWORD dwLogonFlags,
|
|||
if (token->GroupId)
|
||||
{
|
||||
int rc = setgid((gid_t) token->GroupId);
|
||||
|
||||
if (rc < 0)
|
||||
{
|
||||
}
|
||||
|
@ -272,7 +277,6 @@ BOOL _CreateProcessExA(HANDLE hToken, DWORD dwLogonFlags,
|
|||
|
||||
if (token->UserId)
|
||||
setuid((uid_t) token->UserId);
|
||||
|
||||
}
|
||||
|
||||
/* TODO: add better cwd handling and error checking */
|
||||
|
@ -309,16 +313,13 @@ BOOL _CreateProcessExA(HANDLE hToken, DWORD dwLogonFlags,
|
|||
lpProcessInformation->hThread = thread;
|
||||
lpProcessInformation->dwProcessId = (DWORD) pid;
|
||||
lpProcessInformation->dwThreadId = (DWORD) pid;
|
||||
|
||||
ret = TRUE;
|
||||
|
||||
finish:
|
||||
|
||||
/* restore caller's original signal mask */
|
||||
if (restoreSigMask)
|
||||
pthread_sigmask(SIG_SETMASK, &oldSigMask, NULL);
|
||||
|
||||
|
||||
free(filename);
|
||||
|
||||
if (pArgs)
|
||||
|
@ -345,67 +346,81 @@ finish:
|
|||
return ret;
|
||||
}
|
||||
|
||||
BOOL CreateProcessA(LPCSTR lpApplicationName, LPSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes,
|
||||
LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment,
|
||||
LPCSTR lpCurrentDirectory, LPSTARTUPINFOA lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation)
|
||||
BOOL CreateProcessA(LPCSTR lpApplicationName, LPSTR lpCommandLine,
|
||||
LPSECURITY_ATTRIBUTES lpProcessAttributes,
|
||||
LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags,
|
||||
LPVOID lpEnvironment,
|
||||
LPCSTR lpCurrentDirectory, LPSTARTUPINFOA lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation)
|
||||
{
|
||||
return _CreateProcessExA(NULL, 0,
|
||||
lpApplicationName, lpCommandLine, lpProcessAttributes,
|
||||
lpThreadAttributes, bInheritHandles, dwCreationFlags, lpEnvironment,
|
||||
lpCurrentDirectory, lpStartupInfo, lpProcessInformation);
|
||||
lpApplicationName, lpCommandLine, lpProcessAttributes,
|
||||
lpThreadAttributes, bInheritHandles, dwCreationFlags, lpEnvironment,
|
||||
lpCurrentDirectory, lpStartupInfo, lpProcessInformation);
|
||||
}
|
||||
|
||||
BOOL CreateProcessW(LPCWSTR lpApplicationName, LPWSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes,
|
||||
LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment,
|
||||
LPCWSTR lpCurrentDirectory, LPSTARTUPINFOW lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation)
|
||||
BOOL CreateProcessW(LPCWSTR lpApplicationName, LPWSTR lpCommandLine,
|
||||
LPSECURITY_ATTRIBUTES lpProcessAttributes,
|
||||
LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags,
|
||||
LPVOID lpEnvironment,
|
||||
LPCWSTR lpCurrentDirectory, LPSTARTUPINFOW lpStartupInfo,
|
||||
LPPROCESS_INFORMATION lpProcessInformation)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL CreateProcessAsUserA(HANDLE hToken, LPCSTR lpApplicationName, LPSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes,
|
||||
LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment,
|
||||
LPCSTR lpCurrentDirectory, LPSTARTUPINFOA lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation)
|
||||
BOOL CreateProcessAsUserA(HANDLE hToken, LPCSTR lpApplicationName, LPSTR lpCommandLine,
|
||||
LPSECURITY_ATTRIBUTES lpProcessAttributes,
|
||||
LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags,
|
||||
LPVOID lpEnvironment,
|
||||
LPCSTR lpCurrentDirectory, LPSTARTUPINFOA lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation)
|
||||
{
|
||||
return _CreateProcessExA(hToken, 0,
|
||||
lpApplicationName, lpCommandLine, lpProcessAttributes,
|
||||
lpThreadAttributes, bInheritHandles, dwCreationFlags, lpEnvironment,
|
||||
lpCurrentDirectory, lpStartupInfo, lpProcessInformation);
|
||||
lpApplicationName, lpCommandLine, lpProcessAttributes,
|
||||
lpThreadAttributes, bInheritHandles, dwCreationFlags, lpEnvironment,
|
||||
lpCurrentDirectory, lpStartupInfo, lpProcessInformation);
|
||||
}
|
||||
|
||||
BOOL CreateProcessAsUserW(HANDLE hToken, LPCWSTR lpApplicationName, LPWSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes,
|
||||
LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment,
|
||||
LPCWSTR lpCurrentDirectory, LPSTARTUPINFOW lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation)
|
||||
BOOL CreateProcessAsUserW(HANDLE hToken, LPCWSTR lpApplicationName, LPWSTR lpCommandLine,
|
||||
LPSECURITY_ATTRIBUTES lpProcessAttributes,
|
||||
LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags,
|
||||
LPVOID lpEnvironment,
|
||||
LPCWSTR lpCurrentDirectory, LPSTARTUPINFOW lpStartupInfo,
|
||||
LPPROCESS_INFORMATION lpProcessInformation)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL CreateProcessWithLogonA(LPCSTR lpUsername, LPCSTR lpDomain, LPCSTR lpPassword, DWORD dwLogonFlags,
|
||||
LPCSTR lpApplicationName, LPSTR lpCommandLine, DWORD dwCreationFlags, LPVOID lpEnvironment,
|
||||
LPCSTR lpCurrentDirectory, LPSTARTUPINFOA lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation)
|
||||
BOOL CreateProcessWithLogonA(LPCSTR lpUsername, LPCSTR lpDomain, LPCSTR lpPassword,
|
||||
DWORD dwLogonFlags,
|
||||
LPCSTR lpApplicationName, LPSTR lpCommandLine, DWORD dwCreationFlags, LPVOID lpEnvironment,
|
||||
LPCSTR lpCurrentDirectory, LPSTARTUPINFOA lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL CreateProcessWithLogonW(LPCWSTR lpUsername, LPCWSTR lpDomain, LPCWSTR lpPassword, DWORD dwLogonFlags,
|
||||
LPCWSTR lpApplicationName, LPWSTR lpCommandLine, DWORD dwCreationFlags, LPVOID lpEnvironment,
|
||||
LPCWSTR lpCurrentDirectory, LPSTARTUPINFOW lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation)
|
||||
BOOL CreateProcessWithLogonW(LPCWSTR lpUsername, LPCWSTR lpDomain, LPCWSTR lpPassword,
|
||||
DWORD dwLogonFlags,
|
||||
LPCWSTR lpApplicationName, LPWSTR lpCommandLine, DWORD dwCreationFlags, LPVOID lpEnvironment,
|
||||
LPCWSTR lpCurrentDirectory, LPSTARTUPINFOW lpStartupInfo,
|
||||
LPPROCESS_INFORMATION lpProcessInformation)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL CreateProcessWithTokenA(HANDLE hToken, DWORD dwLogonFlags,
|
||||
LPCSTR lpApplicationName, LPSTR lpCommandLine, DWORD dwCreationFlags, LPVOID lpEnvironment,
|
||||
LPCSTR lpCurrentDirectory, LPSTARTUPINFOA lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation)
|
||||
LPCSTR lpApplicationName, LPSTR lpCommandLine, DWORD dwCreationFlags, LPVOID lpEnvironment,
|
||||
LPCSTR lpCurrentDirectory, LPSTARTUPINFOA lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation)
|
||||
{
|
||||
return _CreateProcessExA(NULL, 0,
|
||||
lpApplicationName, lpCommandLine, NULL,
|
||||
NULL, FALSE, dwCreationFlags, lpEnvironment,
|
||||
lpCurrentDirectory, lpStartupInfo, lpProcessInformation);
|
||||
lpApplicationName, lpCommandLine, NULL,
|
||||
NULL, FALSE, dwCreationFlags, lpEnvironment,
|
||||
lpCurrentDirectory, lpStartupInfo, lpProcessInformation);
|
||||
}
|
||||
|
||||
BOOL CreateProcessWithTokenW(HANDLE hToken, DWORD dwLogonFlags,
|
||||
LPCWSTR lpApplicationName, LPWSTR lpCommandLine, DWORD dwCreationFlags, LPVOID lpEnvironment,
|
||||
LPCWSTR lpCurrentDirectory, LPSTARTUPINFOW lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation)
|
||||
LPCWSTR lpApplicationName, LPWSTR lpCommandLine, DWORD dwCreationFlags, LPVOID lpEnvironment,
|
||||
LPCWSTR lpCurrentDirectory, LPSTARTUPINFOW lpStartupInfo,
|
||||
LPPROCESS_INFORMATION lpProcessInformation)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -426,9 +441,7 @@ BOOL GetExitCodeProcess(HANDLE hProcess, LPDWORD lpExitCode)
|
|||
return FALSE;
|
||||
|
||||
process = (WINPR_PROCESS*) hProcess;
|
||||
|
||||
*lpExitCode = process->dwExitCode;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -445,7 +458,6 @@ DWORD GetCurrentProcessId(VOID)
|
|||
DWORD GetProcessId(HANDLE Process)
|
||||
{
|
||||
WINPR_PROCESS* process;
|
||||
|
||||
process = (WINPR_PROCESS*) Process;
|
||||
|
||||
if (!process)
|
||||
|
@ -457,7 +469,6 @@ DWORD GetProcessId(HANDLE Process)
|
|||
BOOL TerminateProcess(HANDLE hProcess, UINT uExitCode)
|
||||
{
|
||||
WINPR_PROCESS* process;
|
||||
|
||||
process = (WINPR_PROCESS*) hProcess;
|
||||
|
||||
if (!process || (process->pid <= 0))
|
||||
|
@ -492,7 +503,7 @@ static BOOL ProcessHandleIsHandle(HANDLE handle)
|
|||
|
||||
static int ProcessGetFd(HANDLE handle)
|
||||
{
|
||||
WINPR_PROCESS *process = (WINPR_PROCESS *)handle;
|
||||
WINPR_PROCESS* process = (WINPR_PROCESS*)handle;
|
||||
|
||||
if (!ProcessHandleIsHandle(handle))
|
||||
return -1;
|
||||
|
@ -502,11 +513,28 @@ static int ProcessGetFd(HANDLE handle)
|
|||
return -1;
|
||||
}
|
||||
|
||||
static HANDLE_OPS ops = {
|
||||
ProcessHandleIsHandle,
|
||||
ProcessHandleCloseHandle,
|
||||
ProcessGetFd,
|
||||
NULL /* CleanupHandle */
|
||||
static HANDLE_OPS ops =
|
||||
{
|
||||
ProcessHandleIsHandle,
|
||||
ProcessHandleCloseHandle,
|
||||
ProcessGetFd,
|
||||
NULL, /* CleanupHandle */
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
HANDLE CreateProcessHandle(pid_t pid)
|
||||
|
@ -520,7 +548,6 @@ HANDLE CreateProcessHandle(pid_t pid)
|
|||
process->pid = pid;
|
||||
process->Type = HANDLE_TYPE_PROCESS;
|
||||
process->ops = &ops;
|
||||
|
||||
return (HANDLE)process;
|
||||
}
|
||||
|
||||
|
|
|
@ -159,7 +159,23 @@ static HANDLE_OPS ops =
|
|||
ThreadIsHandled,
|
||||
ThreadCloseHandle,
|
||||
ThreadGetFd,
|
||||
ThreadCleanupHandle
|
||||
ThreadCleanupHandle,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
|
||||
|
@ -282,10 +298,9 @@ static BOOL thread_compare(const void* a, const void* b)
|
|||
* in thread function. */
|
||||
static void* thread_launcher(void* arg)
|
||||
{
|
||||
void* rc = NULL;
|
||||
DWORD rc = 0;
|
||||
WINPR_THREAD* thread = (WINPR_THREAD*) arg;
|
||||
typedef void* (*fkt_t)(void*);
|
||||
fkt_t fkt;
|
||||
LPTHREAD_START_ROUTINE fkt;
|
||||
|
||||
if (!thread)
|
||||
{
|
||||
|
@ -293,7 +308,7 @@ static void* thread_launcher(void* arg)
|
|||
goto exit;
|
||||
}
|
||||
|
||||
if (!(fkt = (fkt_t)thread->lpStartAddress))
|
||||
if (!(fkt = thread->lpStartAddress))
|
||||
{
|
||||
WLog_ERR(TAG, "Thread function argument is %p", (void*)fkt);
|
||||
goto exit;
|
||||
|
@ -322,7 +337,7 @@ exit:
|
|||
if (thread)
|
||||
{
|
||||
if (!thread->exited)
|
||||
thread->dwExitCode = (DWORD)(size_t)rc;
|
||||
thread->dwExitCode = rc;
|
||||
|
||||
set_event(thread);
|
||||
|
||||
|
@ -330,7 +345,7 @@ exit:
|
|||
cleanup_handle(thread);
|
||||
}
|
||||
|
||||
return rc;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static BOOL winpr_StartThread(WINPR_THREAD* thread)
|
||||
|
|
|
@ -2,75 +2,88 @@
|
|||
#include <winpr/print.h>
|
||||
#include <winpr/stream.h>
|
||||
|
||||
static BOOL TestStream_Verify(wStream* s, int mincap, int len, size_t pos)
|
||||
static BOOL TestStream_Verify(wStream* s, size_t mincap, size_t len, size_t pos)
|
||||
{
|
||||
if (Stream_Buffer(s) == NULL)
|
||||
{
|
||||
printf("stream buffer is null\n");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (Stream_Pointer(s) == NULL)
|
||||
{
|
||||
printf("stream pointer is null\n");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (Stream_Pointer(s) < Stream_Buffer(s))
|
||||
{
|
||||
printf("stream pointer (%p) or buffer (%p) is invalid\n",
|
||||
(void*) Stream_Pointer(s), (void*) Stream_Buffer(s));
|
||||
(void*) Stream_Pointer(s), (void*) Stream_Buffer(s));
|
||||
return FALSE;
|
||||
}
|
||||
if (Stream_Capacity(s) < mincap) {
|
||||
printf("stream capacity is %"PRIuz" but minimum expected value is %d\n",
|
||||
Stream_Capacity(s), mincap);
|
||||
|
||||
if (Stream_Capacity(s) < mincap)
|
||||
{
|
||||
printf("stream capacity is %"PRIuz" but minimum expected value is %"PRIuz"\n",
|
||||
Stream_Capacity(s), mincap);
|
||||
return FALSE;
|
||||
}
|
||||
if (Stream_Length(s) != len) {
|
||||
printf("stream has unexpected length (%"PRIuz" instead of %d)\n",
|
||||
Stream_Length(s), len);
|
||||
|
||||
if (Stream_Length(s) != len)
|
||||
{
|
||||
printf("stream has unexpected length (%"PRIuz" instead of %"PRIuz")\n",
|
||||
Stream_Length(s), len);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (Stream_GetPosition(s) != pos)
|
||||
{
|
||||
printf("stream has unexpected position (%"PRIuz" instead of %"PRIuz")\n",
|
||||
Stream_GetPosition(s), pos);
|
||||
Stream_GetPosition(s), pos);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (Stream_GetPosition(s) > Stream_Length(s))
|
||||
{
|
||||
printf("stream position (%"PRIuz") exceeds length (%"PRIuz")\n",
|
||||
Stream_GetPosition(s), Stream_Length(s));
|
||||
Stream_GetPosition(s), Stream_Length(s));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (Stream_GetPosition(s) > Stream_Capacity(s))
|
||||
{
|
||||
printf("stream position (%"PRIuz") exceeds capacity (%"PRIuz")\n",
|
||||
Stream_GetPosition(s), Stream_Capacity(s));
|
||||
Stream_GetPosition(s), Stream_Capacity(s));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (Stream_Length(s) > Stream_Capacity(s))
|
||||
{
|
||||
printf("stream length (%"PRIuz") exceeds capacity (%"PRIuz")\n",
|
||||
Stream_Length(s), Stream_Capacity(s));
|
||||
Stream_Length(s), Stream_Capacity(s));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (Stream_GetRemainingLength(s) != len - pos)
|
||||
{
|
||||
printf("stream remaining length (%"PRIuz" instead of %"PRIuz")\n",
|
||||
Stream_GetRemainingLength(s), len - pos);
|
||||
Stream_GetRemainingLength(s), len - pos);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL TestStream_New()
|
||||
static BOOL TestStream_New(void)
|
||||
{
|
||||
wStream *s = NULL;
|
||||
wStream* s = NULL;
|
||||
/* Test creation of a 0-size stream with no buffer */
|
||||
s = Stream_New(NULL, 0);
|
||||
|
||||
if (s)
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -79,30 +92,34 @@ static BOOL TestStream_Static()
|
|||
BYTE buffer[20];
|
||||
wStream staticStream, *s = &staticStream;
|
||||
UINT16 v;
|
||||
|
||||
/* Test creation of a static stream */
|
||||
Stream_StaticInit(s, buffer, sizeof(buffer));
|
||||
Stream_Write_UINT16(s, 0xcab1);
|
||||
Stream_SetPosition(s, 0);
|
||||
Stream_Read_UINT16(s, v);
|
||||
|
||||
if (v != 0xcab1)
|
||||
return FALSE;
|
||||
|
||||
Stream_SetPosition(s, 0);
|
||||
Stream_Write_UINT16(s, 1);
|
||||
|
||||
if (!Stream_EnsureRemainingCapacity(s, 10)) /* we can ask for 10 bytes */
|
||||
return FALSE;
|
||||
|
||||
/* 30 is bigger than the buffer, it will be reallocated on the heap */
|
||||
if (!Stream_EnsureRemainingCapacity(s, 30) || !s->isOwner)
|
||||
return FALSE;
|
||||
Stream_Write_UINT16(s, 2);
|
||||
|
||||
Stream_Write_UINT16(s, 2);
|
||||
Stream_SetPosition(s, 0);
|
||||
Stream_Read_UINT16(s, v);
|
||||
|
||||
if (v != 1)
|
||||
return FALSE;
|
||||
|
||||
Stream_Read_UINT16(s, v);
|
||||
|
||||
if (v != 2)
|
||||
return FALSE;
|
||||
|
||||
|
@ -110,29 +127,29 @@ static BOOL TestStream_Static()
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL TestStream_Create(int count, BOOL selfAlloc)
|
||||
static BOOL TestStream_Create(size_t count, BOOL selfAlloc)
|
||||
{
|
||||
int i, len, cap, pos;
|
||||
wStream *s = NULL;
|
||||
size_t i, len, cap, pos;
|
||||
wStream* s = NULL;
|
||||
void* buffer = NULL;
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
len = cap = i+1;
|
||||
len = cap = i + 1;
|
||||
pos = 0;
|
||||
|
||||
if (selfAlloc)
|
||||
{
|
||||
if (!(buffer = malloc(cap)))
|
||||
{
|
||||
printf("%s: failed to allocate buffer of size %d\n", __FUNCTION__, cap);
|
||||
printf("%s: failed to allocate buffer of size %"PRIuz"\n", __FUNCTION__, cap);
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
if (!(s = Stream_New(selfAlloc ? buffer : NULL, len)))
|
||||
{
|
||||
printf("%s: Stream_New failed for stream #%d\n", __FUNCTION__, i);
|
||||
printf("%s: Stream_New failed for stream #%"PRIuz"\n", __FUNCTION__, i);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
|
@ -145,6 +162,7 @@ static BOOL TestStream_Create(int count, BOOL selfAlloc)
|
|||
{
|
||||
Stream_SetPosition(s, pos);
|
||||
Stream_SealLength(s);
|
||||
|
||||
if (!TestStream_Verify(s, cap, pos, pos))
|
||||
{
|
||||
goto fail;
|
||||
|
@ -153,7 +171,8 @@ static BOOL TestStream_Create(int count, BOOL selfAlloc)
|
|||
|
||||
if (selfAlloc)
|
||||
{
|
||||
memset(buffer, i%256, cap);
|
||||
memset(buffer, i % 256, cap);
|
||||
|
||||
if (memcmp(buffer, Stream_Buffer(s), cap))
|
||||
{
|
||||
printf("%s: buffer memory corruption\n", __FUNCTION__);
|
||||
|
@ -166,9 +185,9 @@ static BOOL TestStream_Create(int count, BOOL selfAlloc)
|
|||
}
|
||||
|
||||
return TRUE;
|
||||
|
||||
fail:
|
||||
free(buffer);
|
||||
|
||||
if (s)
|
||||
{
|
||||
Stream_Free(s, buffer ? FALSE : TRUE);
|
||||
|
@ -180,7 +199,7 @@ fail:
|
|||
static BOOL TestStream_Extent(UINT32 maxSize)
|
||||
{
|
||||
UINT32 i;
|
||||
wStream *s = NULL;
|
||||
wStream* s = NULL;
|
||||
BOOL result = FALSE;
|
||||
|
||||
if (!(s = Stream_New(NULL, 1)))
|
||||
|
@ -213,8 +232,8 @@ static BOOL TestStream_Extent(UINT32 maxSize)
|
|||
}
|
||||
|
||||
result = TRUE;
|
||||
|
||||
fail:
|
||||
|
||||
if (s)
|
||||
{
|
||||
Stream_Free(s, TRUE);
|
||||
|
@ -225,54 +244,53 @@ fail:
|
|||
|
||||
#define Stream_Peek_UINT8_BE Stream_Peek_UINT8
|
||||
#define Stream_Read_UINT8_BE Stream_Read_UINT8
|
||||
#define Stream_Peek_INT8_BE Stream_Peek_UINT8
|
||||
#define Stream_Read_INT8_BE Stream_Read_UINT8
|
||||
#define Stream_Peek_INT8_BE Stream_Peek_INT8
|
||||
#define Stream_Read_INT8_BE Stream_Read_INT8
|
||||
|
||||
#define TestStream_PeekAndRead(_s, _r, _t) do \
|
||||
{ \
|
||||
_t _a, _b; \
|
||||
int _i; \
|
||||
BYTE* _p = Stream_Buffer(_s); \
|
||||
Stream_SetPosition(_s, 0); \
|
||||
Stream_Peek_ ## _t(_s, _a); \
|
||||
Stream_Read_ ## _t(_s, _b); \
|
||||
if (_a != _b) \
|
||||
{ \
|
||||
printf("%s: test1 " #_t "_LE failed\n", __FUNCTION__); \
|
||||
_r = FALSE; \
|
||||
} \
|
||||
for (_i=0; _i<sizeof(_t); _i++) { \
|
||||
if (((_a >> (_i * 8)) & 0xFF) != _p[_i]) { \
|
||||
printf("%s: test2 " #_t "_LE failed\n", __FUNCTION__); \
|
||||
_r = FALSE; \
|
||||
break; \
|
||||
} \
|
||||
} \
|
||||
/* printf("a: 0x%016llX\n", a); */ \
|
||||
Stream_SetPosition(_s, 0); \
|
||||
Stream_Peek_ ## _t ## _BE(_s, _a); \
|
||||
Stream_Read_ ## _t ## _BE(_s, _b); \
|
||||
if (_a != _b) \
|
||||
{ \
|
||||
printf("%s: test1 " #_t "_BE failed\n", __FUNCTION__); \
|
||||
_r = FALSE; \
|
||||
} \
|
||||
for (_i=0; _i<sizeof(_t); _i++) { \
|
||||
if (((_a >> (_i * 8)) & 0xFF) != _p[sizeof(_t)-_i-1]) { \
|
||||
printf("%s: test2 " #_t "_BE failed\n", __FUNCTION__); \
|
||||
_r = FALSE; \
|
||||
break; \
|
||||
} \
|
||||
} \
|
||||
/* printf("a: 0x%016llX\n", a); */ \
|
||||
} while (0)
|
||||
{ \
|
||||
_t _a, _b; \
|
||||
size_t _i; \
|
||||
BYTE* _p = Stream_Buffer(_s); \
|
||||
Stream_SetPosition(_s, 0); \
|
||||
Stream_Peek_ ## _t(_s, _a); \
|
||||
Stream_Read_ ## _t(_s, _b); \
|
||||
if (_a != _b) \
|
||||
{ \
|
||||
printf("%s: test1 " #_t "_LE failed\n", __FUNCTION__); \
|
||||
_r = FALSE; \
|
||||
} \
|
||||
for (_i=0; _i<sizeof(_t); _i++) { \
|
||||
if (((_a >> (_i * 8)) & 0xFF) != _p[_i]) { \
|
||||
printf("%s: test2 " #_t "_LE failed\n", __FUNCTION__); \
|
||||
_r = FALSE; \
|
||||
break; \
|
||||
} \
|
||||
} \
|
||||
/* printf("a: 0x%016llX\n", a); */ \
|
||||
Stream_SetPosition(_s, 0); \
|
||||
Stream_Peek_ ## _t ## _BE(_s, _a); \
|
||||
Stream_Read_ ## _t ## _BE(_s, _b); \
|
||||
if (_a != _b) \
|
||||
{ \
|
||||
printf("%s: test1 " #_t "_BE failed\n", __FUNCTION__); \
|
||||
_r = FALSE; \
|
||||
} \
|
||||
for (_i=0; _i<sizeof(_t); _i++) { \
|
||||
if (((_a >> (_i * 8)) & 0xFF) != _p[sizeof(_t)-_i-1]) { \
|
||||
printf("%s: test2 " #_t "_BE failed\n", __FUNCTION__); \
|
||||
_r = FALSE; \
|
||||
break; \
|
||||
} \
|
||||
} \
|
||||
/* printf("a: 0x%016llX\n", a); */ \
|
||||
} while (0)
|
||||
|
||||
|
||||
static BOOL TestStream_Reading(void)
|
||||
{
|
||||
BYTE src[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
|
||||
|
||||
wStream *s = NULL;
|
||||
wStream* s = NULL;
|
||||
BOOL result = TRUE;
|
||||
|
||||
if (!(s = Stream_New(src, sizeof(src))))
|
||||
|
@ -289,9 +307,7 @@ static BOOL TestStream_Reading(void)
|
|||
TestStream_PeekAndRead(s, result, INT32);
|
||||
TestStream_PeekAndRead(s, result, UINT64);
|
||||
TestStream_PeekAndRead(s, result, INT64);
|
||||
|
||||
Stream_Free(s, FALSE);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -304,59 +320,86 @@ static BOOL TestStream_Write(void)
|
|||
UINT64 u64;
|
||||
const BYTE data[] = "someteststreamdata";
|
||||
wStream* s = Stream_New(NULL, 100);
|
||||
|
||||
if (!s)
|
||||
goto out;
|
||||
|
||||
if (s->pointer != s->buffer)
|
||||
goto out;
|
||||
|
||||
Stream_Write(s, data, sizeof(data));
|
||||
|
||||
if (memcmp(Stream_Buffer(s), data, sizeof(data)) == 0)
|
||||
rc = TRUE;
|
||||
|
||||
if (s->pointer != s->buffer + sizeof(data))
|
||||
goto out;
|
||||
|
||||
Stream_SetPosition(s, 0);
|
||||
|
||||
if (s->pointer != s->buffer)
|
||||
goto out;
|
||||
|
||||
Stream_Write_UINT8(s, 42);
|
||||
|
||||
if (s->pointer != s->buffer + 1)
|
||||
goto out;
|
||||
|
||||
Stream_SetPosition(s, 0);
|
||||
|
||||
if (s->pointer != s->buffer)
|
||||
goto out;
|
||||
|
||||
Stream_Peek_UINT8(s, u8);
|
||||
|
||||
if (u8 != 42)
|
||||
goto out;
|
||||
|
||||
Stream_Write_UINT16(s, 0x1234);
|
||||
|
||||
if (s->pointer != s->buffer + 2)
|
||||
goto out;
|
||||
|
||||
Stream_SetPosition(s, 0);
|
||||
|
||||
if (s->pointer != s->buffer)
|
||||
goto out;
|
||||
|
||||
Stream_Peek_UINT16(s, u16);
|
||||
|
||||
if (u16 != 0x1234)
|
||||
goto out;
|
||||
|
||||
Stream_Write_UINT32(s, 0x12345678UL);
|
||||
|
||||
if (s->pointer != s->buffer + 4)
|
||||
goto out;
|
||||
|
||||
Stream_SetPosition(s, 0);
|
||||
|
||||
if (s->pointer != s->buffer)
|
||||
goto out;
|
||||
|
||||
Stream_Peek_UINT32(s, u32);
|
||||
|
||||
if (u32 != 0x12345678UL)
|
||||
goto out;
|
||||
|
||||
Stream_Write_UINT64(s, 0x1234567890ABCDEFULL);
|
||||
|
||||
if (s->pointer != s->buffer + 8)
|
||||
goto out;
|
||||
|
||||
Stream_SetPosition(s, 0);
|
||||
|
||||
if (s->pointer != s->buffer)
|
||||
goto out;
|
||||
|
||||
Stream_Peek_UINT64(s, u64);
|
||||
|
||||
if (u64 != 0x1234567890ABCDEFULL)
|
||||
goto out;
|
||||
|
||||
out:
|
||||
Stream_Free(s, TRUE);
|
||||
return rc;
|
||||
|
@ -366,6 +409,7 @@ static BOOL TestStream_Seek(void)
|
|||
{
|
||||
BOOL rc = FALSE;
|
||||
wStream* s = Stream_New(NULL, 100);
|
||||
|
||||
if (!s)
|
||||
goto out;
|
||||
|
||||
|
@ -373,20 +417,27 @@ static BOOL TestStream_Seek(void)
|
|||
goto out;
|
||||
|
||||
Stream_Seek(s, 5);
|
||||
|
||||
if (s->pointer != s->buffer + 5)
|
||||
goto out;
|
||||
|
||||
Stream_Seek_UINT8(s);
|
||||
|
||||
if (s->pointer != s->buffer + 6)
|
||||
goto out;
|
||||
|
||||
Stream_Seek_UINT16(s);
|
||||
|
||||
if (s->pointer != s->buffer + 8)
|
||||
goto out;
|
||||
|
||||
Stream_Seek_UINT32(s);
|
||||
|
||||
if (s->pointer != s->buffer + 12)
|
||||
goto out;
|
||||
|
||||
Stream_Seek_UINT64(s);
|
||||
|
||||
if (s->pointer != s->buffer + 20)
|
||||
goto out;
|
||||
|
||||
|
@ -400,29 +451,40 @@ static BOOL TestStream_Rewind(void)
|
|||
{
|
||||
BOOL rc = FALSE;
|
||||
wStream* s = Stream_New(NULL, 100);
|
||||
|
||||
if (!s)
|
||||
goto out;
|
||||
|
||||
if (s->pointer != s->buffer)
|
||||
goto out;
|
||||
|
||||
Stream_Seek(s, 100);
|
||||
|
||||
if (s->pointer != s->buffer + 100)
|
||||
goto out;
|
||||
|
||||
Stream_Rewind(s, 10);
|
||||
|
||||
if (s->pointer != s->buffer + 90)
|
||||
goto out;
|
||||
|
||||
Stream_Rewind_UINT8(s);
|
||||
|
||||
if (s->pointer != s->buffer + 89)
|
||||
goto out;
|
||||
|
||||
Stream_Rewind_UINT16(s);
|
||||
|
||||
if (s->pointer != s->buffer + 87)
|
||||
goto out;
|
||||
|
||||
Stream_Rewind_UINT32(s);
|
||||
|
||||
if (s->pointer != s->buffer + 83)
|
||||
goto out;
|
||||
|
||||
Stream_Rewind_UINT64(s);
|
||||
|
||||
if (s->pointer != s->buffer + 75)
|
||||
goto out;
|
||||
|
||||
|
@ -438,27 +500,38 @@ static BOOL TestStream_Zero(void)
|
|||
BOOL rc = FALSE;
|
||||
const BYTE data[] = "someteststreamdata";
|
||||
wStream* s = Stream_New(NULL, sizeof(data));
|
||||
|
||||
if (!s)
|
||||
goto out;
|
||||
|
||||
Stream_Write(s, data, sizeof(data));
|
||||
|
||||
if (memcmp(Stream_Buffer(s), data, sizeof(data)) != 0)
|
||||
goto out;
|
||||
|
||||
Stream_SetPosition(s, 0);
|
||||
|
||||
if (s->pointer != s->buffer)
|
||||
goto out;
|
||||
|
||||
Stream_Zero(s, 5);
|
||||
|
||||
if (s->pointer != s->buffer + 5)
|
||||
goto out;
|
||||
if (memcmp(Stream_Pointer(s), data+5, sizeof(data)-5) != 0)
|
||||
|
||||
if (memcmp(Stream_Pointer(s), data + 5, sizeof(data) - 5) != 0)
|
||||
goto out;
|
||||
|
||||
Stream_SetPosition(s, 0);
|
||||
|
||||
if (s->pointer != s->buffer)
|
||||
goto out;
|
||||
for (x=0; x<5; x++)
|
||||
|
||||
for (x = 0; x < 5; x++)
|
||||
{
|
||||
UINT8 val;
|
||||
Stream_Read_UINT8(s, val);
|
||||
|
||||
if (val != 0)
|
||||
goto out;
|
||||
}
|
||||
|
@ -475,23 +548,33 @@ static BOOL TestStream_Fill(void)
|
|||
const BYTE fill[7] = "XXXXXXX";
|
||||
const BYTE data[] = "someteststreamdata";
|
||||
wStream* s = Stream_New(NULL, sizeof(data));
|
||||
|
||||
if (!s)
|
||||
goto out;
|
||||
|
||||
Stream_Write(s, data, sizeof(data));
|
||||
|
||||
if (memcmp(Stream_Buffer(s), data, sizeof(data)) != 0)
|
||||
goto out;
|
||||
|
||||
Stream_SetPosition(s, 0);
|
||||
|
||||
if (s->pointer != s->buffer)
|
||||
goto out;
|
||||
|
||||
Stream_Fill(s, fill[0], sizeof(fill));
|
||||
|
||||
if (s->pointer != s->buffer + sizeof(fill))
|
||||
goto out;
|
||||
if (memcmp(Stream_Pointer(s), data+sizeof(fill), sizeof(data)-sizeof(fill)) != 0)
|
||||
|
||||
if (memcmp(Stream_Pointer(s), data + sizeof(fill), sizeof(data) - sizeof(fill)) != 0)
|
||||
goto out;
|
||||
|
||||
Stream_SetPosition(s, 0);
|
||||
|
||||
if (s->pointer != s->buffer)
|
||||
goto out;
|
||||
|
||||
if (memcmp(Stream_Pointer(s), fill, sizeof(fill)) != 0)
|
||||
goto out;
|
||||
|
||||
|
@ -507,30 +590,40 @@ static BOOL TestStream_Copy(void)
|
|||
const BYTE data[] = "someteststreamdata";
|
||||
wStream* s = Stream_New(NULL, sizeof(data));
|
||||
wStream* d = Stream_New(NULL, sizeof(data));
|
||||
|
||||
if (!s || !d)
|
||||
goto out;
|
||||
|
||||
if (s->pointer != s->buffer)
|
||||
goto out;
|
||||
|
||||
Stream_Write(s, data, sizeof(data));
|
||||
|
||||
if (memcmp(Stream_Buffer(s), data, sizeof(data)) != 0)
|
||||
goto out;
|
||||
|
||||
if (s->pointer != s->buffer + sizeof(data))
|
||||
goto out;
|
||||
|
||||
Stream_SetPosition(s, 0);
|
||||
|
||||
if (s->pointer != s->buffer)
|
||||
goto out;
|
||||
|
||||
Stream_Copy(s, d, sizeof(data));
|
||||
|
||||
if (s->pointer != s->buffer + sizeof(data))
|
||||
goto out;
|
||||
|
||||
if (d->pointer != d->buffer + sizeof(data))
|
||||
goto out;
|
||||
|
||||
if (Stream_GetPosition(s) != Stream_GetPosition(d))
|
||||
goto out;
|
||||
|
||||
if (memcmp(Stream_Buffer(s), data, sizeof(data)) != 0)
|
||||
goto out;
|
||||
|
||||
if (memcmp(Stream_Buffer(d), data, sizeof(data)) != 0)
|
||||
goto out;
|
||||
|
||||
|
@ -541,9 +634,11 @@ out:
|
|||
return rc;
|
||||
}
|
||||
|
||||
|
||||
int TestStream(int argc, char* argv[])
|
||||
{
|
||||
WINPR_UNUSED(argc);
|
||||
WINPR_UNUSED(argv);
|
||||
|
||||
if (!TestStream_Create(200, FALSE))
|
||||
return 1;
|
||||
|
||||
|
|
Loading…
Reference in New Issue