2017-05-31 10:58:55 +02:00
|
|
|
/*
|
|
|
|
* Android driver initialisation functions
|
|
|
|
*
|
|
|
|
* Copyright 1996, 2013, 2017 Alexandre Julliard
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define NONAMELESSSTRUCT
|
|
|
|
#define NONAMELESSUNION
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <string.h>
|
2021-12-01 15:56:55 +01:00
|
|
|
#include <dlfcn.h>
|
2017-06-26 15:12:44 +02:00
|
|
|
#include <link.h>
|
2017-05-31 10:58:55 +02:00
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
2017-06-12 19:12:30 +02:00
|
|
|
#include "winreg.h"
|
2017-05-31 11:15:17 +02:00
|
|
|
#include "android.h"
|
|
|
|
#include "wine/server.h"
|
2017-05-31 10:58:55 +02:00
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(android);
|
|
|
|
|
2017-05-31 11:15:17 +02:00
|
|
|
unsigned int screen_width = 0;
|
|
|
|
unsigned int screen_height = 0;
|
|
|
|
RECT virtual_screen_rect = { 0, 0, 0, 0 };
|
|
|
|
|
|
|
|
static const unsigned int screen_bpp = 32; /* we don't support other modes */
|
|
|
|
|
2021-12-01 16:02:53 +01:00
|
|
|
static RECT monitor_rc_work;
|
2017-05-31 11:15:17 +02:00
|
|
|
static int device_init_done;
|
2021-12-01 16:02:53 +01:00
|
|
|
static BOOL force_display_devices_refresh;
|
2017-05-31 11:15:17 +02:00
|
|
|
|
2017-05-31 10:58:55 +02:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
struct gdi_physdev dev;
|
|
|
|
} ANDROID_PDEVICE;
|
|
|
|
|
2021-11-11 14:13:16 +01:00
|
|
|
static const struct user_driver_funcs android_drv_funcs;
|
2017-05-31 10:58:55 +02:00
|
|
|
|
2017-05-31 11:15:17 +02:00
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* init_monitors
|
|
|
|
*/
|
|
|
|
void init_monitors( int width, int height )
|
|
|
|
{
|
|
|
|
static const WCHAR trayW[] = {'S','h','e','l','l','_','T','r','a','y','W','n','d',0};
|
|
|
|
RECT rect;
|
|
|
|
HWND hwnd = FindWindowW( trayW, NULL );
|
|
|
|
|
|
|
|
virtual_screen_rect.right = width;
|
|
|
|
virtual_screen_rect.bottom = height;
|
2021-12-01 16:02:53 +01:00
|
|
|
monitor_rc_work = virtual_screen_rect;
|
2017-05-31 11:15:17 +02:00
|
|
|
|
|
|
|
if (!hwnd || !IsWindowVisible( hwnd )) return;
|
|
|
|
if (!GetWindowRect( hwnd, &rect )) return;
|
2021-12-01 16:02:53 +01:00
|
|
|
if (rect.top) monitor_rc_work.bottom = rect.top;
|
|
|
|
else monitor_rc_work.top = rect.bottom;
|
2017-05-31 11:15:17 +02:00
|
|
|
TRACE( "found tray %p %s work area %s\n", hwnd,
|
2021-12-01 16:02:53 +01:00
|
|
|
wine_dbgstr_rect( &rect ), wine_dbgstr_rect( &monitor_rc_work ));
|
|
|
|
|
|
|
|
if (*p_java_vm) /* if we're notified from Java thread, update registry */
|
|
|
|
{
|
|
|
|
UINT32 num_path, num_mode;
|
|
|
|
force_display_devices_refresh = TRUE;
|
|
|
|
/* trigger refresh in win32u */
|
|
|
|
NtUserGetDisplayConfigBufferSizes( QDC_ONLY_ACTIVE_PATHS, &num_path, &num_mode );
|
|
|
|
}
|
2017-05-31 11:15:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-12 19:12:30 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* set_screen_dpi
|
|
|
|
*/
|
|
|
|
void set_screen_dpi( DWORD dpi )
|
|
|
|
{
|
|
|
|
static const WCHAR dpi_key_name[] = {'S','o','f','t','w','a','r','e','\\','F','o','n','t','s',0};
|
|
|
|
static const WCHAR dpi_value_name[] = {'L','o','g','P','i','x','e','l','s',0};
|
|
|
|
HKEY hkey;
|
|
|
|
|
|
|
|
if (!RegCreateKeyW( HKEY_CURRENT_CONFIG, dpi_key_name, &hkey ))
|
|
|
|
{
|
|
|
|
RegSetValueExW( hkey, dpi_value_name, 0, REG_DWORD, (void *)&dpi, sizeof(DWORD) );
|
|
|
|
RegCloseKey( hkey );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-31 11:15:17 +02:00
|
|
|
/**********************************************************************
|
|
|
|
* fetch_display_metrics
|
|
|
|
*/
|
|
|
|
static void fetch_display_metrics(void)
|
|
|
|
{
|
2020-12-08 12:45:18 +01:00
|
|
|
if (*p_java_vm) return; /* for Java threads it will be set when the top view is created */
|
2017-05-31 11:15:17 +02:00
|
|
|
|
|
|
|
SERVER_START_REQ( get_window_rectangles )
|
|
|
|
{
|
|
|
|
req->handle = wine_server_user_handle( GetDesktopWindow() );
|
|
|
|
req->relative = COORDS_CLIENT;
|
|
|
|
if (!wine_server_call( req ))
|
|
|
|
{
|
|
|
|
screen_width = reply->window.right;
|
|
|
|
screen_height = reply->window.bottom;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
|
|
|
|
init_monitors( screen_width, screen_height );
|
|
|
|
TRACE( "screen %ux%u\n", screen_width, screen_height );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* device_init
|
|
|
|
*
|
|
|
|
* Perform initializations needed upon creation of the first device.
|
|
|
|
*/
|
|
|
|
static void device_init(void)
|
|
|
|
{
|
|
|
|
device_init_done = TRUE;
|
|
|
|
fetch_display_metrics();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-05-31 10:58:55 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* create_android_physdev
|
|
|
|
*/
|
|
|
|
static ANDROID_PDEVICE *create_android_physdev(void)
|
|
|
|
{
|
|
|
|
ANDROID_PDEVICE *physdev;
|
|
|
|
|
2017-05-31 11:15:17 +02:00
|
|
|
if (!device_init_done) device_init();
|
|
|
|
|
2017-05-31 10:58:55 +02:00
|
|
|
if (!(physdev = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*physdev) ))) return NULL;
|
|
|
|
return physdev;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* ANDROID_CreateDC
|
|
|
|
*/
|
2021-09-29 14:07:26 +02:00
|
|
|
static BOOL CDECL ANDROID_CreateDC( PHYSDEV *pdev, LPCWSTR device, LPCWSTR output,
|
|
|
|
const DEVMODEW *initData )
|
2017-05-31 10:58:55 +02:00
|
|
|
{
|
|
|
|
ANDROID_PDEVICE *physdev = create_android_physdev();
|
|
|
|
|
|
|
|
if (!physdev) return FALSE;
|
|
|
|
|
2021-11-11 14:13:16 +01:00
|
|
|
push_dc_driver( pdev, &physdev->dev, &android_drv_funcs.dc_funcs );
|
2017-05-31 10:58:55 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* ANDROID_CreateCompatibleDC
|
|
|
|
*/
|
2019-07-06 20:45:50 +02:00
|
|
|
static BOOL CDECL ANDROID_CreateCompatibleDC( PHYSDEV orig, PHYSDEV *pdev )
|
2017-05-31 10:58:55 +02:00
|
|
|
{
|
|
|
|
ANDROID_PDEVICE *physdev = create_android_physdev();
|
|
|
|
|
|
|
|
if (!physdev) return FALSE;
|
|
|
|
|
2021-11-11 14:13:16 +01:00
|
|
|
push_dc_driver( pdev, &physdev->dev, &android_drv_funcs.dc_funcs );
|
2017-05-31 10:58:55 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* ANDROID_DeleteDC
|
|
|
|
*/
|
2019-07-06 20:45:50 +02:00
|
|
|
static BOOL CDECL ANDROID_DeleteDC( PHYSDEV dev )
|
2017-05-31 10:58:55 +02:00
|
|
|
{
|
|
|
|
HeapFree( GetProcessHeap(), 0, dev );
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-21 15:53:40 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* ANDROID_ChangeDisplaySettingsEx
|
|
|
|
*/
|
|
|
|
LONG CDECL ANDROID_ChangeDisplaySettingsEx( LPCWSTR devname, LPDEVMODEW devmode,
|
|
|
|
HWND hwnd, DWORD flags, LPVOID lpvoid )
|
|
|
|
{
|
|
|
|
FIXME( "(%s,%p,%p,0x%08x,%p)\n", debugstr_w( devname ), devmode, hwnd, flags, lpvoid );
|
|
|
|
return DISP_CHANGE_SUCCESSFUL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-05-31 11:15:17 +02:00
|
|
|
/***********************************************************************
|
2021-12-01 16:02:53 +01:00
|
|
|
* ANDROID_UpdateDisplayDevices
|
2017-05-31 11:15:17 +02:00
|
|
|
*/
|
2021-12-01 16:02:53 +01:00
|
|
|
void CDECL ANDROID_UpdateDisplayDevices( const struct gdi_device_manager *device_manager,
|
|
|
|
BOOL force, void *param )
|
2017-05-31 11:15:17 +02:00
|
|
|
{
|
2021-12-01 16:02:53 +01:00
|
|
|
if (force || force_display_devices_refresh)
|
2017-05-31 11:15:17 +02:00
|
|
|
{
|
2021-12-01 16:02:53 +01:00
|
|
|
struct gdi_monitor gdi_monitor =
|
|
|
|
{
|
|
|
|
.rc_monitor = virtual_screen_rect,
|
|
|
|
.rc_work = monitor_rc_work,
|
|
|
|
.state_flags = DISPLAY_DEVICE_ACTIVE | DISPLAY_DEVICE_ATTACHED,
|
|
|
|
};
|
|
|
|
device_manager->add_monitor( &gdi_monitor, param );
|
|
|
|
force_display_devices_refresh = FALSE;
|
2017-05-31 11:15:17 +02:00
|
|
|
}
|
2017-06-21 15:53:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* ANDROID_EnumDisplaySettingsEx
|
|
|
|
*/
|
|
|
|
BOOL CDECL ANDROID_EnumDisplaySettingsEx( LPCWSTR name, DWORD n, LPDEVMODEW devmode, DWORD flags)
|
|
|
|
{
|
|
|
|
static const WCHAR dev_name[CCHDEVICENAME] =
|
|
|
|
{ 'W','i','n','e',' ','A','n','d','r','o','i','d',' ','d','r','i','v','e','r',0 };
|
|
|
|
|
|
|
|
devmode->dmSize = offsetof( DEVMODEW, dmICMMethod );
|
|
|
|
devmode->dmSpecVersion = DM_SPECVERSION;
|
|
|
|
devmode->dmDriverVersion = DM_SPECVERSION;
|
|
|
|
memcpy( devmode->dmDeviceName, dev_name, sizeof(dev_name) );
|
|
|
|
devmode->dmDriverExtra = 0;
|
|
|
|
devmode->u2.dmDisplayFlags = 0;
|
|
|
|
devmode->dmDisplayFrequency = 0;
|
|
|
|
devmode->u1.s2.dmPosition.x = 0;
|
|
|
|
devmode->u1.s2.dmPosition.y = 0;
|
|
|
|
devmode->u1.s2.dmDisplayOrientation = 0;
|
|
|
|
devmode->u1.s2.dmDisplayFixedOutput = 0;
|
|
|
|
|
|
|
|
if (n == ENUM_CURRENT_SETTINGS || n == ENUM_REGISTRY_SETTINGS) n = 0;
|
|
|
|
if (n == 0)
|
|
|
|
{
|
|
|
|
devmode->dmPelsWidth = screen_width;
|
|
|
|
devmode->dmPelsHeight = screen_height;
|
|
|
|
devmode->dmBitsPerPel = screen_bpp;
|
|
|
|
devmode->dmDisplayFrequency = 60;
|
|
|
|
devmode->dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL | DM_DISPLAYFLAGS | DM_DISPLAYFREQUENCY;
|
|
|
|
TRACE( "mode %d -- %dx%d %d bpp @%d Hz\n", n,
|
|
|
|
devmode->dmPelsWidth, devmode->dmPelsHeight,
|
|
|
|
devmode->dmBitsPerPel, devmode->dmDisplayFrequency );
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
TRACE( "mode %d -- not present\n", n );
|
|
|
|
SetLastError( ERROR_NO_MORE_FILES );
|
|
|
|
return FALSE;
|
2017-05-31 11:15:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-22 21:39:08 +02:00
|
|
|
/**********************************************************************
|
|
|
|
* ANDROID_wine_get_wgl_driver
|
|
|
|
*/
|
2022-03-01 21:59:23 +01:00
|
|
|
static struct opengl_funcs * CDECL ANDROID_wine_get_wgl_driver( UINT version )
|
2017-06-22 21:39:08 +02:00
|
|
|
{
|
2022-03-01 21:59:23 +01:00
|
|
|
return get_wgl_driver( version );
|
2017-06-22 21:39:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-11-11 14:13:16 +01:00
|
|
|
static const struct user_driver_funcs android_drv_funcs =
|
2017-05-31 10:58:55 +02:00
|
|
|
{
|
2021-11-11 14:13:16 +01:00
|
|
|
.dc_funcs.pCreateCompatibleDC = ANDROID_CreateCompatibleDC,
|
|
|
|
.dc_funcs.pCreateDC = ANDROID_CreateDC,
|
|
|
|
.dc_funcs.pDeleteDC = ANDROID_DeleteDC,
|
|
|
|
.dc_funcs.priority = GDI_PRIORITY_GRAPHICS_DRV,
|
|
|
|
|
|
|
|
.pGetKeyNameText = ANDROID_GetKeyNameText,
|
|
|
|
.pMapVirtualKeyEx = ANDROID_MapVirtualKeyEx,
|
|
|
|
.pVkKeyScanEx = ANDROID_VkKeyScanEx,
|
|
|
|
.pSetCursor = ANDROID_SetCursor,
|
|
|
|
.pChangeDisplaySettingsEx = ANDROID_ChangeDisplaySettingsEx,
|
|
|
|
.pEnumDisplaySettingsEx = ANDROID_EnumDisplaySettingsEx,
|
2021-12-01 16:02:53 +01:00
|
|
|
.pUpdateDisplayDevices = ANDROID_UpdateDisplayDevices,
|
2021-11-11 14:13:16 +01:00
|
|
|
.pCreateWindow = ANDROID_CreateWindow,
|
|
|
|
.pDestroyWindow = ANDROID_DestroyWindow,
|
|
|
|
.pMsgWaitForMultipleObjectsEx = ANDROID_MsgWaitForMultipleObjectsEx,
|
|
|
|
.pSetCapture = ANDROID_SetCapture,
|
|
|
|
.pSetLayeredWindowAttributes = ANDROID_SetLayeredWindowAttributes,
|
|
|
|
.pSetParent = ANDROID_SetParent,
|
|
|
|
.pSetWindowRgn = ANDROID_SetWindowRgn,
|
|
|
|
.pSetWindowStyle = ANDROID_SetWindowStyle,
|
|
|
|
.pShowWindow = ANDROID_ShowWindow,
|
|
|
|
.pUpdateLayeredWindow = ANDROID_UpdateLayeredWindow,
|
|
|
|
.pWindowMessage = ANDROID_WindowMessage,
|
|
|
|
.pWindowPosChanging = ANDROID_WindowPosChanging,
|
|
|
|
.pWindowPosChanged = ANDROID_WindowPosChanged,
|
2022-03-01 21:59:23 +01:00
|
|
|
.pwine_get_wgl_driver = ANDROID_wine_get_wgl_driver,
|
2017-05-31 10:58:55 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-05-31 11:47:49 +02:00
|
|
|
static const JNINativeMethod methods[] =
|
|
|
|
{
|
|
|
|
{ "wine_desktop_changed", "(II)V", desktop_changed },
|
2017-06-12 19:12:30 +02:00
|
|
|
{ "wine_config_changed", "(I)V", config_changed },
|
2017-06-22 19:36:54 +02:00
|
|
|
{ "wine_surface_changed", "(ILandroid/view/Surface;Z)V", surface_changed },
|
2017-06-08 10:16:41 +02:00
|
|
|
{ "wine_motion_event", "(IIIIII)Z", motion_event },
|
2017-06-08 16:44:20 +02:00
|
|
|
{ "wine_keyboard_event", "(IIII)Z", keyboard_event },
|
2017-05-31 11:47:49 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#define DECL_FUNCPTR(f) typeof(f) * p##f = NULL
|
|
|
|
#define LOAD_FUNCPTR(lib, func) do { \
|
2020-04-06 22:40:19 +02:00
|
|
|
if ((p##func = dlsym( lib, #func )) == NULL) \
|
2017-05-31 11:47:49 +02:00
|
|
|
{ ERR( "can't find symbol %s\n", #func); return; } \
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
DECL_FUNCPTR( __android_log_print );
|
2017-06-02 11:37:16 +02:00
|
|
|
DECL_FUNCPTR( ANativeWindow_fromSurface );
|
|
|
|
DECL_FUNCPTR( ANativeWindow_release );
|
2017-06-06 08:30:23 +02:00
|
|
|
DECL_FUNCPTR( hw_get_module );
|
|
|
|
|
2017-06-26 15:12:44 +02:00
|
|
|
#ifndef DT_GNU_HASH
|
|
|
|
#define DT_GNU_HASH 0x6ffffef5
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static unsigned int gnu_hash( const char *name )
|
|
|
|
{
|
|
|
|
unsigned int h = 5381;
|
|
|
|
while (*name) h = h * 33 + (unsigned char)*name++;
|
|
|
|
return h;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int hash_symbol( const char *name )
|
|
|
|
{
|
|
|
|
unsigned int hi, hash = 0;
|
|
|
|
while (*name)
|
|
|
|
{
|
|
|
|
hash = (hash << 4) + (unsigned char)*name++;
|
|
|
|
hi = hash & 0xf0000000;
|
|
|
|
hash ^= hi;
|
|
|
|
hash ^= hi >> 24;
|
|
|
|
}
|
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *find_symbol( const struct dl_phdr_info* info, const char *var, int type )
|
|
|
|
{
|
|
|
|
const ElfW(Dyn) *dyn = NULL;
|
|
|
|
const ElfW(Phdr) *ph;
|
|
|
|
const ElfW(Sym) *symtab = NULL;
|
|
|
|
const Elf32_Word *hashtab = NULL;
|
|
|
|
const Elf32_Word *gnu_hashtab = NULL;
|
|
|
|
const char *strings = NULL;
|
|
|
|
Elf32_Word idx;
|
|
|
|
|
|
|
|
for (ph = info->dlpi_phdr; ph < &info->dlpi_phdr[info->dlpi_phnum]; ++ph)
|
|
|
|
{
|
|
|
|
if (PT_DYNAMIC == ph->p_type)
|
|
|
|
{
|
|
|
|
dyn = (const ElfW(Dyn) *)(info->dlpi_addr + ph->p_vaddr);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!dyn) return NULL;
|
|
|
|
|
|
|
|
while (dyn->d_tag)
|
|
|
|
{
|
|
|
|
if (dyn->d_tag == DT_STRTAB)
|
|
|
|
strings = (const char*)(info->dlpi_addr + dyn->d_un.d_ptr);
|
|
|
|
if (dyn->d_tag == DT_SYMTAB)
|
|
|
|
symtab = (const ElfW(Sym) *)(info->dlpi_addr + dyn->d_un.d_ptr);
|
|
|
|
if (dyn->d_tag == DT_HASH)
|
|
|
|
hashtab = (const Elf32_Word *)(info->dlpi_addr + dyn->d_un.d_ptr);
|
|
|
|
if (dyn->d_tag == DT_GNU_HASH)
|
|
|
|
gnu_hashtab = (const Elf32_Word *)(info->dlpi_addr + dyn->d_un.d_ptr);
|
|
|
|
dyn++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!symtab || !strings) return NULL;
|
|
|
|
|
|
|
|
if (gnu_hashtab) /* new style hash table */
|
|
|
|
{
|
|
|
|
const unsigned int hash = gnu_hash(var);
|
|
|
|
const Elf32_Word nbuckets = gnu_hashtab[0];
|
|
|
|
const Elf32_Word symbias = gnu_hashtab[1];
|
|
|
|
const Elf32_Word nwords = gnu_hashtab[2];
|
|
|
|
const ElfW(Addr) *bitmask = (const ElfW(Addr) *)(gnu_hashtab + 4);
|
|
|
|
const Elf32_Word *buckets = (const Elf32_Word *)(bitmask + nwords);
|
|
|
|
const Elf32_Word *chains = buckets + nbuckets - symbias;
|
|
|
|
|
|
|
|
if (!(idx = buckets[hash % nbuckets])) return NULL;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if ((chains[idx] & ~1u) == (hash & ~1u) &&
|
|
|
|
ELF32_ST_BIND(symtab[idx].st_info) == STB_GLOBAL &&
|
|
|
|
ELF32_ST_TYPE(symtab[idx].st_info) == type &&
|
|
|
|
!strcmp( strings + symtab[idx].st_name, var ))
|
|
|
|
return (void *)(info->dlpi_addr + symtab[idx].st_value);
|
|
|
|
} while (!(chains[idx++] & 1u));
|
|
|
|
}
|
|
|
|
else if (hashtab) /* old style hash table */
|
|
|
|
{
|
|
|
|
const unsigned int hash = hash_symbol( var );
|
|
|
|
const Elf32_Word nbuckets = hashtab[0];
|
|
|
|
const Elf32_Word *buckets = hashtab + 2;
|
|
|
|
const Elf32_Word *chains = buckets + nbuckets;
|
|
|
|
|
|
|
|
for (idx = buckets[hash % nbuckets]; idx; idx = chains[idx])
|
|
|
|
{
|
|
|
|
if (ELF32_ST_BIND(symtab[idx].st_info) == STB_GLOBAL &&
|
|
|
|
ELF32_ST_TYPE(symtab[idx].st_info) == type &&
|
|
|
|
!strcmp( strings + symtab[idx].st_name, var ))
|
|
|
|
return (void *)(info->dlpi_addr + symtab[idx].st_value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int enum_libs( struct dl_phdr_info* info, size_t size, void* data )
|
|
|
|
{
|
|
|
|
const char *p;
|
|
|
|
|
|
|
|
if (!info->dlpi_name) return 0;
|
|
|
|
if (!(p = strrchr( info->dlpi_name, '/' ))) return 0;
|
|
|
|
if (strcmp( p, "/libhardware.so" )) return 0;
|
|
|
|
TRACE( "found libhardware at %p\n", info->dlpi_phdr );
|
|
|
|
phw_get_module = find_symbol( info, "hw_get_module", STT_FUNC );
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2017-06-06 08:30:23 +02:00
|
|
|
static void load_hardware_libs(void)
|
|
|
|
{
|
|
|
|
const struct hw_module_t *module;
|
2018-11-19 16:06:51 +01:00
|
|
|
int ret;
|
2017-06-06 08:30:23 +02:00
|
|
|
void *libhardware;
|
|
|
|
|
2020-04-06 22:40:19 +02:00
|
|
|
if ((libhardware = dlopen( "libhardware.so", RTLD_GLOBAL )))
|
2017-06-06 08:30:23 +02:00
|
|
|
{
|
|
|
|
LOAD_FUNCPTR( libhardware, hw_get_module );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-06-26 15:12:44 +02:00
|
|
|
/* Android >= N disallows loading libhardware, so we load libandroid (which imports
|
|
|
|
* libhardware), and then we can find libhardware in the list of loaded libraries.
|
|
|
|
*/
|
2020-04-06 22:40:19 +02:00
|
|
|
if (!dlopen( "libandroid.so", RTLD_GLOBAL ))
|
2017-06-26 15:12:44 +02:00
|
|
|
{
|
2020-04-06 22:40:19 +02:00
|
|
|
ERR( "failed to load libandroid.so: %s\n", dlerror() );
|
2017-06-26 15:12:44 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
dl_iterate_phdr( enum_libs, 0 );
|
|
|
|
if (!phw_get_module)
|
|
|
|
{
|
|
|
|
ERR( "failed to find hw_get_module\n" );
|
|
|
|
return;
|
|
|
|
}
|
2017-06-06 08:30:23 +02:00
|
|
|
}
|
|
|
|
|
2018-11-19 16:06:51 +01:00
|
|
|
if ((ret = phw_get_module( GRALLOC_HARDWARE_MODULE_ID, &module )))
|
|
|
|
{
|
|
|
|
ERR( "failed to load gralloc module err %d\n", ret );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
init_gralloc( module );
|
2017-06-06 08:30:23 +02:00
|
|
|
}
|
2017-05-31 11:47:49 +02:00
|
|
|
|
|
|
|
static void load_android_libs(void)
|
|
|
|
{
|
2017-06-02 11:37:16 +02:00
|
|
|
void *libandroid, *liblog;
|
2017-05-31 11:47:49 +02:00
|
|
|
|
2020-04-06 22:40:19 +02:00
|
|
|
if (!(libandroid = dlopen( "libandroid.so", RTLD_GLOBAL )))
|
2017-06-02 11:37:16 +02:00
|
|
|
{
|
2020-04-06 22:40:19 +02:00
|
|
|
ERR( "failed to load libandroid.so: %s\n", dlerror() );
|
2017-06-02 11:37:16 +02:00
|
|
|
return;
|
|
|
|
}
|
2020-04-06 22:40:19 +02:00
|
|
|
if (!(liblog = dlopen( "liblog.so", RTLD_GLOBAL )))
|
2017-05-31 11:47:49 +02:00
|
|
|
{
|
2020-04-06 22:40:19 +02:00
|
|
|
ERR( "failed to load liblog.so: %s\n", dlerror() );
|
2017-05-31 11:47:49 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
LOAD_FUNCPTR( liblog, __android_log_print );
|
2017-06-02 11:37:16 +02:00
|
|
|
LOAD_FUNCPTR( libandroid, ANativeWindow_fromSurface );
|
|
|
|
LOAD_FUNCPTR( libandroid, ANativeWindow_release );
|
2017-05-31 11:47:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#undef DECL_FUNCPTR
|
|
|
|
#undef LOAD_FUNCPTR
|
|
|
|
|
2020-12-08 12:45:18 +01:00
|
|
|
JavaVM **p_java_vm = NULL;
|
|
|
|
jobject *p_java_object = NULL;
|
2020-12-08 12:46:17 +01:00
|
|
|
unsigned short *p_java_gdt_sel = NULL;
|
2020-09-11 11:43:21 +02:00
|
|
|
|
2017-05-31 11:47:49 +02:00
|
|
|
static BOOL process_attach(void)
|
|
|
|
{
|
|
|
|
jclass class;
|
2020-09-11 11:43:21 +02:00
|
|
|
jobject object;
|
2017-05-31 11:47:49 +02:00
|
|
|
JNIEnv *jni_env;
|
|
|
|
JavaVM *java_vm;
|
2020-12-08 12:45:18 +01:00
|
|
|
void *ntdll;
|
2020-09-11 11:43:21 +02:00
|
|
|
|
2020-12-08 12:45:18 +01:00
|
|
|
if (!(ntdll = dlopen( "ntdll.so", RTLD_NOW ))) return FALSE;
|
2020-09-11 11:43:21 +02:00
|
|
|
|
2020-12-08 12:45:18 +01:00
|
|
|
p_java_vm = dlsym( ntdll, "java_vm" );
|
|
|
|
p_java_object = dlsym( ntdll, "java_object" );
|
2020-12-08 12:46:17 +01:00
|
|
|
p_java_gdt_sel = dlsym( ntdll, "java_gdt_sel" );
|
2020-09-11 11:43:21 +02:00
|
|
|
|
2020-12-08 12:45:18 +01:00
|
|
|
object = *p_java_object;
|
2017-05-31 11:47:49 +02:00
|
|
|
|
2017-06-06 08:30:23 +02:00
|
|
|
load_hardware_libs();
|
|
|
|
|
2020-12-08 12:45:18 +01:00
|
|
|
if ((java_vm = *p_java_vm)) /* running under Java */
|
2017-05-31 11:47:49 +02:00
|
|
|
{
|
|
|
|
#ifdef __i386__
|
2020-04-03 10:46:29 +02:00
|
|
|
WORD old_fs;
|
|
|
|
__asm__( "mov %%fs,%0" : "=r" (old_fs) );
|
2017-05-31 11:47:49 +02:00
|
|
|
#endif
|
|
|
|
load_android_libs();
|
|
|
|
(*java_vm)->AttachCurrentThread( java_vm, &jni_env, 0 );
|
|
|
|
class = (*jni_env)->GetObjectClass( jni_env, object );
|
2018-08-16 20:19:30 +02:00
|
|
|
(*jni_env)->RegisterNatives( jni_env, class, methods, ARRAY_SIZE( methods ));
|
2017-05-31 11:47:49 +02:00
|
|
|
(*jni_env)->DeleteLocalRef( jni_env, class );
|
|
|
|
#ifdef __i386__
|
2020-04-03 10:46:29 +02:00
|
|
|
/* the Java VM hijacks %fs for its own purposes, restore it */
|
|
|
|
__asm__( "mov %0,%%fs" :: "r" (old_fs) );
|
2017-05-31 11:47:49 +02:00
|
|
|
#endif
|
|
|
|
}
|
2021-11-11 14:13:16 +01:00
|
|
|
__wine_set_user_driver( &android_drv_funcs, WINE_GDI_DRIVER_VERSION );
|
2017-05-31 11:47:49 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* dll initialisation routine
|
|
|
|
*/
|
|
|
|
BOOL WINAPI DllMain( HINSTANCE inst, DWORD reason, LPVOID reserved )
|
|
|
|
{
|
|
|
|
switch (reason)
|
|
|
|
{
|
|
|
|
case DLL_PROCESS_ATTACH:
|
|
|
|
DisableThreadLibraryCalls( inst );
|
|
|
|
return process_attach();
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|