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