/* Presentation of the rtmk kernel interface. -*-C-*- Copyright 1999-2002 Johan Rydberg, jrydberg@rtmk.org. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* Some frequently used kernel interface functions are implemented as system calls. If that does not work, we revert to RPC. */ #define _XCONCAT(STR1, STR2) STR1 ## STR2 #define CONCAT(STR1, STR2) _XCONCAT(STR1, STR2) #ifndef SYSCALL_OPTIMIZED_PREFIX #define SYSCALL_OPTIMIZED_PREFIX viarpc_ #endif #define SYSCALL(X) CONCAT(SYSCALL_OPTIMIZED_PREFIX, X) presentation rtmk implements rtmk { /* Create a child task to PARENT task. Send right to new task is returned in NEW_TASKP. If INHERIT_P is true, new task inherits parent's memory. */ kern_return_t task_create (rtmk_port_t task, int inherit_p, rtmk_port_t *new_taskp); /* Terminate TASK. All resources held by TASK is destroyed. */ kern_return_t task_terminate (rtmk_port_t task); /* Set special port in TASK to PORT at SLOT in special port array. */ kern_return_t task_special_port_set (rtmk_port_t task, int slot, rtmk_port_t port); /* Get send rights to port SLOT in TASK's special port set. Right is returned in PORTP. */ kern_return_t task_special_port_get (rtmk_port_t task, int slot, rtmk_port_t *portp); /* Return send rights to threads that belong to TASK. Send rights are returned in THREADSP. Memory should be deallocated. */ kern_return_t task_threads (rtmk_port_t task, rtmk_port_t **threadp, in int *count (length-of threadp)); /* Create new thread in TASK's address and IPC space. On return, *NEW_THREADP will hold send right to thread. */ kern_return_t thread_create (rtmk_port_t task, rtmk_port_t *new_threadp); /* Terminate THREAD. */ kern_return_t thread_terminate (rtmk_port_t thread); /* Suspend execution of THREAD, prevent it from running. When this is called, the thread is no longer running (if it was). */ kern_return_t thread_suspend (rtmk_port_t thread); /* Resume execution of THREAD, if its suspend count drops to zero. */ kern_return_t thread_resume (rtmk_port_t thread); /* Get state for THREAD. FLAVOR specifies what type of state. State is returned in BUF. */ kern_return_t thread_state_get (rtmk_port_t thread, int flavor, void *buf, inout int *count (length-of buf, force-encode)); /* Set state for THREAD. FLAVOR specifies what type of state. State is located in BUF. */ kern_return_t thread_state_set (rtmk_port_t thread, int flavor, void *buf, int count (length-of buf)); /* Allocate a new port in TASK's IPC space. If the caller is not a thread within TASK, it will not own any rights to the port. Port name is returned in PORTP. */ kern_return_t port_allocate (rtmk_port_t task, rtmk_port_t *namep); /* Allocate port in TASK's IPC space. We incist on PORT_NAME. */ kern_return_t port_allocate_name (rtmk_port_t task, rtmk_port_name_t port_name); /* Deallocate right to PORT_NAME. */ kern_return_t SYSCALL (port_deallocate) (rtmk_port_t task, rtmk_port_name_t port_name) extends port_deallocate; /* Destroy PORT_NAME. Will make the port a zombie port, until all user references are droped, and the port is deallocated. */ kern_return_t SYSCALL (port_destroy) (rtmk_port_t task, rtmk_port_name_t port_name) extends port_destroy; /* Allocate a new port set. When created the port set does not contain any members. Return receive rights in PSETP. */ kern_return_t port_set_allocate (rtmk_port_t task, rtmk_port_t *psetp); /* Insert PORT into PORT_SET. If PORT_SET is NULL, we remove PORT from the port set it currently belongs to. */ kern_return_t port_move_member (rtmk_port_t task, rtmk_port_name_t port, rtmk_port_name_t port_set); /* Inserts into TASK the caller's right for PORT. RIGHT_NAME is name in TASK's IPC object. PORT_TYPE specifies right type. */ kern_return_t port_insert_right (rtmk_port_t task, rtmk_port_name_t right_name, rtmk_port_t port, rtmk_port_type_t port_type (type-of port)); /* Map SIZE bytes of OBJECT at *ADDRESS in TASKs address space. If ANYWHERE is false, try fixed offset specified by *ADDRESS, otherwise choose available memory location. */ kern_return_t vm_map (rtmk_port_t task, vm_offset_t *address, vm_size_t size, int anywhere, rtmk_port_t object, vm_offset_t offset, int copy, vm_prot_t prot, vm_prot_t max_prot, vm_inherit_t inherit); /* Allocate memory in TASK's address space. SIZE should be rouned up to whole pages. If ANYWHERE is false, try fixed offset specified by *ADDRESS, otherwise choose available memory location. */ kern_return_t vm_allocate (rtmk_port_t task, vm_offset_t *address, vm_size_t size, int anywhere); /* Deallocate memory object at OFFSET within TASK's address space. */ kern_return_t vm_deallocate (rtmk_port_t task, vm_offset_t address, vm_size_t size); /* Sets the protection for address region [ADDRESS, ADDRESS+SIZE) in TASK to PROTECTION. If SETMAX_P is specified, the maximum protection is to be set; otherwise, only the current protection is affected. */ kern_return_t vm_protect (rtmk_port_t task, vm_offset_t address, vm_size_t size, vm_prot_t protection, int setmax); /* Write into TASKs address space at offset DST_OFFSET, from current tasks address space at SRC_OFFSET. Copy LENGTH bytes. */ kern_return_t vm_write (rtmk_port_t task, vm_offset_t dst_offset, vm_offset_t src_offset, vm_size_t length); /* Reboot host. HOST must be master host port. */ kern_return_t host_reboot (rtmk_port_t host); /* Attach event counter EVC to interrupt with vector INTR_NO. */ kern_return_t host_attach_interrupt (rtmk_port_t host, int intr_no, rtmk_port_t evc); /* Get information about the system. FLAVOR specifies what info. */ kern_return_t host_info (rtmk_port_t host, int flavor, void *buf, inout int *count (length-of buf, force-encode)); /* Allocate new event counter for TASK. Return name of it in *EVCP. */ kern_return_t eventcnt_allocate (rtmk_port_t task, rtmk_port_t *evcp); /* Memory object functions. */ /* Make region [OFFSET, OFFSET+SIZE) of memory object PAGER_REQUEST unavailable. Unavailable pages will be zero-filled. */ kern_return_t memory_object_data_unavail (rtmk_port_t mem_obj, vm_offset_t offset, vm_size_t size); /* Supply the kernel with data for MEM_OBJ. OFFSET is the offset into the object. ADDRESS points to the data in current tasks address space. SIZE is the amount of data that user supplys. If DEALLOC is true, the region [ADDRESS, ADDRESS+SIZE) is deallocated. PROT_LOCK specifes locking of pages. If PRECIOUS is true, the page is flushed back to the pager before destroyed. */ kern_return_t memory_object_data_supply (rtmk_port_t mem_obj, vm_offset_t offset, vm_offset_t address, vm_size_t size, int dealloc, vm_prot_t prot_lock, int precious); /* Set attributes for MEM_OBJ. Announce object as ready if READY is true. If CACHE is true, the object can persist. STRATEGY specifices copy strategy for object. */ kern_return_t memory_object_set_attributes (rtmk_port_t mem_obj, int ready, int cache, int strategy); /* Change attributes for MEM_OBJ. If READY is true, the object can persist. STRATEGY specifies copy strategy for object. ??? should we send reply? */ kern_return_t memory_object_change_attributes (rtmk_port_t mem_obj, int ready, int strategy); };