Basic VM and other minor improvements.
Not complete, probably not fully debugged or optimized.
This commit is contained in:
@@ -50,12 +50,12 @@ OBJECTS = \
|
||||
$(SYSTEM)(do_sigreturn.o) \
|
||||
$(SYSTEM)(do_abort.o) \
|
||||
$(SYSTEM)(do_getinfo.o) \
|
||||
$(SYSTEM)(do_vm.o) \
|
||||
$(SYSTEM)(do_vm_setbuf.o) \
|
||||
$(SYSTEM)(do_sprofile.o) \
|
||||
$(SYSTEM)(do_cprofile.o) \
|
||||
$(SYSTEM)(do_profbuf.o) \
|
||||
$(SYSTEM)(do_mapdma.o)
|
||||
$(SYSTEM)(do_mapdma.o) \
|
||||
$(SYSTEM)(do_vmctl.o)
|
||||
|
||||
build $(SYSTEM): $(OBJECTS)
|
||||
aal cr $@ *.o
|
||||
@@ -172,3 +172,6 @@ $(SYSTEM)(do_profbuf.o): do_profbuf.c
|
||||
|
||||
$(SYSTEM)(do_mapdma.o): do_mapdma.c
|
||||
$(CC) do_mapdma.c
|
||||
|
||||
$(SYSTEM)(do_vmctl.o): do_vmctl.c
|
||||
$(CC) do_vmctl.c
|
||||
|
||||
@@ -23,21 +23,25 @@ message *m_ptr; /* pointer to request message */
|
||||
* in the PM (normal abort or panic) or TTY (after CTRL-ALT-DEL).
|
||||
*/
|
||||
int how = m_ptr->ABRT_HOW;
|
||||
int proc_nr;
|
||||
int length;
|
||||
phys_bytes src_phys;
|
||||
|
||||
/* See if the monitor is to run the specified instructions. */
|
||||
if (how == RBT_MONITOR) {
|
||||
int p;
|
||||
static char paramsbuffer[512];
|
||||
int len;
|
||||
len = MIN(m_ptr->ABRT_MON_LEN, sizeof(paramsbuffer)-1);
|
||||
|
||||
if(!isokendpt(m_ptr->ABRT_MON_ENDPT, &proc_nr)) return(EDEADSRCDST);
|
||||
length = m_ptr->ABRT_MON_LEN + 1;
|
||||
if (length > kinfo.params_size) return(E2BIG);
|
||||
src_phys = numap_local(proc_nr,(vir_bytes)m_ptr->ABRT_MON_ADDR,length);
|
||||
if (! src_phys) return(EFAULT);
|
||||
if((p=data_copy(m_ptr->ABRT_MON_ENDPT, (vir_bytes) m_ptr->ABRT_MON_ADDR,
|
||||
SYSTEM, (vir_bytes) paramsbuffer, len)) != OK) {
|
||||
return p;
|
||||
}
|
||||
paramsbuffer[len] = '\0';
|
||||
|
||||
/* Parameters seem ok, copy them and prepare shutting down. */
|
||||
phys_copy(src_phys, kinfo.params_base, (phys_bytes) length);
|
||||
if((p = arch_set_params(paramsbuffer, len+1)) != OK)
|
||||
return p;
|
||||
}
|
||||
|
||||
/* Now prepare to shutdown MINIX. */
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
*/
|
||||
|
||||
#include "../system.h"
|
||||
#include "../vm.h"
|
||||
#include <minix/type.h>
|
||||
|
||||
#if (USE_VIRCOPY || USE_PHYSCOPY)
|
||||
@@ -30,8 +31,9 @@ register message *m_ptr; /* pointer to request message */
|
||||
phys_bytes bytes; /* number of bytes to copy */
|
||||
int i;
|
||||
|
||||
if (m_ptr->m_source != 0 && m_ptr->m_source != 1 &&
|
||||
m_ptr->m_source != 2 && m_ptr->m_source != 3)
|
||||
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)
|
||||
{
|
||||
static int first=1;
|
||||
if (first)
|
||||
@@ -64,9 +66,13 @@ register message *m_ptr; /* pointer to request message */
|
||||
/* Check if process number was given implictly with SELF and is valid. */
|
||||
if (vir_addr[i].proc_nr_e == SELF)
|
||||
vir_addr[i].proc_nr_e = m_ptr->m_source;
|
||||
if (vir_addr[i].segment != PHYS_SEG &&
|
||||
! isokendpt(vir_addr[i].proc_nr_e, &p))
|
||||
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);
|
||||
return(EINVAL);
|
||||
}
|
||||
}
|
||||
|
||||
/* Check if physical addressing is used without SYS_PHYSCOPY. */
|
||||
if ((vir_addr[i].segment & PHYS_SEG) &&
|
||||
@@ -79,7 +85,7 @@ register message *m_ptr; /* pointer to request message */
|
||||
if (bytes != (vir_bytes) bytes) return(E2BIG);
|
||||
|
||||
/* Now try to make the actual virtual copy. */
|
||||
return( virtual_copy(&vir_addr[_SRC_], &vir_addr[_DST_], bytes) );
|
||||
return( virtual_copy_vmcheck(&vir_addr[_SRC_], &vir_addr[_DST_], bytes) );
|
||||
}
|
||||
#endif /* (USE_VIRCOPY || USE_PHYSCOPY) */
|
||||
|
||||
|
||||
@@ -25,8 +25,8 @@ PUBLIC int do_cprofile(m_ptr)
|
||||
register message *m_ptr; /* pointer to request message */
|
||||
{
|
||||
int proc_nr, i, err = 0, k = 0;
|
||||
vir_bytes vir_dst;
|
||||
phys_bytes phys_src, phys_dst, len;
|
||||
phys_bytes len;
|
||||
vir_bytes vir_dst, vir_src;
|
||||
|
||||
switch (m_ptr->PROF_ACTION) {
|
||||
|
||||
@@ -50,10 +50,9 @@ register message *m_ptr; /* pointer to request message */
|
||||
}
|
||||
|
||||
/* Set reset flag. */
|
||||
phys_src = vir2phys((vir_bytes) &cprof_ctl_inst.reset);
|
||||
phys_dst = (phys_bytes) cprof_proc_info[i].ctl;
|
||||
len = (phys_bytes) sizeof(cprof_ctl_inst.reset);
|
||||
phys_copy(phys_src, phys_dst, len);
|
||||
data_copy(SYSTEM, (vir_bytes) &cprof_ctl_inst.reset,
|
||||
cprof_proc_info[i].endpt, cprof_proc_info[i].ctl_v,
|
||||
sizeof(cprof_ctl_inst.reset));
|
||||
}
|
||||
kprintf("\n");
|
||||
|
||||
@@ -71,14 +70,6 @@ register message *m_ptr; /* pointer to request message */
|
||||
if(!isokendpt(m_ptr->PROF_ENDPT, &proc_nr))
|
||||
return EINVAL;
|
||||
|
||||
vir_dst = (vir_bytes) m_ptr->PROF_CTL_PTR;
|
||||
len = (phys_bytes) sizeof (int *);
|
||||
cprof_info_addr = numap_local(proc_nr, vir_dst, len);
|
||||
|
||||
vir_dst = (vir_bytes) m_ptr->PROF_MEM_PTR;
|
||||
len = (phys_bytes) sizeof (char *);
|
||||
cprof_data_addr = numap_local(proc_nr, vir_dst, len);
|
||||
|
||||
cprof_mem_size = m_ptr->PROF_MEM_SIZE;
|
||||
|
||||
kprintf("CPROFILE notice: getting tables:");
|
||||
@@ -101,10 +92,9 @@ register message *m_ptr; /* pointer to request message */
|
||||
}
|
||||
|
||||
/* Copy control struct from proc to local variable. */
|
||||
phys_src = cprof_proc_info[i].ctl;
|
||||
phys_dst = vir2phys((vir_bytes) &cprof_ctl_inst);
|
||||
len = (phys_bytes) sizeof(cprof_ctl_inst);
|
||||
phys_copy(phys_src, phys_dst, len);
|
||||
data_copy(cprof_proc_info[i].endpt, cprof_proc_info[i].ctl_v,
|
||||
SYSTEM, (vir_bytes) &cprof_ctl_inst,
|
||||
sizeof(cprof_ctl_inst));
|
||||
|
||||
/* Calculate memory used. */
|
||||
cprof_proc_info[i].slots_used = cprof_ctl_inst.slots_used;
|
||||
@@ -121,32 +111,33 @@ register message *m_ptr; /* pointer to request message */
|
||||
if (cprof_mem_size < cprof_info.mem_used) cprof_info.mem_used = -1;
|
||||
|
||||
/* Copy the info struct to the user process. */
|
||||
phys_copy(vir2phys((vir_bytes) &cprof_info), cprof_info_addr,
|
||||
(phys_bytes) sizeof(cprof_info));
|
||||
data_copy(SYSTEM, (vir_bytes) &cprof_info,
|
||||
m_ptr->PROF_ENDPT, (vir_bytes) m_ptr->PROF_CTL_PTR,
|
||||
sizeof(cprof_info));
|
||||
|
||||
/* If there is no space or errors occurred, don't bother copying. */
|
||||
if (cprof_info.mem_used == -1 || cprof_info.err) return OK;
|
||||
|
||||
/* For each profiled process, copy its name, slots_used and profiling
|
||||
* table to the user process. */
|
||||
phys_dst = cprof_data_addr;
|
||||
vir_dst = (vir_bytes) m_ptr->PROF_MEM_PTR;
|
||||
for (i=0; i<cprof_procs_no; i++) {
|
||||
phys_src = vir2phys((vir_bytes) cprof_proc_info[i].name);
|
||||
len = (phys_bytes) strlen(cprof_proc_info[i].name);
|
||||
phys_copy(phys_src, phys_dst, len);
|
||||
phys_dst += CPROF_PROCNAME_LEN;
|
||||
data_copy(SYSTEM, (vir_bytes) cprof_proc_info[i].name,
|
||||
m_ptr->PROF_ENDPT, vir_dst, len);
|
||||
vir_dst += CPROF_PROCNAME_LEN;
|
||||
|
||||
phys_src = cprof_proc_info[i].ctl +
|
||||
sizeof(cprof_ctl_inst.reset);
|
||||
len = (phys_bytes) sizeof(cprof_ctl_inst.slots_used);
|
||||
phys_copy(phys_src, phys_dst, len);
|
||||
phys_dst += len;
|
||||
data_copy(cprof_proc_info[i].endpt,
|
||||
cprof_proc_info[i].ctl_v + sizeof(cprof_ctl_inst.reset),
|
||||
m_ptr->PROF_ENDPT, vir_dst, len);
|
||||
vir_dst += len;
|
||||
|
||||
phys_src = cprof_proc_info[i].buf;
|
||||
len = (phys_bytes)
|
||||
(sizeof(cprof_tbl_inst) * cprof_proc_info[i].slots_used);
|
||||
phys_copy(phys_src, phys_dst, len);
|
||||
phys_dst += len;
|
||||
data_copy(cprof_proc_info[i].endpt, cprof_proc_info[i].buf_v,
|
||||
m_ptr->PROF_ENDPT, vir_dst, len);
|
||||
vir_dst += len;
|
||||
}
|
||||
|
||||
return OK;
|
||||
|
||||
@@ -110,9 +110,9 @@ doit:
|
||||
}
|
||||
} else {
|
||||
switch (io_type) {
|
||||
case _DIO_BYTE: outb(m_ptr->DIO_PORT, m_ptr->DIO_VALUE); break;
|
||||
case _DIO_WORD: outw(m_ptr->DIO_PORT, m_ptr->DIO_VALUE); break;
|
||||
case _DIO_LONG: outl(m_ptr->DIO_PORT, m_ptr->DIO_VALUE); break;
|
||||
case _DIO_BYTE: outb(m_ptr->DIO_PORT, m_ptr->DIO_VALUE); break;
|
||||
case _DIO_WORD: outw(m_ptr->DIO_PORT, m_ptr->DIO_VALUE); break;
|
||||
case _DIO_LONG: outl(m_ptr->DIO_PORT, m_ptr->DIO_VALUE); break;
|
||||
default: return(EINVAL);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ register message *m_ptr; /* pointer to request message */
|
||||
{
|
||||
/* Handle sys_exec(). A process has done a successful EXEC. Patch it up. */
|
||||
register struct proc *rp;
|
||||
reg_t sp; /* new sp */
|
||||
phys_bytes phys_name;
|
||||
char *np;
|
||||
int proc;
|
||||
@@ -31,27 +30,18 @@ register message *m_ptr; /* pointer to request message */
|
||||
return EINVAL;
|
||||
|
||||
rp = proc_addr(proc);
|
||||
sp = (reg_t) m_ptr->PR_STACK_PTR;
|
||||
rp->p_reg.sp = sp; /* set the stack pointer */
|
||||
|
||||
#if (_MINIX_CHIP == _CHIP_INTEL)
|
||||
/* wipe extra LDT entries */
|
||||
phys_memset(vir2phys(&rp->p_seg.p_ldt[EXTRA_LDT_INDEX]), 0,
|
||||
(LDT_SIZE - EXTRA_LDT_INDEX) * sizeof(rp->p_seg.p_ldt[0]));
|
||||
#endif
|
||||
rp->p_reg.pc = (reg_t) m_ptr->PR_IP_PTR; /* set pc */
|
||||
RTS_LOCK_UNSET(rp, RECEIVING); /* PM does not reply to EXEC call */
|
||||
|
||||
/* Save command name for debugging, ps(1) output, etc. */
|
||||
phys_name = numap_local(who_p, (vir_bytes) m_ptr->PR_NAME_PTR,
|
||||
(vir_bytes) P_NAME_LEN - 1);
|
||||
if (phys_name != 0) {
|
||||
phys_copy(phys_name, vir2phys(rp->p_name), (phys_bytes) P_NAME_LEN - 1);
|
||||
for (np = rp->p_name; (*np & BYTE) >= ' '; np++) {}
|
||||
*np = 0; /* mark end */
|
||||
} else {
|
||||
if(data_copy(who_e, (vir_bytes) m_ptr->PR_NAME_PTR,
|
||||
SYSTEM, (vir_bytes) rp->p_name, (phys_bytes) P_NAME_LEN - 1) != OK)
|
||||
strncpy(rp->p_name, "<unset>", P_NAME_LEN);
|
||||
}
|
||||
|
||||
|
||||
/* Do architecture-specific exec() stuff. */
|
||||
arch_pre_exec(rp, (u32_t) m_ptr->PR_IP_PTR, (u32_t) m_ptr->PR_STACK_PTR);
|
||||
|
||||
/* No reply to EXEC call */
|
||||
RTS_LOCK_UNSET(rp, RECEIVING);
|
||||
|
||||
return(OK);
|
||||
}
|
||||
#endif /* USE_EXEC */
|
||||
|
||||
@@ -56,9 +56,11 @@ register struct proc *rc; /* slot of process to clean up */
|
||||
/* Don't clear if already cleared. */
|
||||
if(isemptyp(rc)) return;
|
||||
|
||||
|
||||
/* Remove the process' ability to send and receive messages */
|
||||
clear_endpoint(rc);
|
||||
|
||||
|
||||
/* Turn off any alarm timers at the clock. */
|
||||
reset_timer(&priv(rc)->s_alarm_timer);
|
||||
|
||||
@@ -70,10 +72,10 @@ register struct proc *rc; /* slot of process to clean up */
|
||||
/* Check the table with IRQ hooks to see if hooks should be released. */
|
||||
for (i=0; i < NR_IRQ_HOOKS; i++) {
|
||||
int proc;
|
||||
if (rc->p_endpoint == irq_hooks[i].proc_nr_e) {
|
||||
if (rc->p_endpoint == irq_hooks[i].proc_nr_e) {
|
||||
rm_irq_handler(&irq_hooks[i]); /* remove interrupt handler */
|
||||
irq_hooks[i].proc_nr_e = NONE; /* mark hook as free */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Release the process table slot. If this is a system process, also
|
||||
@@ -83,9 +85,12 @@ register struct proc *rc; /* slot of process to clean up */
|
||||
*/
|
||||
if (priv(rc)->s_flags & SYS_PROC) priv(rc)->s_proc_nr = NONE;
|
||||
|
||||
#if 0
|
||||
/* Clean up virtual memory */
|
||||
if (rc->p_misc_flags & MF_VM)
|
||||
if (rc->p_misc_flags & MF_VM) {
|
||||
vm_map_default(rc);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /* USE_EXIT */
|
||||
|
||||
@@ -41,10 +41,10 @@ register message *m_ptr; /* pointer to request message */
|
||||
gen = _ENDPOINT_G(rpc->p_endpoint);
|
||||
#if (_MINIX_CHIP == _CHIP_INTEL)
|
||||
old_ldt_sel = rpc->p_seg.p_ldt_sel; /* backup local descriptors */
|
||||
#endif
|
||||
*rpc = *rpp; /* copy 'proc' struct */
|
||||
#if (_MINIX_CHIP == _CHIP_INTEL)
|
||||
rpc->p_seg.p_ldt_sel = old_ldt_sel; /* restore descriptors */
|
||||
#else
|
||||
*rpc = *rpp; /* copy 'proc' struct */
|
||||
#endif
|
||||
if(++gen >= _ENDPOINT_MAX_GENERATION) /* increase generation */
|
||||
gen = 1; /* generation number wraparound */
|
||||
@@ -77,6 +77,11 @@ register message *m_ptr; /* pointer to request message */
|
||||
/* Install new map */
|
||||
r = newmap(rpc, map_ptr);
|
||||
|
||||
/* Don't schedule process in VM mode until it has a new pagetable. */
|
||||
if(m_ptr->PR_FORK_FLAGS & PFF_VMINHIBIT) {
|
||||
RTS_LOCK_SET(rpc, VMINHIBIT);
|
||||
}
|
||||
|
||||
/* Only one in group should have SIGNALED, child doesn't inherit tracing. */
|
||||
RTS_LOCK_UNSET(rpc, (SIGNALED | SIG_PENDING | P_STOP));
|
||||
sigemptyset(&rpc->p_pending);
|
||||
|
||||
@@ -10,13 +10,7 @@
|
||||
*/
|
||||
|
||||
#include "../system.h"
|
||||
|
||||
#if !( POWERPC )
|
||||
|
||||
static unsigned long bios_buf[1024]; /* 4K, what about alignment */
|
||||
static vir_bytes bios_buf_vir, bios_buf_len;
|
||||
|
||||
#endif /* #if !( POWERPC ) */
|
||||
#include "../vm.h"
|
||||
|
||||
|
||||
#if USE_GETINFO
|
||||
@@ -31,35 +25,44 @@ register message *m_ptr; /* pointer to request message */
|
||||
* call simply copies entire data structures to the caller.
|
||||
*/
|
||||
size_t length;
|
||||
phys_bytes src_phys;
|
||||
phys_bytes dst_phys;
|
||||
int proc_nr, nr_e, nr;
|
||||
vir_bytes src_vir;
|
||||
int proc_nr, nr_e, nr, hz;
|
||||
struct proc *caller;
|
||||
phys_bytes ph;
|
||||
|
||||
caller = proc_addr(who_p);
|
||||
|
||||
/* Set source address and length based on request type. */
|
||||
switch (m_ptr->I_REQUEST) {
|
||||
case GET_MACHINE: {
|
||||
length = sizeof(struct machine);
|
||||
src_phys = vir2phys(&machine);
|
||||
src_vir = (vir_bytes) &machine;
|
||||
break;
|
||||
}
|
||||
case GET_KINFO: {
|
||||
length = sizeof(struct kinfo);
|
||||
src_phys = vir2phys(&kinfo);
|
||||
src_vir = (vir_bytes) &kinfo;
|
||||
break;
|
||||
}
|
||||
case GET_LOADINFO: {
|
||||
length = sizeof(struct loadinfo);
|
||||
src_phys = vir2phys(&kloadinfo);
|
||||
src_vir = (vir_bytes) &kloadinfo;
|
||||
break;
|
||||
}
|
||||
case GET_HZ: {
|
||||
length = sizeof(hz);
|
||||
src_vir = (vir_bytes) &hz;
|
||||
hz = HZ;
|
||||
break;
|
||||
}
|
||||
case GET_IMAGE: {
|
||||
length = sizeof(struct boot_image) * NR_BOOT_PROCS;
|
||||
src_phys = vir2phys(image);
|
||||
src_vir = (vir_bytes) image;
|
||||
break;
|
||||
}
|
||||
case GET_IRQHOOKS: {
|
||||
length = sizeof(struct irq_hook) * NR_IRQ_HOOKS;
|
||||
src_phys = vir2phys(irq_hooks);
|
||||
src_vir = (vir_bytes) irq_hooks;
|
||||
break;
|
||||
}
|
||||
case GET_SCHEDINFO: {
|
||||
@@ -67,36 +70,44 @@ register message *m_ptr; /* pointer to request message */
|
||||
* at once, otherwise the scheduling information may be incorrect.
|
||||
* Copy the queue heads and fall through to copy the process table.
|
||||
*/
|
||||
if((ph=umap_local(caller, D, (vir_bytes) m_ptr->I_VAL_PTR2,length)) == 0)
|
||||
return EFAULT;
|
||||
length = sizeof(struct proc *) * NR_SCHED_QUEUES;
|
||||
src_phys = vir2phys(rdy_head);
|
||||
okendpt(m_ptr->m_source, &proc_nr);
|
||||
dst_phys = numap_local(proc_nr, (vir_bytes) m_ptr->I_VAL_PTR2,
|
||||
length);
|
||||
if (src_phys == 0 || dst_phys == 0) return(EFAULT);
|
||||
phys_copy(src_phys, dst_phys, length);
|
||||
/* fall through */
|
||||
CHECKRANGE_OR_SUSPEND(proc_addr(who_p), ph, length, 1);
|
||||
data_copy(SYSTEM, (vir_bytes) rdy_head,
|
||||
who_e, (vir_bytes) m_ptr->I_VAL_PTR2, length);
|
||||
/* fall through to GET_PROCTAB */
|
||||
}
|
||||
case GET_PROCTAB: {
|
||||
length = sizeof(struct proc) * (NR_PROCS + NR_TASKS);
|
||||
src_phys = vir2phys(proc);
|
||||
src_vir = (vir_bytes) proc;
|
||||
break;
|
||||
}
|
||||
case GET_PRIVTAB: {
|
||||
length = sizeof(struct priv) * (NR_SYS_PROCS);
|
||||
src_phys = vir2phys(priv);
|
||||
src_vir = (vir_bytes) priv;
|
||||
break;
|
||||
}
|
||||
case GET_PROC: {
|
||||
nr_e = (m_ptr->I_VAL_LEN2_E == SELF) ?
|
||||
m_ptr->m_source : m_ptr->I_VAL_LEN2_E;
|
||||
who_e : m_ptr->I_VAL_LEN2_E;
|
||||
if(!isokendpt(nr_e, &nr)) return EINVAL; /* validate request */
|
||||
length = sizeof(struct proc);
|
||||
src_phys = vir2phys(proc_addr(nr));
|
||||
src_vir = (vir_bytes) proc_addr(nr);
|
||||
break;
|
||||
}
|
||||
case GET_WHOAMI: {
|
||||
int len;
|
||||
/* GET_WHOAMI uses m3 and only uses the message contents for info. */
|
||||
m_ptr->GIWHO_EP = who_e;
|
||||
len = MIN(sizeof(m_ptr->GIWHO_NAME), sizeof(caller->p_name))-1;
|
||||
strncpy(m_ptr->GIWHO_NAME, caller->p_name, len);
|
||||
m_ptr->GIWHO_NAME[len] = '\0';
|
||||
return OK;
|
||||
}
|
||||
case GET_MONPARAMS: {
|
||||
src_phys = kinfo.params_base; /* already is a physical */
|
||||
length = kinfo.params_size;
|
||||
src_vir = (vir_bytes) params_buffer;
|
||||
length = sizeof(params_buffer);
|
||||
break;
|
||||
}
|
||||
case GET_RANDOMNESS: {
|
||||
@@ -109,44 +120,25 @@ register message *m_ptr; /* pointer to request message */
|
||||
krandom.bin[i].r_next = 0;
|
||||
}
|
||||
length = sizeof(struct randomness);
|
||||
src_phys = vir2phys(©);
|
||||
src_vir = (vir_bytes) ©
|
||||
break;
|
||||
}
|
||||
case GET_KMESSAGES: {
|
||||
length = sizeof(struct kmessages);
|
||||
src_phys = vir2phys(&kmess);
|
||||
src_vir = (vir_bytes) &kmess;
|
||||
break;
|
||||
}
|
||||
#if DEBUG_TIME_LOCKS
|
||||
case GET_LOCKTIMING: {
|
||||
length = sizeof(timingdata);
|
||||
src_phys = vir2phys(timingdata);
|
||||
src_vir = (vir_bytes) timingdata;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !( POWERPC )
|
||||
case GET_BIOSBUFFER:
|
||||
bios_buf_vir = (vir_bytes)bios_buf;
|
||||
bios_buf_len = sizeof(bios_buf);
|
||||
|
||||
length = sizeof(bios_buf_len);
|
||||
src_phys = vir2phys(&bios_buf_len);
|
||||
if (length != m_ptr->I_VAL_LEN2_E) return (EINVAL);
|
||||
if(!isokendpt(m_ptr->m_source, &proc_nr))
|
||||
panic("bogus source", m_ptr->m_source);
|
||||
dst_phys = numap_local(proc_nr, (vir_bytes) m_ptr->I_VAL_PTR2, length);
|
||||
if (src_phys == 0 || dst_phys == 0) return(EFAULT);
|
||||
phys_copy(src_phys, dst_phys, length);
|
||||
|
||||
length = sizeof(bios_buf_vir);
|
||||
src_phys = vir2phys(&bios_buf_vir);
|
||||
break;
|
||||
#endif /* #if !( POWERPC ) */
|
||||
|
||||
case GET_IRQACTIDS: {
|
||||
length = sizeof(irq_actids);
|
||||
src_phys = vir2phys(irq_actids);
|
||||
src_vir = (vir_bytes) irq_actids;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -162,11 +154,10 @@ register message *m_ptr; /* pointer to request message */
|
||||
|
||||
/* Try to make the actual copy for the requested data. */
|
||||
if (m_ptr->I_VAL_LEN > 0 && length > m_ptr->I_VAL_LEN) return (E2BIG);
|
||||
if(!isokendpt(m_ptr->m_source, &proc_nr))
|
||||
panic("bogus source", m_ptr->m_source);
|
||||
dst_phys = numap_local(proc_nr, (vir_bytes) m_ptr->I_VAL_PTR, length);
|
||||
if (src_phys == 0 || dst_phys == 0) return(EFAULT);
|
||||
phys_copy(src_phys, dst_phys, length);
|
||||
if((ph=umap_local(caller, D, (vir_bytes) m_ptr->I_VAL_PTR,length)) == 0)
|
||||
return EFAULT;
|
||||
CHECKRANGE_OR_SUSPEND(caller, ph, length, 1);
|
||||
data_copy(SYSTEM, src_vir, who_e, (vir_bytes) m_ptr->I_VAL_PTR, length);
|
||||
return(OK);
|
||||
}
|
||||
|
||||
|
||||
@@ -46,8 +46,9 @@ register message *m_ptr; /* pointer to request message */
|
||||
if (irq_hook_id >= NR_IRQ_HOOKS || irq_hook_id < 0 ||
|
||||
irq_hooks[irq_hook_id].proc_nr_e == NONE) return(EINVAL);
|
||||
if (irq_hooks[irq_hook_id].proc_nr_e != m_ptr->m_source) return(EPERM);
|
||||
if (m_ptr->IRQ_REQUEST == IRQ_ENABLE)
|
||||
if (m_ptr->IRQ_REQUEST == IRQ_ENABLE) {
|
||||
enable_irq(&irq_hooks[irq_hook_id]);
|
||||
}
|
||||
else
|
||||
disable_irq(&irq_hooks[irq_hook_id]);
|
||||
break;
|
||||
@@ -64,7 +65,7 @@ register message *m_ptr; /* pointer to request message */
|
||||
privp= priv(rp);
|
||||
if (!privp)
|
||||
{
|
||||
kprintf("no priv structure!\n");
|
||||
kprintf("do_irqctl: no priv structure!\n");
|
||||
return EPERM;
|
||||
}
|
||||
if (privp->s_flags & CHECK_IRQ)
|
||||
@@ -143,14 +144,12 @@ irq_hook_t *hook;
|
||||
*/
|
||||
get_randomness(hook->irq);
|
||||
|
||||
/* Check if the handler is still alive. If not, forget about the
|
||||
* interrupt. This should never happen, as processes that die
|
||||
/* Check if the handler is still alive.
|
||||
* If it's dead, this should never happen, as processes that die
|
||||
* automatically get their interrupt hooks unhooked.
|
||||
*/
|
||||
if(!isokendpt(hook->proc_nr_e, &proc)) {
|
||||
hook->proc_nr_e = NONE;
|
||||
return 0;
|
||||
}
|
||||
if(!isokendpt(hook->proc_nr_e, &proc))
|
||||
minix_panic("invalid interrupt handler", hook->proc_nr_e);
|
||||
|
||||
/* Add a bit for this interrupt to the process' pending interrupts. When
|
||||
* sending the notification message, this bit map will be magically set
|
||||
|
||||
@@ -31,14 +31,13 @@ register message *m_ptr; /* pointer to request message */
|
||||
|
||||
proc = proc_addr(proc_p);
|
||||
|
||||
phys_base= umap_local(proc, D, base, size);
|
||||
if (!phys_base)
|
||||
{
|
||||
kprintf("do_mapdma: umap_local failed\n");
|
||||
phys_base= umap_virtual(proc, D, base, size);
|
||||
if (!phys_base)
|
||||
{
|
||||
kprintf("do_mapdma: umap_virtual failed\n");
|
||||
return EFAULT;
|
||||
}
|
||||
|
||||
m_ptr->CP_DST_ADDR = phys_base;
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,10 +16,10 @@
|
||||
PUBLIC int do_newmap(m_ptr)
|
||||
message *m_ptr; /* pointer to request message */
|
||||
{
|
||||
/* Handle sys_newmap(). Fetch the memory map from PM. */
|
||||
/* Handle sys_newmap(). Fetch the memory map. */
|
||||
register struct proc *rp; /* process whose map is to be loaded */
|
||||
struct mem_map *map_ptr; /* virtual address of map inside caller (PM) */
|
||||
phys_bytes src_phys; /* physical address of map at the PM */
|
||||
struct mem_map *map_ptr; /* virtual address of map inside caller */
|
||||
phys_bytes src_phys; /* physical address of map at the */
|
||||
int proc;
|
||||
|
||||
map_ptr = (struct mem_map *) m_ptr->PR_MEM_PTR;
|
||||
@@ -36,18 +36,15 @@ message *m_ptr; /* pointer to request message */
|
||||
*===========================================================================*/
|
||||
PUBLIC int newmap(rp, map_ptr)
|
||||
struct proc *rp; /* process whose map is to be loaded */
|
||||
struct mem_map *map_ptr; /* virtual address of map inside caller (PM) */
|
||||
struct mem_map *map_ptr; /* virtual address of map inside caller */
|
||||
{
|
||||
/* Fetch the memory map from PM. */
|
||||
phys_bytes src_phys; /* physical address of map at the PM */
|
||||
int proc;
|
||||
|
||||
/* Copy the map from PM. */
|
||||
src_phys = umap_local(proc_addr(who_p), D, (vir_bytes) map_ptr,
|
||||
sizeof(rp->p_memmap));
|
||||
if (src_phys == 0) return(EFAULT);
|
||||
phys_copy(src_phys,vir2phys(rp->p_memmap),
|
||||
(phys_bytes)sizeof(rp->p_memmap));
|
||||
int r;
|
||||
/* Fetch the memory map. */
|
||||
if((r=data_copy(who_e, (vir_bytes) map_ptr,
|
||||
SYSTEM, (vir_bytes) rp->p_memmap, sizeof(rp->p_memmap))) != OK) {
|
||||
kprintf("newmap: data_copy failed! (%d)\n", r);
|
||||
return r;
|
||||
}
|
||||
|
||||
alloc_segments(rp);
|
||||
|
||||
|
||||
@@ -28,8 +28,7 @@ message *m_ptr; /* pointer to request message */
|
||||
register struct priv *sp;
|
||||
int proc_nr;
|
||||
int priv_id;
|
||||
int i;
|
||||
phys_bytes caller_phys, kernel_phys;
|
||||
int i, r;
|
||||
struct io_range io_range;
|
||||
struct mem_range mem_range;
|
||||
struct priv priv;
|
||||
@@ -100,12 +99,9 @@ message *m_ptr; /* pointer to request message */
|
||||
if (m_ptr->CTL_ARG_PTR)
|
||||
{
|
||||
/* Copy privilege structure from caller */
|
||||
caller_phys = umap_local(caller_ptr, D,
|
||||
(vir_bytes) m_ptr->CTL_ARG_PTR, sizeof(priv));
|
||||
if (caller_phys == 0)
|
||||
return EFAULT;
|
||||
kernel_phys = vir2phys(&priv);
|
||||
phys_copy(caller_phys, kernel_phys, sizeof(priv));
|
||||
if((r=data_copy(who_e, (vir_bytes) m_ptr->CTL_ARG_PTR,
|
||||
SYSTEM, (vir_bytes) &priv, sizeof(priv))) != OK)
|
||||
return r;
|
||||
|
||||
/* Copy the call mask */
|
||||
for (i= 0; i<CALL_MASK_SIZE; i++)
|
||||
@@ -180,12 +176,8 @@ message *m_ptr; /* pointer to request message */
|
||||
#endif
|
||||
|
||||
/* Get the I/O range */
|
||||
caller_phys = umap_local(caller_ptr, D, (vir_bytes) m_ptr->CTL_ARG_PTR,
|
||||
sizeof(io_range));
|
||||
if (caller_phys == 0)
|
||||
return EFAULT;
|
||||
kernel_phys = vir2phys(&io_range);
|
||||
phys_copy(caller_phys, kernel_phys, sizeof(io_range));
|
||||
data_copy(who_e, (vir_bytes) m_ptr->CTL_ARG_PTR,
|
||||
SYSTEM, (vir_bytes) &io_range, sizeof(io_range));
|
||||
priv(rp)->s_flags |= CHECK_IO_PORT; /* Check I/O accesses */
|
||||
i= priv(rp)->s_nr_io_range;
|
||||
if (i >= NR_IO_RANGE)
|
||||
@@ -206,12 +198,9 @@ message *m_ptr; /* pointer to request message */
|
||||
return EPERM;
|
||||
|
||||
/* Get the memory range */
|
||||
caller_phys = umap_local(caller_ptr, D, (vir_bytes) m_ptr->CTL_ARG_PTR,
|
||||
sizeof(mem_range));
|
||||
if (caller_phys == 0)
|
||||
return EFAULT;
|
||||
kernel_phys = vir2phys(&mem_range);
|
||||
phys_copy(caller_phys, kernel_phys, sizeof(mem_range));
|
||||
if((r=data_copy(who_e, (vir_bytes) m_ptr->CTL_ARG_PTR,
|
||||
SYSTEM, (vir_bytes) &mem_range, sizeof(mem_range))) != OK)
|
||||
return r;
|
||||
priv(rp)->s_flags |= CHECK_MEM; /* Check I/O accesses */
|
||||
i= priv(rp)->s_nr_mem_range;
|
||||
if (i >= NR_MEM_RANGE)
|
||||
|
||||
@@ -25,26 +25,24 @@ register message *m_ptr; /* pointer to request message */
|
||||
* about the location of their profiling table and the control structure
|
||||
* which is used to enable the kernel to have the tables cleared.
|
||||
*/
|
||||
int proc_nr, len;
|
||||
int proc_nr;
|
||||
vir_bytes vir_dst;
|
||||
struct proc *rp;
|
||||
|
||||
/* Store process name, control struct, table locations. */
|
||||
isokendpt(m_ptr->m_source, &proc_nr);
|
||||
if(!isokendpt(m_ptr->m_source, &proc_nr))
|
||||
return EDEADSRCDST;
|
||||
|
||||
if(cprof_procs_no >= NR_SYS_PROCS)
|
||||
return ENOSPC;
|
||||
|
||||
rp = proc_addr(proc_nr);
|
||||
|
||||
cprof_proc_info[cprof_procs_no].endpt = who_e;
|
||||
cprof_proc_info[cprof_procs_no].name = rp->p_name;
|
||||
|
||||
len = (phys_bytes) sizeof (void *);
|
||||
|
||||
vir_dst = (vir_bytes) m_ptr->PROF_CTL_PTR;
|
||||
cprof_proc_info[cprof_procs_no].ctl =
|
||||
numap_local(proc_nr, vir_dst, len);
|
||||
|
||||
vir_dst = (vir_bytes) m_ptr->PROF_MEM_PTR;
|
||||
cprof_proc_info[cprof_procs_no].buf =
|
||||
numap_local(proc_nr, vir_dst, len);
|
||||
cprof_proc_info[cprof_procs_no].ctl_v = (vir_bytes) m_ptr->PROF_CTL_PTR;
|
||||
cprof_proc_info[cprof_procs_no].buf_v = (vir_bytes) m_ptr->PROF_MEM_PTR;
|
||||
|
||||
cprof_procs_no++;
|
||||
|
||||
|
||||
@@ -14,14 +14,19 @@
|
||||
* VSCP_VEC_SIZE number of significant elements in vector
|
||||
*/
|
||||
|
||||
#include "../system.h"
|
||||
#include <minix/type.h>
|
||||
#include <minix/safecopies.h>
|
||||
|
||||
#include "../system.h"
|
||||
#include "../vm.h"
|
||||
|
||||
#define MEM_TOP 0xFFFFFFFFUL
|
||||
|
||||
FORWARD _PROTOTYPE(int safecopy, (endpoint_t, endpoint_t, cp_grant_id_t, int, int, size_t, vir_bytes, vir_bytes, int));
|
||||
|
||||
#define HASGRANTTABLE(gr) \
|
||||
(!RTS_ISSET(gr, NO_PRIV) && priv(gr) && priv(gr)->s_grant_table > 0)
|
||||
|
||||
/*===========================================================================*
|
||||
* verify_grant *
|
||||
*===========================================================================*/
|
||||
@@ -38,7 +43,7 @@ endpoint_t *e_granter; /* new granter (magic grants) */
|
||||
static cp_grant_t g;
|
||||
static int proc_nr;
|
||||
static struct proc *granter_proc;
|
||||
static phys_bytes phys_grant;
|
||||
int r;
|
||||
|
||||
/* Get granter process slot (if valid), and check range of
|
||||
* grant id.
|
||||
@@ -51,23 +56,9 @@ endpoint_t *e_granter; /* new granter (magic grants) */
|
||||
|
||||
/* If there is no priv. structure, or no grant table in the
|
||||
* priv. structure, or the grant table in the priv. structure
|
||||
* is too small for the grant,
|
||||
*
|
||||
* then there exists no such grant, so
|
||||
*
|
||||
* return EPERM.
|
||||
*
|
||||
* (Don't leak how big the grant table is by returning
|
||||
* EINVAL for grant-out-of-range, in case this turns out to be
|
||||
* interesting information.)
|
||||
* is too small for the grant, return EPERM.
|
||||
*/
|
||||
if(RTS_ISSET(granter_proc, NO_PRIV) || !(priv(granter_proc)) ||
|
||||
priv(granter_proc)->s_grant_table < 1) {
|
||||
kprintf("verify_grant: grant verify failed in ep %d proc %d: "
|
||||
"no priv table, or no grant table\n",
|
||||
granter, proc_nr);
|
||||
return(EPERM);
|
||||
}
|
||||
if(!HASGRANTTABLE(granter_proc)) return EPERM;
|
||||
|
||||
if(priv(granter_proc)->s_grant_entries <= grant) {
|
||||
static int curr= 0, limit= 100, extra= 20;
|
||||
@@ -94,25 +85,25 @@ endpoint_t *e_granter; /* new granter (magic grants) */
|
||||
* (presumably) set an invalid grant table entry by returning
|
||||
* EPERM, just like with an invalid grant id.
|
||||
*/
|
||||
if(!(phys_grant = umap_local(granter_proc, D,
|
||||
priv(granter_proc)->s_grant_table + sizeof(g)*grant, sizeof(g)))) {
|
||||
kprintf("verify_grant: grant verify failed: umap failed\n");
|
||||
if((r=data_copy(granter,
|
||||
priv(granter_proc)->s_grant_table + sizeof(g)*grant,
|
||||
SYSTEM, (vir_bytes) &g, sizeof(g))) != OK) {
|
||||
kprintf("verify_grant: grant verify: data_copy failed\n");
|
||||
return EPERM;
|
||||
}
|
||||
|
||||
phys_copy(phys_grant, vir2phys(&g), sizeof(g));
|
||||
|
||||
/* Check validity. */
|
||||
if((g.cp_flags & (CPF_USED | CPF_VALID)) != (CPF_USED | CPF_VALID)) {
|
||||
kprintf(
|
||||
"verify_grant: grant verify failed: unused or invalid\n");
|
||||
"verify_grant: grant failed: invalid (%d flags 0x%lx)\n",
|
||||
grant, g.cp_flags);
|
||||
return EPERM;
|
||||
}
|
||||
|
||||
/* Check access of grant. */
|
||||
if(((g.cp_flags & access) != access)) {
|
||||
kprintf(
|
||||
"verify_grant: grant verify failed: access invalid; want %x, have %x\n",
|
||||
"verify_grant: grant verify failed: access invalid; want 0x%x, have 0x%x\n",
|
||||
access, g.cp_flags);
|
||||
return EPERM;
|
||||
}
|
||||
@@ -210,6 +201,11 @@ int access; /* CPF_READ for a copy from granter to grantee, CPF_WRITE
|
||||
static vir_bytes v_offset;
|
||||
int r;
|
||||
endpoint_t new_granter, *src, *dst;
|
||||
struct proc *granter_p;
|
||||
|
||||
/* See if there is a reasonable grant table. */
|
||||
if(!(granter_p = endpoint_lookup(granter))) return EINVAL;
|
||||
if(!HASGRANTTABLE(granter_p)) return EPERM;
|
||||
|
||||
/* Decide who is src and who is dst. */
|
||||
if(access & CPF_READ) {
|
||||
@@ -227,9 +223,11 @@ int access; /* CPF_READ for a copy from granter to grantee, CPF_WRITE
|
||||
|
||||
if (curr < limit+extra)
|
||||
{
|
||||
#if 0
|
||||
kprintf(
|
||||
"grant %d verify to copy %d->%d by %d failed: err %d\n",
|
||||
grantid, *src, *dst, grantee, r);
|
||||
#endif
|
||||
} else if (curr == limit+extra)
|
||||
{
|
||||
kprintf(
|
||||
@@ -265,7 +263,7 @@ int access; /* CPF_READ for a copy from granter to grantee, CPF_WRITE
|
||||
}
|
||||
|
||||
/* Do the regular copy. */
|
||||
return virtual_copy(&v_src, &v_dst, bytes);
|
||||
return virtual_copy_vmcheck(&v_src, &v_dst, bytes);
|
||||
|
||||
}
|
||||
|
||||
@@ -288,7 +286,7 @@ register message *m_ptr; /* pointer to request message */
|
||||
src_seg = SCP_INFO2SEG(m_ptr->SCP_INFO);
|
||||
dst_seg = D;
|
||||
access = CPF_WRITE;
|
||||
} else panic("Impossible system call nr. ", sys_call_code);
|
||||
} else minix_panic("Impossible system call nr. ", sys_call_code);
|
||||
|
||||
return safecopy(m_ptr->SCP_FROM_TO, who_e, m_ptr->SCP_GID,
|
||||
src_seg, dst_seg, m_ptr->SCP_BYTES, m_ptr->SCP_OFFSET,
|
||||
@@ -304,6 +302,7 @@ register message *m_ptr; /* pointer to request message */
|
||||
static struct vscp_vec vec[SCPVEC_NR];
|
||||
static struct vir_addr src, dst;
|
||||
int r, i, els;
|
||||
size_t bytes;
|
||||
|
||||
/* Set vector copy parameters. */
|
||||
src.proc_nr_e = who_e;
|
||||
@@ -314,9 +313,10 @@ register message *m_ptr; /* pointer to request message */
|
||||
|
||||
/* No. of vector elements. */
|
||||
els = m_ptr->VSCP_VEC_SIZE;
|
||||
bytes = els * sizeof(struct vscp_vec);
|
||||
|
||||
/* Obtain vector of copies. */
|
||||
if((r=virtual_copy(&src, &dst, els * sizeof(struct vscp_vec))) != OK)
|
||||
if((r=virtual_copy_vmcheck(&src, &dst, bytes)) != OK)
|
||||
return r;
|
||||
|
||||
/* Perform safecopies. */
|
||||
|
||||
@@ -26,18 +26,16 @@ message *m_ptr; /* pointer to request message */
|
||||
*/
|
||||
struct sigcontext sc;
|
||||
register struct proc *rp;
|
||||
phys_bytes src_phys;
|
||||
int proc;
|
||||
int proc, r;
|
||||
|
||||
if (! isokendpt(m_ptr->SIG_ENDPT, &proc)) return(EINVAL);
|
||||
if (iskerneln(proc)) return(EPERM);
|
||||
rp = proc_addr(proc);
|
||||
|
||||
/* Copy in the sigcontext structure. */
|
||||
src_phys = umap_local(rp, D, (vir_bytes) m_ptr->SIG_CTXT_PTR,
|
||||
(vir_bytes) sizeof(struct sigcontext));
|
||||
if (src_phys == 0) return(EFAULT);
|
||||
phys_copy(src_phys, vir2phys(&sc), (phys_bytes) sizeof(struct sigcontext));
|
||||
if((r=data_copy(m_ptr->SIG_ENDPT, (vir_bytes) m_ptr->SIG_CTXT_PTR,
|
||||
SYSTEM, (vir_bytes) &sc, sizeof(struct sigcontext))) != OK)
|
||||
return r;
|
||||
|
||||
/* Restore user bits of psw from sc, maintain system bits from proc. */
|
||||
sc.sc_psw = (sc.sc_psw & X86_FLAGS_USER) |
|
||||
|
||||
@@ -25,20 +25,18 @@ message *m_ptr; /* pointer to request message */
|
||||
|
||||
struct sigmsg smsg;
|
||||
register struct proc *rp;
|
||||
phys_bytes src_phys, dst_phys;
|
||||
struct sigcontext sc, *scp;
|
||||
struct sigframe fr, *frp;
|
||||
int proc;
|
||||
int proc, r;
|
||||
|
||||
if (!isokendpt(m_ptr->SIG_ENDPT, &proc)) return(EINVAL);
|
||||
if (iskerneln(proc)) return(EPERM);
|
||||
rp = proc_addr(proc);
|
||||
|
||||
/* Get the sigmsg structure into our address space. */
|
||||
src_phys = umap_local(proc_addr(PM_PROC_NR), D, (vir_bytes)
|
||||
m_ptr->SIG_CTXT_PTR, (vir_bytes) sizeof(struct sigmsg));
|
||||
if (src_phys == 0) return(EFAULT);
|
||||
phys_copy(src_phys,vir2phys(&smsg),(phys_bytes) sizeof(struct sigmsg));
|
||||
if((r=data_copy(PM_PROC_NR, (vir_bytes) m_ptr->SIG_CTXT_PTR,
|
||||
SYSTEM, (vir_bytes) &smsg, (phys_bytes) sizeof(struct sigmsg))) != OK)
|
||||
return r;
|
||||
|
||||
/* Compute the user stack pointer where sigcontext will be stored. */
|
||||
scp = (struct sigcontext *) smsg.sm_stkptr - 1;
|
||||
@@ -56,10 +54,9 @@ message *m_ptr; /* pointer to request message */
|
||||
sc.sc_mask = smsg.sm_mask;
|
||||
|
||||
/* Copy the sigcontext structure to the user's stack. */
|
||||
dst_phys = umap_local(rp, D, (vir_bytes) scp,
|
||||
(vir_bytes) sizeof(struct sigcontext));
|
||||
if (dst_phys == 0) return(EFAULT);
|
||||
phys_copy(vir2phys(&sc), dst_phys, (phys_bytes) sizeof(struct sigcontext));
|
||||
if((r=data_copy(SYSTEM, (vir_bytes) &sc, m_ptr->SIG_ENDPT, (vir_bytes) scp,
|
||||
(vir_bytes) sizeof(struct sigcontext))) != OK)
|
||||
return r;
|
||||
|
||||
/* Initialize the sigframe structure. */
|
||||
frp = (struct sigframe *) scp - 1;
|
||||
@@ -73,10 +70,10 @@ message *m_ptr; /* pointer to request message */
|
||||
fr.sf_retadr = (void (*)()) smsg.sm_sigreturn;
|
||||
|
||||
/* Copy the sigframe structure to the user's stack. */
|
||||
dst_phys = umap_local(rp, D, (vir_bytes) frp,
|
||||
(vir_bytes) sizeof(struct sigframe));
|
||||
if (dst_phys == 0) return(EFAULT);
|
||||
phys_copy(vir2phys(&fr), dst_phys, (phys_bytes) sizeof(struct sigframe));
|
||||
if((r=data_copy(SYSTEM, (vir_bytes) &fr, m_ptr->SIG_ENDPT, (vir_bytes) frp,
|
||||
(vir_bytes) sizeof(struct sigframe))) != OK)
|
||||
return r;
|
||||
|
||||
|
||||
#if ( _MINIX_CHIP == _CHIP_POWERPC ) /* stuff that can't be done in the assembler code. */
|
||||
/* When the signal handlers C code is called it will write this value
|
||||
@@ -95,8 +92,13 @@ message *m_ptr; /* pointer to request message */
|
||||
/* Reschedule if necessary. */
|
||||
if(RTS_ISSET(rp, NO_PRIORITY))
|
||||
RTS_LOCK_UNSET(rp, NO_PRIORITY);
|
||||
else
|
||||
else {
|
||||
struct proc *caller;
|
||||
caller = proc_addr(who_p);
|
||||
kprintf("system: warning: sigsend a running process\n");
|
||||
kprintf("caller stack: ");
|
||||
proc_stacktrace(caller);
|
||||
}
|
||||
|
||||
return(OK);
|
||||
}
|
||||
|
||||
@@ -17,6 +17,9 @@
|
||||
|
||||
#if SPROFILE
|
||||
|
||||
/* user address to write info struct */
|
||||
PRIVATE vir_bytes sprof_info_addr_vir;
|
||||
|
||||
/*===========================================================================*
|
||||
* do_sprofile *
|
||||
*===========================================================================*/
|
||||
@@ -41,15 +44,14 @@ register message *m_ptr; /* pointer to request message */
|
||||
return EBUSY;
|
||||
}
|
||||
|
||||
isokendpt(m_ptr->PROF_ENDPT, &proc_nr);
|
||||
/* Test endpoint number. */
|
||||
if(!isokendpt(m_ptr->PROF_ENDPT, &proc_nr))
|
||||
return EINVAL;
|
||||
|
||||
vir_dst = (vir_bytes) m_ptr->PROF_CTL_PTR;
|
||||
length = (phys_bytes) sizeof (int *);
|
||||
sprof_info_addr = numap_local(proc_nr, vir_dst, length);
|
||||
|
||||
vir_dst = (vir_bytes) m_ptr->PROF_MEM_PTR;
|
||||
length = (phys_bytes) sizeof (char *);
|
||||
sprof_data_addr = numap_local(proc_nr, vir_dst, length);
|
||||
/* Set parameters for statistical profiler. */
|
||||
sprof_ep = m_ptr->PROF_ENDPT;
|
||||
sprof_info_addr_vir = (vir_bytes) m_ptr->PROF_CTL_PTR;
|
||||
sprof_data_addr_vir = (vir_bytes) m_ptr->PROF_MEM_PTR;
|
||||
|
||||
sprof_info.mem_used = 0;
|
||||
sprof_info.total_samples = 0;
|
||||
@@ -80,8 +82,8 @@ register message *m_ptr; /* pointer to request message */
|
||||
|
||||
stop_profile_clock();
|
||||
|
||||
phys_copy(vir2phys((vir_bytes) &sprof_info),
|
||||
sprof_info_addr, (phys_bytes) sizeof(sprof_info));
|
||||
data_copy(SYSTEM, (vir_bytes) &sprof_info,
|
||||
sprof_ep, sprof_info_addr_vir, sizeof(sprof_info));
|
||||
|
||||
return OK;
|
||||
|
||||
|
||||
@@ -40,7 +40,6 @@ register message *m_ptr;
|
||||
*/
|
||||
|
||||
register struct proc *rp;
|
||||
phys_bytes src, dst;
|
||||
vir_bytes tr_addr = (vir_bytes) m_ptr->CTL_ADDRESS;
|
||||
long tr_data = m_ptr->CTL_DATA;
|
||||
int tr_request = m_ptr->CTL_REQUEST;
|
||||
@@ -48,6 +47,26 @@ register message *m_ptr;
|
||||
unsigned char ub;
|
||||
int i;
|
||||
|
||||
#define COPYTOPROC(seg, addr, myaddr, length) { \
|
||||
struct vir_addr fromaddr, toaddr; \
|
||||
fromaddr.proc_nr_e = SYSTEM; \
|
||||
toaddr.proc_nr_e = tr_proc_nr_e; \
|
||||
fromaddr.offset = (myaddr); \
|
||||
toaddr.offset = (addr); \
|
||||
fromaddr.segment = D; \
|
||||
toaddr.segment = (seg); \
|
||||
}
|
||||
|
||||
#define COPYFROMPROC(seg, addr, myaddr, length) { \
|
||||
struct vir_addr fromaddr, toaddr; \
|
||||
fromaddr.proc_nr_e = tr_proc_nr_e; \
|
||||
toaddr.proc_nr_e = SYSTEM; \
|
||||
fromaddr.offset = (addr); \
|
||||
toaddr.offset = (myaddr); \
|
||||
fromaddr.segment = (seg); \
|
||||
toaddr.segment = D; \
|
||||
}
|
||||
|
||||
if(!isokendpt(tr_proc_nr_e, &tr_proc_nr)) return(EINVAL);
|
||||
if (iskerneln(tr_proc_nr)) return(EPERM);
|
||||
|
||||
@@ -61,16 +80,14 @@ register message *m_ptr;
|
||||
|
||||
case T_GETINS: /* return value from instruction space */
|
||||
if (rp->p_memmap[T].mem_len != 0) {
|
||||
if ((src = umap_local(rp, T, tr_addr, TR_VLSIZE)) == 0) return(EIO);
|
||||
phys_copy(src, vir2phys(&tr_data), (phys_bytes) sizeof(long));
|
||||
COPYTOPROC(T, tr_addr, (vir_bytes) &tr_data, sizeof(long));
|
||||
m_ptr->CTL_DATA = tr_data;
|
||||
break;
|
||||
}
|
||||
/* Text space is actually data space - fall through. */
|
||||
|
||||
case T_GETDATA: /* return value from data space */
|
||||
if ((src = umap_local(rp, D, tr_addr, TR_VLSIZE)) == 0) return(EIO);
|
||||
phys_copy(src, vir2phys(&tr_data), (phys_bytes) sizeof(long));
|
||||
COPYTOPROC(D, tr_addr, (vir_bytes) &tr_data, sizeof(long));
|
||||
m_ptr->CTL_DATA= tr_data;
|
||||
break;
|
||||
|
||||
@@ -83,16 +100,14 @@ register message *m_ptr;
|
||||
|
||||
case T_SETINS: /* set value in instruction space */
|
||||
if (rp->p_memmap[T].mem_len != 0) {
|
||||
if ((dst = umap_local(rp, T, tr_addr, TR_VLSIZE)) == 0) return(EIO);
|
||||
phys_copy(vir2phys(&tr_data), dst, (phys_bytes) sizeof(long));
|
||||
COPYFROMPROC(T, tr_addr, (vir_bytes) &tr_data, sizeof(long));
|
||||
m_ptr->CTL_DATA = 0;
|
||||
break;
|
||||
}
|
||||
/* Text space is actually data space - fall through. */
|
||||
|
||||
case T_SETDATA: /* set value in data space */
|
||||
if ((dst = umap_local(rp, D, tr_addr, TR_VLSIZE)) == 0) return(EIO);
|
||||
phys_copy(vir2phys(&tr_data), dst, (phys_bytes) sizeof(long));
|
||||
COPYFROMPROC(D, tr_addr, (vir_bytes) &tr_data, sizeof(long));
|
||||
m_ptr->CTL_DATA = 0;
|
||||
break;
|
||||
|
||||
@@ -136,28 +151,12 @@ register message *m_ptr;
|
||||
break;
|
||||
|
||||
case T_READB_INS: /* get value from instruction space */
|
||||
if (rp->p_memmap[T].mem_len != 0) {
|
||||
if ((dst = umap_local(rp, T, tr_addr, 1)) == 0) return(EFAULT);
|
||||
phys_copy(dst, vir2phys(&ub), (phys_bytes) 1);
|
||||
m_ptr->CTL_DATA = ub;
|
||||
break;
|
||||
}
|
||||
|
||||
if ((dst = umap_local(rp, D, tr_addr, 1)) == 0) return(EFAULT);
|
||||
phys_copy(dst, vir2phys(&ub), (phys_bytes) 1);
|
||||
COPYFROMPROC(rp->p_memmap[T].mem_len > 0 ? T : D, tr_addr, (vir_bytes) &ub, 1);
|
||||
m_ptr->CTL_DATA = ub;
|
||||
break;
|
||||
|
||||
case T_WRITEB_INS: /* set value in instruction space */
|
||||
if (rp->p_memmap[T].mem_len != 0) {
|
||||
if ((dst = umap_local(rp, T, tr_addr, 1)) == 0) return(EFAULT);
|
||||
phys_copy(vir2phys(&tr_data), dst, (phys_bytes) 1);
|
||||
m_ptr->CTL_DATA = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
if ((dst = umap_local(rp, D, tr_addr, 1)) == 0) return(EFAULT);
|
||||
phys_copy(vir2phys(&tr_data), dst, (phys_bytes) 1);
|
||||
COPYTOPROC(rp->p_memmap[T].mem_len > 0 ? T : D,tr_addr, (vir_bytes) &tr_data, 1);
|
||||
m_ptr->CTL_DATA = 0;
|
||||
break;
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
*/
|
||||
|
||||
#include "../system.h"
|
||||
#include "../vm.h"
|
||||
|
||||
#if USE_UMAP
|
||||
|
||||
@@ -25,8 +26,11 @@ register message *m_ptr; /* pointer to request message */
|
||||
vir_bytes offset = m_ptr->CP_SRC_ADDR;
|
||||
int count = m_ptr->CP_NR_BYTES;
|
||||
int endpt = (int) m_ptr->CP_SRC_ENDPT;
|
||||
int proc_nr;
|
||||
phys_bytes phys_addr;
|
||||
int proc_nr, r;
|
||||
int naughty = 0;
|
||||
phys_bytes phys_addr = 0, lin_addr = 0;
|
||||
int caller_pn;
|
||||
struct proc *targetpr, *caller;
|
||||
|
||||
/* Verify process number. */
|
||||
if (endpt == SELF)
|
||||
@@ -34,27 +38,88 @@ register message *m_ptr; /* pointer to request message */
|
||||
else
|
||||
if (! isokendpt(endpt, &proc_nr))
|
||||
return(EINVAL);
|
||||
targetpr = proc_addr(proc_nr);
|
||||
|
||||
okendpt(who_e, &caller_pn);
|
||||
caller = proc_addr(caller_pn);
|
||||
|
||||
/* See which mapping should be made. */
|
||||
switch(seg_type) {
|
||||
case LOCAL_SEG:
|
||||
phys_addr = umap_local(proc_addr(proc_nr), seg_index, offset, count);
|
||||
phys_addr = lin_addr = umap_local(targetpr, seg_index, offset, count);
|
||||
if(!lin_addr) return EFAULT;
|
||||
CHECKRANGE_OR_SUSPEND(targetpr, lin_addr, count, 1);
|
||||
naughty = 1;
|
||||
break;
|
||||
case REMOTE_SEG:
|
||||
phys_addr = umap_remote(proc_addr(proc_nr), seg_index, offset, count);
|
||||
phys_addr = lin_addr = umap_remote(targetpr, seg_index, offset, count);
|
||||
if(!lin_addr) return EFAULT;
|
||||
CHECKRANGE_OR_SUSPEND(targetpr, lin_addr, count, 1);
|
||||
naughty = 1;
|
||||
break;
|
||||
#if _MINIX_CHIP == _CHIP_INTEL
|
||||
case BIOS_SEG:
|
||||
phys_addr = umap_bios(proc_addr(proc_nr), offset, count);
|
||||
break;
|
||||
#endif
|
||||
case GRANT_SEG:
|
||||
phys_addr = umap_grant(proc_addr(proc_nr), offset, count);
|
||||
naughty = 1;
|
||||
case LOCAL_VM_SEG:
|
||||
if(seg_index == MEM_GRANT || seg_type == GRANT_SEG) {
|
||||
vir_bytes newoffset;
|
||||
endpoint_t newep;
|
||||
int new_proc_nr;
|
||||
|
||||
if(verify_grant(targetpr->p_endpoint, ANY, offset, count, 0, 0,
|
||||
&newoffset, &newep) != OK) {
|
||||
kprintf("SYSTEM: do_umap: verify_grant in %s, grant %d, bytes 0x%lx, failed, caller %s\n", targetpr->p_name, offset, count, caller->p_name);
|
||||
proc_stacktrace(caller);
|
||||
return EFAULT;
|
||||
}
|
||||
|
||||
if(!isokendpt(newep, &new_proc_nr)) {
|
||||
kprintf("SYSTEM: do_umap: isokendpt failed\n");
|
||||
return EFAULT;
|
||||
}
|
||||
|
||||
/* New lookup. */
|
||||
offset = newoffset;
|
||||
targetpr = proc_addr(new_proc_nr);
|
||||
seg_index = D;
|
||||
}
|
||||
|
||||
if(seg_index == T || seg_index == D || seg_index == S) {
|
||||
phys_addr = lin_addr = umap_local(targetpr, seg_index, offset, count);
|
||||
} else {
|
||||
kprintf("SYSTEM: bogus seg type 0x%lx\n", seg_index);
|
||||
return EFAULT;
|
||||
}
|
||||
if(!lin_addr) {
|
||||
kprintf("SYSTEM:do_umap: umap_local failed\n");
|
||||
return EFAULT;
|
||||
}
|
||||
CHECKRANGE_OR_SUSPEND(targetpr, lin_addr, count, 1);
|
||||
if(vm_lookup(targetpr, lin_addr, &phys_addr, NULL) != OK) {
|
||||
kprintf("SYSTEM:do_umap: vm_lookup failed\n");
|
||||
return EFAULT;
|
||||
}
|
||||
if(phys_addr == 0)
|
||||
minix_panic("vm_lookup returned zero physical address", NO_NUM);
|
||||
break;
|
||||
default:
|
||||
return(EINVAL);
|
||||
if((r=arch_umap(targetpr, offset, count, seg_type, &lin_addr))
|
||||
!= OK)
|
||||
return r;
|
||||
phys_addr = lin_addr;
|
||||
}
|
||||
|
||||
if(vm_running && !vm_contiguous(targetpr, lin_addr, count)) {
|
||||
kprintf("SYSTEM:do_umap: not contiguous\n");
|
||||
return EFAULT;
|
||||
}
|
||||
|
||||
m_ptr->CP_DST_ADDR = phys_addr;
|
||||
if(naughty || phys_addr == 0) {
|
||||
kprintf("kernel: umap 0x%x done by %d / %s, pc 0x%lx, 0x%lx -> 0x%lx\n",
|
||||
seg_type, who_e, caller->p_name, caller->p_reg.pc, offset, phys_addr);
|
||||
kprintf("caller stack: ");
|
||||
proc_stacktrace(caller);
|
||||
}
|
||||
return (phys_addr == 0) ? EFAULT: OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
PUBLIC int do_unused(m)
|
||||
message *m; /* pointer to request message */
|
||||
{
|
||||
kprintf("SYSTEM: got unused request %d from %d", m->m_type, m->m_source);
|
||||
kprintf("SYSTEM: got unused request %d from %d\n", m->m_type, m->m_source);
|
||||
return(EBADREQUEST); /* illegal message type */
|
||||
}
|
||||
|
||||
|
||||
@@ -25,13 +25,13 @@ register message *m_ptr; /* pointer to request message */
|
||||
* requests. Although a single handler function is used, there are two
|
||||
* different kernel calls so that permissions can be checked.
|
||||
*/
|
||||
int nr_req;
|
||||
int nr_req, r;
|
||||
vir_bytes caller_vir;
|
||||
phys_bytes caller_phys;
|
||||
phys_bytes kernel_phys;
|
||||
phys_bytes bytes;
|
||||
int i,s;
|
||||
struct vir_cp_req *req;
|
||||
struct vir_addr src, dst;
|
||||
struct proc *pr;
|
||||
|
||||
{ static int first=1;
|
||||
if (first)
|
||||
@@ -41,17 +41,23 @@ register message *m_ptr; /* pointer to request message */
|
||||
}
|
||||
}
|
||||
|
||||
if(!(pr = endpoint_lookup(who_e)))
|
||||
minix_panic("do_vcopy: caller doesn't exist", who_e);
|
||||
|
||||
/* Check if request vector size is ok. */
|
||||
nr_req = (unsigned) m_ptr->VCP_VEC_SIZE;
|
||||
if (nr_req > VCOPY_VEC_SIZE) return(EINVAL);
|
||||
bytes = nr_req * sizeof(struct vir_cp_req);
|
||||
|
||||
/* Calculate physical addresses and copy (port,value)-pairs from user. */
|
||||
caller_vir = (vir_bytes) m_ptr->VCP_VEC_ADDR;
|
||||
caller_phys = umap_local(proc_addr(who_p), D, caller_vir, bytes);
|
||||
if (0 == caller_phys) return(EFAULT);
|
||||
kernel_phys = vir2phys(vir_cp_req);
|
||||
phys_copy(caller_phys, kernel_phys, (phys_bytes) bytes);
|
||||
src.segment = dst.segment = D;
|
||||
src.proc_nr_e = who_e;
|
||||
dst.proc_nr_e = SYSTEM;
|
||||
dst.offset = (vir_bytes) vir_cp_req;
|
||||
src.offset = (vir_bytes) m_ptr->VCP_VEC_ADDR;
|
||||
|
||||
if((r=virtual_copy_vmcheck(&src, &dst, bytes)) != OK)
|
||||
return r;
|
||||
|
||||
/* Assume vector with requests is correct. Try to copy everything. */
|
||||
m_ptr->VCP_NR_OK = 0;
|
||||
@@ -62,7 +68,7 @@ register message *m_ptr; /* pointer to request message */
|
||||
/* Check if physical addressing is used without SYS_PHYSVCOPY. */
|
||||
if (((req->src.segment | req->dst.segment) & PHYS_SEG) &&
|
||||
m_ptr->m_type != SYS_PHYSVCOPY) return(EPERM);
|
||||
if ((s=virtual_copy(&req->src, &req->dst, req->count)) != OK)
|
||||
if ((s=virtual_copy_vmcheck(&req->src, &req->dst, req->count)) != OK)
|
||||
return(s);
|
||||
m_ptr->VCP_NR_OK ++;
|
||||
}
|
||||
|
||||
@@ -36,14 +36,13 @@ register message *m_ptr; /* pointer to request message */
|
||||
int vec_size; /* size of vector */
|
||||
int io_in; /* true if input */
|
||||
size_t bytes; /* # bytes to be copied */
|
||||
vir_bytes caller_vir; /* virtual address at caller */
|
||||
phys_bytes caller_phys; /* physical address at caller */
|
||||
port_t port;
|
||||
int i, j, io_size, nr_io_range;
|
||||
int io_dir, io_type;
|
||||
struct proc *rp;
|
||||
struct priv *privp;
|
||||
struct io_range *iorp;
|
||||
int r;
|
||||
|
||||
/* Get the request, size of the request vector, and check the values. */
|
||||
io_dir = m_ptr->DIO_REQUEST & _DIO_DIRMASK;
|
||||
@@ -69,11 +68,10 @@ register message *m_ptr; /* pointer to request message */
|
||||
}
|
||||
if (bytes > sizeof(vdevio_buf)) return(E2BIG);
|
||||
|
||||
/* Calculate physical addresses and copy (port,value)-pairs from user. */
|
||||
caller_vir = (vir_bytes) m_ptr->DIO_VEC_ADDR;
|
||||
caller_phys = umap_local(proc_addr(who_p), D, caller_vir, bytes);
|
||||
if (0 == caller_phys) return(EFAULT);
|
||||
phys_copy(caller_phys, vir2phys(vdevio_buf), (phys_bytes) bytes);
|
||||
/* Copy (port,value)-pairs from user. */
|
||||
if((r=data_copy(who_e, (vir_bytes) m_ptr->DIO_VEC_ADDR,
|
||||
SYSTEM, (vir_bytes) vdevio_buf, bytes)) != OK)
|
||||
return r;
|
||||
|
||||
rp= proc_addr(who_p);
|
||||
privp= priv(rp);
|
||||
@@ -110,7 +108,20 @@ register message *m_ptr; /* pointer to request message */
|
||||
* the entire switch is wrapped in lock() and unlock() to prevent the I/O
|
||||
* batch from being interrupted.
|
||||
*/
|
||||
lock(13, "do_vdevio");
|
||||
#if 0
|
||||
if(who_e == 71091) {
|
||||
static int vd = 0;
|
||||
if(vd++ < 100) {
|
||||
kprintf("proc %d does vdevio no %d; type %d, direction %s\n",
|
||||
who_e, vd, io_type, io_in ? "input" : "output");
|
||||
kprintf("(");
|
||||
for (i=0; i<vec_size; i++)
|
||||
kprintf("%2d:0x%x,0x%x ", i, pvb[i].port, pvb[i].value);
|
||||
kprintf(")\n");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
lock;
|
||||
switch (io_type) {
|
||||
case _DIO_BYTE: /* byte values */
|
||||
if (io_in) for (i=0; i<vec_size; i++)
|
||||
@@ -158,14 +169,18 @@ register message *m_ptr; /* pointer to request message */
|
||||
}
|
||||
}
|
||||
}
|
||||
unlock(13);
|
||||
unlock;
|
||||
|
||||
/* Almost done, copy back results for input requests. */
|
||||
if (io_in) phys_copy(vir2phys(vdevio_buf), caller_phys, (phys_bytes) bytes);
|
||||
if (io_in)
|
||||
if((r=data_copy(SYSTEM, (vir_bytes) vdevio_buf,
|
||||
who_e, (vir_bytes) m_ptr->DIO_VEC_ADDR,
|
||||
(phys_bytes) bytes)) != OK)
|
||||
return r;
|
||||
return(OK);
|
||||
|
||||
bad:
|
||||
panic("do_vdevio: unaligned port\n", port);
|
||||
minix_panic("do_vdevio: unaligned port", port);
|
||||
return EPERM;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,83 +0,0 @@
|
||||
/* The system call implemented in this file:
|
||||
* m_type: SYS_VM_MAP
|
||||
*
|
||||
* The parameters for this system call are:
|
||||
* m4_l1: Process that requests map (VM_MAP_ENDPT)
|
||||
* m4_l2: Map (TRUE) or unmap (FALSE) (VM_MAP_MAPUNMAP)
|
||||
* m4_l3: Base address (VM_MAP_BASE)
|
||||
* m4_l4: Size (VM_MAP_SIZE)
|
||||
* m4_l5: address (VM_MAP_ADDR)
|
||||
*/
|
||||
#include "../system.h"
|
||||
|
||||
PRIVATE int vm_needs_init= 1;
|
||||
|
||||
#include <sys/vm.h>
|
||||
|
||||
/*===========================================================================*
|
||||
* do_vm_map *
|
||||
*===========================================================================*/
|
||||
PUBLIC int do_vm_map(m_ptr)
|
||||
message *m_ptr; /* pointer to request message */
|
||||
{
|
||||
int proc_nr, do_map;
|
||||
phys_bytes base, size, offset, p_phys;
|
||||
struct proc *pp;
|
||||
|
||||
/* do_serial_debug= 1; */
|
||||
if (vm_needs_init)
|
||||
{
|
||||
vm_needs_init= 0;
|
||||
vm_init();
|
||||
}
|
||||
|
||||
if (m_ptr->VM_MAP_ENDPT == SELF) {
|
||||
proc_nr = who_p;
|
||||
} else {
|
||||
if(!isokendpt(m_ptr->VM_MAP_ENDPT, &proc_nr))
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
do_map= m_ptr->VM_MAP_MAPUNMAP;
|
||||
base= m_ptr->VM_MAP_BASE;
|
||||
size= m_ptr->VM_MAP_SIZE;
|
||||
offset= m_ptr->VM_MAP_ADDR;
|
||||
|
||||
pp= proc_addr(proc_nr);
|
||||
p_phys= umap_local(pp, D, base, size);
|
||||
if (p_phys == 0)
|
||||
return EFAULT;
|
||||
|
||||
if (do_map)
|
||||
{
|
||||
pp->p_misc_flags |= MF_VM;
|
||||
|
||||
vm_map_range(p_phys, size, offset);
|
||||
}
|
||||
else
|
||||
{
|
||||
vm_map_range(p_phys, size, p_phys);
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
/*===========================================================================*
|
||||
* vm_map_default *
|
||||
*===========================================================================*/
|
||||
PUBLIC void vm_map_default(pp)
|
||||
struct proc *pp;
|
||||
{
|
||||
phys_bytes base_clicks, size_clicks;
|
||||
|
||||
if (vm_needs_init)
|
||||
panic("vm_map_default: VM not initialized?", NO_NUM);
|
||||
pp->p_misc_flags &= ~MF_VM;
|
||||
base_clicks= pp->p_memmap[D].mem_phys;
|
||||
size_clicks= pp->p_memmap[S].mem_phys+pp->p_memmap[S].mem_len -
|
||||
base_clicks;
|
||||
vm_map_range(base_clicks << CLICK_SHIFT,
|
||||
size_clicks << CLICK_SHIFT, base_clicks << CLICK_SHIFT);
|
||||
}
|
||||
|
||||
104
kernel/system/do_vmctl.c
Normal file
104
kernel/system/do_vmctl.c
Normal file
@@ -0,0 +1,104 @@
|
||||
/* The kernel call implemented in this file:
|
||||
* m_type: SYS_VMCTL
|
||||
*
|
||||
* The parameters for this kernel call are:
|
||||
* SVMCTL_WHO which process
|
||||
* SVMCTL_PARAM set this setting (VMCTL_*)
|
||||
* SVMCTL_VALUE to this value
|
||||
*/
|
||||
|
||||
#include "../system.h"
|
||||
#include "../vm.h"
|
||||
#include "../debug.h"
|
||||
#include <minix/type.h>
|
||||
|
||||
/*===========================================================================*
|
||||
* do_vmctl *
|
||||
*===========================================================================*/
|
||||
PUBLIC int do_vmctl(m_ptr)
|
||||
register message *m_ptr; /* pointer to request message */
|
||||
{
|
||||
int proc_nr, i;
|
||||
endpoint_t ep = m_ptr->SVMCTL_WHO;
|
||||
struct proc *p, *rp;
|
||||
|
||||
if(ep == SELF) { ep = m_ptr->m_source; }
|
||||
|
||||
vm_init();
|
||||
|
||||
if(m_ptr->m_source != VM_PROC_NR) {
|
||||
kprintf("do_vmctl: source %d, not VM\n", m_ptr->m_source);
|
||||
return ENOSYS;
|
||||
}
|
||||
|
||||
if(!isokendpt(ep, &proc_nr)) {
|
||||
kprintf("do_vmctl: unexpected endpoint %d from VM\n", ep);
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
p = proc_addr(proc_nr);
|
||||
|
||||
switch(m_ptr->SVMCTL_PARAM) {
|
||||
case VMCTL_CLEAR_PAGEFAULT:
|
||||
RTS_LOCK_UNSET(p, PAGEFAULT);
|
||||
return OK;
|
||||
case VMCTL_MEMREQ_GET:
|
||||
/* Send VM the information about the memory request. */
|
||||
if(!(rp = vmrequest))
|
||||
return ESRCH;
|
||||
if(!RTS_ISSET(rp, VMREQUEST))
|
||||
minix_panic("do_vmctl: no VMREQUEST set", NO_NUM);
|
||||
|
||||
/* Reply with request fields. */
|
||||
m_ptr->SVMCTL_MRG_ADDR = (char *) rp->p_vmrequest.start;
|
||||
m_ptr->SVMCTL_MRG_LEN = rp->p_vmrequest.length;
|
||||
m_ptr->SVMCTL_MRG_WRITE = rp->p_vmrequest.writeflag;
|
||||
m_ptr->SVMCTL_MRG_EP = rp->p_vmrequest.who;
|
||||
rp->p_vmrequest.vmresult = VMSUSPEND;
|
||||
|
||||
/* Remove from request chain. */
|
||||
vmrequest = vmrequest->p_vmrequest.nextrequestor;
|
||||
|
||||
return OK;
|
||||
case VMCTL_MEMREQ_REPLY:
|
||||
if(!(rp = p->p_vmrequest.requestor))
|
||||
minix_panic("do_vmctl: no requestor set", ep);
|
||||
p->p_vmrequest.requestor = NULL;
|
||||
if(!RTS_ISSET(rp, VMREQUEST))
|
||||
minix_panic("do_vmctl: no VMREQUEST set", ep);
|
||||
if(rp->p_vmrequest.vmresult != VMSUSPEND)
|
||||
minix_panic("do_vmctl: result not VMSUSPEND set",
|
||||
rp->p_vmrequest.vmresult);
|
||||
rp->p_vmrequest.vmresult = m_ptr->SVMCTL_VALUE;
|
||||
if(rp->p_vmrequest.vmresult == VMSUSPEND)
|
||||
minix_panic("VM returned VMSUSPEND?", NO_NUM);
|
||||
if(rp->p_vmrequest.vmresult != OK)
|
||||
kprintf("SYSTEM: VM replied %d to mem request\n",
|
||||
rp->p_vmrequest.vmresult);
|
||||
|
||||
/* Put on restart chain. */
|
||||
rp->p_vmrequest.nextrestart = vmrestart;
|
||||
vmrestart = rp;
|
||||
|
||||
#if DEBUG_VMASSERT
|
||||
/* Sanity check. */
|
||||
if(rp->p_vmrequest.vmresult == OK) {
|
||||
if(CHECKRANGE(p,
|
||||
rp->p_vmrequest.start,
|
||||
rp->p_vmrequest.length,
|
||||
rp->p_vmrequest.writeflag) != OK) {
|
||||
kprintf("SYSTEM: request %d:0x%lx-0x%lx, wrflag %d, failed\n",
|
||||
rp->p_endpoint,
|
||||
rp->p_vmrequest.start, rp->p_vmrequest.start + rp->p_vmrequest.length,
|
||||
rp->p_vmrequest.writeflag);
|
||||
|
||||
minix_panic("SYSTEM: fail but VM said OK", NO_NUM);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return OK;
|
||||
}
|
||||
|
||||
/* Try architecture-specific vmctls. */
|
||||
return arch_do_vmctl(m_ptr, p);
|
||||
}
|
||||
Reference in New Issue
Block a user