shared-wine-patch 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. diff -ruN wine/configure.ac wine-patched/configure.ac
  2. --- wine/configure.ac 2004-03-03 13:30:46.000000000 -0700
  3. +++ wine-patched/configure.ac 2004-03-04 17:44:34.000000000 -0700
  4. @@ -1670,6 +1670,7 @@
  5. programs/uninstaller/Makefile
  6. programs/view/Makefile
  7. programs/wcmd/Makefile
  8. +programs/wine-sharedlib/Makefile
  9. programs/wineboot/Makefile
  10. programs/winebrowser/Makefile
  11. programs/winecfg/Makefile
  12. diff -ruN wine/dlls/kernel/process.c wine-patched/dlls/kernel/process.c
  13. --- wine/dlls/kernel/process.c 2004-02-20 13:19:24.000000000 -0700
  14. +++ wine-patched/dlls/kernel/process.c 2004-03-04 17:44:34.000000000 -0700
  15. @@ -756,8 +756,12 @@
  16. SetLastError( 0 ); /* clear error code */
  17. if (peb->BeingDebugged) DbgBreakPoint();
  18. - ExitProcess( entry( peb ) );
  19. + if (__wine_shared_lib==0) {
  20. + // This starts the main app and then exits wine
  21. + ExitProcess( entry( peb ) );
  22. + }
  23. }
  24. +
  25. __EXCEPT(UnhandledExceptionFilter)
  26. {
  27. TerminateThread( GetCurrentThread(), GetExceptionCode() );
  28. @@ -895,13 +899,20 @@
  29. set_library_wargv( __wine_main_argv );
  30. if (!build_command_line( __wine_main_wargv )) goto error;
  31. - stack_size = RtlImageNtHeader(peb->ImageBaseAddress)->OptionalHeader.SizeOfStackReserve;
  32. + if (__wine_shared_lib==1) {
  33. + /* We don't want a new stack if we're going shared. Screws up our return path */
  34. + start_process(NULL);
  35. + } else {
  36. + stack_size = RtlImageNtHeader(peb->ImageBaseAddress)->OptionalHeader.SizeOfStackReserve;
  37. - /* allocate main thread stack */
  38. - if (!THREAD_InitStack( NtCurrentTeb(), stack_size )) goto error;
  39. + /* allocate main thread stack */
  40. + if (!THREAD_InitStack( NtCurrentTeb(), stack_size )) goto error;
  41. +
  42. + /* switch to the new stack */
  43. + wine_switch_to_stack( start_process, NULL, NtCurrentTeb()->Tib.StackBase );
  44. + }
  45. + return;
  46. - /* switch to the new stack */
  47. - wine_switch_to_stack( start_process, NULL, NtCurrentTeb()->Tib.StackBase );
  48. error:
  49. ExitProcess( GetLastError() );
  50. diff -ruN wine/dlls/ntdll/loader.c wine-patched/dlls/ntdll/loader.c
  51. --- wine/dlls/ntdll/loader.c 2004-02-23 18:25:03.000000000 -0700
  52. +++ wine-patched/dlls/ntdll/loader.c 2004-03-04 17:44:34.000000000 -0700
  53. @@ -1951,7 +1951,9 @@
  54. WINE_MODREF *wm;
  55. NTSTATUS status;
  56. ANSI_STRING func_name;
  57. - void (* DECLSPEC_NORETURN init_func)();
  58. + /* We might return for shared-lib startup */
  59. + /* void (* DECLSPEC_NORETURN init_func)(); */
  60. + void (* init_func)();
  61. extern void __wine_dbg_ntdll_init(void);
  62. thread_init();
  63. diff -ruN wine/include/wine/library.h wine-patched/include/wine/library.h
  64. --- wine/include/wine/library.h 2004-01-02 14:08:05.000000000 -0700
  65. +++ wine-patched/include/wine/library.h 2004-03-04 17:44:34.000000000 -0700
  66. @@ -49,6 +49,7 @@
  67. extern void wine_dll_unload( void *handle );
  68. extern int wine_dll_get_owner( const char *name, char *buffer, int size, int *file_exists );
  69. +extern int __wine_shared_lib;
  70. extern int __wine_main_argc;
  71. extern char **__wine_main_argv;
  72. extern WCHAR **__wine_main_wargv;
  73. diff -ruN wine/libs/wine/loader.c wine-patched/libs/wine/loader.c
  74. --- wine/libs/wine/loader.c 2004-01-02 14:08:05.000000000 -0700
  75. +++ wine-patched/libs/wine/loader.c 2004-03-04 17:44:34.000000000 -0700
  76. @@ -46,6 +46,7 @@
  77. char **__wine_main_argv = NULL;
  78. WCHAR **__wine_main_wargv = NULL;
  79. char **__wine_main_environ = NULL;
  80. +int __wine_shared_lib = 0;
  81. struct dll_path_context
  82. {
  83. diff -ruN wine/libs/wine/wine.def wine-patched/libs/wine/wine.def
  84. --- wine/libs/wine/wine.def 2004-02-04 19:01:35.000000000 -0700
  85. +++ wine-patched/libs/wine/wine.def 2004-03-04 17:44:34.000000000 -0700
  86. @@ -9,6 +9,7 @@
  87. __wine_dbgstr_an
  88. __wine_dbgstr_wn
  89. __wine_dll_register
  90. + __wine_shared_lib
  91. __wine_main_argc
  92. __wine_main_argv
  93. __wine_main_environ
  94. diff -ruN wine/libs/wine/wine.map wine-patched/libs/wine/wine.map
  95. --- wine/libs/wine/wine.map 2004-02-12 15:54:00.000000000 -0700
  96. +++ wine-patched/libs/wine/wine.map 2004-03-04 17:44:34.000000000 -0700
  97. @@ -9,6 +9,7 @@
  98. __wine_dbgstr_an;
  99. __wine_dbgstr_wn;
  100. __wine_dll_register;
  101. + __wine_shared_lib;
  102. __wine_main_argc;
  103. __wine_main_argv;
  104. __wine_main_environ;
  105. diff -ruN wine/programs/Makefile.in wine-patched/programs/Makefile.in
  106. --- wine/programs/Makefile.in 2004-01-06 13:49:59.000000000 -0700
  107. +++ wine-patched/programs/Makefile.in 2004-03-04 17:44:34.000000000 -0700
  108. @@ -11,6 +11,7 @@
  109. cmdlgtst \
  110. control \
  111. expand \
  112. + wine-sharedlib \
  113. notepad \
  114. progman \
  115. regedit \
  116. @@ -41,6 +42,7 @@
  117. clock \
  118. control \
  119. expand \
  120. + wine-sharedlib \
  121. notepad \
  122. progman \
  123. regedit \
  124. @@ -179,6 +181,9 @@
  125. icinfo.exe$(DLLEXT): avitools/icinfo.exe$(DLLEXT)
  126. $(RM) $@ && $(LN_S) avitools/icinfo.exe$(DLLEXT) $@
  127. +wine-sharedlib.exe$(DLLEXT): wine-sharedlib/wine-sharedlib.exe$(DLLEXT)
  128. + $(RM) $@ && $(LN_S) wine-sharedlib/wine-sharedlib.exe$(DLLEXT) $@
  129. +
  130. notepad.exe$(DLLEXT): notepad/notepad.exe$(DLLEXT)
  131. $(RM) $@ && $(LN_S) notepad/notepad.exe$(DLLEXT) $@
  132. @@ -255,6 +260,7 @@
  133. control/control.exe$(DLLEXT): control
  134. expand/expand.exe$(DLLEXT): expand
  135. avitools/icinfo.exe$(DLLEXT): avitools
  136. +wine-sharedlib/wine-sharedlib.exe$(DLLEXT): wine-sharedlib
  137. notepad/notepad.exe$(DLLEXT): notepad
  138. progman/progman.exe$(DLLEXT): progman
  139. regedit/regedit.exe$(DLLEXT): regedit
  140. diff -ruN wine/programs/wine-sharedlib/Makefile.in wine-patched/programs/wine-sharedlib/Makefile.in
  141. --- wine/programs/wine-sharedlib/Makefile.in 1969-12-31 17:00:00.000000000 -0700
  142. +++ wine-patched/programs/wine-sharedlib/Makefile.in 2004-03-04 17:44:34.000000000 -0700
  143. @@ -0,0 +1,27 @@
  144. +TOPSRCDIR = @top_srcdir@
  145. +TOPOBJDIR = ../..
  146. +SRCDIR = @srcdir@
  147. +VPATH = @srcdir@
  148. +MODULE = wine-sharedlib.exe
  149. +APPMODE = -mwindows
  150. +IMPORTS = kernel32
  151. +DELAYIMPORTS = user32
  152. +EXTRAINCL =
  153. +EXTRADEFS = -DDLLPATH=\"${exec_prefix}/lib/wine\" -DLIBPATH=\"${exec_prefix}/lib\"
  154. +EXTRALIBS = -ldl -lpthread
  155. +C_SRCS = \
  156. + wine-sharedlib.c \
  157. + ../../loader/pthread.c
  158. +
  159. +RC_SRCS =
  160. +RC_BINSRC =
  161. +RC_BINARIES =
  162. +
  163. +PLTESTS =
  164. +
  165. +EXTRASUBDIRS =
  166. +
  167. +@MAKE_PROG_RULES@
  168. +
  169. +dlldir = ${exec_prefix}/lib
  170. +### Dependencies:
  171. diff -ruN wine/programs/wine-sharedlib/wine-sharedlib.c wine-patched/programs/wine-sharedlib/wine-sharedlib.c
  172. --- wine/programs/wine-sharedlib/wine-sharedlib.c 1969-12-31 17:00:00.000000000 -0700
  173. +++ wine-patched/programs/wine-sharedlib/wine-sharedlib.c 2004-03-04 17:47:06.000000000 -0700
  174. @@ -0,0 +1,81 @@
  175. +/*
  176. + * wine-sharedlib code
  177. + *
  178. + * Copyright 2004 Novell, Inc. (http://www.novell.com/)
  179. + *
  180. + * This library is free software; you can redistribute it and/or
  181. + * modify it under the terms of the GNU Lesser General Public
  182. + * License as published by the Free Software Foundation; either
  183. + * version 2.1 of the License, or (at your option) any later version.
  184. + *
  185. + * This library is distributed in the hope that it will be useful,
  186. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  187. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  188. + * Lesser General Public License for more details.
  189. + *
  190. + * You should have received a copy of the GNU Lesser General Public
  191. + * License along with this library; if not, write to the Free Software
  192. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  193. + */
  194. +
  195. +
  196. +#include <wine/library.h>
  197. +#include <stdio.h>
  198. +#include <windows.h>
  199. +#include <winsock.h>
  200. +#include <dlfcn.h>
  201. +
  202. +/*
  203. + Dummy WinMain. If __wine_shared_lib is set this function is never actually called
  204. +*/
  205. +
  206. +int WINAPI
  207. +WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
  208. +{
  209. + return(0);
  210. +}
  211. +
  212. +HMODULE WINAPI (*LoadLibraryF)(LPCSTR libname);
  213. +FARPROC WINAPI (*GetProcAddressF)(HMODULE hModule, LPCSTR function);
  214. +
  215. +/*
  216. + WineLoadLibrary is used by System.Windows.Forms to import the Wine dlls
  217. +*/
  218. +void *
  219. +WineLoadLibrary(unsigned char *dll)
  220. +{
  221. + return(LoadLibraryF(dll));
  222. +}
  223. +
  224. +void *
  225. +WineGetProcAddress(void *handle, unsigned char *function)
  226. +{
  227. + return(GetProcAddressF(handle, function));
  228. +}
  229. +
  230. +/*
  231. + SharedWineInit() Must be called to initialize Wine. Sets the __wine_shared_lib flag
  232. + to make wine return after initialization instead of running WinMain
  233. +*/
  234. +
  235. +int
  236. +SharedWineInit(void)
  237. +{
  238. + unsigned char Error[1024]="";
  239. + char *WineArguments[] = {"sharedapp", LIBPATH "/wine-sharedlib.exe.so", NULL};
  240. +
  241. + __wine_shared_lib=1;
  242. +
  243. + wine_init(2, WineArguments, Error, sizeof(Error));
  244. + if (Error[0]!='\0') {
  245. + printf("Wine initialization error:%s\n", Error);
  246. + exit(-1);
  247. + }
  248. +
  249. + putenv ("_WINE_SHAREDLIB_PATH=" DLLPATH);
  250. +
  251. + LoadLibraryF=LoadLibraryA;
  252. + GetProcAddressF=GetProcAddress;
  253. +
  254. + return(0);
  255. +}
  256. diff -ruN wine/tools/winebuild/spec32.c wine-patched/tools/winebuild/spec32.c
  257. --- wine/tools/winebuild/spec32.c 2004-02-16 13:24:32.000000000 -0700
  258. +++ wine-patched/tools/winebuild/spec32.c 2004-03-04 17:44:34.000000000 -0700
  259. @@ -568,6 +568,7 @@
  260. fprintf( outfile, "extern int __wine_main_argc;\n" );
  261. fprintf( outfile, "extern char **__wine_main_argv;\n" );
  262. fprintf( outfile, "extern char **__wine_main_environ;\n" );
  263. + fprintf( outfile, "extern int __wine_shared_lib;\n" );
  264. fprintf( outfile, "extern unsigned short **__wine_main_wargv;\n" );
  265. fprintf( outfile, "extern void _init(int, char**, char**);\n" );
  266. fprintf( outfile, "extern void _fini();\n" );