Skip to content

Add Mono EventPipe rundown support. #47339

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

Merged
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
3 changes: 3 additions & 0 deletions src/mono/mono/eglib/eglib-remap.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#define g_clear_error monoeg_g_clear_error
#define g_convert monoeg_g_convert
#define g_convert_error_quark monoeg_g_convert_error_quark
#define g_fixed_buffer_custom_allocator monoeg_g_fixed_buffer_custom_allocator
#define g_dir_close monoeg_g_dir_close
#define g_dir_open monoeg_g_dir_open
#define g_dir_read_name monoeg_g_dir_read_name
Expand Down Expand Up @@ -261,6 +262,7 @@
#define g_usleep monoeg_g_usleep
#define g_utf16_to_ucs4 monoeg_g_utf16_to_ucs4
#define g_utf16_to_utf8 monoeg_g_utf16_to_utf8
#define g_utf16_to_utf8_custom_alloc monoeg_g_utf16_to_utf8_custom_alloc
#define g_utf16_ascii_equal monoeg_g_utf16_ascii_equal
#define g_utf16_asciiz_equal monoeg_g_utf16_asciiz_equal
#define g_utf8_jump_table monoeg_g_utf8_jump_table
Expand All @@ -272,6 +274,7 @@
#define g_utf8_strup monoeg_g_utf8_strup
#define g_utf8_to_ucs4_fast monoeg_g_utf8_to_ucs4_fast
#define g_utf8_to_utf16 monoeg_g_utf8_to_utf16
#define g_utf8_to_utf16_custom_alloc monoeg_g_utf8_to_utf16_custom_alloc
#define g_utf8_validate monoeg_g_utf8_validate
#define g_unichar_to_utf8 monoeg_g_unichar_to_utf8
#define g_unichar_is_space monoeg_g_unichar_is_space
Expand Down
74 changes: 65 additions & 9 deletions src/mono/mono/eglib/giconv.c
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ g_utf8_to_ucs4_fast (const gchar *str, glong len, glong *items_written)
}

