home *** CD-ROM | disk | FTP | other *** search
/ RISCWORLD 7 / RISCWORLD_VOL7.iso / Software / Issue2 / SDL.ARC / !gcc / docs / UnixLib < prev   
Encoding:
Text File  |  2004-10-05  |  10.8 KB  |  308 lines

  1.                                    UnixLib
  2.                                    =======
  3.  
  4. The library name UnixLib
  5. ~~~~~~~~~~~~~~~~~~~~~~~~
  6.  
  7. Don't confuse this library with the UnixLib library provided by RISCOS Ltd.
  8. RISCOS Ltd.'s UnixLib is part of the TCPIPLibs and also provides a
  9. lot of Unix function calls like this library does but it is not a
  10. Run Time library.
  11.  
  12.  
  13. Run-time features
  14. ~~~~~~~~~~~~~~~~~
  15.  
  16. Certain features of UnixLib can be enabled/disabled by defining environment
  17. variables. These can be applied to all UnixLib based applications running
  18. on the system, or to specific programs.
  19.  
  20. To set globally use:
  21.   *Set UnixEnv$<features>
  22.  
  23. To set per-program use:
  24.   *Set UnixEnv$<program name>$<features>
  25.  
  26. The list of recognised features are:
  27.  
  28. 1. nonametrans
  29.  
  30.    If set, all file paths and filenames will be used verbatim i.e. without
  31.    the usual Unix to RISC OS conversions.  Its value is not important.
  32.  
  33.    This corresponds with having the __RISCOSIFY_NO_PROCESS bit in
  34.    __riscosify_flags set of the __riscosify() routine or having that bit
  35.    in the WEAK symbol __riscosify_control specified.  See <unixlib/local.h>
  36.    include file for more information.
  37.  
  38. 2. sfix
  39.  
  40.    Default: a:c:cc:f:h:i:ii:l:o:p:s:y
  41.    This defines the list of suffices with will be used to do suffix
  42.    swapping when suffix swapping is enabled.  Suffix swapping is enabled
  43.    by default and can be disabled by having the __RISCOSIFY_NO_SUFFIX
  44.    bit specified in __riscosify_flags of the __riscosify() routine or
  45.    having that bit specified in the WEAK symbol __riscosify_control.
  46.    See <unixlib/local.h> include file for more information.
  47.  
  48.    Suffix swapping can also be disabled by defining the
  49.    UnixEnv$<program name>$sfix environment variable as an empty string :
  50.  
  51.      *Set UnixEnv$my_program$sfix ""
  52.  
  53.    Note that doing :
  54.  
  55.      *UnSet UnixEnv$my_program$sfix
  56.  
  57.    will *enable* suffix swapping with the default suffix list
  58.    mentioned above unless __RISCOSIFY_NO_SUFFIX is specified in the
  59.    __riscosify_flags variable or __riscosify()'s flags parameter.
  60.  
  61. 3. uid
  62.  
  63.    Default: 1
  64.    If set, then its value is used to set the UNIX uid and euid values.
  65.  
  66.  
  67. Another important runtime feature is the environment variable UnixFS$/
  68. followed by a non-zero length string.  This non-zero length string is
  69. an Unix subdirectory name in the root directory or an Unix
  70. subdirectory name in /usr or /var directories which you would like to
  71. map to specific RISC OS directories.
  72.  
  73. The Unix subdirectory in /usr and /var directories mapping has higher
  74. priority than the Unix subdirectory in the root directory mapping.
  75.  
  76. Note that defining UnixFS$/ does not have any effect.
  77.  
  78. E.g. :
  79.   *Set UnixFS$/home ADFS::4.$.MyHome
  80.  
  81.     Maps Unix file or directories names like /home/a_file and
  82.     /home/a_dir/another_dir to ADFS::4.$.MyHome.a_file and
  83.     ADFS::4.$.MyHome.a_dir.another_dir respectively.
  84.  
  85.   *Set UnixFS$/mail ADFS::4.$.Mail
  86.  
  87.     Maps the Unix filenames /usr/mail or /var/mail directory
  88.     to filenames inside ADFS::4.$.Mail directory.
  89.  
  90. Currently, up to 16 UnixFS$/ definitions can be made.  By default, the
  91. following two are defined :
  92.  
  93.   *Set UnixFS$/tmp <Wimp$ScrapDir>
  94.   *Set UnixFS$/pipe <Wimp$ScrapDir>
  95.  
  96.  
  97. <programname>$Heap
  98. Causes the heap to be placed in a dynamic area instead of the Wimpslot. Does
  99. not have to have any specific value. Can be overridden by the __dynamic_no_da
  100. weak variable. eg. *Set my_program$Heap ""
  101.  
  102. <programname>$HeapMax
  103. Specifies the maximum size (in MB) to use when creating a dynamic area for
  104. the heap. When not defined, it defaults to 32MB or the value specified
  105. by the __dynamic_da_max_size weak variable.
  106. eg. *SetEval my_program$HeapMax 64
  107.  
  108. UnixLib$env
  109. This is an environment variable used by UnixLib internally and should
  110. not be used by, nor relied on, clients of UnixLib.
  111.  
  112.  
  113. Link-time features
  114. ~~~~~~~~~~~~~~~~~~
  115.  
  116. There are 'WEAK'ly defined symbols which can be used to control
  117. certain UnixLib features too.  i.e. those symbols can, but not have to,
  118. be *defined* outside UnixLib and when they are defined, they will be
  119. used by the relevant UnixLib functions.  When they are not defined,
  120. they have an implicit value 0.
  121.  
  122. Its intended use is to provoke as less as possible changes in ported
  123. Unix programs by simply defining an extra RISC OS specific source file
  124. containing just something like e.g. :
  125.  
  126. ---8<---
  127. #include <unixlib/local.h>
  128.  
  129. int __feature_imagefs_is_file = 1;
  130. ---8<---
  131.  
  132. The list of current 'WEAK'ly defined symbols :
  133.  
  134. 1. __riscosify_control
  135.  
  136. Header file: <unixlib/local.h>, default value 0.
  137. This symbol controls how riscosify_std() processes filenames and
  138. that routine is used by UnixLib to convert (nearly) all Unix filenames
  139. to RISC OS filenames before those filenames are passed on to RISC OS
  140. itself.
  141.  
  142. 2. __feature_imagefs_is_file
  143.  
  144. Header file: <unixlib/features.h>, default value 0.
  145. When non zero, files with filetypes recognized by an active ImageFS will
  146. be considered as regular files and not as directories.
  147.  
  148. 3. __dynamic_no_da
  149.  
  150. Header file: <unixlib/features.h>.
  151. When defined (value is unimportant), no dynamic area will be created
  152. for the memory pool, even on RISC OS versions supporting dynamic area's.
  153.  
  154. 4. __dynamic_da_name
  155.  
  156. Header file: <unixlib/features.h>.
  157. Specifies the dynamic area name when there is one created for keeping
  158. the memory pool.  When __dynamic_da_name is not defined, the dynamic
  159. area name will be <program name> + "$Heap".
  160.  
  161. 5. __dynamic_da_max_size
  162.  
  163. Header file: <unixlib/features.h>.
  164. Specifies the maximum size to use when creating a dynamic area for
  165. the heap. When not defined, it defaults to 32MB. Can be overridden by
  166. the programname$HeapMax variable.
  167.  
  168.  
  169. Compile-time features
  170. ~~~~~~~~~~~~~~~~~~~~~
  171.  
  172. We try to restrict the number of compile-time features so that one
  173. binary release of UnixLib can satisfy most programmers.  These
  174. features, together with a short explanation, are defined in
  175. at the bottom of source.clib.unixlib.h.features.  Note that these
  176. feature settings are also reflected in the source.clib.unixlib.s.asm_dec
  177. file and should be kept in sync at all times.
  178.  
  179.  
  180. Stub functions
  181. ~~~~~~~~~~~~~~
  182.  
  183. A few functions are stub functions.  They are provided in UnixLib
  184. as either placeholders for functions that await implementation or those
  185. that simply cannot be; possibly because they are not relevant to RISC OS.
  186. For a complete list, see the autogenerated file source/clib/unixlib/stubs.h
  187.  
  188.  
  189. Stack and heap
  190. ~~~~~~~~~~~~~~
  191.  
  192. The way the stack and heap are organised has changed from previous
  193. UnixLib versions. Previously, the stack started at the top of the
  194. wimpslot, and grew downwards in a contiguous manner until it ran out of
  195. space. The new system extends the stack in chunks, in a similar way
  196. that the Shared C Library does. This change should be unnoticable to
  197. user programs.  However, as a consequence of this change, it is now possible
  198. for the wimpslot to be extended automatically if more stack or heap space is
  199. needed.
  200.  
  201. There is one caveat; if a fork() and exec() call is made (or system()
  202. which uses fork and exec internally) then there must be sufficient free
  203. space already inside the wimpslot to start the child program - the
  204. wimpslot cannot be extended in this situation. It is intended that this
  205. limitation will be removed in the future.
  206.  
  207. This raises the question of whether a program should use dynamic areas
  208. for the heap or not. If it uses only a few megabytes of memory and never
  209. calls fork/system then the wimpslot is the best place. If the program
  210. calls fork/system then using a dynamic area is probably best, although
  211. in some cases where the child program uses lots of memory but the
  212. parent doesn't (as is the case for gcc) then the wimpslot may be
  213. equally good. If the program requires large amounts of memory, in
  214. particular greater than 28MB, then it depends on the OS. For RISC OS
  215. 3 and 4 the wimpslot is limited to 28MB and so if you need more then you
  216. must use dynamic areas, but on RISC OS 5 the wimpslot can be a lot
  217. larger, whereas dynamic area space may be limited.
  218.  
  219.  
  220. pthreads
  221. ~~~~~~~~
  222.  
  223. UnixLib now provides support for threading, using the POSIX pthreads
  224. interface as defined in IEEE Std 1003.1 2003
  225. <URL:http://www.opengroup.org/onlinepubs/007904975/>.
  226.  
  227. The threading code has been tested in a variety of applications, and
  228. although probably a few bugs remain, it is stable. The details of how to use
  229. threads are far too complex to describe here, but there are many books and
  230. tutorials available on the web which should be suitable.
  231.  
  232. Thread contexts are pre-emptivly switched, however there are certain
  233. times when threads cannot be switched, in particular during SWI calls.
  234. Therefore if a thread calls, for example, OS_ReadLine (either directly,
  235. or via a UnixLib function) then none of the other threads will get a
  236. chance to run until OS_ReadLine returns.
  237.  
  238. Thread safety
  239.  
  240. IEEE 1003.1 defines which functions within UnixLib should be thread safe
  241. and which may not be. You must ensure that any third party libraries you
  242. use are also thread safe. Calling SWIs is generally safe, as the SWI
  243. will not be preempted, however if the SWI returns a pointer to internal
  244. storage that might change the next time the SWI is called then it would
  245. not be thread safe unless you ensure only one thread will ever access
  246. it, or protect it with a mutex.
  247.  
  248. Multitasking
  249.  
  250. Running a threaded program in a taskwindow is possible, however there
  251. are a few known bugs related to this at present, and context switching
  252. may not occur very often.
  253.  
  254. Explicitly calling Wimp_Poll is possible, but you must disable the
  255. thread interrupt before calling Wimp_Poll and then reenable it
  256. afterwards, as follows:
  257.  
  258. __pthread_stop_ticker();
  259. /* Call Wimp_Poll here */
  260. __pthread_start_ticker();
  261.  
  262. You may also find it beneficial to put a pthread_yield() call somewhere
  263. inside the Wimp_Poll loop, to ensure other threads get a better chance
  264. of running.
  265.  
  266. In addition, you may find it appropriate to disable threads during Wimp
  267. redraw loops.
  268.  
  269.  
  270. Sound support
  271. ~~~~~~~~~~~~~
  272.  
  273. Unixlib implements the OSS sound interface via the /dev/dsp device.  It
  274. makes use of the DigitalRenderer module which can be fetched from:
  275.  
  276.   http://home.t-online.de/home/zarquon/Software.html
  277.  
  278. This is a new feature, and it is likely improvements can be made.
  279.  
  280.  
  281. iconv support
  282. ~~~~~~~~~~~~~
  283.  
  284. Previously, use of iconv in programs required linking in of the standable
  285. iconv library, which adds around 1MB to Unixlib programs - mainly because
  286. of the lack of a shared library system on RISC OS.  In this version,   
  287. iconv support is in an external module, and Unixlib provides a C interface
  288. to call this.  It should act much like the inbuilt iconv support in GLIBC.
  289.  
  290. The iconv module is currently available from:
  291.  
  292. http://moose.mine.nu:6888/iconv002.zip
  293.  
  294.  
  295. Name registration
  296. ~~~~~~~~~~~~~~~~~
  297.  
  298. On behalf of the "GCCSDK developers", the following names have been
  299. registered for use in and by UnixLib :
  300.  
  301. - OS system variables : UnixEnv$* and UnixFS$*
  302. - Application names : UnixLib and GCC
  303.   [ Which also means that the UnixLib$* and GCC$* OS system variables
  304.     are registered too. ]
  305.  
  306. The previous usage of the OS system variables Unix$* has been discontinued.
  307.  
  308. -EOF-