minix/kernel/system/do_copy.c

86 lines
2.9 KiB
C
Raw Normal View History

/* The kernel call implemented in this file:
* m_type: SYS_VIRCOPY, SYS_PHYSCOPY
*
* The parameters for this kernel call are:
* m5_l1: CP_SRC_ADDR source offset within segment
2010-01-01 21:18:05 +01:00
* m5_i1: CP_SRC_ENDPT source process number
* m5_l2: CP_DST_ADDR destination offset within segment
2010-01-01 21:18:05 +01:00
* m5_i2: CP_DST_ENDPT destination process number
* m5_l3: CP_NR_BYTES number of bytes to copy
*/
2010-04-02 00:22:33 +02:00
#include "kernel/system.h"
#include <minix/type.h>
#if (USE_VIRCOPY || USE_PHYSCOPY)
/*===========================================================================*
* do_copy *
*===========================================================================*/
2012-03-25 20:25:53 +02:00
int do_copy(struct proc * caller, message * m_ptr)
{
/* Handle sys_vircopy() and sys_physcopy(). Copy data using virtual or
* physical addressing. Although a single handler function is used, there
* are two different kernel calls so that permissions can be checked.
*/
struct vir_addr vir_addr[2]; /* virtual source and destination address */
phys_bytes bytes; /* number of bytes to copy */
int i;
endpoint_t pe;
#if 0
if (caller->p_endpoint != PM_PROC_NR && caller->p_endpoint != VFS_PROC_NR &&
caller->p_endpoint != RS_PROC_NR && caller->p_endpoint != MEM_PROC_NR &&
caller->p_endpoint != VM_PROC_NR)
{
static int first=1;
if (first)
{
first= 0;
printf(
"do_copy: got request from %d (source %d, destination %d)\n",
caller->p_endpoint,
m_ptr->CP_SRC_ENDPT,
m_ptr->CP_DST_ENDPT);
}
}
#endif
/* Dismember the command message. */
pe = vir_addr[_SRC_].proc_nr_e = m_ptr->CP_SRC_ENDPT;
vir_addr[_SRC_].segment = (pe == NONE ? PHYS_SEG : D);
vir_addr[_SRC_].offset = (vir_bytes) m_ptr->CP_SRC_ADDR;
pe = vir_addr[_DST_].proc_nr_e = m_ptr->CP_DST_ENDPT;
vir_addr[_DST_].segment = (pe == NONE ? PHYS_SEG : D);
vir_addr[_DST_].offset = (vir_bytes) m_ptr->CP_DST_ADDR;
bytes = (phys_bytes) m_ptr->CP_NR_BYTES;
/* Now do some checks for both the source and destination virtual address.
* This is done once for _SRC_, then once for _DST_.
*/
for (i=_SRC_; i<=_DST_; i++) {
'proc number' is process slot, 'endpoint' are generation-aware process instance numbers, encoded and decoded using macros in <minix/endpoint.h>. proc number -> endpoint migration . proc_nr in the interrupt hook is now an endpoint, proc_nr_e. . m_source for messages and notifies is now an endpoint, instead of proc number. . isokendpt() converts an endpoint to a process number, returns success (but fails if the process number is out of range, the process slot is not a living process, or the given endpoint number does not match the endpoint number in the process slot, indicating an old process). . okendpt() is the same as isokendpt(), but panic()s if the conversion fails. This is mainly used for decoding message.m_source endpoints, and other endpoint numbers in kernel data structures, which should always be correct. . if DEBUG_ENABLE_IPC_WARNINGS is enabled, isokendpt() and okendpt() get passed the __FILE__ and __LINE__ of the calling lines, and print messages about what is wrong with the endpoint number (out of range proc, empty proc, or inconsistent endpoint number), with the caller, making finding where the conversion failed easy without having to include code for every call to print where things went wrong. Sometimes this is harmless (wrong arg to a kernel call), sometimes it's a fatal internal inconsistency (bogus m_source). . some process table fields have been appended an _e to indicate it's become and endpoint. . process endpoint is stored in p_endpoint, without generation number. it turns out the kernel never needs the generation number, except when fork()ing, so it's decoded then. . kernel calls all take endpoints as arguments, not proc numbers. the one exception is sys_fork(), which needs to know in which slot to put the child.
2006-03-03 11:00:02 +01:00
int p;
/* Check if process number was given implictly with SELF and is valid. */
'proc number' is process slot, 'endpoint' are generation-aware process instance numbers, encoded and decoded using macros in <minix/endpoint.h>. proc number -> endpoint migration . proc_nr in the interrupt hook is now an endpoint, proc_nr_e. . m_source for messages and notifies is now an endpoint, instead of proc number. . isokendpt() converts an endpoint to a process number, returns success (but fails if the process number is out of range, the process slot is not a living process, or the given endpoint number does not match the endpoint number in the process slot, indicating an old process). . okendpt() is the same as isokendpt(), but panic()s if the conversion fails. This is mainly used for decoding message.m_source endpoints, and other endpoint numbers in kernel data structures, which should always be correct. . if DEBUG_ENABLE_IPC_WARNINGS is enabled, isokendpt() and okendpt() get passed the __FILE__ and __LINE__ of the calling lines, and print messages about what is wrong with the endpoint number (out of range proc, empty proc, or inconsistent endpoint number), with the caller, making finding where the conversion failed easy without having to include code for every call to print where things went wrong. Sometimes this is harmless (wrong arg to a kernel call), sometimes it's a fatal internal inconsistency (bogus m_source). . some process table fields have been appended an _e to indicate it's become and endpoint. . process endpoint is stored in p_endpoint, without generation number. it turns out the kernel never needs the generation number, except when fork()ing, so it's decoded then. . kernel calls all take endpoints as arguments, not proc numbers. the one exception is sys_fork(), which needs to know in which slot to put the child.
2006-03-03 11:00:02 +01:00
if (vir_addr[i].proc_nr_e == SELF)
vir_addr[i].proc_nr_e = caller->p_endpoint;
if (vir_addr[i].segment != PHYS_SEG) {
if(! isokendpt(vir_addr[i].proc_nr_e, &p)) {
printf("do_copy: %d: seg 0x%x, %d not ok endpoint\n",
i, vir_addr[i].segment, vir_addr[i].proc_nr_e);
return(EINVAL);
}
}
}
/* Check for overflow. This would happen for 64K segments and 16-bit
* vir_bytes. Especially copying by the PM on do_fork() is affected.
*/
if (bytes != (phys_bytes) (vir_bytes) bytes) return(E2BIG);
/* Now try to make the actual virtual copy. */
return( virtual_copy_vmcheck(caller, &vir_addr[_SRC_],
&vir_addr[_DST_], bytes) );
}
#endif /* (USE_VIRCOPY || USE_PHYSCOPY) */