/*---------------------------------------------------------------------*/ static PT_THREAD(recv_tcpthread(struct pt *pt)) { PT_BEGIN(pt); /* Read the header. */ PT_WAIT_UNTIL(pt, uip_newdata() && uip_datalen() > 0); if(uip_datalen() < sizeof(struct codeprop_tcphdr)) { PRINTF(("codeprop: header not found in first tcp segment\n")); uip_abort(); goto thread_done; } s.len = uip_htons(((struct codeprop_tcphdr *)uip_appdata)->len); s.addr = 0; uip_appdata += sizeof(struct codeprop_tcphdr); uip_len -= sizeof(struct codeprop_tcphdr); xmem_erase(XMEM_ERASE_UNIT_SIZE, EEPROMFS_ADDR_CODEPROP); /* Read the rest of the data. */ do { if(uip_len > 0) { xmem_pwrite(uip_appdata, uip_len, EEPROMFS_ADDR_CODEPROP + s.addr); s.addr += uip_len; } if(s.addr < s.len) { PT_YIELD_UNTIL(pt, uip_newdata()); } } while(s.addr < s.len); /* Kill old program. */ elfloader_unload(); /* Link, load, and start new program. */ int s; static char msg[30 + 10]; s = elfloader_load(EEPROMFS_ADDR_CODEPROP); if (s == ELFLOADER_OK) sprintf(msg, "ok\n"); else sprintf(msg, "err %d %s\n", s, elfloader_unknown); /* Return "ok" message. */ do { s = strlen(msg); uip_send(msg, s); PT_WAIT_UNTIL(pt, uip_acked() || uip_rexmit() || uip_closed()); } while(uip_rexmit()); /* Close the connection. */ uip_close(); thread_done:; PT_END(pt); }
void elfexec_destroy(struct elfexec *holder) { if (holder->priv_cookie) { exec_stop(holder->priv_cookie); exec_destroy(holder->priv_cookie); } if (holder->pd != NULL) { elfloader_unload(holder->pd); } object_free_token(holder->cspace); // TODO: recursively free this first? object_free_token(holder->page_directory); holder->page_directory = holder->cspace = NULL; holder->priv_cookie = 0; holder->pd = NULL; }
/*---------------------------------------------------------------------*/ PROCESS_THREAD(codeprop_process, ev, data) { PROCESS_BEGIN(); s.id = 0/*random_rand()*/; send_time = CLOCK_SECOND/4; PT_INIT(&s.udpthread_pt); PT_INIT(&s.recv_udpthread_pt); tcp_listen(HTONS(CODEPROP_DATA_PORT)); udp_conn = udp_broadcast_new(HTONS(CODEPROP_DATA_PORT), NULL); codeprop_event_quit = process_alloc_event(); s.state = STATE_NONE; s.received = 0; s.addr = 0; s.len = 0; while(1) { PROCESS_YIELD(); if(ev == EVENT_START_PROGRAM) { /* First kill old program. */ elfloader_unload(); elfloader_load(EEPROMFS_ADDR_CODEPROP); } else if(ev == tcpip_event) { uipcall(data); } else if(ev == PROCESS_EVENT_TIMER) { tcpip_poll_udp(udp_conn); } } PROCESS_END(); }