support for starting wine as an interpreter by kernel (execve)

Jukka A. Ukkonen jau at iki.fi
Sun Sep 29 13:48:00 CDT 2002


	Hi!

	I complained about this matter a week or two ago, and got
	the pretty asocial answer: "This list is for patches only."
	So, no ideas, no discussion.
	Anyhow seeing some value in the kernel being able to start
	wine completely automatically as an "interpreter" for win/dos
	binaries I did the relative small changes that were needed.

	When wine is modified the way I did, it starts by checking
	whether argv[0] refers to itself. If that is true everything
	continues as before.
	(This also happens when the test fails. Potential reasons
	for failure are that the host system has no /proc file system
	at all or /proc has no entry pointing to the actual running
	binary.)

	If argv[0] refers to some other file than the wine binary
	itself (by what ever name) it is assumed that argv[0] is
	the target binary and the rest of the argv stuff needs to
	be passed to the target binary.
	In the latter case there can be no command line options to
	wine, and only default configuration from the config files
	or environment will be used.

	I have also an imgact_wine() function as an extension for
	FreeBSD kernel to recognise win/dos binaries and start wine
	(or any other windows emulator selectable by a sysctl()
	variable), if the kernel has been compiled with the USER_LDT
	option.
	The whole thing works largely the same way as starting a
	shell script with a #!/path/to/shell at the beginning of the
	file with the obvious exception that the interpreter name
	is taken from a sysctl() variable instead from the executed
	file itself.

	As a result of these modifications a win/dos binary which
	has the suitable x bits on (e.g. chmod a+x /path/to/w32prog)
	can be started automatically with the emulator. The user
	never needs to worry about knowing how to start a windows
	binary in a unix environment. It just magically happens.

	This also allows a unix ignoramus who is a potential former
	windows user to simply click an icon for his/her imported
	windows program in a unix desktop file browser (KDE, Gnome,
	...), and the right (= the expected) thing simply happens.
	This should lower the psychologic threshold for windows
	users to move over to using unix.


	Cheers,
		// jau
.---  ..-  -.-  -.-  .-    .-  .-.-.-    ..-  -.-  -.-  ---  -.  .  -.
  /    Jukka A. Ukkonen,                            Mawit Ltd, Finland
 /__   M.Sc. (sw-eng & cs)                    (Phone) +358-500-606-671
   /   Internet: Jukka.Ukkonen(a)Mawit.Com      (Home) +358-9-6215-280
  /    Internet: ukkonen(a)nic.funet.fi
 v     Internet: jau(a)iki.fi               

+ + + + My opinions are mine and mine alone, not my employers. + + + +

 o
  \ /
-  X ------------------------- clip clip ------------------------------
  / \
 O

--- wine/scheduler/process.c.orig	Sun Sep 29 17:08:44 2002
+++ wine/scheduler/process.c	Sun Sep 29 18:07:17 2002
@@ -461,7 +461,8 @@
     PTHREAD_init_done();
 
     /* Copy the parent environment */
