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