home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / dev / gcc / ixemulsrc.lha / ixemul / README < prev    next >
Text File  |  1996-12-11  |  17KB  |  341 lines

  1. README for ixemul.library and ixnet.library version 45.1
  2.  
  3.  
  4.  
  5. IMPORTANT
  6.  
  7. Always read the NEWS file for information about new features! The NEWS file
  8. is part of the ixemul source archive.
  9.  
  10. Starting with ixemul.library version 42.0 the ssystem() function is no longer
  11. supported. The only two applications use this function are (to my knowledge)
  12. gcc and man. You should either upgrade to the latest gcc (2.7.2 or higher)
  13. or replace gcc by gccv (which is part of older gcc distributions). You can
  14. find a new 'man' version on ADE.
  15.  
  16. Starting with ixemul.library version 43.1 various networking functions have
  17. been moved to libc.a. See the NEWS file for details. It only concerns
  18. certain somewhat specialized functions, so 'normal' clients and daemons
  19. shouldn't be affected.
  20.  
  21. This library is part of ADE: the Amiga Developers Environment. For more
  22. information see ftp.ninemoons.com, /pub/ade.
  23.  
  24. INTRODUCTION
  25.  
  26. Originally created in 1991 or 1992 by Markus Wild, the ixemul.library has
  27. become the driving force behind the ADE project.
  28.  
  29. Essentially it is a BSD Unix kernel running under the Amiga OS.  The
  30. code for handling Unix signals is taken almost verbatim from the BSD kernel
  31. sources, for example.  Multitasking and file I/O is, of course, passed on
  32. to the Amiga OS.  Because the library resembles BSD Unix so closely, it has
  33. made it possible to port almost all Unix programs.
  34.  
  35. However, because of the conformance to BSD, the library is not too
  36. conservative with resources or overly concerned with Amiga standards.  For
  37. example, command line expansion uses Unix semantics and doesn't use
  38. ReadArgs().  The purpose of ixemul.library is to emulate Unix as well as is
  39. technically possible.  So given a choice between Amiga behavior or Unix
  40. behavior, the last one is chosen.
  41.  
  42. HISTORY
  43.  
  44. As I mentioned, the library was originally created by Markus Wild.  It
  45. allowed him to port Unix programs, most notably gcc and a Unix shell
  46. (pdksh), which in turn gave him the opportunity to start porting NetBSD
  47. Unix.  At some point he stopped working on ixemul.library and continued
  48. with the real thing, NetBSD.
  49.  
  50. Although Markus made some snapshots of his library available on Internet,
  51. he was about the only one who could actually compile it.  The snapshots
  52. where never complete and didn't use a standard Make tool.
  53.  
  54. Rafael W. Luebbert managed around June 1994 to actually compile the
  55. library using bits and pieces from four different source releases.  Even
  56. then he had to write some missing code and had to debug a lot before he got
  57. it working.  Luebbert released versions 40.1 through 40.4.  Since this was
  58. the only version available that could actually be compiled, Fred Fish
  59. switched to version 40.4 for his FreshFish CDROM series.
  60.  
  61. Leonard Norrgard also started working on 40.4, fixing a variety of
  62. problems.  So for a time there were two versions of the library, both
  63. derived from 40.4.  Around March 1995 I began contributing my own fixes for
  64. the library to Fred, including a fix for a horrible memory trashing bug
  65. which substantially improved the stability of the library.  Starting with
  66. version 42.0 I became the new maintainer of the library.  I merged
  67. Leonard's version of the library into 42.0, the whole source distribution
  68. was cleaned up and reorganized and many bugs were fixed.  Also new
  69. functionality was added such as timezone support.
  70.  
  71. Thanks to Jeff Shepherd the support for network functions has been totally
  72. reorganized for version 43.0.  A new ixnet.library was introduced that
  73. contains all the network handling.  This new library supports both AS225
  74. and AmiTCP.  Furthermore, there is no longer any need to maintain two
  75. versions of an Internet client or daemon as ixnet.library will do the
  76. multiplexing for you.  The program itself is completely shielded from the
  77. actual networking package in use.  Also, should a new networking package
  78. appear for the Amiga, then it is relatively easy to add support for that
  79. package to ixnet.library.  All existing programs will automatically be able
  80. to work with the new package too.
  81.  
  82. Version 43.0 also introduced support for automatic stack extension
  83. (provided you compiled your program with the -mstackextend flag).  This
  84. support was done by Matthias Fleischer.
  85.  
  86. Last, but not least, I've added the ptrace() function, which was essential
  87. for porting the GNU debugger, GDB.  So it is now possible to use a decent
  88. debugger with gcc (and with the GNU C++, fortran and ADA compilers).
  89.  
  90. Version 43.1 was a bug-fix release, which further improved stability.
  91.  
  92. Version 44.0 made the library much more (Net)BSD compatible, making it even
  93. easier to port Unix programs. Also many bugs were fixed.
  94.  
  95. Version 45.0 fixes a few bugs, improves stack extension (see the new ixstack
  96. utility) and further improves Ctrl-C handling by adding 'sessions', something
  97. that was needed for the ADE X port.
  98.  
  99. Version 45.1 is a bug-fix release, and also improves uid/gid handling.
  100.  
  101. USAGE
  102.  
  103. The Aminet distribution of ixemul consists of several archives:  one for
  104. each flavor (CPU/FPU combination) of the library, one for the timezone
  105. support, an archive for documentation, an archive for various utilities and
  106. an SDK archive, containing headers, libraries and C-objects that provide
  107. the startup code.  There is also an ixemul source archive.  If you don't
  108. mind recompiling everything, and if you have a decent ADE environment, then
  109. all you have to do is retrieve this archive, as all the other archives are
  110. generated from this source distribution.
  111.  
  112. Besides the library itself, there are also some utilities and other
  113. goodies.  First of all, there is a special trace version of the library.
  114. Together with the ixtrace tool it allows you to see which library functions
  115. are called by the program you want to debug.  If you compile the library
  116. yourself you will also get, as part of the compile process, a debug version
  117. of the library.  If you get an Enforcer hit in the library, and if you have
  118. SegTracker installed, then you can track down in which source and at which
  119. line the hit took place using the gccfindhit tool (available from Aminet
  120. and ADE) that is similar to the FindHit tool which is part of the Enforcer
  121. package.  I've used this with great success in the past.
  122.  
  123. Various settings that influence the behavior of the library can be set
  124. using the ixprefs utility.  A small tool ixrun allowing you to run AmigaOS
  125. scripts from within the Unix shell is also provided.  An ixemul-specific
  126. pipe-handler allows you to set up a pipe between an AmigaOS utility and an
  127. Unix program.  A pipe between two Unix programs is handled by the
  128. ixemul.library itself, but since AmigaOS programs are not under the
  129. control of the library, this handler is used instead.
  130.  
  131. Finally, the tools zic (for manipulating the timezone databases) and
  132. ixtimezone are also part of ixemul.  The ixtimezone tool can be used to
  133. automatically adjust the Amiga time based on the currently selected
  134. timezone.  The best way to use this tool is to install the timezone
  135. databases (in etc:zoneinfo), set the TZ environment variable correctly (in
  136. my case "Europe/Amsterdam"), add the line "ixtimezone -patch-resource
  137. >nil:" to your user-startup and set the Amiga clock to Greenwich Mean Time
  138. (or Universal Time, as it is now called).  Now you will never have to worry
  139. about things like Daylight Saving Time as each time ixtimezone is called,
  140. this tool checks the current timezone and will patch the Amiga clock to the
  141. right time.  This tool is also very useful if you also run NetBSD or Linux,
  142. as these OSes expect that the internal Amiga clock adheres to GMT.
  143.  
  144. MEMORY REQUIREMENTS
  145.  
  146. The library itself needs about 150 Kb, but if you want to do some useful
  147. work, such as compiling programs, I advise at least 4 Mb.  More importantly
  148. is the stack size:  set it to at least 50 Kb.  For large compile jobs a
  149. bigger stack may be needed.  Fred Fish has reported that compiling some
  150. really big programs (e.g.  octave) requires 1 Mb of stack.  However, this
  151. is extreme.  Usually 50-100 Kb suffices.
  152.  
  153. The reason for these large stacks is that the Unix operating system
  154. automatically extends the stack if it is too small. Therefore some Unix
  155. programs aren't exactly conservative with their stack space.
  156.  
  157. PROGRAMMING WITH IXEMUL
  158.  
  159. There is really very little to do.  If you have a decent ADE setup with the
  160. necessary compilers and tools, and if you have installed the ixemul SDK,
  161. then you are ready to go.  There is no need to do anything special, the
  162. communication between your program and ixemul.library is handled by the
  163. startup code (the *crt0.o files in the /ade/lib directory) and the standard
  164. C library (libc.a, also in /ade/lib) which are automatically linked with
  165. your program.  Note that ixemul.library together with the compile tools
  166. also provides profiling support (compile and link with -pg), and
  167. base-relative and resident support (compile with -fbaserel or -resident).
  168. Compile and link with -g to add debug information so that you can debug
  169. your program with gdb.
  170.  
  171. If you start gdb with the -enforcer option, then the program you are
  172. debugging will automatically stop and drop into the debugger as soon as an
  173. Enforcer hit occurs.  This is obviously very useful.
  174.  
  175. The startup code will automatically expand the command-line for you (e.g.
  176. 'echo *' will expand to 'echo <filenames in current directory>'). If you
  177. want to disable this in your program, then you should add the line:
  178.  
  179.     int expand_cmd_line = 0;
  180.  
  181. to your source. This global variable will tell the system not to expand the
  182. command-line.
  183.  
  184. Code like you would on a Unix system, so DON'T USE any information
  185. private to the library!
  186.  
  187. PORTING UNIX PROGRAMS
  188.  
  189. Most programs compile out-of-the-box.  There are a few exceptions to this
  190. rule.  First of all, programs like linkers and the like that have to be
  191. able to read or write the standard Amiga hunk format obviously need a lot
  192. of work.
  193.  
  194. Secondly, there is no virtual memory support, and therefore no real fork()
  195. function.  In most cases the fork() function is only used to spawn a new
  196. program, and in such cases it is possible to replace fork() by vfork(),
  197. which is a light-weight fork() replacement that was originally created for
  198. Unix to reduce the overhead a real fork() introduced.
  199.  
  200. A vfork() doesn't create a copy of itself as fork() does, but uses the
  201. parent's code and data.  Since the child will quickly call execve() to
  202. spawn another program, this sharing of the code and data is no problem and
  203. saves a lot of time.
  204.  
  205. In some cases, such as a Unix shell (pdksh for example), you really want to
  206. be able to port a program that uses a fork() that cannot be replaced with
  207. vfork().  There is a way to do this, although it is a lot of work.  First
  208. of all, the program has to be compiled with -resident.  Now you replace the
  209. fork() by a vfork2() call, and in the child code you call vfork_setup_child()
  210. (new for 44.0!  Replaces the ix_resident()/ix_get_vars2() pair) to copy the
  211. original data hunk to a new location.  Next you have to copy all the
  212. parent's data structures to the child.  In other words, you have to copy
  213. the complete state of the parent process to the child process.  This can be
  214. a lot of work.  Finally, you call vfork_resume() which unblocks the parent
  215. so that you now have two processes running separately from each other.
  216.  
  217. It is important to realize that you should never exit() from the parent
  218. before all vfork()'ed children have died.  Since exiting from the parent
  219. causes the parents code and data segments to be deallocated, the child
  220. would find itself without code space to run on, and would probably cause a
  221. severe machine crash!
  222.  
  223. So always call at least `wait (0)' before returning from the parent.
  224.  
  225. For an example of how this works, see jobs.c from the pdksh source
  226. distribution.  It's a kind of poor-man's fork().
  227.  
  228. The third case I've come across that couldn't easily be ported were
  229. programs that dump their state to a new file.  Emacs does this, as does GNU
  230. Common Lisp.  The idea is that such a program will read lots of packages,
  231. and then dump itself to a new file.  That new file can in turn be executed,
  232. and you will no longer have to load all those packages.  All this assumes
  233. that each time you load a program, all the code and data ends up at the same
  234. memory addresses as before.  Something that is true for Unix, but not for
  235. the Amiga due to the lack of virtual memory.
  236.  
  237. However, if someone wants to do a port of such a program, please contact me
  238. as I have developed a technique to implement this.  At least, I've made
  239. this work with a small test program.  I've tried to use it with GNU Common
  240. Lisp, but time constraints prevented me from developing this further.
  241.  
  242. The last problematic category I've seen is GNU Emacs.  This program assumes
  243. that all the data it allocates will always end up in a continuous memory
  244. block, and that the upper 8 bits of each memory address are always the
  245. same.  The Amiga, however, can have multiple memory blocks positioned at
  246. various places in memory.  While there is a GNU Emacs port, this port does
  247. assume this limitation and if you have an Amiga with many memory blocks (as
  248. I had) GNU Emacs may easily crash.  No easy solution exists.
  249.  
  250. AMIGA PROGRAMMING & IXEMUL
  251.  
  252. If you use Amiga specific resources like Windows and Screens from
  253. Intuition, make sure to add an atexit() handler to close those resources,
  254. if the user should decide to interrupt your program.  Before the program is
  255. left, the chain of registered atexit-handlers is called in exit().  So
  256. PLEASE NEVER EVER call _exit() if you have registered any custom atexit()
  257. handlers.  It is a bad habit anyway, but normally you may call _exit()
  258. without resource lossage (stdio won't flush its buffers, but that's about
  259. all).
  260.  
  261. Ixemul provides a new unique Amiga specific signal called SIGMSG.  If you
  262. set up a handler for this signal, then the default mapping from
  263. SIGBREAKB_CTRL_C into SIGINT will no longer occur, and your handler is
  264. called with the following arguments:  signal_handler(SIGMSG,
  265. new_exec_signal_mask).
  266.  
  267. In this case, you have to deal with Exec signals yourself, so don't forget
  268. to clear those signals that you want to receive notification about again
  269. later.  Thus if you'd want to handle SIGBREAKB_CTRL_C yourself, don't
  270. forget to
  271.  
  272.   SetSignal (0, SIGBREAKF_CTRL_C)
  273.  
  274. at the end of the handler, or you'll never get notification about that
  275. signal again.
  276.  
  277. Most of the original BSD signals are implemented.  I don't think SIGSTOP is
  278. currently implemented, although it would be relatively easy to add.  The
  279. mechanisms are already in place.
  280.  
  281.  
  282. HANDLING OF UID/GID IN IXEMUL.LIBRARY
  283.  
  284. The following information was provided by Norbert Pueschel:
  285.  
  286. Here is a list of functions that are concerned with uid/gid management
  287. and access to user/group information:
  288.  
  289. a) uid/gid management:
  290.    get(e)uid, set((r)e)uid, get(e)gid, set((r)e)gid, (init|set|get)groups
  291.  
  292. b) access to user/group informations:
  293.    set(pass|group)ent, (set|get|end)pwent, get(pw|gr)nam, getpwuid, getgrgid,
  294.    (_)getlogin, setlogin
  295.  
  296. c) other functions:
  297.    setsid, crypt
  298.  
  299.  
  300. Ixemul.library has several options how to implement these functions:
  301.  
  302. 1) When MultiUser is installed, ixemul.library will use it to implement the
  303.    functions named above.
  304.  
  305. 2) When MultiUser is _not_ installed, ixemul.library will use its own
  306.    uid/gid handling: uids and gids will be inherited by child processes
  307.    and files and directories created by ixemul using programs will have
  308.    the current user and group set as long as the filesystem supports that.
  309.    However, for file accesses only the setting of the flags for the file
  310.    owner is used (as for any other AmigaOS program).
  311.  
  312. Processes that are not started by other ixemul using programs use
  313. environment variables to determine their (e)uid and (e)gid:
  314.  
  315. They will first check the variables LOGNAME and USER for a valid user
  316. name. If they find this user in the passwd file, they will set up (e)uid
  317. and (e)gid respectively. Then the environment variables UID, EUID, GID and
  318. EGID will be queried, and, if present, their values will be used.
  319.  
  320. If none of the above variables is found, the process will be owned by
  321. nobody/nogroup (uid/gid -2).
  322.  
  323.  
  324. Ixemul.library has three different methods to get user/group
  325. informations:
  326.  
  327. a) If networking software (AmiTCP or Inet) is installed, it will use their
  328.    user/group databases.
  329.  
  330. b) If no networking is available, it will try to read the files etc:passwd
  331.    and etc:group.
  332.  
  333. c) If both a) and b) fails, it will use a builtin user/group database.
  334.    This database only knows the nobody/nogroup (uid/gid -2), root/wheel
  335.    (uid/gid 0) and a user/group combination described by the environment
  336.    variables LOGNAME or USER, GROUP, UID and GID.
  337.  
  338.                       Hans Verkuil (hans@wyst.hobby.nl, September 18, 1996)
  339.  
  340. (Parts of this README are from the original README by Markus Wild).
  341.