home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / dev / gcc / ixemulsrc.lha / ixemul / library / ix_exec_entry.c < prev    next >
C/C++ Source or Header  |  1996-12-11  |  4KB  |  131 lines

  1. /*
  2.  *  This file is part of ixemul.library for the Amiga.
  3.  *  Copyright (C) 1991, 1992  Markus M. Wild
  4.  *  Portions Copyright (C) 1995 Jeff Shepherd
  5.  *
  6.  *  This library is free software; you can redistribute it and/or
  7.  *  modify it under the terms of the GNU Library General Public
  8.  *  License as published by the Free Software Foundation; either
  9.  *  version 2 of the License, or (at your option) any later version.
  10.  *
  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.  *  Library General Public License for more details.
  15.  *
  16.  *  You should have received a copy of the GNU Library General Public
  17.  *  License along with this library; if not, write to the Free
  18.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  *
  20.  *  ix_exec_entry.c,v 1.1.1.1 1994/04/04 04:30:55 amiga Exp
  21.  *
  22.  *  ix_exec_entry.c,v
  23.  * Revision 1.1.1.1  1994/04/04  04:30:55  amiga
  24.  * Initial CVS check in.
  25.  *
  26.  *  Revision 1.3  1992/08/09  20:47:19  amiga
  27.  *  call main thru exit, or no atexit handlers will be called!
  28.  *
  29.  *  Revision 1.2  1992/07/04  19:13:42  mwild
  30.  *  add SIGWINCH handler installation/removal
  31.  *
  32.  * Revision 1.1  1992/05/14  19:55:40  mwild
  33.  * Initial revision
  34.  *
  35.  */
  36.  
  37. #define _KERNEL
  38. #include "ixemul.h"
  39. #include "kprintf.h"
  40. #include <sys/wait.h>
  41. #include <string.h>
  42.  
  43. int
  44. ix_exec_entry (int argc, char **argv, char **environ, int *real_errno, 
  45.            int (*main)(int, char **, char **))
  46. {
  47.   struct Process *me = (struct Process *) SysBase->ThisTask;
  48.  
  49.   /* we're coming from another process here, either after vfork() or from a
  50.    * process that wants to `replace' itself with this program. Thus the fpu
  51.    * is probably already initialized to some bogus state. That's why we
  52.    * HAVE to restore it into a default state here. */
  53.  
  54.   if (gotanfpu())
  55.     resetfpu();
  56.  
  57.   if (is_ixconfig(argv[0]))
  58.     {
  59.       u.p_xstat = W_EXITCODE(20, 0);
  60.       return u.p_xstat;
  61.     }
  62.  
  63.   /* a program started by ix_exec_entry() must have some ix'like shell
  64.      around, that takes care of printing exit-states, so don't print them
  65.      again in sig_exit() */
  66.   u.u_argline = 0;
  67.   u.u_arglinelen = 0;
  68.  
  69.   /* put some AmiTCP and AS225 stuff in here since it can't go into ix_open
  70.    * I need a pointer to the REAL errno
  71.    */
  72.   if (real_errno)
  73.     {
  74.       u.u_errno = real_errno;
  75.       if (u.u_ixnetbase)
  76.     netcall(NET_set_errno, real_errno, NULL);
  77.     }
  78.  
  79.   KPRINTF (("&errno = %lx\n", real_errno));
  80.  
  81.   if (!_setjmp (u.u_jmp_buf))
  82.     {
  83.       /* install the signal mask that was active before execve() was called */
  84.       syscall (SYS_sigsetmask, u.u_oldmask);
  85.  
  86.       /* this is not really the right thing to do, the user should call
  87.          ix_get_vars2 () to initialize environ to the address of the variable
  88.          in the calling program. However, this setting guarantees that 
  89.          the user area entry is valid for getenv() calls. */
  90.       u.u_environ = &environ;
  91.  
  92.       ix_install_sigwinch ();
  93.  
  94.       /* If this process is traced (under debugger control)
  95.      then cause a sigtrap.  */
  96.       if (u.p_flag & STRC)
  97.     {
  98.       KPRINTF(("ix_exec_entry(): STRC: _psignal (me=%08lx, SIGTRAP);\n", (long)me));
  99.  
  100.       _psignal ((struct Task *) me, SIGTRAP);
  101.  
  102.       /* A context switch is guaranteed to have taken place at this time,
  103.          since we signalled ourselves.  As we are continuing now, it means
  104.          the debugger process has told us to continue.  */
  105.     }
  106.       /* the first time thru call the program */
  107.       exit (main (argc, argv, environ));
  108.       /* not reached! */
  109.     }
  110.   /* we came from a longjmp-call */
  111.  
  112.   ix_remove_sigwinch ();
  113.  
  114.   return u.p_xstat;
  115. }
  116.  
  117. /* ixconfig is no longer supported and can actually crash ixemul, so
  118.    abort if the user tries to start ixconfig. */
  119. int is_ixconfig(char *prog)
  120. {
  121.   int len;
  122.  
  123.   if ((len = strlen(prog)) <= 8 || strchr("/:", prog[len - 9]))
  124.     if (len >= 8 && !stricmp(&prog[len - 8], "ixconfig"))
  125.       {
  126.         ix_panic("Please use ixprefs instead of ixconfig!");
  127.         return 1;
  128.       }
  129.   return 0;
  130. }
  131.