home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 15 / AACD15.ISO / AACD / System / MorphOS / Developer / emulinclude / includestd / ix.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-11-02  |  9.9 KB  |  336 lines

  1. #ifndef __IX_H
  2. #define __IX_H
  3.  
  4. /* This header provides prototypes for ixemul specific functions and
  5.  * variables available in ixemul.library or libc.a.
  6.  *
  7.  * Each function is also documented in this header (or will be). Sometimes
  8.  * an ixemul extension is described here, but for ease of use the original
  9.  * prototype or macro is defined elsewhere.
  10.  */
  11.  
  12. /* Some forward declarations...
  13.  */
  14. struct Library;
  15. struct __res_state;
  16. struct timeval;
  17. struct Process;
  18. struct WBStartup;
  19.  
  20.  
  21. /* This tells you which OS you are running on.
  22.  */
  23. extern int ix_os;
  24.  
  25. #define OS_IS_AMIGAOS   0
  26. #define OS_IS_POS       0x704F5300      /* 'pOS\0' */
  27.  
  28.  
  29. /* This is the name of the program without the path. E.g., if argv[0] is
  30.  * "/gg/bin/cat", then __progname is "cat".
  31.  */
  32. extern char *__progname;
  33.  
  34.  
  35. /* This macro can be ORed with the other flags you pass to open(). It will
  36.  * make the open() function case sensitive. This macro is defined in
  37.  * sys/fcntl.h.
  38.  *
  39.  * #define     O_CASE          0x1000
  40.  */
  41.  
  42.  
  43. /* Like vfork(), but the memory that the child allocates will be owned by
  44.  * the child. vfork() uses the parent's memory list, but since ix_vfork() is
  45.  * used as a fork() emulation, this would be undesirable, not in the least
  46.  * because that memory wouldn't be released until the parent exits. Causing
  47.  * a huge memory leak.
  48.  */
  49. int ix_vfork(void);
  50.  
  51.  
  52. /* This function is used to obtain and set variables from ixemul.library.
  53.  * In general, this is not a function you should call yourself.
  54.  * Only the startup code should use this. If you need to call this
  55.  * function for some reason, I recommend that the ix_get_variables()
  56.  * function from crt0.c is used instead (see below).
  57.  */
  58. void ix_get_vars(int argc, char **ctype, int *_sys_nerr, 
  59.               struct Library **sysbase, struct Library **dosbase,
  60.               FILE ***fpp, char ***environ_out, char ***environ_in,
  61.               int *real_errno, int *real_h_errno, struct __res_state *_res,
  62.               int *_res_socket, int *ExecLib);
  63.  
  64.  
  65. /* A wrapper function for ix_get_vars(). This is not an ixemul function,
  66.  * but it is part of crt0.c. The single argument should be set to 0.
  67.  */
  68. void ix_get_variables(int from_vfork_setup_child);
  69.  
  70.  
  71. /* This is a wrapper intended to make life just a little bit easier for those
  72.  * who need to use the ix_vfork()/ix_vfork_resume() trick.  It replaces the old
  73.  * 'ix_resident()/ix_get_vars()' pair.
  74.  */
  75. void ix_vfork_setup_child(void);
  76.  
  77.  
  78. /* This is an implementation extension to the `real' ix_vfork(). Normally you
  79.  * can only cause the parent to resume by calling _exit() or execve() from
  80.  * the child. Since there is no real fork() in ixemul, this function
  81.  * is a third possibility to make the parent resume. You have then two
  82.  * concurrent processes sharing the same frame and global data. Please be
  83.  * EXTREMELY careful what you may do and what not. ix_vfork() itself is a hack,
  84.  * this is an even greater one...
  85.  *
  86.  * DO NOT use this function in combination with vfork(), or you'll get a big
  87.  * memory leak. Only use it with ix_vfork().
  88.  */
  89. void ix_vfork_resume(void);
  90.  
  91.  
  92. /* This function will show a requester with the given formatted string as
  93.  * the body text and with one or two buttons. If button1 is NULL, then an
  94.  * Abort button is shown. If button1 is not NULL, but button2 is, then only
  95.  * a single button is shown. The title of the requester is passed in the
  96.  * first argument. If that argument is NULL, then ixemul will use the program
  97.  * name instead. Use this function to show a message in an OS independent
  98.  * fashion.
  99.  *
  100.  * The function returns 0 is button1 is pressed and 1 otherwise.
  101.  *
  102.  * Example: ix_req(NULL, "Abort", NULL, "%s only supports AmigaOS!", __progname);
  103.  * choice = ix_req(NULL, "Abort", "Continue", "Cannot find file %s", filename);
  104.  */
  105. int ix_req(char *title, char *button1, char *button2, char *fmt, ...);
  106.  
  107.  
  108. /* Similar to chmod(), but obtains the original OS protection bits.
  109.  * No translation to Unix protection bits has taken place.
  110.  */
  111. int ix_chmod(char *name, int mode);
  112.  
  113.  
  114. /* Like select() but you can pass a pointer to an extra bitmask as the last
  115.  * argument. In that case select() will also wait on these signal bits and
  116.  * return if one of these signals came in. The contents of mask will be set
  117.  * to the signals that arrived.
  118.  */
  119. int ix_select(int nfd, fd_set *ifd, fd_set *ofd, fd_set *efd,
  120.               struct timeval *timeout, long *mask);
  121.  
  122. /* Use ix_wait instead of Wait(): this way ixemul will handle Ctrl-C correctly
  123.  * for you and will also take care of ASYNC file streams, sending a SIGIO
  124.  * signal if something arrives.
  125.  */
  126. #define ix_wait(pmask) ix_select(0, NULL, NULL, NULL, NULL, pmask)
  127.  
  128. /* This function returns the internal OS filehandle for a given ixemul file
  129.  * descriptor. Note that this function can return 0 as not every descriptor
  130.  * is actually a file. Use this function very restrictively: it lets you
  131.  * use OS functions on ixemul descriptors and mixing these two can be a
  132.  * tricky thing.
  133.  */
  134. long ix_filehandle(int fd);
  135.  
  136.  
  137. /* These two functions can be used to walk through all the segments in a
  138.  * segmentlist. These functions are used by gdb using segment list pointers
  139.  * obtained through the ptrace() call. They are generally used like this:
  140.  *
  141.  *      ix_segment *seg;
  142.  *
  143.  *    for (seg = ix_get_first_segment(seglist);
  144.  *           seg;
  145.  *           seg = ix_get_next_segment())
  146.  *      {
  147.  *        .....
  148.  *      }
  149.  */
  150.  
  151. /* These are the possible segment type values
  152.  */
  153. #define IX_SEG_TYPE_UNKNOWN 0
  154. #define IX_SEG_TYPE_TEXT    1
  155. #define IX_SEG_TYPE_DATA    2
  156. #define IX_SEG_TYPE_BSS     3
  157. #define IX_SEG_TYPE_MAX     3
  158.  
  159. /* The segment info is stored in this static (!) structure.
  160.  * So you cannot walk through two segment lists at the same time
  161.  * in the same program.
  162.  */
  163. typedef struct
  164. {
  165.   void *start;
  166.   unsigned long size;
  167.   int type;
  168. } ix_segment;
  169.  
  170.  
  171. /* The function prototypes
  172.  */
  173. ix_segment *ix_get_first_segment(long seglist);
  174. ix_segment *ix_get_next_segment(void);
  175.  
  176.  
  177. /* Flush the instruction cache from the given address with the given
  178.  * length.
  179.  */
  180. void ix_flush_insn_cache(void *addr, int length);
  181.  
  182.  
  183. /* Flush the data cache from the given address with the given
  184.  * length.
  185.  */
  186. void ix_flush_data_cache(void *addr, int length);
  187.  
  188.  
  189. /* Flush all caches completely
  190.  */
  191. void ix_flush_caches(void);
  192.  
  193.  
  194. /* These two function query and set certain properties of ixemul.library.
  195.  * Given a certain ID, ix_get_long will return the corresponding value or
  196.  * -1 if not found. Some IDs may require extra information passed in the 
  197.  * 'extra' argument. Set to 0 unless stated otherwise in the ID
  198.  * description.
  199.  *
  200.  * ix_set_long will set the value of the given ID. It returns -1 if it
  201.  * couldn't set the value and it returns the old value otherwise.
  202.  */
  203. long ix_get_long(unsigned long id, unsigned long extra);
  204. long ix_set_long(unsigned long id, long value);
  205.  
  206. /* Valid IDs: */
  207.  
  208. /* The version number of the library, output only
  209.  */
  210. #define IXID_VERSION          0
  211.  
  212. /* The revision number of the library, output only
  213.  */
  214. #define IXID_REVISION         1
  215.  
  216. /* Get/set the per-task freely usable user field, input/output
  217.  */
  218. #define IXID_USERDATA         2
  219.  
  220. /* Get the pointer to the user struct, output only
  221.  */
  222. #define IXID_USER             3
  223.  
  224. /* Get the number of reserved a4 pointers (for the shared ixlibraries),
  225.  * output only.
  226.  */
  227. #define IXID_A4_PTRS           4
  228.  
  229. /* Return TRUE if an FPU is present
  230.  */
  231. #define IXID_HAVE_FPU           5
  232.  
  233. /* Return CPU identification (see below)
  234.  */
  235. #define IXID_CPU                6
  236.  
  237. /* Return OS identification (see description of ix_os above)
  238.  */
  239. #define IXID_OS                 7
  240.  
  241. /* Return u_ofile[] from the user struct
  242.  */
  243. #define IXID_OFILE              8
  244.  
  245. /* Return u_environ from the user struct
  246.  */
  247. #define IXID_ENVIRON            9
  248.  
  249. /* Return u_expand_cmd_line from the user struct
  250.  */
  251. #define IXID_EXPAND_CMD_LINE    10
  252.  
  253.  
  254. /* CPU identifications: */
  255. #define IX_CPU_68000        0
  256. #define IX_CPU_68010        1
  257. #define IX_CPU_68020        2
  258. #define IX_CPU_68030        3
  259. #define IX_CPU_68040        4
  260. #define IX_CPU_68060        6
  261.  
  262.  
  263. /* Duplicates and releases the socket "fd" to the TCP/IP stack so
  264.  * other processes can use it. The return value should be used with
  265.  * obtainsocket(). NOTE: The original socket is still valid!
  266.  */
  267. int ix_release_socket(int fdes);
  268.  
  269. /* Gains access to the socket with id "id". id was the return value of
  270.  * releasesocket() and the domain, type, protocol should match the arguments
  271.  * of the socket() call.
  272.  */
  273. int ix_obtain_socket(long id, int inet, int stream, int protocol);
  274.  
  275. /* Structure for OS independent semaphores. The 124 bytes buffer is
  276.  * big enough to store an AmigaOS or a p.OS semaphore and leaves enough
  277.  * room for future expansion.
  278.  *
  279.  * Before using this structure you must ensure that ix_mutex_initialized
  280.  * is 0!
  281.  */
  282. struct ix_mutex
  283. {
  284.   int  ix_mutex_initialized;
  285.   char ix_mutex_buf[124];
  286. };
  287.  
  288.  
  289. /* Lock this mutex. Locks may be nested!
  290.  * Returns 0 if succeeds, -1 if it fails. In case of failure, errno will
  291.  * contain the cause. Currently it never fails, but in the future it may
  292.  * fail and set errno to EINTR.
  293.  */
  294. int ix_mutex_lock(struct ix_mutex *mutex);
  295.  
  296. /* Try to lock this mutex. Locks may be nested!
  297.  * Returns 0 if succeeds, -1 if it fails. In case of failure, errno will
  298.  * contain the cause. If it couldn't lock the mutex, errno will be set to
  299.  * EAGAIN.
  300.  */
  301. int ix_mutex_attempt_lock(struct ix_mutex *mutex);
  302.  
  303. /* Unlock the mutex.
  304.  */
  305. void ix_mutex_unlock(struct ix_mutex *mutex);
  306.  
  307. /* Do not use: low level functions. Required for ppc support.
  308.  */
  309. char **__ix_get_environ(void);
  310. void __ix_init_ids(void);
  311. void __ix_cli_parse(struct Process *this_proc, long alen, char *_aptr, int *argc, char ***argv);
  312. int  __ix_wb_parse(struct Process *ThisProcess, struct WBStartup *WBenchMsg, char *default_wb_window);
  313. void __ix_install_sigwinch (void);
  314. void __ix_remove_sigwinch (void);
  315.  
  316. #if 0
  317. ix_resident
  318. // use ix_geta4 in callbacks installed using funopen() when -resident
  319. ix_geta4
  320. ix_check_cpu
  321. ix_tracecntl
  322. ix_default_wb_window
  323. ix_get_gmt_offset
  324. ix_set_gmt_offset
  325. ix_get_default_settings
  326. ix_get_settings
  327. ix_set_settings
  328. __init_stk_limit
  329. __stkovf
  330. __stkext
  331. __stkext_f
  332. __stkrst
  333. #endif
  334.  
  335. #endif
  336.