2005-10-14 10:58:59 +02:00
|
|
|
/* The kernel call implemented in this file:
|
2005-07-14 17:12:12 +02:00
|
|
|
* m_type: SYS_VIRCOPY, SYS_PHYSCOPY
|
|
|
|
*
|
2005-10-14 10:58:59 +02:00
|
|
|
* The parameters for this kernel call are:
|
2005-08-10 12:23:55 +02:00
|
|
|
* m5_c1: CP_SRC_SPACE source virtual segment
|
|
|
|
* m5_l1: CP_SRC_ADDR source offset within segment
|
|
|
|
* m5_i1: CP_SRC_PROC_NR source process number
|
|
|
|
* m5_c2: CP_DST_SPACE destination virtual segment
|
|
|
|
* m5_l2: CP_DST_ADDR destination offset within segment
|
|
|
|
* m5_i2: CP_DST_PROC_NR destination process number
|
|
|
|
* m5_l3: CP_NR_BYTES number of bytes to copy
|
2005-07-14 17:12:12 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "../system.h"
|
2008-11-19 13:26:10 +01:00
|
|
|
#include "../vm.h"
|
2005-07-14 17:12:12 +02:00
|
|
|
#include <minix/type.h>
|
|
|
|
|
|
|
|
#if (USE_VIRCOPY || USE_PHYSCOPY)
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* do_copy *
|
|
|
|
*===========================================================================*/
|
|
|
|
PUBLIC int do_copy(m_ptr)
|
|
|
|
register message *m_ptr; /* pointer to request message */
|
|
|
|
{
|
|
|
|
/* Handle sys_vircopy() and sys_physcopy(). Copy data using virtual or
|
2005-07-21 20:36:40 +02:00
|
|
|
* physical addressing. Although a single handler function is used, there
|
2005-10-14 10:58:59 +02:00
|
|
|
* are two different kernel calls so that permissions can be checked.
|
2005-07-14 17:12:12 +02:00
|
|
|
*/
|
|
|
|
struct vir_addr vir_addr[2]; /* virtual source and destination address */
|
2005-08-02 17:28:09 +02:00
|
|
|
phys_bytes bytes; /* number of bytes to copy */
|
2005-07-14 17:12:12 +02:00
|
|
|
int i;
|
|
|
|
|
2009-11-03 12:12:23 +01:00
|
|
|
#if 0
|
2008-11-19 13:26:10 +01:00
|
|
|
if (m_ptr->m_source != PM_PROC_NR && m_ptr->m_source != VFS_PROC_NR &&
|
|
|
|
m_ptr->m_source != RS_PROC_NR && m_ptr->m_source != MEM_PROC_NR &&
|
|
|
|
m_ptr->m_source != VM_PROC_NR)
|
2006-07-10 14:27:26 +02:00
|
|
|
{
|
|
|
|
static int first=1;
|
|
|
|
if (first)
|
|
|
|
{
|
|
|
|
first= 0;
|
|
|
|
kprintf(
|
|
|
|
"do_copy: got request from %d (source %d, seg %d, destination %d, seg %d)\n",
|
|
|
|
m_ptr->m_source,
|
|
|
|
m_ptr->CP_SRC_ENDPT,
|
|
|
|
m_ptr->CP_SRC_SPACE,
|
|
|
|
m_ptr->CP_DST_ENDPT,
|
|
|
|
m_ptr->CP_DST_SPACE);
|
|
|
|
}
|
|
|
|
}
|
2009-11-03 12:12:23 +01:00
|
|
|
#endif
|
2006-07-10 14:27:26 +02:00
|
|
|
|
2005-07-14 17:12:12 +02:00
|
|
|
/* Dismember the command message. */
|
'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
|
|
|
vir_addr[_SRC_].proc_nr_e = m_ptr->CP_SRC_ENDPT;
|
2005-07-14 17:12:12 +02:00
|
|
|
vir_addr[_SRC_].segment = m_ptr->CP_SRC_SPACE;
|
|
|
|
vir_addr[_SRC_].offset = (vir_bytes) m_ptr->CP_SRC_ADDR;
|
'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
|
|
|
vir_addr[_DST_].proc_nr_e = m_ptr->CP_DST_ENDPT;
|
2005-07-14 17:12:12 +02:00
|
|
|
vir_addr[_DST_].segment = m_ptr->CP_DST_SPACE;
|
|
|
|
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;
|
2005-07-14 17:12:12 +02:00
|
|
|
/* 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 = m_ptr->m_source;
|
2008-11-19 13:26:10 +01:00
|
|
|
if (vir_addr[i].segment != PHYS_SEG) {
|
|
|
|
if(! isokendpt(vir_addr[i].proc_nr_e, &p)) {
|
|
|
|
kprintf("do_copy: %d: seg 0x%x, %d not ok endpoint\n",
|
|
|
|
i, vir_addr[i].segment, vir_addr[i].proc_nr_e);
|
2005-07-14 17:12:12 +02:00
|
|
|
return(EINVAL);
|
2008-11-19 13:26:10 +01:00
|
|
|
}
|
|
|
|
}
|
2005-07-14 17:12:12 +02:00
|
|
|
|
|
|
|
/* Check if physical addressing is used without SYS_PHYSCOPY. */
|
|
|
|
if ((vir_addr[i].segment & PHYS_SEG) &&
|
|
|
|
m_ptr->m_type != SYS_PHYSCOPY) return(EPERM);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for overflow. This would happen for 64K segments and 16-bit
|
|
|
|
* vir_bytes. Especially copying by the PM on do_fork() is affected.
|
|
|
|
*/
|
2005-07-19 14:21:36 +02:00
|
|
|
if (bytes != (vir_bytes) bytes) return(E2BIG);
|
2005-07-14 17:12:12 +02:00
|
|
|
|
|
|
|
/* Now try to make the actual virtual copy. */
|
2008-11-19 13:26:10 +01:00
|
|
|
return( virtual_copy_vmcheck(&vir_addr[_SRC_], &vir_addr[_DST_], bytes) );
|
2005-07-14 17:12:12 +02:00
|
|
|
}
|
|
|
|
#endif /* (USE_VIRCOPY || USE_PHYSCOPY) */
|
|
|
|
|