⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 system.c

📁 一个简单的操作系统minix的核心代码
💻 C
📖 第 1 页 / 共 4 页
字号:
15226	 */
15227	
15228	  struct sigcontext sc;
15229	  register struct proc *rp;
15230	  phys_bytes src_phys;
15231	
15232	  if (!isokusern(m_ptr->PROC1)) return(E_BAD_PROC);
15233	  rp = proc_addr(m_ptr->PROC1);
15234	
15235	  /* Copy in the sigcontext structure. */
15236	  src_phys = umap(rp, D, (vir_bytes) m_ptr->SIG_CTXT_PTR,
15237	                  (vir_bytes) sizeof(struct sigcontext));
15238	  if (src_phys == 0) return(EFAULT);
15239	  phys_copy(src_phys, vir2phys(&sc), (phys_bytes) sizeof(struct sigcontext));
15240	
15241	  /* Make sure that this is not just a jmp_buf. */
15242	  if ((sc.sc_flags & SC_SIGCONTEXT) == 0) return(EINVAL);
15243	
15244	  /* Fix up only certain key registers if the compiler doesn't use
15245	   * register variables within functions containing setjmp.
15246	   */
15247	  if (sc.sc_flags & SC_NOREGLOCALS) {
15248	        rp->p_reg.retreg = sc.sc_retreg;
15249	        rp->p_reg.fp = sc.sc_fp;
15250	        rp->p_reg.pc = sc.sc_pc;
15251	        rp->p_reg.sp = sc.sc_sp;
15252	        return (OK);
15253	  }
15254	  sc.sc_psw  = rp->p_reg.psw;
15255	
15256	#if (CHIP == INTEL)
15257	  /* Don't panic kernel if user gave bad selectors. */
15258	  sc.sc_cs = rp->p_reg.cs;
15259	  sc.sc_ds = rp->p_reg.ds;
15260	  sc.sc_es = rp->p_reg.es;
15261	#if _WORD_SIZE == 4
15262	  sc.sc_fs = rp->p_reg.fs;
15263	  sc.sc_gs = rp->p_reg.gs;
15264	#endif
15265	#endif
15266	
15267	  /* Restore the registers. */
15268	  memcpy(&rp->p_reg, (char *)&sc.sc_regs, sizeof(struct sigregs));
15269	
15270	  return(OK);
15271	}
	
15273	/*===========================================================================*
15274	 *                              do_kill                                      *
15275	 *===========================================================================*/
15276	PRIVATE int do_kill(m_ptr)
15277	register message *m_ptr;        /* pointer to request message */
15278	{
15279	/* Handle sys_kill(). Cause a signal to be sent to a process via MM.
15280	 * Note that this has nothing to do with the kill (2) system call, this
15281	 * is how the FS (and possibly other servers) get access to cause_sig to
15282	 * send a KSIG message to MM
15283	 */
15284	
15285	  if (!isokusern(m_ptr->PR)) return(E_BAD_PROC);
15286	  cause_sig(m_ptr->PR, m_ptr->SIGNUM);
15287	  return(OK);
15288	}
	
	
15291	/*===========================================================================*
15292	 *                            do_endsig                                      *
15293	 *===========================================================================*/
15294	PRIVATE int do_endsig(m_ptr)
15295	register message *m_ptr;        /* pointer to request message */
15296	{
15297	/* Finish up after a KSIG-type signal, caused by a SYS_KILL message or a call
15298	 * to cause_sig by a task
15299	 */
15300	
15301	  register struct proc *rp;
15302	
15303	  if (!isokusern(m_ptr->PROC1)) return(E_BAD_PROC);
15304	  rp = proc_addr(m_ptr->PROC1);
15305	
15306	  /* MM has finished one KSIG. */
15307	  if (rp->p_pendcount != 0 && --rp->p_pendcount == 0
15308	      && (rp->p_flags &= ~SIG_PENDING) == 0)
15309	        lock_ready(rp);
15310	  return(OK);
15311	}
	