static gunichar2 *
eg_utf8_to_utf16_general (const gchar *str, glong len, glong *items_read, glong *items_written, gboolean include_nuls, gboolean replace_invalid_codepoints, GError **err)
eg_utf8_to_utf16_general (const gchar *str, glong len, glong *items_read, glong *items_written, gboolean include_nuls, gboolean replace_invalid_codepoints, GCustomAllocator custom_alloc_func, gpointer custom_alloc_data, GError **err)
{
gunichar2 *outbuf, *outptr;
size_t outlen = 0;
Expand Down Expand Up @@ -881,7 +881,16 @@ eg_utf8_to_utf16_general (const gchar *str, glong len, glong *items_read, glong
if (items_written)
*items_written = outlen;

outptr = outbuf = g_malloc ((outlen + 1) * sizeof (gunichar2));
if (G_LIKELY (!custom_alloc_func))
outptr = outbuf = g_malloc ((outlen + 1) * sizeof (gunichar2));
else
outptr = outbuf = (gunichar2 *)custom_alloc_func ((outlen + 1) * sizeof (gunichar2), custom_alloc_data);

if (G_UNLIKELY (custom_alloc_func && !outbuf)) {
mono_set_errno (ENOMEM);
goto error;
}

inptr = (char *) str;
inleft = len;

Expand All @@ -908,8 +917,11 @@ eg_utf8_to_utf16_general (const gchar *str, glong len, glong *items_read, glong

return outbuf;

error:
if (errno == EILSEQ) {
error:
if (errno == ENOMEM) {
g_set_error (err, G_CONVERT_ERROR, G_CONVERT_ERROR_NO_MEMORY,
"Allocation failed.");
} else if (errno == EILSEQ) {
g_set_error (err, G_CONVERT_ERROR, G_CONVERT_ERROR_ILLEGAL_SEQUENCE,
"Illegal byte sequence encounted in the input.");
} else if (items_read) {
Expand All @@ -931,19 +943,25 @@ eg_utf8_to_utf16_general (const gchar *str, glong len, glong *items_read, glong
gunichar2 *
g_utf8_to_utf16 (const gchar *str, glong len, glong *items_read, glong *items_written, GError **err)
{
return eg_utf8_to_utf16_general (str, len, items_read, items_written, FALSE, FALSE, err);
return eg_utf8_to_utf16_general (str, len, items_read, items_written, FALSE, FALSE, NULL, NULL, err);
}

gunichar2 *
g_utf8_to_utf16_custom_alloc (const gchar *str, glong len, glong *items_read, glong *items_written, GCustomAllocator custom_alloc_func, gpointer custom_alloc_data, GError **err)
{
return eg_utf8_to_utf16_general (str, len, items_read, items_written, FALSE, FALSE, custom_alloc_func, custom_alloc_data, err);
}

gunichar2 *
eg_utf8_to_utf16_with_nuls (const gchar *str, glong len, glong *items_read, glong *items_written, GError **err)
{
return eg_utf8_to_utf16_general (str, len, items_read, items_written, TRUE, FALSE, err);
return eg_utf8_to_utf16_general (str, len, items_read, items_written, TRUE, FALSE, NULL, NULL, err);
}

gunichar2 *
eg_wtf8_to_utf16 (const gchar *str, glong len, glong *items_read, glong *items_written, GError **err)
{
return eg_utf8_to_utf16_general (str, len, items_read, items_written, TRUE, TRUE, err);
return eg_utf8_to_utf16_general (str, len, items_read, items_written, TRUE, TRUE, NULL, NULL, err);
}

gunichar *
Expand Down Expand Up @@ -1018,8 +1036,9 @@ g_utf8_to_ucs4 (const gchar *str, glong len, glong *items_read, glong *items_wri
return outbuf;
}

static
gchar *
g_utf16_to_utf8 (const gunichar2 *str, glong len, glong *items_read, glong *items_written, GError **err)
eg_utf16_to_utf8_general (const gunichar2 *str, glong len, glong *items_read, glong *items_written, GCustomAllocator custom_alloc_func, gpointer custom_alloc_data, GError **err)
{
char *inptr, *outbuf, *outptr;
size_t outlen = 0;
Expand Down Expand Up @@ -1077,8 +1096,19 @@ g_utf16_to_utf8 (const gunichar2 *str, glong len, glong *items_read, glong *item

if (items_written)
*items_written = outlen;

if (G_LIKELY (!custom_alloc_func))
outptr = outbuf = g_malloc (outlen + 1);
else
outptr = outbuf = (char *)custom_alloc_func (outlen + 1, custom_alloc_data);

if (G_UNLIKELY (custom_alloc_func && !outbuf)) {
g_set_error (err, G_CONVERT_ERROR, G_CONVERT_ERROR_NO_MEMORY, "Allocation failed.");
if (items_written)
*items_written = 0;
return NULL;
}

outptr = outbuf = g_malloc (outlen + 1);
inptr = (char *) str;
inleft = len * 2;

Expand All @@ -1098,6 +1128,18 @@ g_utf16_to_utf8 (const gunichar2 *str, glong len, glong *items_read, glong *item
return outbuf;
}

gchar *
g_utf16_to_utf8 (const gunichar2 *str, glong len, glong *items_read, glong *items_written, GError **err)
{
return eg_utf16_to_utf8_general (str, len, items_read, items_written, NULL, NULL, err);
}

gchar *
g_utf16_to_utf8_custom_alloc (const gunichar2 *str, glong len, glong *items_read, glong *items_written, GCustomAllocator custom_alloc_func, gpointer custom_alloc_data, GError **err)
{
return eg_utf16_to_utf8_general (str, len, items_read, items_written, custom_alloc_func, custom_alloc_data, err);
}

gunichar *
g_utf16_to_ucs4 (const gunichar2 *str, glong len, glong *items_read, glong *items_written, GError **err)
{
Expand Down Expand Up @@ -1302,3 +1344,17 @@ g_ucs4_to_utf16 (const gunichar *str, glong len, glong *items_read, glong *items

return outbuf;
}

gpointer
g_fixed_buffer_custom_allocator (gsize req_size, gpointer custom_alloc_data)
{
GFixedBufferCustomAllocatorData *fixed_buffer_custom_alloc_data = (GFixedBufferCustomAllocatorData *)custom_alloc_data;
if (!fixed_buffer_custom_alloc_data)
return NULL;

fixed_buffer_custom_alloc_data->req_buffer_size = req_size;
if (req_size > fixed_buffer_custom_alloc_data->buffer_size)
return NULL;

return fixed_buffer_custom_alloc_data->buffer;
}
17 changes: 16 additions & 1 deletion src/mono/mono/eglib/glib.h
Original file line number Diff line number Diff line change
Expand Up @@ -1004,7 +1004,8 @@ typedef enum {
G_CONVERT_ERROR_FAILED,
G_CONVERT_ERROR_PARTIAL_INPUT,
G_CONVERT_ERROR_BAD_URI,
G_CONVERT_ERROR_NOT_ABSOLUTE_PATH
G_CONVERT_ERROR_NOT_ABSOLUTE_PATH,
G_CONVERT_ERROR_NO_MEMORY
} GConvertError;

gchar *g_utf8_strup (const gchar *str, gssize len);
Expand All @@ -1031,6 +1032,20 @@ size_t g_utf16_len (const gunichar2 *);
#define u16to8(str) g_utf16_to_utf8(str, (glong)strlen(str), NULL, NULL, NULL)
#endif

typedef gpointer (*GCustomAllocator) (gsize req_size, gpointer custom_alloc_data);

typedef struct {
gpointer buffer;
gsize buffer_size;
gsize req_buffer_size;
} GFixedBufferCustomAllocatorData;

gpointer
g_fixed_buffer_custom_allocator (gsize req_size, gpointer custom_alloc_data);

gunichar2 *g_utf8_to_utf16_custom_alloc (const gchar *str, glong len, glong *items_read, glong *items_written, GCustomAllocator custom_alloc_func, gpointer custom_alloc_data, GError **err);
gchar *g_utf16_to_utf8_custom_alloc (const gunichar2 *str, glong len, glong *items_read, glong *items_written, GCustomAllocator custom_alloc_func, gpointer custom_alloc_data, GError **err);

/*
* Path
*/
Expand Down
10 changes: 7 additions & 3 deletions src/mono/mono/eglib/gmodule-win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,17 +163,21 @@ g_module_address (void *addr, char *file_name, size_t file_name_len,
* this being an exception.
*/
BOOL ret = GetModuleHandleExW (GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (LPCWSTR)addr, &module);
if (ret)
if (!ret)
return FALSE;

if (file_name != NULL && file_name_len >= 1) {
/* sigh, non-const. AIX for POSIX is the same way. */
WCHAR fname [MAX_PATH];
DWORD bytes = GetModuleFileNameW (module, fname, G_N_ELEMENTS (fname));
/* XXX: check for ERROR_INSUFFICIENT_BUFFER? */
if (bytes) {
/* Convert back to UTF-8 from wide for runtime */
*file_name = '\0'; /* XXX */
GFixedBufferCustomAllocatorData custom_alloc_data;
custom_alloc_data.buffer = file_name;
custom_alloc_data.buffer_size = file_name_len;
custom_alloc_data.req_buffer_size = 0;
if (!g_utf16_to_utf8_custom_alloc (fname, -1, NULL, NULL, g_fixed_buffer_custom_allocator, &custom_alloc_data, NULL))
*file_name = '\0';
} else {
*file_name = '\0';
}
Expand Down
Loading