#include <config.h>
#include <glib.h>
+#include <string.h>
#include <mono/metadata/object.h>
#include <mono/metadata/process.h>
#include <mono/metadata/appdomain.h>
#include <mono/metadata/image.h>
#include <mono/metadata/cil-coff.h>
+#include <mono/metadata/exception.h>
#include <mono/io-layer/io-layer.h>
#undef DEBUG
{
HANDLE handle;
+ MONO_ARCH_SAVE_REGS;
+
/* GetCurrentProcess returns a pseudo-handle, so use
* OpenProcess instead
*/
guint32 ves_icall_System_Diagnostics_Process_GetPid_internal (void)
{
+ MONO_ARCH_SAVE_REGS;
+
return(GetCurrentProcessId ());
}
void ves_icall_System_Diagnostics_Process_Process_free_internal (MonoObject *this,
HANDLE process)
{
+ MONO_ARCH_SAVE_REGS;
+
#ifdef THREAD_DEBUG
g_message (G_GNUC_PRETTY_FUNCTION ": Closing process %p, handle %p",
this, process);
static gpointer process_get_versioninfo_block (gpointer data,
version_data *block)
{
- block->data_len=*(((guint16 *)data)++);
- block->value_len=*(((guint16 *)data)++);
+ block->data_len=*((guint16 *)data);
+ data = (char *)data + sizeof(guint16);
+ block->value_len=*((guint16 *)data);
+ data = (char *)data + sizeof(guint16);
/* No idea what the type is supposed to indicate */
- block->type=*(((guint16 *)data)++);
+ block->type=*((guint16 *)data);
+ data = (char *)data + sizeof(guint16);
block->key=((gunichar2 *)data);
/* skip over the key (including the terminator) */
return(data_ptr);
}
-/* Returns a pointer to the byte following the String block */
+/* Returns a pointer to the byte following the String block, or NULL
+ * if the data read hits padding. We can't recover from this because
+ * the data length does not include padding bytes, so it's not
+ * possible to just return the start position + length.
+ */
static gpointer process_read_string_block (MonoObject *filever,
gpointer data_ptr,
guint16 data_len,
data_ptr=(gpointer)(((unsigned)data_ptr+3) & (~3));
data_ptr=process_get_versioninfo_block (data_ptr, &block);
+ if(block.data_len==0) {
+ /* We must have hit padding, so give up
+ * processing now
+ */
+#ifdef DEBUG
+ g_message (G_GNUC_PRETTY_FUNCTION
+ ": Hit 0-length block, giving up");
+#endif
+ return(NULL);
+ }
+
string_len=string_len+block.data_len;
value=(gunichar2 *)data_ptr;
/* Skip over the value */
return(data_ptr);
}
-/* returns a pointer to the byte following the Stringtable block */
+/* returns a pointer to the byte following the Stringtable block, or
+ * NULL if the data read hits padding. We can't recover from this
+ * because the data length does not include padding bytes, so it's not
+ * possible to just return the start position + length
+ */
static gpointer process_read_stringtable_block (MonoObject *filever,
gpointer data_ptr,
guint16 data_len)
data_ptr=(gpointer)(((unsigned)data_ptr+3) & (~3));
data_ptr=process_get_versioninfo_block (data_ptr, &block);
+ if(block.data_len==0) {
+ /* We must have hit padding, so give up
+ * processing now
+ */
+#ifdef DEBUG
+ g_message (G_GNUC_PRETTY_FUNCTION
+ ": Hit 0-length block, giving up");
+#endif
+ return(NULL);
+ }
string_len=string_len+block.data_len;
if(!memcmp (block.key, &uni_key, unicode_bytes (block.key)) ||
block.data_len,
FALSE);
}
+
+ if(data_ptr==NULL) {
+ /* Child block hit padding */
+#ifdef DEBUG
+ g_message (G_GNUC_PRETTY_FUNCTION ": Child block hit 0-length block, giving up");
+#endif
+ return(NULL);
+ }
}
return(data_ptr);
return;
}
- ffi=(((VS_FIXEDFILEINFO *)data_ptr)++);
+ ffi=((VS_FIXEDFILEINFO *)data_ptr);
+ data_ptr = (char *)data_ptr + sizeof(VS_FIXEDFILEINFO);
if((ffi->dwSignature!=VS_FFI_SIGNATURE) ||
(ffi->dwStrucVersion!=VS_FFI_STRUCVERSION)) {
#ifdef DEBUG
data_ptr=(gpointer)(((unsigned)data_ptr+3) & (~3));
data_ptr=process_get_versioninfo_block (data_ptr, &block);
+ if(block.data_len==0) {
+ /* We must have hit padding, so give up
+ * processing now
+ */
+#ifdef DEBUG
+ g_message (G_GNUC_PRETTY_FUNCTION
+ ": Hit 0-length block, giving up");
+#endif
+ return;
+ }
+
data_len=data_len-block.data_len;
if(!memcmp (block.key, &var_key, unicode_bytes (block.key))) {
return;
#endif
}
+
+ if(data_ptr==NULL) {
+ /* Child block hit padding */
+#ifdef DEBUG
+ g_message (G_GNUC_PRETTY_FUNCTION ": Child block hit 0-length block, giving up");
+#endif
+ return;
+ }
}
}
MonoArray *arr;
guint32 i;
+ MONO_ARCH_SAVE_REGS;
+
STASH_SYS_ASS (this);
/* Make sure the first entry is the main module */
MonoImage *image;
guchar *filename_utf8;
+ MONO_ARCH_SAVE_REGS;
+
STASH_SYS_ASS (this);
filename_utf8=mono_string_to_utf8 (filename);
STARTUPINFO startinfo={0};
PROCESS_INFORMATION procinfo;
+ MONO_ARCH_SAVE_REGS;
+
startinfo.cb=sizeof(STARTUPINFO);
startinfo.dwFlags=STARTF_USESTDHANDLES;
startinfo.hStdInput=stdin_handle;
ret=CreateProcess (NULL, mono_string_chars (cmd), NULL, NULL, TRUE, CREATE_UNICODE_ENVIRONMENT, NULL, dir, &startinfo, &procinfo);
- if(ret==TRUE) {
+ if(ret) {
process_info->process_handle=procinfo.hProcess;
process_info->thread_handle=procinfo.hThread;
process_info->pid=procinfo.dwProcessId;
{
guint32 ret;
+ MONO_ARCH_SAVE_REGS;
+
if(ms<0) {
/* Wait forever */
ret=WaitForSingleObject (process, INFINITE);
gint64 ticks;
FILETIME create_time, exit_time, kernel_time, user_time;
+ MONO_ARCH_SAVE_REGS;
+
ret=GetProcessTimes (process, &create_time, &exit_time, &kernel_time,
&user_time);
if(ret==TRUE) {
gint64 ticks;
FILETIME create_time, exit_time, kernel_time, user_time;
+ MONO_ARCH_SAVE_REGS;
+
ret=GetProcessTimes (process, &create_time, &exit_time, &kernel_time,
&user_time);
if(ret==TRUE) {
{
guint32 code;
+ MONO_ARCH_SAVE_REGS;
+
GetExitCodeProcess (process, &code);
#ifdef DEBUG
guint32 needed;
guint32 len;
+ MONO_ARCH_SAVE_REGS;
+
ok=EnumProcessModules (process, &mod, sizeof(mod), &needed);
if(ok==FALSE) {
return(NULL);
guint32 needed, count, i;
guint32 pids[1024];
+ MONO_ARCH_SAVE_REGS;
+
ret=EnumProcesses (pids, sizeof(pids), &needed);
if(ret==FALSE) {
/* FIXME: throw an exception */
{
gboolean ret;
+ MONO_ARCH_SAVE_REGS;
+
ret=GetProcessWorkingSetSize (process, min, max);
return(ret);
guint32 ws_min;
guint32 ws_max;
+ MONO_ARCH_SAVE_REGS;
+
ret=GetProcessWorkingSetSize (process, &ws_min, &ws_max);
if(ret==FALSE) {
return(FALSE);