dinput: Clear DIA_APPNOMAP BuildActionMap flag with specific device semantic.
[wine.git] / dlls / wineandroid.drv / dllmain.c
blob3f6dbd388ebf822437b000ee87fc1b4973767976
1 /*
2 * wineandroid.drv entry points
4 * Copyright 2022 Jacek Caban for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdarg.h>
22 #include "ntstatus.h"
23 #define WIN32_NO_STATUS
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winternl.h"
27 #include "winioctl.h"
28 #include "ddk/wdm.h"
29 #include "unixlib.h"
30 #include "wine/debug.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(android);
35 extern NTSTATUS CDECL wine_ntoskrnl_main_loop( HANDLE stop_event );
36 static HANDLE stop_event;
37 static HANDLE thread;
40 static NTSTATUS WINAPI ioctl_callback( DEVICE_OBJECT *device, IRP *irp )
42 struct ioctl_params params = { .irp = irp, .client_id = HandleToUlong(PsGetCurrentProcessId()) };
43 NTSTATUS status = ANDROID_CALL( dispatch_ioctl, &params );
44 IoCompleteRequest( irp, IO_NO_INCREMENT );
45 return status;
48 static NTSTATUS CALLBACK init_android_driver( DRIVER_OBJECT *driver, UNICODE_STRING *name )
50 static const WCHAR device_nameW[] = {'\\','D','e','v','i','c','e','\\','W','i','n','e','A','n','d','r','o','i','d',0 };
51 static const WCHAR device_linkW[] = {'\\','?','?','\\','W','i','n','e','A','n','d','r','o','i','d',0 };
53 UNICODE_STRING nameW, linkW;
54 DEVICE_OBJECT *device;
55 NTSTATUS status;
57 driver->MajorFunction[IRP_MJ_DEVICE_CONTROL] = ioctl_callback;
59 RtlInitUnicodeString( &nameW, device_nameW );
60 RtlInitUnicodeString( &linkW, device_linkW );
62 if ((status = IoCreateDevice( driver, 0, &nameW, 0, 0, FALSE, &device ))) return status;
63 return IoCreateSymbolicLink( &linkW, &nameW );
66 static DWORD CALLBACK device_thread( void *arg )
68 static const WCHAR driver_nameW[] = {'\\','D','r','i','v','e','r','\\','W','i','n','e','A','n','d','r','o','i','d',0 };
70 HANDLE start_event = arg;
71 UNICODE_STRING nameW;
72 NTSTATUS status;
73 DWORD ret;
75 TRACE( "starting process %lx\n", GetCurrentProcessId() );
77 if (ANDROID_CALL( java_init, NULL )) return 0; /* not running under Java */
79 RtlInitUnicodeString( &nameW, driver_nameW );
80 if ((status = IoCreateDriver( &nameW, init_android_driver )))
82 FIXME( "failed to create driver error %lx\n", status );
83 return status;
86 stop_event = CreateEventW( NULL, TRUE, FALSE, NULL );
87 SetEvent( start_event );
89 ret = wine_ntoskrnl_main_loop( stop_event );
91 ANDROID_CALL( java_uninit, NULL );
92 return ret;
95 static NTSTATUS WINAPI android_start_device(void *param, ULONG size)
97 HANDLE handles[2];
99 handles[0] = CreateEventW( NULL, TRUE, FALSE, NULL );
100 handles[1] = thread = CreateThread( NULL, 0, device_thread, handles[0], 0, NULL );
101 WaitForMultipleObjects( 2, handles, FALSE, INFINITE );
102 CloseHandle( handles[0] );
103 return HandleToULong( thread );
107 static void CALLBACK register_window_callback( ULONG_PTR arg1, ULONG_PTR arg2, ULONG_PTR arg3 )
109 struct register_window_params params = { .arg1 = arg1, .arg2 = arg2, .arg3 = arg3 };
110 ANDROID_CALL( register_window, &params );
114 /***********************************************************************
115 * dll initialisation routine
117 BOOL WINAPI DllMain( HINSTANCE inst, DWORD reason, LPVOID reserved )
119 struct init_params params;
120 void **callback_table;
122 if (reason == DLL_PROCESS_ATTACH) return TRUE;
124 DisableThreadLibraryCalls( inst );
125 if (__wine_init_unix_call()) return FALSE;
127 params.register_window_callback = register_window_callback;
128 if (ANDROID_CALL( init, &params )) return FALSE;
130 callback_table = NtCurrentTeb()->Peb->KernelCallbackTable;
131 callback_table[client_start_device] = android_start_device;
133 return TRUE;
137 /***********************************************************************
138 * wine_create_desktop (wineandroid.@)
140 BOOL CDECL wine_create_desktop( UINT width, UINT height )
142 return ANDROID_CALL( create_desktop, NULL );