This allows loading a test DLL on Wine.
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- programs/services/services.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/programs/services/services.c b/programs/services/services.c index eba98d6..1973d27 100644 --- a/programs/services/services.c +++ b/programs/services/services.c @@ -723,7 +723,7 @@ static DWORD get_service_binary_path(const struct service_entry *service_entry, return ERROR_SUCCESS; }
-static DWORD get_winedevice_binary_path(WCHAR **path, BOOL *is_wow64) +static DWORD get_winedevice_binary_path(struct service_entry *service_entry, WCHAR **path, BOOL *is_wow64) { static const WCHAR winedeviceW[] = {'\','w','i','n','e','d','e','v','i','c','e','.','e','x','e',0}; WCHAR system_dir[MAX_PATH]; @@ -734,7 +734,7 @@ static DWORD get_winedevice_binary_path(WCHAR **path, BOOL *is_wow64) else if (GetBinaryTypeW(*path, &type)) *is_wow64 = (type == SCS_32BIT_BINARY); else - return GetLastError(); + *is_wow64 = service_entry->is_wow64;
GetSystemDirectoryW(system_dir, MAX_PATH); HeapFree(GetProcessHeap(), 0, *path); @@ -857,7 +857,7 @@ static DWORD service_start_process(struct service_entry *service_entry, struct p struct service_entry *winedevice_entry; WCHAR *group;
- if ((err = get_winedevice_binary_path(&path, &is_wow64))) + if ((err = get_winedevice_binary_path(service_entry, &path, &is_wow64))) { service_unlock(service_entry); HeapFree(GetProcessHeap(), 0, path);
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- tools/winegcc/winegcc.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
diff --git a/tools/winegcc/winegcc.c b/tools/winegcc/winegcc.c index 4be35d5..f628ff2 100644 --- a/tools/winegcc/winegcc.c +++ b/tools/winegcc/winegcc.c @@ -210,6 +210,7 @@ struct options const char* image_base; const char* section_align; const char* lib_suffix; + const char* subsystem; strarray* prefix; strarray* lib_dirs; strarray* linker_args; @@ -916,6 +917,9 @@ static void build(struct options* opts) if (opts->nodefaultlibs) strarray_add(link_args, "-nodefaultlibs"); }
+ if (opts->subsystem) + strarray_add(link_args, strmake("-Wl,--subsystem,%s", opts->subsystem)); + for ( j = 0 ; j < opts->linker_args->size ; j++ ) strarray_add(link_args, opts->linker_args->base[j]);
@@ -1070,6 +1074,12 @@ static void build(struct options* opts) if (opts->large_address_aware) strarray_add( spec_args, "--large-address-aware" ); }
+ if (opts->subsystem) + { + strarray_add(spec_args, "--subsystem"); + strarray_add(spec_args, opts->subsystem); + } + for ( j = 0; j < lib_dirs->size; j++ ) strarray_add(spec_args, strmake("-L%s", lib_dirs->base[j]));
@@ -1600,6 +1610,11 @@ int main(int argc, char **argv) opts.large_address_aware = 1; continue; } + if (!strcmp(Wl->base[j], "--subsystem") && j < Wl->size - 1) + { + opts.subsystem = strdup( Wl->base[++j] ); + continue; + } if (!strcmp(Wl->base[j], "-static")) linking = -1; strarray_add(opts.linker_args, strmake("-Wl,%s",Wl->base[j])); }
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- tools/winegcc/winegcc.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
diff --git a/tools/winegcc/winegcc.c b/tools/winegcc/winegcc.c index f628ff2..ce059b3 100644 --- a/tools/winegcc/winegcc.c +++ b/tools/winegcc/winegcc.c @@ -211,6 +211,7 @@ struct options const char* section_align; const char* lib_suffix; const char* subsystem; + const char* entry; strarray* prefix; strarray* lib_dirs; strarray* linker_args; @@ -923,6 +924,14 @@ static void build(struct options* opts) for ( j = 0 ; j < opts->linker_args->size ; j++ ) strarray_add(link_args, opts->linker_args->base[j]);
+ if (opts->entry) + { + if (opts->target_cpu == CPU_x86) + strarray_add(link_args, strmake("-Wl,--entry,_%s,--enable-stdcall-fixup", opts->entry)); + else + strarray_add(link_args, strmake("-Wl,--entry,%s", opts->entry)); + } + strarray_add(link_args, "-o"); strarray_add(link_args, output_file);
@@ -1080,6 +1089,12 @@ static void build(struct options* opts) strarray_add(spec_args, opts->subsystem); }
+ if (opts->entry) + { + strarray_add(spec_args, "--entry"); + strarray_add(spec_args, opts->entry); + } + for ( j = 0; j < lib_dirs->size; j++ ) strarray_add(spec_args, strmake("-L%s", lib_dirs->base[j]));
@@ -1615,6 +1630,12 @@ int main(int argc, char **argv) opts.subsystem = strdup( Wl->base[++j] ); continue; } + if ((!strcmp(Wl->base[j], "--entry") || !strcmp(Wl->base[j], "-e")) + && j < Wl->size - 1) + { + opts.entry = strdup( Wl->base[++j] ); + continue; + } if (!strcmp(Wl->base[j], "-static")) linking = -1; strarray_add(opts.linker_args, strmake("-Wl,%s",Wl->base[j])); }
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- tools/makedep.c | 1 + 1 file changed, 1 insertion(+)
diff --git a/tools/makedep.c b/tools/makedep.c index 2c5b40a..ca96752 100644 --- a/tools/makedep.c +++ b/tools/makedep.c @@ -2880,6 +2880,7 @@ static void output_source_spec( struct makefile *make, struct incl_file *source, output_filename( strmake( "-B%s", tools_dir_path( make, "winebuild" ))); if (tools_dir) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make, "" ))); output_filename( "--lib-suffix=.cross.a" ); + output_filenames( make->extradllflags ); output_filename( "-shared" ); output_filename( source->filename ); output_filename( strmake( "%s.cross.o", obj_dir_path( make, obj )));
From: Sebastian Lackner sebastian@fds-team.de
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- configure | 1 + configure.ac | 1 + dlls/ntoskrnl.exe/tests/Makefile.in | 10 +++ dlls/ntoskrnl.exe/tests/driver.c | 126 ++++++++++++++++++++++++++++ dlls/ntoskrnl.exe/tests/driver.h | 27 ++++++ dlls/ntoskrnl.exe/tests/driver.spec | 0 dlls/ntoskrnl.exe/tests/ntoskrnl.c | 159 ++++++++++++++++++++++++++++++++++++ 7 files changed, 324 insertions(+) create mode 100644 dlls/ntoskrnl.exe/tests/Makefile.in create mode 100644 dlls/ntoskrnl.exe/tests/driver.c create mode 100644 dlls/ntoskrnl.exe/tests/driver.h create mode 100644 dlls/ntoskrnl.exe/tests/driver.spec create mode 100644 dlls/ntoskrnl.exe/tests/ntoskrnl.c
diff --git a/configure b/configure index fcf3259..45b9d23 100755 --- a/configure +++ b/configure @@ -18892,6 +18892,7 @@ wine_fn_config_makefile dlls/ntdll/tests enable_tests wine_fn_config_makefile dlls/ntdsapi enable_ntdsapi wine_fn_config_makefile dlls/ntdsapi/tests enable_tests wine_fn_config_makefile dlls/ntoskrnl.exe enable_ntoskrnl_exe +wine_fn_config_makefile dlls/ntoskrnl.exe/tests enable_tests wine_fn_config_makefile dlls/ntprint enable_ntprint wine_fn_config_makefile dlls/ntprint/tests enable_tests wine_fn_config_makefile dlls/objsel enable_objsel diff --git a/configure.ac b/configure.ac index 6d35df7..f7f69f6 100644 --- a/configure.ac +++ b/configure.ac @@ -3508,6 +3508,7 @@ WINE_CONFIG_MAKEFILE(dlls/ntdll/tests) WINE_CONFIG_MAKEFILE(dlls/ntdsapi) WINE_CONFIG_MAKEFILE(dlls/ntdsapi/tests) WINE_CONFIG_MAKEFILE(dlls/ntoskrnl.exe) +WINE_CONFIG_MAKEFILE(dlls/ntoskrnl.exe/tests) WINE_CONFIG_MAKEFILE(dlls/ntprint) WINE_CONFIG_MAKEFILE(dlls/ntprint/tests) WINE_CONFIG_MAKEFILE(dlls/objsel) diff --git a/dlls/ntoskrnl.exe/tests/Makefile.in b/dlls/ntoskrnl.exe/tests/Makefile.in new file mode 100644 index 0000000..2581398 --- /dev/null +++ b/dlls/ntoskrnl.exe/tests/Makefile.in @@ -0,0 +1,10 @@ +TESTDLL = ntoskrnl.exe +IMPORTS = advapi32 + +driver_IMPORTS = ntoskrnl winecrt0 +EXTRADLLFLAGS = -Wl,--subsystem,native -nodefaultlibs -nostartfiles -Wl,--entry,DriverEntry + +SOURCES = \ + driver.c \ + driver.spec \ + ntoskrnl.c diff --git a/dlls/ntoskrnl.exe/tests/driver.c b/dlls/ntoskrnl.exe/tests/driver.c new file mode 100644 index 0000000..a6f4971 --- /dev/null +++ b/dlls/ntoskrnl.exe/tests/driver.c @@ -0,0 +1,126 @@ +/* + * ntoskrnl.exe testing framework + * + * Copyright 2015 Sebastian Lackner + * Copyright 2015 Michael Müller + * Copyright 2015 Christian Costa + * + * 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 + */ + +#include <stdarg.h> + +#include "ntstatus.h" +#define WIN32_NO_STATUS +#include "windef.h" +#include "winbase.h" +#include "winternl.h" +#include "winioctl.h" +#include "ddk/wdm.h" + +#include "driver.h" + +const WCHAR driver_device[] = {'\','D','e','v','i','c','e', + '\','W','i','n','e','T','e','s','t','D','r','i','v','e','r',0}; +const WCHAR driver_link[] = {'\','D','o','s','D','e','v','i','c','e','s', + '\','W','i','n','e','T','e','s','t','D','r','i','v','e','r',0}; + +static NTSTATUS test_basic_ioctl(IRP *irp, IO_STACK_LOCATION *stack, ULONG_PTR *info) +{ + ULONG length = stack->Parameters.DeviceIoControl.OutputBufferLength; + char *buffer = irp->AssociatedIrp.SystemBuffer; + + if (!buffer) + return STATUS_ACCESS_VIOLATION; + + if (length < sizeof(teststr)) + return STATUS_BUFFER_TOO_SMALL; + + strcpy(buffer, teststr); + *info = sizeof(teststr); + + return STATUS_SUCCESS; +} + +static NTSTATUS WINAPI driver_Create(DEVICE_OBJECT *device, IRP *irp) +{ + irp->IoStatus.Status = STATUS_SUCCESS; + IoCompleteRequest(irp, IO_NO_INCREMENT); + return STATUS_SUCCESS; +} + +static NTSTATUS WINAPI driver_IoControl(DEVICE_OBJECT *device, IRP *irp) +{ + IO_STACK_LOCATION *stack = IoGetCurrentIrpStackLocation(irp); + NTSTATUS status = STATUS_NOT_SUPPORTED; + + switch (stack->Parameters.DeviceIoControl.IoControlCode) + { + case IOCTL_WINETEST_BASIC_IOCTL: + status = test_basic_ioctl(irp, stack, &irp->IoStatus.Information); + break; + default: + break; + } + + irp->IoStatus.Status = status; + IoCompleteRequest(irp, IO_NO_INCREMENT); + return status; +} + +static NTSTATUS WINAPI driver_Close(DEVICE_OBJECT *device, IRP *irp) +{ + irp->IoStatus.Status = STATUS_SUCCESS; + IoCompleteRequest(irp, IO_NO_INCREMENT); + return STATUS_SUCCESS; +} + +static VOID WINAPI driver_Unload(DRIVER_OBJECT *driver) +{ + UNICODE_STRING linkW; + + DbgPrint("unloading driver\n"); + + RtlInitUnicodeString(&linkW, driver_link); + IoDeleteSymbolicLink(&linkW); + + IoDeleteDevice(driver->DeviceObject); +} + +NTSTATUS WINAPI DriverEntry(DRIVER_OBJECT *driver, PUNICODE_STRING registry) +{ + UNICODE_STRING nameW, linkW; + DEVICE_OBJECT *device; + NTSTATUS status; + + DbgPrint("loading driver\n"); + + /* Allow unloading of the driver */ + driver->DriverUnload = driver_Unload; + + /* Set driver functions */ + driver->MajorFunction[IRP_MJ_CREATE] = driver_Create; + driver->MajorFunction[IRP_MJ_DEVICE_CONTROL] = driver_IoControl; + driver->MajorFunction[IRP_MJ_CLOSE] = driver_Close; + + RtlInitUnicodeString(&nameW, driver_device); + RtlInitUnicodeString(&linkW, driver_link); + + if (!(status = IoCreateDevice(driver, 0, &nameW, FILE_DEVICE_UNKNOWN, + FILE_DEVICE_SECURE_OPEN, FALSE, &device))) + status = IoCreateSymbolicLink(&linkW, &nameW); + + return status; +} diff --git a/dlls/ntoskrnl.exe/tests/driver.h b/dlls/ntoskrnl.exe/tests/driver.h new file mode 100644 index 0000000..8c32bf2 --- /dev/null +++ b/dlls/ntoskrnl.exe/tests/driver.h @@ -0,0 +1,27 @@ +/* + * ntoskrnl.exe testing framework + * + * Copyright 2015 Sebastian Lackner + * Copyright 2015 Michael Müller + * Copyright 2015 Christian Costa + * + * 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 + */ + + +/* All custom IOCTLs need to have a function value >= 0x800. */ +#define IOCTL_WINETEST_BASIC_IOCTL CTL_CODE(FILE_DEVICE_UNKNOWN, 0x800, METHOD_BUFFERED, FILE_ANY_ACCESS) + +static const char teststr[] = "Wine is not an emulator"; diff --git a/dlls/ntoskrnl.exe/tests/driver.spec b/dlls/ntoskrnl.exe/tests/driver.spec new file mode 100644 index 0000000..e69de29 diff --git a/dlls/ntoskrnl.exe/tests/ntoskrnl.c b/dlls/ntoskrnl.exe/tests/ntoskrnl.c new file mode 100644 index 0000000..623e10d --- /dev/null +++ b/dlls/ntoskrnl.exe/tests/ntoskrnl.c @@ -0,0 +1,159 @@ +/* + * ntoskrnl.exe testing framework + * + * Copyright 2015 Sebastian Lackner + * Copyright 2015 Michael Müller + * Copyright 2015 Christian Costa + * + * 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 + */ + +#include "windows.h" +#include "winsvc.h" +#include "winioctl.h" +#include "wine/test.h" + +#include "driver.h" + +static const char driver_name[] = "WineTestDriver"; +static const char device_path[] = "\\.\WineTestDriver"; + +static HANDLE device; + +static void load_resource(const char *name, char *filename) +{ + static char path[MAX_PATH]; + DWORD written; + HANDLE file; + HRSRC res; + void *ptr; + + GetTempPathA(sizeof(path), path); + GetTempFileNameA(path, name, 0, filename); + + file = CreateFileA(filename, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0); + ok(file != INVALID_HANDLE_VALUE, "file creation failed, at %s, error %d\n", filename, GetLastError()); + + res = FindResourceA(NULL, name, "TESTDLL"); + ok( res != 0, "couldn't find resource\n" ); + ptr = LockResource( LoadResource( GetModuleHandleA(NULL), res )); + WriteFile( file, ptr, SizeofResource( GetModuleHandleA(NULL), res ), &written, NULL ); + ok( written == SizeofResource( GetModuleHandleA(NULL), res ), "couldn't write resource\n" ); + CloseHandle( file ); +} + +static void unload_driver(SC_HANDLE service) +{ + SERVICE_STATUS status; + + CloseHandle(device); + + ControlService(service, SERVICE_CONTROL_STOP, &status); + while (status.dwCurrentState == SERVICE_STOP_PENDING) + { + Sleep(100); + ok(QueryServiceStatus(service, &status), "QueryServiceStatus failed: %u\n", GetLastError()); + } + ok(status.dwCurrentState == SERVICE_STOPPED, + "expected SERVICE_STOPPED, got %d\n", status.dwCurrentState); + + DeleteService(service); + CloseServiceHandle(service); +} + +static SC_HANDLE load_driver(char *filename) +{ + SC_HANDLE manager, service; + SERVICE_STATUS status; + BOOL ret; + + manager = OpenSCManagerA(NULL, NULL, SC_MANAGER_ALL_ACCESS); + if (!manager && GetLastError() == ERROR_ACCESS_DENIED) + { + skip("Failed to open SC manager, not enough permissions\n"); + return FALSE; + } + ok(!!manager, "OpenSCManager failed\n"); + + /* before we start with the actual tests, make sure to terminate + * any old wine test drivers. */ + service = OpenServiceA(manager, driver_name, SERVICE_ALL_ACCESS); + if (service) unload_driver(service); + + load_resource("driver.dll", filename); + trace("Trying to load driver %s\n", filename); + + service = CreateServiceA(manager, driver_name, driver_name, + SERVICE_ALL_ACCESS, SERVICE_KERNEL_DRIVER, + SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL, + filename, NULL, NULL, NULL, NULL, NULL); + ok(!!service, "CreateService failed: %u\n", GetLastError()); + CloseServiceHandle(manager); + + SetLastError(0xdeadbeef); + ret = StartServiceA(service, 0, NULL); + if (!ret && GetLastError() == ERROR_DRIVER_BLOCKED) + { + /* If Secure Boot is enabled or the machine is 64-bit, it will reject an unsigned driver. */ + skip("Failed to start service; probably your machine doesn't accept unsigned drivers.\n"); + DeleteService(service); + CloseServiceHandle(service); + DeleteFileA(filename); + return NULL; + } + ok(ret, "StartService failed: %u\n", GetLastError()); + + /* wait for the service to start up properly */ + ok(QueryServiceStatus(service, &status), "QueryServiceStatus failed: %u\n", GetLastError()); + while (status.dwCurrentState == SERVICE_START_PENDING) + { + Sleep(100); + ok(QueryServiceStatus(service, &status), "QueryServiceStatus failed: %u\n", GetLastError()); + } + ok(status.dwCurrentState == SERVICE_RUNNING, + "expected SERVICE_RUNNING, got %d\n", status.dwCurrentState); + + device = CreateFileA(device_path, 0, 0, NULL, OPEN_EXISTING, 0, NULL); + ok(device != INVALID_HANDLE_VALUE, "failed to open device: %u\n", GetLastError()); + + return service; +} + +static void test_basic_ioctl(void) +{ + DWORD written; + char buf[32]; + BOOL res; + + res = DeviceIoControl(device, IOCTL_WINETEST_BASIC_IOCTL, NULL, 0, buf, + sizeof(buf), &written, NULL); + ok(res, "DeviceIoControl failed: %u\n", GetLastError()); + ok(written == sizeof(teststr), "got size %d\n", written); + ok(!strcmp(buf, teststr), "got '%s'\n", buf); +} + +START_TEST(ntoskrnl) +{ + char filename[MAX_PATH]; + SC_HANDLE service; + + if (!(service = load_driver(filename))) + return; + + test_basic_ioctl(); + + unload_driver(service); + ok(DeleteFileA(filename), "DeleteFile failed: %u\n", GetLastError()); +}
Hi,
While running your changed tests on Windows, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check? Full results can be found at https://testbot.winehq.org/JobDetails.pl?Key=38115
Your paranoid android.
=== build (build) === Unable to regenerate dlls/ntoskrnl/Makefile Recreation of tests/Makefile failed