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
23 #define WIN32_NO_STATUS
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
;
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
, ¶ms
);
44 IoCompleteRequest( irp
, IO_NO_INCREMENT
);
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
;
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
;
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
);
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
);
95 static NTSTATUS WINAPI
android_start_device(void *param
, ULONG size
)
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
, ¶ms
);
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
, ¶ms
)) return FALSE
;
130 callback_table
= NtCurrentTeb()->Peb
->KernelCallbackTable
;
131 callback_table
[client_start_device
] = android_start_device
;
137 /***********************************************************************
138 * wine_create_desktop (wineandroid.@)
140 BOOL CDECL
wine_create_desktop( UINT width
, UINT height
)
142 return ANDROID_CALL( create_desktop
, NULL
);