====== MINIX 3 Kernel API ======
int sys_memset(endpoint_t who, unsigned long pattern, phys_bytes base, phys_bytes bytes);
The **sys_memset** function sets //length// bytes starting from physical address //base// to the low-order byte of //pattern//.
**Return values**:\\
OK: Call always succeeds.
**Notes**: \\
This function is used, for example, to zero the BSS segment on an exec() POSIX-call. The kernel is asked to do the work for performance reasons.
==== .SYS_NEWMAP ====
This is an obsolete call. Description is kept here just to understand old code.
Install a new memory map for a newly forked process or if a process's memory map is changed. The kernel fetches the new memory map from PM and updates its data structures.
**request parameters**\\ PR_ENDPT: Install new map for this process.\\ PR_MEM_PTR: Pointer to memory map at PM.\\
**return value**\\ OK: New map was successfully installed. \\ EFAULT: Incorrect address for new memory map. \\ EINVAL: Invalid process number. \\
**library functions**\\ int sys_newmap(endpoint_t proc_nr, struct mem_map *ptr);
==== .SYS_NICE ====
This is an obsolete call. Description is kept here just to understand old code.
Change a process' priority. This is done by passing a nice value between PRIO_MIN(negative) and PRIO_MAX(positive). A nice value of zero resets the priority to the default.
**request parameters**\\ PR_ENDPT: Process whose priority should be changed.\\ PR_PRIORITY: New nice value for process' priority.
**return value**\\ OK: New priority was successfully set.\\ EINVAL: Invalid process number of priority.\\ EPERM: Cannot change priority of kernel task.
**library functions**\\ int sys_nice(endpoint_t proc_nr, int priority);
==== SYS_PADCONF ====
**request parameters**\\ //(to be documented)//
**response parameters**\\ //(to be documented)//
**return value**\\ //(to be documented)//
**library functions**\\ //(to be documented)//
==== SYS_PHYSCOPY ====
Copy data using physical addressing. The source and/or destination address can be virtual like with [[#sys_vircopy|SYS_VIRCOPY]], but in addition an arbitrary physical address is accepted with PHYS_SEG.
**request parameters**\\ CP_SRC_SPACE: Source segment.\\ CP_SRC_ADDR: Virtual source address.\\ CP_SRC_ENDPT: Process number of the source process.\\ CP_DST_SPACE: Destination segment.\\ CP_DST_ADDR: Virtual destination address.\\ CP_DST_ENDPT: Process number of the destination process.\\ CP_NR_BYTES: Number of bytes to copy.
**return value**\\ OK: The copying was done.\\ EDOM: Invalid copy count.\\ EFAULT: Virtual to physical mapping failed.\\ EINVAL: Incorrect segment type of process number.\\ EPERM: Only owner of REMOTE_SEG can copy to or from it.
**library functions**\\ int sys_abscopy(phys_bytes src_phys, phys_bytes dst_phys, phys_bytes count);\\ int sys_physcopy(endpoint_t src_proc, vir_bytes src_vir, endpoint_t dst_proc, vir_bytes dst_vir, phys_bytes count);
==== SYS_PRIVCTL ====
Get a private privilege structure and update a process' privileges. This is used to dynamically start system services. For VM, this call also supports querying a memory range for previously added memory permissions.
**request parameters**\\ CTL_ENDPT: Process whose privileges should be updated/queried.\\ CTL_REQUEST: The privilege modification/query request.
* SYS_PRIV_ALLOW: Allow a process to run.
* SYS_PRIV_DISALLOW: Disallow a process from running.
* SYS_PRIV_SET_SYS: Give a process system privileges.
* SYS_PRIV_SET_USER: Give a process user privileges.
* SYS_PRIV_ADD_IO: Add an I/O range to the process's resources.
* SYS_PRIV_ADD_MEM: Add a memory range to the process's resources
* SYS_PRIV_ADD_IRQ: Add an IRQ to the process's resources.
* SYS_PRIV_QUERY_MEM: Check if the process has permission to access a physical memory range.
CTL_ARG_PTR: Pointer to arguments for this request (**not** for SYS_PRIV_QUERY_MEM).\\ CTL_PHYSSTART: Start of physical memory range to test (only for SYS_PRIV_QUERY_MEM).\\ CTL_PHYSLEN: Length of physical memory range to test (only for SYS_PRIV_QUERY_MEM).
**return value**\\ OK: The calls succeeded.\\ EINVAL: Invalid process number, request, or arguments.\\ ENOSPC: No free privilege structure found.\\ EPERM: Resources can not be added to user processes, or permission denied.\\ ENOMEM: No storage available for this resource.
**library functions**\\ int sys_privctl(endpoint_t proc, int req, void *p);\\ int sys_privquery_mem(endpoint_t proc, phys_bytes start, phys_bytes len);
==== .SYS_PROFBUF ====
Obsolete call.
==== SYS_READBIOS ====
Copy from the BIOS area.
**request parameters**\\ RDB_ADDR: Absolute address in BIOS area.\\ RDB_BUF: Buffer address in the requesting process.\\ RDB_SIZE: The number of bytes to copy.
**return value**\\ OK: The call succeeded.\\ EDOM: Invalid number of bytes.\\ EFAULT: Invalid buffer address.
**library functions**\\ int sys_readbios(phys_bytes address, void *buf, size_t size);
==== SYS_RUNCTL ====
Control the process's PROC_STOP flag. Used for process management (by PM). Stopping a process is generally done for the purpose of either setting up a signal handler or stopping a process that is about to be killed. When stopping for setting up a signal handler, the RC_DELAY flag will be supplied. This means that if the process is queued sending a message, or stopped for system call tracing, then this call will, instead of stopping the process, return EBUSY and later send a //SIGNDELAY// pseudo-signal to the process when it has been established that this process will not send a message anymore. The process never becomes actually runnable before PM eventually tells the kernel that it is done processing the SIGNDELAY (using [[.:#sys_endksig|SYS_ENDKSIG]]). This "delay stop" mechanism is used by PM to make sure that no signal is delivered to a process that still has a call pending to a system server. This is required for POSIX compliance.
**request parameters**\\ RC_ENDPT: The process number to control.\\ RC_ACTION: Stop or resume the process.
* RC_STOP: Stop the process.
* RC_RESUME: Resume the process.
RC_FLAGS: Request flags.
* RC_DELAY: Delay stop if process is sending.
**return value**\\ OK: The call succeeded.\\ EINVAL: Invalid process number.\\ EPERM: The caller is a kernel task.\\ EBUSY: The process is blocked sending a message or blocked for system call tracing.
**library functions**\\ int sys_runctl(endpoint_t proc_ep, int action, int flags);\\ int sys_stop(endpoint_t proc_ep);\\ int sys_delay_stop(endpoint_t proc_ep);\\ int sys_resume(endpoint_t proc_ep);
==== SYS_SAFECOPYFROM ====
Copy data from a granted memory area of another process, into one's own address space. The caller must have CPF_READ access to the grant.
**request parameters**\\ SCP_FROM_TO: The process endpoint to copy from.\\ SCP_SEG: The segment within the caller to copy to (typically D).\\ SCP_GID: The grant ID.\\ SCP_OFFSET: Starting byte offset within the grant.\\ SCP_ADDRESS: Pointer to buffer to store the data in.\\ SCP_BYTES: Number of bytes to copy.
**return value**\\ OK: The call succeeded.\\ EINVAL: Invalid process number.\\ EPERM: Invalid grant ID, insufficient access, or bad byte range.\\ ELOOP: Chain of indirect grants too long.
**library functions**\\ int sys_safecopyfrom(endpoint_t source, cp_grant_id_t grant, vir_bytes grant_offset, vir_bytes my_address, size_t bytes);
==== SYS_SAFECOPYTO ====
Copy data from one's own address space, to a granted memory area of another process. The caller must have CPF_WRITE access to the grant.
**request parameters**\\ SCP_FROM_TO: The process endpoint to copy to.\\ SCP_SEG: The segment within the caller to copy from (typically D).\\ SCP_GID: The grant ID.\\ SCP_OFFSET: Starting byte offset within the grant.\\ SCP_ADDRESS: Pointer to data to copy.\\ SCP_BYTES: Number of bytes to copy.
**return value**\\ OK: The call succeeded.\\ EINVAL: Invalid process number.\\ EPERM: Invalid grant ID, insufficient access, or bad byte range.\\ ELOOP: Chain of indirect grants too long.
**library functions**\\ int sys_safecopyto(endpoint_t dest, cp_grant_id_t grant, vir_bytes grant_offset, vir_bytes my_address, size_t bytes);
==== SYS_SAFEMEMSET ====
Fill a memory grant with a constant pattern byte.
int sys_safememset(endpoint_t endpt, cp_grant_id_t grant, vir_bytes grant_offset, int pattern, size_t bytes);
The **sys_safememset** function sets //bytes// bytes from offset //grant_offset// in memory grant //grant// to the low-order byte of //pattern//.
**Return values** (not complete):\\
OK: //bytes// bytes filled with the pattern byte.\\
EPERM: Caller has no write permissions (CPF_WRITE) for //grant//. \\
EPERM: Permission checks for //grant// failed. \\
**Notes:** \\
The memory driver uses this function for reads of /dev/zero to set a requestor's buffer to all '\0'.
==== SYS_SCHEDCTL ====
**request parameters**\\ //(to be documented)//
**response parameters**\\ //(to be documented)//
**return value**\\ //(to be documented)//
**library functions**\\ //(to be documented)//
==== SYS_SCHEDULE ====
**request parameters**\\ //(to be documented)//
**response parameters**\\ //(to be documented)//
**return value**\\ //(to be documented)//
**library functions**\\ //(to be documented)//
==== SYS_SDEVIO ====
Perform device I/O on behalf of a user-space device driver. Note that this call supports only byte and word granularity. The driver can request input or output of an entire buffer. Also see [[#sys_devio|SYS_DEVIO]] and [[#sys_vdevio|SYS_VDEVIO]] kernel calls.
**request parameters**\\ DIO_REQUEST: Flags indicating what to do.
* _DIO_INPUT: Read one or more values from the given port.
* _DIO_OUTPUT: Write one or more values to the given port.\\\\
* _DIO_BYTE: Read/write byte values.
* _DIO_WORD: Read/write word values.\\\\
* _DIO_SAFE: The given address is a grant.
DIO_PORT: The port to be read or written.\\ DIO_VEC_ENDPT: Process number where buffer is.\\ DIO_VEC_ADDR: Virtual address of buffer, or grant ID.\\ DIO_VEC_SIZE: Number of elements to input or output.\\ DIO_OFFSET: Offset into grant.
**return value**\\ OK: The port I/O was successfully done.\\ EINVAL: Invalid request or port granularity.\\ EPERM: Cannot do I/O for kernel tasks.\\ EFAULT: Invalid virtual address of buffer.
**library functions**\\ int sys_insb(port_t port, u8_t buffer, int count);\\ int sys_insw(port_t port, u16_t buffer, int count);\\ int sys_outsb(port_t port, u8_t buffer, int count);\\ int sys_outsw(port_t port, u16_t buffer, int count);\\ int sys_safe_insb(port_t port, endpoint_t proc_nr, void *grant, int count, vir_bytes offset);\\ int sys_safe_insw(port_t port, endpoint_t proc_nr, void *grant, int count, vir_bytes offset);\\ int sys_safe_outsb(port_t port, endpoint_t proc_nr, void *grant, int count, vir_bytes offset);\\ int sys_safe_outsw(port_t port, endpoint_t proc_nr, void *grant, int count, vir_bytes offset);\\ int sys_sdevio(int req, long port, endpoint_t proc_nr, void *buffer, int count, vir_bytes offset);
==== SYS_SETALARM ====
Set or reset a synchronous alarm timer. When the timer expires it causes a SYN_ALARM notification message with the current uptime as an argument to be sent to the caller. Only system processes can request synchronous alarms.
**request parameters**\\ ALRM_EXP_TIME: Absolute or relative expiration time in ticks for this alarm.\\ ALRM_ABS_TIME: Zero if expire time is relative to the current uptime.
**response parameters**\\ ALRM_TIME_LEFT: Ticks left on the previous alarm.
**return value**\\ OK: The alarm was successfully set.\\ EPERM: User processes cannot request alarms.
**library functions**\\ int sys_setalarm(clock_t expire_time, int abs_flag);
==== SYS_SETGRANT ====
Set the address and size of the process's grant table. The previous address and size will be replaced.
**request parameters**\\ SG_ADDR: Address of grant table in own address space.\\ SG_SIZE: Number of entries.
**return value**\\ OK: The grant table has been set.\\ EPERM: The caller has no privilege table.
**library functions**\\ int sys_setgrant(cp_grant_t *grants, int ngrants);
==== SYS_SETMCONTEXT ====
**request parameters**\\ //(to be documented)//
**response parameters**\\ //(to be documented)//
**return value**\\ //(to be documented)//
**library functions**\\ //(to be documented)//
==== SYS_SETTIME ====
**request parameters**\\ //(to be documented)//
**response parameters**\\ //(to be documented)//
**return value**\\ //(to be documented)//
**library functions**\\ //(to be documented)//
==== SYS_SIGRETURN ====
Return from a POSIX-style signal handler. The PM requests the kernel to put things in order before the signalled process can resume execution. Also see the [[#sys_sigsend|SYS_SIGSEND]] kernel call that pushes a signal context frame onto the stack.
**request parameters**\\ SIG_ENDPT: Indicates the process was signalled.\\ SIG_CTXT_PTR: Pointer to context structure for POSIX-style signal handling.
**return value**\\ OK: Signal handling action successfully performed.\\ EINVAL: Invalid process number or context structure.\\ EFAULT: Invalid context structure address, or could not copy signal frame.
**library functions**\\ int sys_sigreturn(endpoint_t proc_nr, struct sigmsg *sig_context);
==== SYS_SIGSEND ====
Signal a process on behalf of the PM by placing the context structure onto the stack. The kernel fetches the structure, initializes it, and copies it to the user's stack.
**request parameters**\\ SIG_ENDPT: Indicates the process that was signalled.\\ SIG_CTXT_PTR: Pointer to content structure for POSIX-style signal handling.
**return value**\\ OK: Signal handling action successfully performed.\\ EINVAL: Invalid process number.\\ EPERM: Cannot signal kernel tasks.\\ EFAULT: Invalid context structure address, or could not copy signal frame.
**library functions**\\ int sys_sigsend(endpoint_t proc_nr, struct sigmsg *sig_context);
==== SYS_SPROF ====
**request parameters**\\ //(to be documented)//
**response parameters**\\ //(to be documented)//
**return value**\\ //(to be documented)//
**library functions**\\ //(to be documented)//
==== SYS_STATECTL ====
**request parameters**\\ //(to be documented)//
**response parameters**\\ //(to be documented)//
**return value**\\ //(to be documented)//
**library functions**\\ //(to be documented)//
==== SYS_STIME ====
Set the boot time. This effectively sets the current time, as the current time is computed by adding the uptime to the boot time.
**request parameters**\\ T_BOOTTIME: Boot time in seconds.
**return value**\\ OK: Always succeeds.
**library functions**\\ int sys_stime(time_t boottime);
==== .SYS_SYSCTL ====
Renamed to [[#sys_diagctl|SYS_DIAGCTL]].
==== SYS_TIMES ====
Get the kernel's uptime since boot and process execution times.
**request parameters**\\ T_ENDPT: Process for which to request the user and system time, or NONE.
**response parameters**\\ T_USER_TIME: Process' user time in ticks, if given endpoint is not NONE.\\ T_SYSTEM_TIME: Process's system time in ticks, if given endpoint is not NONE.\\ T_BOOT_TICKS: Number of ticks since MINIX boot (uptime).\\ T_BOOTTIME: Boot time in seconds.
**return value**\\ OK: Always succeeds.
**library functions**\\ int sys_times(endpoint_t proc_nr, clock_t *user_time, clock_t *system_time, clock_t *uptime);
==== SYS_TRACE ====
Monitor or control execution of the given process. Handle the debugging commands supported by the ptrace() system call.
**request parameters**\\ CTL_REQUEST: The tracing request.
* T_STOP: Stop the process.
* T_GETINS: Return value from instruction space.
* T_GETDATA: Return value from data space.
* T_GETUSER: Return value from user process table.
* T_SETINS: Set value from instruction space.
* T_SETDATA: Set value from data space.
* T_SETUSER: Set value in user process table.
* T_RESUME: Resume execution.
* T_STEP: Set trace bit.
* T_SYSCALL: Trace system call.
* T_DETACH: Detach from a traced process.
CTL_ENDPT: The process number that is being traced.\\ CTL_ADDRESS: Virtual address in the traced process' space.\\ CTL_DATA: Data to be written.
**response parameters**\\ CTL_DATA: Data to be returned.
**return value**\\ OK: Trace operation succeeded.\\ EIO: Set or get value failed.\\ EINVAL: Unsupported trace request.\\ PERM: Can only trace user processes.
**library functions**\\ int sys_trace(int request, endpoint_t proc_nr, long addr, long *data_ptr);
==== SYS_UMAP ====
Map a virtual address to a physical address and return the physical address. The virtual address can be in LOCAL_SEG, REMOTE_SEG or BIOS_SEG. An offset in bytes can be passed to verify whether this also falls within the segment.
**request parameters**\\ CP_SRC_ENDPT: Process number of the address relates to.\\ CP_SRC_SPACE: Segment identifier.\\ CP_SRC_ADDR: Offset within segment.\\ CP_NR_BYTES: Number of bytes from start.
**response parameters**\\ CP_DST_ADDR: Physical address if mapping succeeded.
**return value**\\ OK: The copying was done.\\ EFAULT: Virtual to physical mapping failed.\\ EINVAL: Incorrect segment type or process number.
**remarks**\\ Address zero within BIOS_SEG returns EFAULT, while the zeroth BIOS interrupt vector is in fact a valid address.
**library functions**\\ int sys_umap(endpoint_t proc_nr, int seg, vir_bytes vir_addr, vir_bytes count, phys_bytes *phys_addr);
==== SYS_UMAP_REMOTE ====
**request parameters**\\ //(to be documented)//
**response parameters**\\ //(to be documented)//
**return value**\\ //(to be documented)//
**library functions**\\ //(to be documented)//
==== SYS_UPDATE ====
**request parameters**\\ //(to be documented)//
**response parameters**\\ //(to be documented)//
**return value**\\ //(to be documented)//
**library functions**\\ //(to be documented)//
==== SYS_VDEVIO ====
Perform a series of device I/O on behalf of a user process. The call accepts a pointer to the first element of an array of (port,value)-pairs that are to be handled at once. Hardware interrupts are temporarily disabled to prevent the batch of I/O calls to be interrupted. Also see [[#sys_devio|SYS_DEVIO]] and [[#sys_sdevio|SYS_SDEVIO]].
**request parameters**\\ DIO_REQUEST: Flags indicating what to do.
* _DIO_INPUT: Read values from ports.
* _DIO_OUTPUT: Write values to ports.\\\\
* _DIO_BYTE: Read/write byte values.
* _DIO_WORD: Read/write word values.
* _DIO_LONG: Read/write long values.
DIO_VEC_SIZE: The number of ports to be handled.\\ DIO_VEC_ADDR: Virtual address of the (port,address)-pairs in the caller's space.
**return value**\\ OK: The port I/O was successfully done.\\ EINVAL: Invalid request or granularity.\\ E2BIG: Vector size exceeds maximum that can be handled.\\ EFAULT: The address of the (port,value)-pair is erroneous.
**library functions**\\ int sys_voutb(pvb_pair_t *pvb_vec, int vec_size);\\ int sys_voutw(pvb_pair_t *pvw_vec, int vec_size);\\ int sys_voutl(pvb_pair_t *pvl_vec, int vec_size);\\ int sys_vinb(pvb_pair_t *pvb_vec, int vec_size);\\ int sys_vinw(pvb_pair_t *pvw_vec, int vec_size);\\ int sys_vinl(pvb_pair_t *pvl_vec, int vec_size);
==== SYS_VIRCOPY ====
Copy data using virtual addressing. The virtual can be in three segments: LOCAL_SEG(text, stack, data segments), REMOTE_SEG(e.g. RAM disk, video memory) and the BIOS_SEG(BIOS interrupt vectors, BIOS data area). This is the most common system call relating to copying.
**request parameters**\\ CP_SRC_SPACE: Source segment\\ CP_SRC_ADDR: Virtual source address.\\ CP_SRC_ENDPT: Process number of the source process.\\ CP_DST_SPACE: Destination segment. \\ CP_DST_ADDR: Virtual destination address.\\ CP_DST_ENDPT: Process number of the destination process.\\ CP_NR_BYTES: Number of bytes to copy.
**return value**\\ OK: The copying was done.\\ EDOM: Invalid copy count. \\ EFAULT: Virtual to physical mapping failed.\\ EPERM: No permission to use PHYS_SEG.\\ EINVAL: Incorrect segment type or process number.\\ EPERM: Only owner of REMOTE_SEG can copy to or from it.
**library functions**\\ int sys_biosin(vir_bytes bios_vir, vir_bytes dst_vir, phys_bytes bytes);\\ int sys_biosout(vir_bytes src_vir, vir_bytes bios_vir, phys_bytes bytes);\\ int sys_datacopy(endpoint_t src_proc, vir_bytes src_vir, endpoint_t dst_proc, vir_bytes dst_vir, phys_bytes bytes);\\ int sys_textcopy(endpoint_t src_proc, vir_bytes src_vir, endpoint_t dst_proc, vir_bytes dst_vir, phys_bytes bytes);\\ int sys_stackcopy(endpoint_t src_proc, vir_bytes src_vir, endpoint_t dst_proc, vir_bytes dst_vir, phys_bytes bytes);\\ int sys_vircopy(endpoint_t src_proc, vir_bytes src_vir, endpoint_t dst_proc, vir_bytes dst_vir, phys_bytes bytes);
==== SYS_VMCTL ====
**request parameters**\\ //(to be documented)//
**response parameters**\\ //(to be documented)//
**return value**\\ //(to be documented)//
**library functions**\\ int sys_vmctl(endpoint_t who, int param, u32_t value);\\ int sys_vmctl_get_pagefault_i386(endpoint_t *who, u32_t *cr2, u32_t *err);\\ int sys_vmctl_get_cr3_i386(endpoint_t who, u32_t *cr3);\\ int sys_vmctl_get_memreq(endpoint_t *who, vir_bytes *mem, vir_bytes *len, int *wrflag, endpoint_t *who_s, vir_bytes *mem_s, endpoint_t *);\\ int sys_vmctl_enable_paging(struct mem_map *);\\ int sys_vmctl_get_mapping(int index, phys_bytes *addr, phys_bytes *len, int *flags);\\ int sys_vmctl_reply_mapping(int index, vir_bytes addr);
==== SYS_VSAFECOPY ====
Perform a vectored safecopy operation. Each vector element specifies the source, destination, grant ID, grant offset, pointer into caller's address space, and number of bytes to copy. For each element, either source or destination must be set to SELF. The data segment is used for both source and destination.
**request parameters**\\ VSCP_VEC_ADDR: Pointer to a vector of //struct vscp_vec// elements.\\ VSCP_VEC_SIZE: Number of elements in the given vector.
**return value**\\ OK: The call succeeded.\\ EDOM: Invalid number of vector elements.\\ EFAULT: Invalid address.\\ EINVAL: Invalid process number, or neither source nor destination is set to SELF.\\ EPERM: Invalid grant ID, insufficient access, or bad byte range.\\ ELOOP: Chain of indirect grants too long.
**remarks**\\ The operation does not fail atomically: Upon failure, the receiving buffers should be considered to be in an undefined state.
**library functions**\\ int sys_vsafecopy(struct vscp_vec *copyvec, int elements);
==== SYS_VTIMER ====
Set and/or retrieve the value of one of a process' virtual timers. Each process may have two virtual timers: a **virtual** timer that is decreased as the process itself executes (user time), and a **profile** timer that decreases as the process executes (user time) //or// a system server executes on behalf of the process (system time). If a timer expires, the process will get a SIGVTALRM or SIGPROF signal, respectively.
**request parameters**\\ VT_WHICH: The timer to set/retrieve: VT_VIRTUAL for the virtual timer, or VT_PROF for the profile timer.\\ VT_SET: A flag indicating whether to set, or just retrieve, the timer's value.\\ VT_VALUE: The new expiration time, if VT_SET is nonzero.\\ VT_ENDPT: Endpoint of the target process.
**response parameters**\\ VT_VALUE: The old expiration time.
**return value**\\ OK: The timer was set (if requested), and the old timer value was returned.\\ EPERM: User processes cannot request timers.\\ EINVAL: Invalid timer or process.
**library functions**\\ int sys_vtimer(endpoint_t proc_nr, int which, clock_t *newval, clock_t *oldval);
==== SYS_VUMAP ====
Batch mapping of virtual to physical addresses.
int sys_vumap(endpoint_t endpt, struct vumap_vir *vvec, int vcount, size_t offset, int access, struct vumap_phys *pvec, int *pcount);
The **sys_vumap** function perform batch conversion of one or more virtual buffers, to a series of physical addresses for those buffers. It is intended to be used by drivers that want to perform DMA directly from or to buffers in another process, authorized by that other process by means of memory grants. It can also be used to look up local addresses in the calling processes itself.
The buffers to convert are provided in the //vvec// vector. Each entry in this vector contains either a grant identifier (//vv_grant//) or a local virtual address (//vv_addr//) for the buffer, and a size (//vv_size//) of the buffer. The owner of the buffer is specified using the //endpt// parameter; If //endpt// is set to SELF, the local virtual addresses are used; otherwise, the grant identifiers are used. The //vcount// parameter specifies the number of entries in the //vvec// vector. The caller must provide at least one entry. No more than ''MAPVEC_NR'' input entries are processed in one call.
The //offset// parameter determines the offset into the first entry of the //vvec// vector. This allows the caller to perform multiple **sys_vumap** calls to map input that exceeds the size limits for a single call. The offset affects both the address and the size of the first entry.
The //access// parameter specifies the access requested for the buffers. At least one of the following flags must be specified: ''VUA_READ'' (to read from the buffers), ''VUA_WRITE'' (to write to the buffers). If the ''VUA_READ'' flag is not set, any unallocated pages in the address range will be allocated automatically. If the ''VUA_READ'' flag is set, the caller must always provide allocated pages. The requested access must match that of the given grants, and thus acts as a sanity check; it however does not prevent the caller from performing DMA in the wrong direction on the resolved physical addresses.
The kernel stores the resulting physical addresses in the //pvec// vector. Each entry in this vector contains a physical address (//pv_addr//) and a size (//pv_size//). The caller must set the //pcount// integer to the maximum number of entries in the //pvec// vector; upon success, the variable will be set to the number of entries filled in by the kernel. The caller must provide at least one entry. Upon success, at least one and at most ''MAPVEC_NR'' output entries are returned. Upon failure, the //pvec// and //pcount// contents are unchanged.
The caller is encouraged not to pay too much attention to the returned //pcount// value for determining whether the entire input vector has been mapped. Instead, it should consider the sizes returned in the //pvec// entries. If the sum of the sizes in the //pvec// vector equals the sum of the sizes in the //vvec// vector, the entire virtual vector has been resolved. Otherwise, additional **sys_vumap** calls are necessary to resolve the rest of the virtual vector.
**Return values** (not complete):\\ OK: addresses successfully mapped\\ EINVAL: //vcount// or //pcount// is negative or zero\\ EINVAL: //access// contains neither ''VUA_READ'' nor ''VUA_WRITE''\\ EFAULT: //vvec// or //pvec// point to invalid memory\\ EINVAL: one of the entries in //vvec// is zero-sized\\ EINVAL: one of the grants in //vvec// is invalid\\ EPERM: one of the grants in //vvec// is revoked\\ EPERM: the requested access does not match the granted access\\ EFAULT: the memory provided in one of the //vvec// entries is invalid\\ EFAULT: ''VUA_READ'' access is specified, and part of the given memory is not allocated\\
----
===== References =====
~-[[http://www.minix3.org/doc/kernel-api.pdf|Original MINIX 3 Kernel API Document]] by Jorrit N. Herder jnhderder AT cs DOT vu DOT nl