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