15313	/*===========================================================================*
15314	 *                              do_copy                                      *
15315	 *===========================================================================*/
15316	PRIVATE int do_copy(m_ptr)
15317	register message *m_ptr;        /* pointer to request message */
15318	{
15319	/* Handle sys_copy().  Copy data for MM or FS. */
15320	
15321	  int src_proc, dst_proc, src_space, dst_space;
15322	  vir_bytes src_vir, dst_vir;
15323	  phys_bytes src_phys, dst_phys, bytes;
15324	
15325	  /* Dismember the command message. */
15326	  src_proc = m_ptr->SRC_PROC_NR;
15327	  dst_proc = m_ptr->DST_PROC_NR;
15328	  src_space = m_ptr->SRC_SPACE;
15329	  dst_space = m_ptr->DST_SPACE;
15330	  src_vir = (vir_bytes) m_ptr->SRC_BUFFER;
15331	  dst_vir = (vir_bytes) m_ptr->DST_BUFFER;
15332	  bytes = (phys_bytes) m_ptr->COPY_BYTES;
15333	
15334	  /* Compute the source and destination addresses and do the copy. */
15335	  if (src_proc == ABS)
15336	        src_phys = (phys_bytes) m_ptr->SRC_BUFFER;
15337	  else {
15338	        if (bytes != (vir_bytes) bytes)
15339	                /* This would happen for 64K segments and 16-bit vir_bytes.
15340	                 * It would happen a lot for do_fork except MM uses ABS
15341	                 * copies for that case.
15342	                 */
15343	                panic("overflow in count in do_copy", NO_NUM);
15344	
15345	        src_phys = umap(proc_addr(src_proc), src_space, src_vir,
15346	                        (vir_bytes) bytes);
15347	        }
15348	
15349	  if (dst_proc == ABS)
15350	        dst_phys = (phys_bytes) m_ptr->DST_BUFFER;
15351	  else
15352	        dst_phys = umap(proc_addr(dst_proc), dst_space, dst_vir,
15353	                        (vir_bytes) bytes);
15354	
15355	  if (src_phys == 0 || dst_phys == 0) return(EFAULT);
15356	  phys_copy(src_phys, dst_phys, bytes);
15357	  return(OK);
15358	}
	
	
15361	/*===========================================================================*
15362	 *                              do_vcopy                                     *
15363	 *===========================================================================*/
15364	PRIVATE int do_vcopy(m_ptr)
15365	register message *m_ptr;        /* pointer to request message */
15366	{
15367	/* Handle sys_vcopy(). Copy multiple blocks of memory */
15368	
15369	  int src_proc, dst_proc, vect_s, i;
15370	  vir_bytes src_vir, dst_vir, vect_addr;
15371	  phys_bytes src_phys, dst_phys, bytes;
15372	  cpvec_t cpvec_table[CPVEC_NR];
15373	
15374	  /* Dismember the command message. */
15375	  src_proc = m_ptr->m1_i1;
15376	  dst_proc = m_ptr->m1_i2;
15377	  vect_s = m_ptr->m1_i3;
15378	  vect_addr = (vir_bytes)m_ptr->m1_p1;
15379	
15380	  if (vect_s > CPVEC_NR) return EDOM;
15381	
15382	  src_phys= numap (m_ptr->m_source, vect_addr, vect_s * sizeof(cpvec_t));
15383	  if (!src_phys) return EFAULT;
15384	  phys_copy(src_phys, vir2phys(cpvec_table),
15385	                                (phys_bytes) (vect_s * sizeof(cpvec_t)));
15386	
15387	  for (i = 0; i < vect_s; i++) {
15388	        src_vir= cpvec_table[i].cpv_src;
15389	        dst_vir= cpvec_table[i].cpv_dst;
15390	        bytes= cpvec_table[i].cpv_size;
15391	        src_phys = numap(src_proc,src_vir,(vir_bytes)bytes);
15392	        dst_phys = numap(dst_proc,dst_vir,(vir_bytes)bytes);
15393	        if (src_phys == 0 || dst_phys == 0) return(EFAULT);
15394	        phys_copy(src_phys, dst_phys, bytes);
15395	  }
15396	  return(OK);
15397	}
	
	
15400	/*==========================================================================*
15401	 *                              do_gboot                                    *
15402	 *==========================================================================*/
15403	PUBLIC struct bparam_s boot_parameters;
15404	
15405	PRIVATE int do_gboot(m_ptr)
15406	message *m_ptr;                 /* pointer to request message */
15407	{
15408	/* Copy the boot parameters.  Normally only called during fs init. */
15409	
15410	  phys_bytes dst_phys;
15411	
15412	  dst_phys = umap(proc_addr(m_ptr->PROC1), D, (vir_bytes) m_ptr->MEM_PTR,
15413	                                (vir_bytes) sizeof(boot_parameters));
15414	  if (dst_phys == 0) panic("bad call to SYS_GBOOT", NO_NUM);
15415	  phys_copy(vir2phys(&boot_parameters), dst_phys,
15416	                                (phys_bytes) sizeof(boot_parameters));
15417	  return(OK);
15418	}
	
	
15421	/*===========================================================================*
15422	 *                              do_mem                                       *
15423	 *===========================================================================*/
15424	PRIVATE int do_mem(m_ptr)
15425	register message *m_ptr;        /* pointer to request message */
15426	{
15427	/* Return the base and size of the next chunk of memory. */
15428	
15429	  struct memory *memp;
15430	
15431	  for (memp = mem; memp < &mem[NR_MEMS]; ++memp) {
15432	        m_ptr->m1_i1 = memp->base;
15433	        m_ptr->m1_i2 = memp->size;
15434	        m_ptr->m1_i3 = tot_mem_size;
15435	        memp->size = 0;
15436	        if (m_ptr->m1_i2 != 0) break;           /* found a chunk */
15437	  }
15438	  return(OK);
15439	}
	
	
15442	/*==========================================================================*
15443	 *                              do_umap                                     *
15444	 *==========================================================================*/
15445	PRIVATE int do_umap(m_ptr)
15446	register message *m_ptr;        /* pointer to request message */
15447	{
15448	/* Same as umap(), for non-kernel processes. */
15449	
15450	  m_ptr->SRC_BUFFER = umap(proc_addr((int) m_ptr->SRC_PROC_NR),
15451	                           (int) m_ptr->SRC_SPACE,
15452	                           (vir_bytes) m_ptr->SRC_BUFFER,
15453	                           (vir_bytes) m_ptr->COPY_BYTES);
15454	  return(OK);
15455	}
	
	
15458	/*==========================================================================*
15459	 *                              do_trace                                    *
15460	 *==========================================================================*/
15461	#define TR_PROCNR       (m_ptr->m2_i1)
15462	#define TR_REQUEST      (m_ptr->m2_i2)
15463	#define TR_ADDR         ((vir_bytes) m_ptr->m2_l1)
15464	#define TR_DATA         (m_ptr->m2_l2)
15465	#define TR_VLSIZE       ((vir_bytes) sizeof(long))
15466	
15467	PRIVATE int do_trace(m_ptr)
15468	register message *m_ptr;
15469	{
15470	/* Handle the debugging commands supported by the ptrace system call
15471	 * The commands are:
15472	 * T_STOP       stop the process
15473	 * T_OK         enable tracing by parent for this process
15474	 * T_GETINS     return value from instruction space
15475	 * T_GETDATA    return value from data space
15476	 * T_GETUSER    return value from user process table
15477	 * T_SETINS     set value from instruction space
15478	 * T_SETDATA    set value from data space
15479	 * T_SETUSER    set value in user process table
15480	 * T_RESUME     resume execution
15481	 * T_EXIT       exit
15482	 * T_STEP       set trace bit
15483	 *
15484	 * The T_OK and T_EXIT commands are handled completely by the memory manager,
15485	 * all others come here.
15486	 */
15487	
15488	  register struct proc *rp;
15489	  phys_bytes src, dst;
15490	  int i;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -