/** * @brief Exec new memory map for a process * @param stack_topp[out] top of the stack * @param load_textp[out] load text segment (otherwise present) * @param allow_setuidp[out] setuid execution is allowed (update uid and gid fields) * @param proc_e[in] process number (endpoint) * @param ex[in] pointer exec structure */ static int aout_exec_newmem(vir_bytes *stack_topp, int *load_textp, int *allow_setuidp, int proc_e, struct exec_newmem *ex) { int err; kipc_msg_t m; m.m_type = KCNR_EXEC_NEWMEM; m.EXC_NM_PROC = proc_e; m.EXC_NM_PTR = (s32)ex; err = kipc_module_call(KIPC_SENDREC, 0, PM_PROC_NR, &m); if (err) return err; #if CONFIG_DEBUG_VFS_AOUT printk("exec_newmem: err = %d, m_type = %d\n", err, m.m_type); #endif *stack_topp= m.m_data1; *load_textp= !!(m.m_data2 & EXC_NM_RF_LOAD_TEXT); *allow_setuidp= !!(m.m_data2 & EXC_NM_RF_ALLOW_SETUID); #if CONFIG_DEBUG_VFS_AOUT printk("exec_newmem: stack_top = 0x%x\n", *stack_topp); printk("exec_newmem: load_text = %d\n", *load_textp); #endif return m.m_type; }
void main(void) { mq_t *mq; int r; int source, m_type, timerand, fd; u32_t tasknr; struct fssignon device; u8_t randbits[32]; struct timeval tv; #if DEBUG printk("Starting inet...\n"); printk("%s\n", version); #endif #if HZ_DYNAMIC system_hz = sys_hz(); #endif /* Read configuration. */ nw_conf(); /* Get a random number */ timerand= 1; fd= open(RANDOM_DEV_NAME, O_RDONLY | O_NONBLOCK); if (fd != -1) { r= read(fd, randbits, sizeof(randbits)); if (r == sizeof(randbits)) timerand= 0; else { printk("inet: unable to read random data from %s: %s\n", RANDOM_DEV_NAME, r == -1 ? strerror(errno) : r == 0 ? "EOF" : "not enough data"); } close(fd); } else { printk("inet: unable to open random device %s: %s\n", RANDOM_DEV_NAME, strerror(errno)); } if (timerand) { printk("inet: using current time for random-number seed\n"); r= gettimeofday(&tv, NULL); if (r == -1) { printk("sysutime failed: %s\n", strerror(errno)); exit(1); } memcpy(randbits, &tv, sizeof(tv)); } init_rand256(randbits); /* Our new identity as a server. */ r= ds_retrieve_u32("inet", &tasknr); if (r != 0) ip_panic(("inet: ds_retrieve_u32 failed for 'inet': %d", r)); this_proc= tasknr; /* Register the device group. */ device.dev= ip_dev; device.style= STYLE_CLONE; if (svrctl(FSSIGNON, (void *) &device) == -1) { printk("inet: error %d on registering ethernet devices\n", errno); pause(); } #ifdef BUF_CONSISTENCY_CHECK inet_buf_debug= (getenv("inetbufdebug") && (strcmp(getenv("inetbufdebug"), "on") == 0)); inet_buf_debug= 100; if (inet_buf_debug) { ip_warning(( "buffer consistency check enabled" )); } #endif if (getenv("killerinet")) { ip_warning(( "killer inet active" )); killer_inet= 1; } nw_init(); while (TRUE) { #ifdef BUF_CONSISTENCY_CHECK if (inet_buf_debug) { static int buf_debug_count= 0; if (++buf_debug_count >= inet_buf_debug) { buf_debug_count= 0; if (!bf_consistency_check()) break; } } #endif if (ev_head) { ev_process(); continue; } if (clck_call_expire) { clck_expire_timers(); continue; } mq= mq_get(); if (!mq) ip_panic(("out of messages")); r = kipc_module_call(KIPC_RECEIVE, 0, ENDPT_ANY, &mq->mq_mess); if (r<0) { ip_panic(("unable to receive: %d", r)); } reset_time(); source= mq->mq_mess.m_source; m_type= mq->mq_mess.m_type; if (source == VFS_PROC_NR) { sr_rec(mq); } else if (is_notify(m_type)) { if (_ENDPOINT_P(source) == CLOCK) { clck_tick(&mq->mq_mess); mq_free(mq); } else if (_ENDPOINT_P(source) == PM_PROC_NR) { /* signaled */ /* probably SIGTERM */ mq_free(mq); } else { /* A driver is (re)started. */ eth_check_drivers(&mq->mq_mess); mq_free(mq); } } else if (m_type == DL_CONF_REPLY || m_type == DL_TASK_REPLY || m_type == DL_NAME_REPLY || m_type == DL_STAT_REPLY) { eth_rec(&mq->mq_mess); mq_free(mq); } else { printk("inet: got bad message type 0x%x from %d\n", mq->mq_mess.m_type, mq->mq_mess.m_source); mq_free(mq); } } ip_panic(("task is not allowed to terminate")); }
/*===========================================================================* * main * *===========================================================================*/ int main(void) { kipc_msg_t msg; int result, who_e; #if SANITYCHECKS incheck = nocheck = 0; FIXME("VM SANITYCHECKS are on"); #endif vm_paged = 1; env_parse("vm_paged", "d", 0, &vm_paged, 0, 1); #if SANITYCHECKS env_parse("vm_sanitychecklevel", "d", 0, &vm_sanitychecklevel, 0, SCL_MAX); #endif vm_init(); /* This is VM's main loop. */ while (TRUE) { int r, c; SANITYCHECK(SCL_TOP); if(missing_spares > 0) { pt_cycle(); /* pagetable code wants to be called */ } SANITYCHECK(SCL_DETAIL); if ((r=kipc_module_call(KIPC_RECEIVE, 0, ENDPT_ANY, &msg)) != 0) vm_panic("receive() error", r); SANITYCHECK(SCL_DETAIL); if(msg.m_type & NOTIFY_MESSAGE) { switch(msg.m_source) { case SYSTEM: /* Kernel wants to have memory ranges * verified, and/or pagefaults handled. */ do_memory(); break; case HARDWARE: do_pagefaults(); break; case PM_PROC_NR: /* PM sends a notify() on shutdown, which * is OK and we ignore. */ break; default: /* No-one else should send us notifies. */ printk("VM: ignoring notify() from %d\n", msg.m_source); break; } continue; } who_e = msg.m_source; c = CALLNUMBER(msg.m_type); result = -ENOSYS; /* Out of range or restricted calls return this. */ if(c < 0 || !vm_calls[c].vmc_func) { printk("VM: out of range or missing callnr %d from %d\n", msg.m_type, who_e); } else if (vm_acl_ok(who_e, c) != 0) { printk("VM: unauthorized %s by %d\n", vm_calls[c].vmc_name, who_e); } else { SANITYCHECK(SCL_FUNCTIONS); result = vm_calls[c].vmc_func(&msg); SANITYCHECK(SCL_FUNCTIONS); } /* Send reply message, unless the return code is SUSPEND, * which is a pseudo-result suppressing the reply message. */ if(result != SUSPEND) { SANITYCHECK(SCL_DETAIL); msg.m_type = result; if((r=kipc_module_call(KIPC_SEND, 0, who_e, &msg)) != 0) { printk("VM: couldn't send %d to %d (err %d)\n", msg.m_type, who_e, r); vm_panic("send() error", NO_NUM); } SANITYCHECK(SCL_DETAIL); } SANITYCHECK(SCL_DETAIL); } return 0; }