Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mono / metadata / w32process-win32-uwp.c
1 /**
2  * \file
3  * UWP process support for Mono.
4  *
5  * Copyright 2016 Microsoft
6  * Licensed under the MIT license. See LICENSE file in the project root for full license information.
7 */
8 #include <config.h>
9 #include <glib.h>
10 #include "mono/utils/mono-compiler.h"
11
12 #if G_HAVE_API_SUPPORT(HAVE_UWP_WINAPI_SUPPORT)
13 #include <windows.h>
14 #include <mono/metadata/object-internals.h>
15 #include "mono/metadata/w32process.h"
16 #include "mono/metadata/w32process-internals.h"
17 #include "mono/metadata/w32process-win32-internals.h"
18
19 gboolean
20 mono_process_win_enum_processes (DWORD *pids, DWORD count, DWORD *needed)
21 {
22         g_unsupported_api ("EnumProcesses");
23         *needed = 0;
24         SetLastError (ERROR_NOT_SUPPORTED);
25
26         return FALSE;
27 }
28
29 HANDLE
30 ves_icall_System_Diagnostics_Process_GetProcess_internal (guint32 pid)
31 {
32         MonoError mono_error;
33         error_init (&mono_error);
34
35         g_unsupported_api ("OpenProcess");
36
37         mono_error_set_not_supported (&mono_error, G_UNSUPPORTED_API, "OpenProcess");
38         mono_error_set_pending_exception (&mono_error);
39
40         SetLastError (ERROR_NOT_SUPPORTED);
41
42         return NULL;
43 }
44
45 void
46 mono_w32process_get_fileversion (MonoObject *filever, gunichar2 *filename, MonoError *error)
47 {
48         g_unsupported_api ("GetFileVersionInfoSize, GetFileVersionInfo, VerQueryValue, VerLanguageName");
49
50         error_init (error);
51         mono_error_set_not_supported (error, G_UNSUPPORTED_API, "GetFileVersionInfoSize, GetFileVersionInfo, VerQueryValue, VerLanguageName");
52
53         SetLastError (ERROR_NOT_SUPPORTED);
54 }
55
56 MonoObject*
57 process_add_module (HANDLE process, HMODULE mod, gunichar2 *filename, gunichar2 *modulename, MonoClass *proc_class, MonoError *error)
58 {
59         g_unsupported_api ("GetModuleInformation");
60
61         error_init (error);
62         mono_error_set_not_supported (error, G_UNSUPPORTED_API, "GetModuleInformation");
63
64         SetLastError (ERROR_NOT_SUPPORTED);
65
66         return NULL;
67 }
68
69 MonoArray *
70 ves_icall_System_Diagnostics_Process_GetModules_internal (MonoObject *this_obj, HANDLE process)
71 {
72         MonoError mono_error;
73         error_init (&mono_error);
74
75         g_unsupported_api ("EnumProcessModules, GetModuleBaseName, GetModuleFileNameEx");
76
77         mono_error_set_not_supported (&mono_error, G_UNSUPPORTED_API, "EnumProcessModules, GetModuleBaseName, GetModuleFileNameEx");
78         mono_error_set_pending_exception (&mono_error);
79
80         SetLastError (ERROR_NOT_SUPPORTED);
81
82         return NULL;
83 }
84
85 MonoBoolean
86 ves_icall_System_Diagnostics_Process_ShellExecuteEx_internal (MonoW32ProcessStartInfo *proc_start_info, MonoW32ProcessInfo *process_info)
87 {
88         MonoError mono_error;
89         error_init (&mono_error);
90
91         g_unsupported_api ("ShellExecuteEx");
92
93         mono_error_set_not_supported (&mono_error, G_UNSUPPORTED_API, "ShellExecuteEx");
94         mono_error_set_pending_exception (&mono_error);
95
96         process_info->pid = (guint32)(-ERROR_NOT_SUPPORTED);
97         SetLastError (ERROR_NOT_SUPPORTED);
98
99         return FALSE;
100 }
101
102 MonoString *
103 ves_icall_System_Diagnostics_Process_ProcessName_internal (HANDLE process)
104 {
105         MonoError error;
106         MonoString *string;
107         gunichar2 name[MAX_PATH];
108         guint32 len;
109
110         len = GetModuleFileName (NULL, name, G_N_ELEMENTS (name));
111         if (len == 0)
112                 return NULL;
113
114         string = mono_string_new_utf16_checked (mono_domain_get (), name, len, &error);
115         if (!mono_error_ok (&error))
116                 mono_error_set_pending_exception (&error);
117
118         return string;
119 }
120
121 void
122 mono_process_init_startup_info (HANDLE stdin_handle, HANDLE stdout_handle, HANDLE stderr_handle, STARTUPINFO *startinfo)
123 {
124         startinfo->cb = sizeof(STARTUPINFO);
125         startinfo->dwFlags = 0;
126         startinfo->hStdInput = INVALID_HANDLE_VALUE;
127         startinfo->hStdOutput = INVALID_HANDLE_VALUE;
128         startinfo->hStdError = INVALID_HANDLE_VALUE;
129         return;
130 }
131
132 gboolean
133 mono_process_create_process (MonoW32ProcessInfo *mono_process_info, MonoString *cmd, guint32 creation_flags,
134         gunichar2 *env_vars, gunichar2 *dir, STARTUPINFO *start_info, PROCESS_INFORMATION *process_info)
135 {
136         MonoError       mono_error;
137         gchar           *api_name = "";
138
139         if (mono_process_info->username) {
140                 api_name = "CreateProcessWithLogonW";
141         } else {
142                 api_name = "CreateProcess";
143         }
144
145         memset (&process_info, 0, sizeof (PROCESS_INFORMATION));
146         g_unsupported_api (api_name);
147
148         error_init (&mono_error);
149         mono_error_set_not_supported (&mono_error, G_UNSUPPORTED_API, api_name);
150         mono_error_set_pending_exception (&mono_error);
151
152         SetLastError (ERROR_NOT_SUPPORTED);
153
154         return FALSE;
155 }
156
157 MonoBoolean
158 mono_icall_get_process_working_set_size (gpointer handle, gsize *min, gsize *max)
159 {
160         MonoError mono_error;
161         error_init (&mono_error);
162
163         g_unsupported_api ("GetProcessWorkingSetSize");
164
165         mono_error_set_not_supported(&mono_error, G_UNSUPPORTED_API, "GetProcessWorkingSetSize");
166         mono_error_set_pending_exception (&mono_error);
167
168         SetLastError (ERROR_NOT_SUPPORTED);
169
170         return FALSE;
171 }
172
173 MonoBoolean
174 mono_icall_set_process_working_set_size (gpointer handle, gsize min, gsize max)
175 {
176         MonoError mono_error;
177         error_init (&mono_error);
178
179         g_unsupported_api ("SetProcessWorkingSetSize");
180
181         mono_error_set_not_supported (&mono_error, G_UNSUPPORTED_API, "SetProcessWorkingSetSize");
182         mono_error_set_pending_exception (&mono_error);
183
184         SetLastError (ERROR_NOT_SUPPORTED);
185
186         return FALSE;
187 }
188
189 gint32
190 mono_icall_get_priority_class (gpointer handle)
191 {
192         MonoError mono_error;
193         error_init (&mono_error);
194
195         g_unsupported_api ("GetPriorityClass");
196
197         mono_error_set_not_supported (&mono_error, G_UNSUPPORTED_API, "GetPriorityClass");
198         mono_error_set_pending_exception (&mono_error);
199
200         SetLastError (ERROR_NOT_SUPPORTED);
201
202         return FALSE;
203 }
204
205 MonoBoolean
206 mono_icall_set_priority_class (gpointer handle, gint32 priorityClass)
207 {
208         MonoError mono_error;
209         error_init (&mono_error);
210
211         g_unsupported_api ("SetPriorityClass");
212
213         mono_error_set_not_supported(&mono_error, G_UNSUPPORTED_API, "SetPriorityClass");
214         mono_error_set_pending_exception (&mono_error);
215
216         SetLastError (ERROR_NOT_SUPPORTED);
217
218         return FALSE;
219 }
220
221 #else /* G_HAVE_API_SUPPORT(HAVE_UWP_WINAPI_SUPPORT) */
222
223 MONO_EMPTY_SOURCE_FILE (process_windows_uwp);
224 #endif /* G_HAVE_API_SUPPORT(HAVE_UWP_WINAPI_SUPPORT) */