/* * This function may be called to close socket . * Paramters: a pointer to socket structure * Returns: None * */ void app_glue_close_socket(void *sk) { struct socket *sock = (struct socket *)sk; if(sock->read_queue_present) { TAILQ_REMOVE(&read_ready_socket_list_head,sock,read_queue_entry); sock->read_queue_present = 0; } if(sock->write_queue_present) { TAILQ_REMOVE(&write_ready_socket_list_head,sock,write_queue_entry); sock->write_queue_present = 0; } if(sock->accept_queue_present) { struct socket *newsock = NULL; while(kernel_accept(sock, &newsock, 0) == 0) { kernel_close(newsock); } TAILQ_REMOVE(&accept_ready_socket_list_head,sock,accept_queue_entry); sock->accept_queue_present = 0; } if(sock->closed_queue_present) { TAILQ_REMOVE(&closed_socket_list_head,sock,closed_queue_entry); sock->closed_queue_present = 0; } if(sock->sk) sock->sk->sk_user_data = NULL; kernel_close(sock); }
/* * This function walks on closable, acceptable and readable lists and calls. * the application's (user's) function. Called from app_glue_periodic * Paramters: None * Returns: None * */ static inline void process_rx_ready_sockets() { struct socket *sock; uint64_t idx,limit; while(!TAILQ_EMPTY(&closed_socket_list_head)) { sock = TAILQ_FIRST(&closed_socket_list_head); user_on_socket_fatal(sock); sock->closed_queue_present = 0; TAILQ_REMOVE(&closed_socket_list_head,sock,closed_queue_entry); sock_put(sock->sk); kernel_close(sock); } while(!TAILQ_EMPTY(&accept_ready_socket_list_head)) { sock = TAILQ_FIRST(&accept_ready_socket_list_head); user_on_accept(sock); sock->accept_queue_present = 0; TAILQ_REMOVE(&accept_ready_socket_list_head,sock,accept_queue_entry); sock_put(sock->sk); } idx = 0; limit = read_sockets_queue_len; while((idx < limit)&&(!TAILQ_EMPTY(&read_ready_socket_list_head))) { sock = TAILQ_FIRST(&read_ready_socket_list_head); sock->read_queue_present = 0; TAILQ_REMOVE(&read_ready_socket_list_head,sock,read_queue_entry); user_data_available_cbk(sock); sock_put(sock->sk); read_sockets_queue_len--; idx++; } }
void kernel_runloop() { volatile TaskDescriptor* td; int** sp_pointer; idleTimeStart = 0; totalIdleTime = 0; lastReportTime = 0; latestIdle = 999; while (LIKELY((td = scheduler_get()) != (TaskDescriptor *)NULL && notQuit)) { if (idleTid == td->id) idleTimeStart = GET_TIMER4(); sp_pointer = (int**)&(td->sp); scheduler_set_running(td); int is_interrupt = asm_switch_to_usermode(sp_pointer); unsigned int current = GET_TIMER4(); if (idleTid == td->id) { totalIdleTime += current - idleTimeStart; } if ((current - lastReportTime) > 200000) { latestIdle = totalIdleTime*10000 / (current - lastReportTime); lastReportTime = current; totalIdleTime = 0; } if (is_interrupt) { scheduler_move2ready(); kernel_handle_interrupt(); } else { int *arg0 = *sp_pointer; int request = *arg0 & MASK_LOWER; ASSERT(request >= 0 && request < LAST_SYSCALL, "System call not in range."); (*syscall_handler[request])(*sp_pointer, (*sp_pointer)[1], (*sp_pointer)[2], (*sp_pointer)[3]); if (request <= SYSCALL_REPLY) { scheduler_move2ready(); } } } // End kernel loop; kernel_close(); }
/* Init task - the job of this task is to initialise all * installed drivers, mount the root filesystem and * bootstrap the system */ int init_task(void *priv) { uint32_t ret; struct file *file; char buf[20]; int rval; /* Initialise kernel subsystems */ blk_init(); vfs_init(); pci_init(); do_initcalls(); /* Mount the root filesystem etc.. */ if ( vfs_mount_root("ext2", "floppy0") ) { panic("Unable to mount root filesystem\n"); } file = kernel_open("/test.txt", 0); if ( NULL == file ) { printk("init_task: open failed, returned %u\n", -1); } else { rval = kernel_read(file, buf, 16); if ( rval < 0 ) printk("read error: %d\n", rval); else if ( rval == 0 ) printk("read returned EOF\n"); else { buf[rval] = '\0'; printk("read: %s.\n", buf); } rval = kernel_write(file, buf, 16); kernel_close(file); } ret = _kernel_exec("/bin/bash"); ret = _kernel_exec("/sbin/init"); ret = _kernel_exec("/bin/cat"); printk("exec: /sbin/init: %i\n", (int)ret); return ret; }
int main(int argc, char *argv[]) { int c; const char *config_file = DEFAULT_CONFIG; const char *adm_socket = DEFAULT_ADM_SOCKET; int verbose = 0; static struct ev_loop *loop; static struct ev_signal signal_watcher; pid_t pid; while ((c = getopt(argc, argv, "a:c:dhp:Vv")) != -1) { switch (c) { case 'a': adm_socket = optarg; break; case 'c': config_file = optarg; break; case 'd': pingu_daemonize++; break; case 'h': return usage(basename(argv[0])); case 'p': pid_file = optarg; break; case 'V': print_version(basename(argv[0])); return 0; case 'v': verbose++; break; } } argc -= optind; argv += optind; log_init("pingu", verbose); pid = get_running_pid(); if (pid) errx(1, "appears to be running already (pid %i)", pid); loop = ev_default_loop(0); if (pingu_conf_parse(config_file) < 0) return 1; if (pingu_iface_init(loop) < 0) return 1; if (pingu_host_init(loop) < 0) return 1; if (pingu_adm_init(loop, adm_socket) < 0) return 1; if (pingu_daemonize) { if (daemonize() == -1) return 1; } kernel_init(loop); ev_signal_init(&signal_watcher, sigint_cb, SIGINT); ev_signal_start(loop, &signal_watcher); ev_run(loop, 0); log_info("Shutting down"); pingu_iface_cleanup(loop); pingu_host_cleanup(); kernel_close(); ev_loop_destroy(loop); return 0; }