-    if (!(current_process.env_db = ENV_InitStartupInfo( info_size, main_exe_name,
+    if (!(current_process.env_db = ENV_InitStartupInfo( info_size,
+						        main_exe_name,
                                                         sizeof(main_exe_name) )))
         return FALSE;
 
@@ -575,13 +576,51 @@
  */
 void PROCESS_InitWine( int argc, char *argv[], LPSTR win16_exe_name, HANDLE *win16_exe_file )
 {
-    char error[100], *p;
-    DWORD stack_size = 0;
+    char	error[100], *p;
+    DWORD	stack_size = 0;
+    int		av0_is_wine = 0;
+    extern int	iscurprocfile ();
 
     /* Initialize everything */
-    if (!process_init( argv )) exit(1);
 
-    argv++;  /* remove argv[0] (wine itself) */
+    av0_is_wine = iscurprocfile (argv[0]);
+
+    if (av0_is_wine) {
+	/*
+	 *  Wine has been started the traditional way
+	 *  using a shell command.
+	 */
+
+	if (av0_is_wine < 0) {
+	    fprintf (stderr,
+		     "wine: Failed to check whether `%s' refers "
+		     "to wine itself or to the actual win32/dos binary.\n"
+		     "Assuming `%s' is wine itself.\n", argv[0], argv[0]);
+	}
+	
+	if (! process_init( argv )) exit(1);
+
+	argv++;  /* remove argv[0] (wine itself) */
+    }
+    else {
+	char	fake_argv[2];
+
+	/*
+	 *  Wine has been started by the kernel
+	 *  as an interpreter for an executable
+	 *  which cannot be handled by the kernel
+	 *  itself. (= A shell for windoze binaries!!)
+	 *
+	 *  Now argv[0] is the name of the actual
+	 *  target executable.
+	 */
+
+	fake_argv[0] = "wine";	/* Could be curprocfile (); */
+	fake_argv[1] = NULL;
+
+	if (! process_init( argv ))
+	    exit(1);
+    }
 
     TRACE( "starting process name=%s file=%x argv[0]=%s\n",
            debugstr_a(main_exe_name), main_exe_file, debugstr_a(argv[0]) );
--- /dev/null	Sun Sep 29 18:13:29 2002
+++ wine/scheduler/iscurprocfile.c	Sun Sep 29 21:32:17 2002
@@ -0,0 +1,120 @@
+/*
+ *  %W%	(Jukka Ukkonen)	%E%
+ * Copyright (c) 1992-%E% Jukka A. Ukkonen
+ * All rights reserved.
+ *
+ * This software is not subject to any license of the following
+ *  - American Telephone and Telegraph Company (AT&T),
+ *  - X/Open or UNIX System Laboratories (the owners of UNIX & SysV),
+ *  - the Regents of the University of California (the owner of BSD) or
+ *  - the Free Software Foundation (the owner of GNU).
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions with it's included disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *	This product includes software developed by Jukka A. Ukkonen
+ *	by appointment with Thunderbolt Ltd. (Finland)
+ *
+ * 4. None of the names Jukka Antero Ukkonen or Thunderbolt Ltd. may be
+ *    used to endorse or promote products derived from this software without
+ *    specific prior written permission.
+ *
+ * 5. The origin of this software must not be misrepresented, either by
+ *    explicit claim or by omission.  Since few users ever read sources,
+ *    credits must appear in the documentation.
+ *
+ * 6. Altered versions must be explicitly marked as such, and must not be
+ *    misrepresented as being the original software.  Since few users ever
+ *    read sources, such statements must appear also in the documentation.
+ *
+ * 7. This notice may not be removed or altered.
+ *    The license and distribution terms for any publically available
+ *    version or derivative of this code cannot be changed.  I.e. this
+ *    code cannot simply be copied and put under another distrubution
+ *    license [including the GNU Public License.]
+ *    The reason behind this being stated in this direct manner is past
+ *    experience in code simply being copied and the attribution removed
+ *    from it and then being distributed as part of other packages.
+ *
+ * 8. This software is provided by Jukka Antero Ukkonen ``AS IS'' and any
+ *    express or implied warranties, including, but NOT LIMITED TO, the
+ *    implied warranties of merchantability and fitness for any particular
+ *    purpose are DISCLAIMED.
+ *
+ * 9. IN NO EVENT shall Jukka Antero Ukkonen BE LIABLE FOR ANY direct,
+ *    indirect, incidental, special, exemplary, or consequential DAMAGES
+ *    (including, BUT NOT LIMITED TO, procurement of substitute goods or
+ *    services; loss of use, data, or profits; or business interruption)
+ *    HOWEVER CAUSED and ON ANY THEORY OF LIABILITY, whether in contract,
+ *    strict liability, or tort (including negligence or otherwise)
+ *    arising in any way out of the use of this software, EVEN IF ADVISED
+ *    OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef	lint
+/*
+ *  static const char sccsid[] = "%W%\t(Jukka Ukkonen)\t%E%";
+ */
+static const char   sccsid[] =
+    "@(#)" __FILE__ "\t(Jukka A. Ukkonen)\t" __DATE__;
+static const char   rcsid[] =
+    "@(#)$Id$";
+#endif
+
+#include <sys/param.h>		/* for BSD >= 199303 */
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <limits.h>
+
+#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) \
+    || (defined(BSD) && (BSD >= 199303))
+#  define CURPROC_FILE	"/proc/curproc/file"
+#endif
+
+#if defined(__linux__)
+#  define CURPROC_FILE	"/proc/self/exe"
+#endif
+
+#if defined(__sun)
+#  define CURPROC_FILE	"/proc/self/object/a.out"
+#endif
+
+#ifndef	CURPROC_FILE
+#  warning File system entry for current process unknown.
+#  warning Default path is FreeBSD style "/proc/curproc/file".
+#  define CURPROC_FILE	"/proc/curproc/file"
+#endif
+
+static const char   curproc_file[] = CURPROC_FILE;
+
+int
+iscurprocfile (path)
+    const char	*path;
+{
+    struct stat	    curproc;
+    struct stat	    target;
+
+    if (stat (curproc_file, &curproc) < 0)
+	return (-1);
+
+    if (stat (path, &target) < 0)
+	return (-1);
+
+    if ((curproc.st_dev != target.st_dev)
+	|| (curproc.st_ino != target.st_ino)) {
+
+	return (0);
+    }
+
+    return (1);
+}



More information about the wine-patches mailing list