home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (c) 1995, NeXT Computer, Inc.
- * All Rights Reserved.
- *
- * Derived from the CMU mach headers.
- */
-
- #ifndef _MACH_EMULATION_H
- #define _MACH_EMULATION_H
-
- #ifndef MACHEXPORT
- #if defined(WIN32) && defined(NEXTPDO)
- #define MACHEXPORT NEXTPDO
- #else
- #define MACHEXPORT extern
- #endif
- #endif
-
- /*
- * The greatly revered boolean type
- */
-
- #ifdef __svr4__
-
- #include <sys/types.h>
-
- #ifndef TRUE
- #define TRUE B_TRUE
- #endif
-
- #ifndef FALSE
- #define FALSE B_FALSE
- #endif
-
- #else
-
- typedef unsigned int boolean_t;
-
- #ifndef TRUE
- #define TRUE ((boolean_t) 1)
- #endif
-
- #ifndef FALSE
- #define FALSE ((boolean_t) 0)
- #endif
-
- #endif
-
-
-
- /*
- * Not a mach type, but lots of things need it.
- */
- #if defined(WIN32) && !defined(NEXT_CRT)
-
- #ifndef _DEFINE_PID_T
- #define _DEFINE_PID_T
- typedef unsigned long pid_t;
- #endif _DEFINE_PID_T
-
- #endif
-
-
- /*
- * Basic mach types
- */
-
- typedef unsigned int port_t;
- typedef unsigned int task_t;
-
-
-
- /*
- * Kernel return values
- */
-
- typedef int kern_return_t;
-
- #define KERN_SUCCESS 0
- #define KERN_INVALID_ADDRESS 1
- #define KERN_PROTECTION_FAILURE 2
- #define KERN_NO_SPACE 3
- #define KERN_INVALID_ARGUMENT 4
- #define KERN_FAILURE 5
- #define KERN_RESOURCE_SHORTAGE 6
- #define KERN_NOT_RECEIVER 7
- #define KERN_NO_ACCESS 8
- #define KERN_MEMORY_FAILURE 9
- #define KERN_MEMORY_ERROR 10
- #define KERN_ALREADY_IN_SET 11 /* obsolete */
- #define KERN_NOT_IN_SET 12
- #define KERN_NAME_EXISTS 13
- #define KERN_ABORTED 14
- #define KERN_INVALID_NAME 15
- #define KERN_INVALID_TASK 16
- #define KERN_INVALID_RIGHT 17
- #define KERN_INVALID_VALUE 18
- #define KERN_UREFS_OVERFLOW 19
- #define KERN_INVALID_CAPABILITY 20
- #define KERN_RIGHT_EXISTS 21
- #define KERN_INVALID_HOST 22
- #define KERN_MEMORY_PRESENT 23
-
-
-
- /*
- * Tasks
- */
-
- #define TASK_KERNEL_PORT 1 /* Not implemented */
- #define TASK_NOTIFY_PORT 2 /* Task receives kernel IPC notifications */
- #define TASK_EXCEPTION_PORT 3 /* Not implemented */
- #define TASK_BOOTSTRAP_PORT 4 /* Bootstrap server port */
-
- #define task_get_kernel_port(task, port) \
- (task_get_special_port((task), TASK_KERNEL_PORT, (port)))
- #define task_set_kernel_port(task, port) \
- (task_set_special_port((task), TASK_KERNEL_PORT, (port)))
- #define task_get_notify_port(task, port) \
- (task_get_special_port((task), TASK_NOTIFY_PORT, (port)))
- #define task_set_notify_port(task, port) \
- (task_set_special_port((task), TASK_NOTIFY_PORT, (port)))
- #define task_get_exception_port(task, port) \
- (task_get_special_port((task), TASK_EXCEPTION_PORT, (port)))
- #define task_set_exception_port(task, port) \
- (task_set_special_port((task), TASK_EXCEPTION_PORT, (port)))
- #define task_get_bootstrap_port(task, port) \
- (task_get_special_port((task), TASK_BOOTSTRAP_PORT, (port)))
- #define task_set_bootstrap_port(task, port) \
- (task_set_special_port((task), TASK_BOOTSTRAP_PORT, (port)))
-
-
-
- /*
- * Ports
- */
-
- typedef int port_type_t;
- typedef port_t port_all_t;
- typedef port_t port_name_t;
- typedef port_t port_set_name_t;
- typedef port_t port_name_array_t;
- typedef port_t *port_array_t;
-
- #define PORT_TYPE_NONE 0 /* No rights */
- #define PORT_TYPE_SEND 1 /* Send rights */
- #define PORT_TYPE_RECEIVE_OWN 7 /* Send, receive, ownership */
- #define PORT_TYPE_OWN 7 /* Same diff in our world */
- #define PORT_TYPE_SET 9 /* Port set ownership */
-
- #ifdef WIN32
- #define PORT_TYPE_MSGQ 10
- #define PORT_TYPE_HANDLE 11
- #endif
-
- #define PORT_NULL ((port_t) 0)
-
- #define PORT_BACKLOG_DEFAULT 5
- #define PORT_BACKLOG_MAX 16
-
-
-
- /*
- * vm types
- */
-
- typedef unsigned long vm_offset_t;
- typedef unsigned long vm_size_t;
-
- typedef vm_offset_t pointer_t;
- typedef vm_offset_t vm_address_t;
-
- typedef vm_offset_t vm_region_t;
- typedef vm_region_t *vm_region_array_t;
-
- vm_size_t __vm_page_size (void);
- #define vm_page_size __vm_page_size()
-
- #define round_page(x) (((vm_offset_t)(x) + (vm_page_size - 1)) & ~(vm_page_size - 1))
- #define trunc_page(x) ((vm_offset_t)(x) & ~(vm_page_size - 1))
-
- /*
- * Message data structures.
- *
- * Messages consist of two parts: a fixed-size header, immediately
- * followed by a variable-size array of typed data items.
- *
- */
-
- typedef unsigned int msg_size_t;
-
- typedef struct {
- unsigned int msg_unused : 24,
- msg_simple : 8;
- msg_size_t msg_size;
- int msg_type;
- port_t msg_local_port;
- port_t msg_remote_port;
- int msg_id;
- } msg_header_t;
-
- #define msg_info_bits msg_unused
- #define MSG_IS_LOCAL (0x1)
-
- #define MSG_SIZE_MAX 8192
-
- /*
- * Known values for the msg_type field.
- */
-
- #define MSG_TYPE_NORMAL 0
- #define MSG_TYPE_EMERGENCY 1
- #define MSG_TYPE_ENCRYPTED (1 << 7)
- #define MSG_TYPE_RPC (1 << 8)
-
- /*
- * Each data item is preceded by a description of that
- * item, including what type of data, how big it is, and
- * how many of them are present.
- *
- * The actual data will either follow this type
- * descriptor ("inline") or will be specified by a pointer.
- *
- * If the type name, size, or number is too large to be encoded
- * in this structure, the "longform" option may be selected,
- * and those fields must immediately follow in full integer fields.
- *
- * For convenience, out-of-line data regions or port rights may
- * be deallocated when the message is sent by specifying the
- * "deallocate" field. Beware: if the data item in question is both
- * out-of-line and contains port rights, then both will be deallocated.
- */
-
- typedef struct {
- unsigned int msg_type_name : 8, /* What kind of data */
- msg_type_size : 8, /* How many bits is each item */
- msg_type_number : 12, /* How many items are there */
- msg_type_inline : 1, /* If true, data follows; else a pointer */
- msg_type_longform : 1, /* Name, size, number follow: see above */
- msg_type_deallocate : 1, /* Deallocate port rights or memory */
- msg_type_unused : 1;
- } msg_type_t;
-
-
- typedef struct {
- msg_type_t msg_type_header;
- short msg_type_long_name;
- short msg_type_long_size;
- int msg_type_long_number;
- } msg_type_long_t;
-
- /*
- * Known values for the msg_type_name field.
- *
- * The only types known to the Mach kernel are
- * the port types, and those types used in the
- * kernel RPC interface.
- */
-
- #define MSG_TYPE_UNSTRUCTURED 0
- #define MSG_TYPE_BIT 0
- #define MSG_TYPE_BOOLEAN 0
- #define MSG_TYPE_INTEGER_16 1
- #define MSG_TYPE_INTEGER_32 2
- #define MSG_TYPE_PORT_ALL 5
- #define MSG_TYPE_PORT 6
- #define MSG_TYPE_CHAR 8
- #define MSG_TYPE_BYTE 9
- #define MSG_TYPE_INTEGER_8 9
- #define MSG_TYPE_REAL 10
- #define MSG_TYPE_STRING 12
- #define MSG_TYPE_STRING_C 12
- #define MSG_TYPE_PORT_NAME 15 /* A capability name */
-
- #define MSG_TYPE_POLYMORPHIC ((unsigned int) -1)
-
- /*
- * Is a given item a port?
- */
- #define MSG_TYPE_PORT_ANY(x) \
- (((x) == MSG_TYPE_PORT) || ((x) == MSG_TYPE_PORT_ALL))
-
- /*
- * Options to IPC primitives.
- *
- * These can be combined by or'ing; the combination RPC call
- * uses both SEND_ and RCV_ options at once.
- */
-
- typedef int msg_option_t;
- typedef int msg_timeout_t;
-
-
- #define MSG_OPTION_NONE 0x0000
-
- #define SEND_TIMEOUT 0x0001 /* Terminate on timeout elapsed */
- #define SEND_NOTIFY 0x0002 /* Terminate with reply message if need be (unimplemented) */
- #define SEND_INTERRUPT 0x0004 /* Terminate on software interrupt (unimplemented) */
- #define SEND_SWITCH 0x0020 /* Use handoff scheduling (unimplemented) */
-
- #define RCV_TIMEOUT 0x0100 /* Terminate on timeout elapsed */
- #define RCV_NO_SENDERS 0x0200 /* Terminate if I'm the only sender left (unimplemented) */
- #define RCV_INTERRUPT 0x0400 /* Terminate on software interrupt (unimplemented) */
- #define RCV_LARGE 0x1000 /* Don't dequeue too large messages */
-
-
- /*
- * Returns from IPC primitives.
- *
- * Values are separate in order to allow RPC users to
- * distinguish which operation failed; for successful completion,
- * this doesn't matter.
- */
-
- typedef int msg_return_t;
-
- #define SEND_SUCCESS KERN_SUCCESS
- #define SEND_INVALID_MEMORY -101 /* Message or OOL data invalid */
- #define SEND_INVALID_PORT -102 /* Reference to inacessible port */
- #define SEND_TIMED_OUT -103 /* Terminated due to timeout */
- #define SEND_WILL_NOTIFY -105 /* Msg accepted provisionally */
- #define SEND_NOTIFY_IN_PROGRESS -106 /* Already awaiting a notification */
- #define SEND_KERNEL_REFUSED -107 /* Message to the kernel refused */
- #define SEND_INTERRUPTED -108 /* Software interrupt during send */
- #define SEND_MSG_TOO_LARGE -109 /* Message specified was too large */
- #define SEND_MSG_TOO_SMALL -110 /* Data specified exceeds msg size */
-
- #define RCV_SUCCESS KERN_SUCCESS
- #define RCV_INVALID_MEMORY -201
- #define RCV_INVALID_PORT -202
- #define RCV_TIMED_OUT -203
- #define RCV_TOO_LARGE -204 /* Msg structure too small for data */
- #define RCV_NOT_ENOUGH_MEMORY -205 /* Can't find space for OOL data */
- #define RCV_ONLY_SENDER -206 /* Receiver is only sender */
- #define RCV_INTERRUPTED -207
- #define RCV_PORT_CHANGE -208 /* Port was put in a set */
- #define RCV_KERNEL_REFUSED -209 /* PDO specific */
-
- #define RPC_SUCCESS KERN_SUCCESS
-
-
- /*
- * MIG errors.
- */
-
- #define MIG_TYPE_ERROR -300 /* client type check failure */
- #define MIG_REPLY_MISMATCH -301 /* wrong reply message ID */
- #define MIG_REMOTE_ERROR -302 /* server detected error */
- #define MIG_BAD_ID -303 /* bad request message ID */
- #define MIG_BAD_ARGUMENTS -304 /* server type check failure */
- #define MIG_NO_REPLY -305 /* no reply should be sent */
- #define MIG_EXCEPTION -306 /* server raised exception */
- #define MIG_ARRAY_TOO_LARGE -307 /* array not large enough */
- #define MIG_SERVER_DIED -308 /* server died */
- #define MIG_DESTROY_REQUEST -309 /* destroy request with no reply */
-
- typedef struct {
- msg_header_t Head;
- msg_type_t RetCodeType;
- kern_return_t RetCode;
- } death_pill_t;
-
-
-
-
- /*
- * The IPC primitive functions themselves
- */
-
-
- MACHEXPORT msg_return_t msg_send (msg_header_t *header, msg_option_t option, msg_timeout_t timeout);
- MACHEXPORT msg_return_t msg_receive (msg_header_t *header, msg_option_t option, msg_timeout_t timeout);
- MACHEXPORT msg_return_t msg_rpc (msg_header_t *header, msg_option_t option, msg_size_t rcv_size, msg_timeout_t send_timeout, msg_timeout_t rcv_timeout);
-
- /*
- * task routines
- */
-
- //#define task_self() ((task_t) 1)
- //XXX #warning fix this when building in rc
- #define task_self() ((task_t) 0)
-
-
- /*
- * special port routines
- */
-
- MACHEXPORT kern_return_t task_get_special_port (task_t task, int type, port_t *port);
- MACHEXPORT kern_return_t task_set_special_port (task_t task, int type, port_t port);
-
- /*
- * vm routines
- */
-
- MACHEXPORT kern_return_t vm_allocate (task_t task, vm_address_t *addr, vm_size_t size, boolean_t anywhere);
- MACHEXPORT kern_return_t vm_deallocate (task_t task, vm_address_t addr, vm_size_t size);
- MACHEXPORT kern_return_t vm_copy (task_t task, vm_address_t src, vm_size_t size, vm_address_t dst);
- MACHEXPORT kern_return_t map_fd (int fd, vm_offset_t offset, vm_offset_t *addr, boolean_t find_space, vm_size_t size);
-
- /*
- * port routines
- */
-
- MACHEXPORT kern_return_t port_allocate (task_t task, port_t *p);
- MACHEXPORT kern_return_t port_deallocate (task_t task, port_t p);
- MACHEXPORT kern_return_t port_set_backlog (task_t task, port_t port, unsigned backlog);
- MACHEXPORT kern_return_t port_type (task_t task, port_name_t port, port_type_t *type);
- MACHEXPORT kern_return_t port_status (task_t task, port_name_t port, port_set_name_t *set, int *num_msgs, int *backlog, boolean_t *owner, boolean_t *receiver);
-
- #ifdef WIN32
- MACHEXPORT kern_return_t port_msgq_allocate (task_t task, unsigned long mask, port_t *p);
- MACHEXPORT kern_return_t port_handle_allocate (task_t task, void *handle, port_t *p);
- #endif
-
- /*
- * port set routines
- */
-
- MACHEXPORT kern_return_t port_set_allocate (task_t task, port_set_name_t *portsetp);
- MACHEXPORT kern_return_t port_set_deallocate (task_t task, port_set_name_t portset);
- MACHEXPORT kern_return_t port_set_add (task_t task, port_set_name_t portset, port_t port);
- MACHEXPORT kern_return_t port_set_remove (task_t task, port_t port);
- MACHEXPORT kern_return_t port_set_status(task_t task, port_set_name_t set_name, port_name_array_t *members, unsigned int *members_count);
- MACHEXPORT kern_return_t port_set_add_again (task_t task, port_set_name_t portset, port_t port);
- MACHEXPORT kern_return_t port_set_remove_once (task_t task, port_set_name_t portset, port_t port);
-
- /*
- * error routines
- */
-
- MACHEXPORT const char *mach_error_string (kern_return_t error_value);
- MACHEXPORT void mach_error (const char *str, kern_return_t error_value);
- MACHEXPORT char *mach_errormsg (kern_return_t error_value);
-
- /*
- * special ports
- */
- MACHEXPORT port_t bootstrap_port;
- MACHEXPORT port_t name_server_port;
-
- #include <mach/notify.h>
- #include <mach/cthreads.h>
- #include <servers/bootstrap.h>
- #include <servers/netname.h>
-
- #endif _MACH_EMULATION_H
-
-