From: Philip Homburg Date: Thu, 11 May 2006 14:49:46 +0000 (+0000) Subject: Better initialization of the memory map of processes that are part of the X-Git-Tag: v3.1.3~367 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/doc/processing.js?a=commitdiff_plain;h=15b8fe54a8267f8d0a9133f735986fea992558f2;p=minix.git Better initialization of the memory map of processes that are part of the image. Removed NO_MAP flag. --- diff --git a/kernel/debug.h b/kernel/debug.h index 71e874317..534ae06a5 100644 --- a/kernel/debug.h +++ b/kernel/debug.h @@ -7,6 +7,7 @@ * other kernel headers. */ +#include #include "config.h" /* Enable prints such as diff --git a/kernel/exception.c b/kernel/exception.c index def5a7e07..d269f4af9 100755 --- a/kernel/exception.c +++ b/kernel/exception.c @@ -57,6 +57,17 @@ unsigned vec_nr; * k_reenter larger than zero. */ if (k_reenter == 0 && ! iskernelp(saved_proc)) { +#if 0 + { + kprintf( + "exception for process %d, pc = 0x%x:0x%x, sp = 0x%x:0x%x\n", + proc_nr(saved_proc), + saved_proc->p_reg.cs, saved_proc->p_reg.pc, + saved_proc->p_reg.ss, saved_proc->p_reg.sp); + kprintf("edi = 0x%x\n", saved_proc->p_reg.di); + } +#endif + cause_sig(proc_nr(saved_proc), ep->signum); return; } diff --git a/kernel/main.c b/kernel/main.c index 33bf1e71f..e521011b8 100755 --- a/kernel/main.c +++ b/kernel/main.c @@ -38,7 +38,7 @@ PUBLIC void main() register int i, s; int hdrindex; /* index to array of a.out headers */ phys_clicks text_base; - vir_clicks text_clicks, data_clicks; + vir_clicks text_clicks, data_clicks, st_clicks; reg_t ktsb; /* kernel task stack base */ struct exec e_hdr; /* for a copy of an a.out header */ @@ -108,14 +108,21 @@ PUBLIC void main() /* Convert addresses to clicks and build process memory map */ text_base = e_hdr.a_syms >> CLICK_SHIFT; text_clicks = (e_hdr.a_text + CLICK_SIZE-1) >> CLICK_SHIFT; - if (!(e_hdr.a_flags & A_SEP)) text_clicks = 0; /* common I&D */ - data_clicks = (e_hdr.a_total + CLICK_SIZE-1) >> CLICK_SHIFT; + data_clicks = (e_hdr.a_data+e_hdr.a_bss + CLICK_SIZE-1) >> CLICK_SHIFT; + st_clicks= (e_hdr.a_total + CLICK_SIZE-1) >> CLICK_SHIFT; + if (!(e_hdr.a_flags & A_SEP)) + { + data_clicks= (e_hdr.a_text+e_hdr.a_data+e_hdr.a_bss + + CLICK_SIZE-1) >> CLICK_SHIFT; + text_clicks = 0; /* common I&D */ + } rp->p_memmap[T].mem_phys = text_base; rp->p_memmap[T].mem_len = text_clicks; rp->p_memmap[D].mem_phys = text_base + text_clicks; rp->p_memmap[D].mem_len = data_clicks; - rp->p_memmap[S].mem_phys = text_base + text_clicks + data_clicks; - rp->p_memmap[S].mem_vir = data_clicks; /* empty - stack is in data */ + rp->p_memmap[S].mem_phys = text_base + text_clicks + st_clicks; + rp->p_memmap[S].mem_vir = st_clicks; + rp->p_memmap[S].mem_len = 0; /* Set initial register values. The processor status word for tasks * is different from that of other processes because tasks can @@ -138,7 +145,7 @@ PUBLIC void main() rp->p_rts_flags = 0; /* runnable if no flags */ lock_enqueue(rp); /* add to scheduling queues */ } else { - rp->p_rts_flags = NO_MAP; /* prevent from running */ + rp->p_rts_flags = NO_PRIORITY; /* prevent from running */ } /* Code and data segments must be allocated in protected mode. */ diff --git a/kernel/proc.h b/kernel/proc.h index ec51bacbb..728190ceb 100755 --- a/kernel/proc.h +++ b/kernel/proc.h @@ -61,15 +61,14 @@ struct proc { /* Bits for the runtime flags. A process is runnable iff p_rts_flags == 0. */ #define SLOT_FREE 0x01 /* process slot is free */ -#define NO_MAP 0x02 /* keeps unmapped forked child from running */ +#define NO_PRIORITY 0x02 /* process has been stopped */ #define SENDING 0x04 /* process blocked trying to send */ #define RECEIVING 0x08 /* process blocked trying to receive */ #define SIGNALED 0x10 /* set when new kernel signal arrives */ #define SIG_PENDING 0x20 /* unready while signal being processed */ #define P_STOP 0x40 /* set when process is being traced */ #define NO_PRIV 0x80 /* keep forked system process from running */ -#define NO_PRIORITY 0x100 /* process has been stopped */ -#define NO_ENDPOINT 0x200 /* process cannot send or receive messages */ +#define NO_ENDPOINT 0x100 /* process cannot send or receive messages */ /* Misc flags */ #define REPLY_PENDING 0x01 /* reply to IPC_REQUEST is pending */ diff --git a/kernel/proto.h b/kernel/proto.h index 738dfbe96..ab031d450 100755 --- a/kernel/proto.h +++ b/kernel/proto.h @@ -61,6 +61,9 @@ _PROTOTYPE( phys_bytes umap_bios, (struct proc *rp, vir_bytes vir_addr, vir_bytes bytes) ); _PROTOTYPE( void clear_endpoint, (struct proc *rc) ); +/* system/do_newmap.c */ +_PROTOTYPE( int newmap, (struct proc *rp, struct mem_map *map_ptr) ); + #if (CHIP == INTEL) /* exception.c */ diff --git a/kernel/system/do_endksig.c b/kernel/system/do_endksig.c index 63d4b20a6..642a77669 100644 --- a/kernel/system/do_endksig.c +++ b/kernel/system/do_endksig.c @@ -28,7 +28,7 @@ message *m_ptr; /* pointer to request message */ * process is already dead its flags will be reset. */ if(!isokendpt(m_ptr->SIG_ENDPT, &proc)) - return EINVAL; + return EINVAL; rp = proc_addr(proc); if (! (rp->p_rts_flags & SIG_PENDING)) return(EINVAL); diff --git a/kernel/system/do_fork.c b/kernel/system/do_fork.c index aba2715ac..18437425e 100644 --- a/kernel/system/do_fork.c +++ b/kernel/system/do_fork.c @@ -28,6 +28,7 @@ register message *m_ptr; /* pointer to request message */ #endif register struct proc *rpc; /* child process pointer */ struct proc *rpp; /* parent process pointer */ + struct mem_map *map_ptr; /* virtual address of map inside caller (PM) */ int i, gen; int p_proc; @@ -37,6 +38,8 @@ register message *m_ptr; /* pointer to request message */ rpc = proc_addr(m_ptr->PR_SLOT); if (isemptyp(rpp) || ! isemptyp(rpc)) return(EINVAL); + map_ptr= (struct mem_map *) m_ptr->PR_MEM_PTR; + /* Copy parent 'proc' struct to child. And reinitialize some fields. */ gen = _ENDPOINT_G(rpc->p_endpoint); #if (CHIP == INTEL) @@ -52,7 +55,6 @@ register message *m_ptr; /* pointer to request message */ rpc->p_endpoint = _ENDPOINT(gen, rpc->p_nr); /* new endpoint of slot */ /* Only one in group should have SIGNALED, child doesn't inherit tracing. */ - rpc->p_rts_flags |= NO_MAP; /* inhibit process from running */ rpc->p_rts_flags &= ~(SIGNALED | SIG_PENDING | P_STOP); sigemptyset(&rpc->p_pending); @@ -79,7 +81,8 @@ register message *m_ptr; /* pointer to request message */ /* Calculate endpoint identifier, so caller knows what it is. */ m_ptr->PR_ENDPT = rpc->p_endpoint; - return(OK); + /* Install new map */ + return newmap(rpc, map_ptr); } #endif /* USE_FORK */ diff --git a/kernel/system/do_newmap.c b/kernel/system/do_newmap.c index 1da7b80ca..fb24fa748 100644 --- a/kernel/system/do_newmap.c +++ b/kernel/system/do_newmap.c @@ -28,6 +28,22 @@ message *m_ptr; /* pointer to request message */ if (iskerneln(proc)) return(EPERM); rp = proc_addr(proc); + return newmap(rp, map_ptr); +} + + +/*===========================================================================* + * newmap * + *===========================================================================*/ +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) */ +{ +/* Fetch the memory map from PM. */ + phys_bytes src_phys; /* physical address of map at the PM */ + int old_flags; /* value of flags before modification */ + int proc; + /* Copy the map from PM. */ src_phys = umap_local(proc_addr(who_p), D, (vir_bytes) map_ptr, sizeof(rp->p_memmap)); @@ -40,7 +56,6 @@ message *m_ptr; /* pointer to request message */ pmmu_init_proc(rp); #endif old_flags = rp->p_rts_flags; /* save the previous value of the flags */ - rp->p_rts_flags &= ~NO_MAP; if (old_flags != 0 && rp->p_rts_flags == 0) lock_enqueue(rp); return(OK); diff --git a/kernel/system/do_nice.c b/kernel/system/do_nice.c index 51430a512..bf5aad9e1 100644 --- a/kernel/system/do_nice.c +++ b/kernel/system/do_nice.c @@ -49,6 +49,7 @@ PUBLIC int do_nice(message *m_ptr) * Put the process back in its new queue if it is runnable. */ lock_dequeue(rp); + rp->p_rts_flags &= ~NO_PRIORITY; rp->p_max_priority = rp->p_priority = new_q; if (! rp->p_rts_flags) lock_enqueue(rp); diff --git a/kernel/table.c b/kernel/table.c index a5b5a7273..3460ac182 100755 --- a/kernel/table.c +++ b/kernel/table.c @@ -80,7 +80,7 @@ PUBLIC char *t_stack[TOT_STACK_SPACE / sizeof(char *)]; #define RS_C ~0 #define DS_C ~0 #define PM_C ~(c(SYS_DEVIO) | c(SYS_SDEVIO) | c(SYS_VDEVIO) | c(SYS_IRQCTL) | c(SYS_INT86)) -#define FS_C (c(SYS_KILL) | c(SYS_VIRCOPY) | c(SYS_VIRVCOPY) | c(SYS_UMAP) | c(SYS_GETINFO) | c(SYS_EXIT) | c(SYS_TIMES) | c(SYS_SETALARM)) +#define FS_C (c(SYS_KILL) | c(SYS_VIRCOPY) | c(SYS_VIRVCOPY) | c(SYS_UMAP) | c(SYS_GETINFO) | c(SYS_EXIT) | c(SYS_TIMES) | c(SYS_SETALARM) | c(SYS_TRACE)) #define DRV_C (FS_C | c(SYS_SEGCTL) | c(SYS_IRQCTL) | c(SYS_INT86) | c(SYS_DEVIO) | c(SYS_SDEVIO) | c(SYS_VDEVIO)) #define TTY_C (DRV_C | c(SYS_ABORT) | c(SYS_VM_MAP) | c(SYS_IOPENABLE)) #define MEM_C (DRV_C | c(SYS_PHYSCOPY) | c(SYS_PHYSVCOPY) | c(SYS_VM_MAP) | \