int cell_main(int argc, char **argv) { struct disk_message *msg; int status; unsigned long disk_size, sector; msg = malloc(DISK_MESSAGE_SIZE); // Query the disk to get its size so we know how to do our // reads. msg->type = DISK_MSG_GET_SIZE; if ((status = channel_send(to_disk1, msg))) { printf("[cell1] Could not send disk message: %d\n", status); return 1; } else printf("[cell1] sent size request\n"); if ((status = channel_recv(from_disk1, msg))) { printf("[cell1] Could not get disk reply: %d\n", status); return 1; } if (msg->type != DISK_MSG_GET_SIZE) { printf("[cell1] Something bad happened; got non-size reply (type %d)\n", msg->type); return 1; } disk_size = msg->body.device_size; sector = 0; // Loop forever, reading sectors from disk one at a time and // sending them to the neighboring cell. When we reach the end of // the disk, start over. while (1) { msg->type = DISK_MSG_IO_REQUEST; msg->body.io_request.type = DISK_IO_REQUEST_READ; msg->body.io_request.num_sectors = 1; msg->body.io_request.start_sector = sector; if ((status = channel_send(to_disk1, msg))) { printf("[cell1] Could not send disk read for sector %ld: %d\n", sector, status); return 1; } if ((status = channel_recv(from_disk1, msg))) { printf("[cell1] Could not receive disk read result: %d\n", status); return 1; } if ((status = channel_send(middle, msg))) { printf("[cell1] Could not send disk data to cell 2: %d\n", status); return 1; } sector = (sector + 1) % (disk_size / SECTOR_SIZE); } return 0; }
int disk_client_poll(struct disk_client *c) { struct disk_msg msg; struct disk_client_slot *slot; int slot_num; while (channel_can_recv(c->resp_chan)) { channel_recv(c->resp_chan, &msg); slot_num = msg.handle; slot = get_slot(c, slot_num); if (msg.status != 0) { slot->err(&msg); } else { if (msg.type == DISK_SIZE) { slot->cb.size(msg.device_size); } else if (msg.type == DISK_READ) { slot->cb.read(msg.num_sectors, msg.start_sector, msg.payload); } else { slot->cb.write(msg.num_sectors, msg.start_sector); } } free_slot(c, slot_num); } return 0; }
int cell_main(int argc, char ** argv) { unsigned char msg; #if defined(SEL4_DEBUG_KERNEL) SET_MUSLC_SYSCALL_TABLE; platsupport_serial_setup_bootinfo_failsafe(); #endif // Read characater data from the input memory region, filter it (remove // vowels), and then emit it to the output memory region. // // This implementation uses a sequence number paired with each character to // facilitate data loss detection when scheduling interferes with memory // read/write operations in adjacent cells. while (1) { channel_recv(chan1, &msg); if (msg > 0) { if (msg == 'a' || msg == 'e' || msg == 'i' || msg == 'o' || msg == 'u') msg = '*'; channel_send(chan2, &msg); } } return 0; }
/*===========================================================================* * rpc_query * *===========================================================================*/ int rpc_query(void) { /* Send a HGFS RPC query over the backdoor channel. Return OK upon success, or * a negative error code otherwise; EAGAIN is returned if shared folders are * disabled. In general, we make the assumption that the sender (= VMware) * speaks the protocol correctly. Hence, the callers of this function do not * check for lengths. */ int r, len, id, err; len = RPC_LEN; /* A more robust version of this call could reopen the channel and * retry the request upon low-level failure. */ r = channel_send(&rpc_chan, rpc_buf, len); if (r < 0) return r; r = channel_recv(&rpc_chan, rpc_buf, sizeof(rpc_buf)); if (r < 0) return r; if (r < 2 || (len > 2 && r < 10)) return EIO; RPC_RESET; if (RPC_NEXT8 != '1') return EAGAIN; if (RPC_NEXT8 != ' ') return EAGAIN; if (len <= 2) return OK; id = RPC_NEXT32; err = RPC_NEXT32; return error_convert(err); }
void mwChannel_recv(struct mwChannel *chan, struct mwMsgChannelSend *msg) { if(chan->state == mwChannel_OPEN) { channel_recv(chan, msg); } else { queue_incoming(chan, msg); } }
void * receive(void * ptr) { int r; msg_t tmp; while(1) { r = channel_recv(chan_r,&tmp); if(r == 0) break; } pthread_exit(NULL); }
void * forward(void * ptr) { int err, s, i = 0; msg_t tmp; msg_t vtmp[NB_MSG]; while((err = channel_recv(chan_s,&tmp)) != 0) { if(err == -1) { perror("FWD - error channel_recv"); channel_close(chan_s); channel_close(chan_r); break; } if(i < NB_MSG) { memcpy(&vtmp[i],&tmp,sizeof(msg_t)); i++; continue; } else { do{ s = channel_vsend(chan_r,vtmp,NB_MSG); if(s > -1) n += s; }while(s == 0); i = 0; } if(n >= MAX_FWD_MSG) { channel_close(chan_s); channel_close(chan_r); break; } } pthread_exit(NULL); }
void * receive(void * ptr) { int err; msg_t tmp; channel_set chset; chset.chan = chan_r; chset.events = CHANNEL_EVENT_READ|CHANNEL_EVENT_CLOSE; while(1) { chset.revents = CHANNEL_EVENT_NOEVT; err = channel_select(&chset,1,-1); if(err == -1) { perror("recv - channel_select()"); channel_close(chan_s); channel_close(chan_r); break; } else if(err == 0) continue; if(CHAN_READ_EVT(chset.revents)) { err = channel_recv(chan_r,&tmp); if(err <= 0) { break; } /*else if(err > 0) printf("%s",tmp.content);*/ } else if(CHAN_CLOSE_EVT(chset.revents)) { channel_close(chan_r); break; } } pthread_exit(NULL); }
static void flush_channel(struct mwChannel *chan) { GSList *l; for(l = chan->incoming_queue; l; l = l->next) { struct mwMsgChannelSend *msg = (struct mwMsgChannelSend *) l->data; l->data = NULL; channel_recv(chan, msg); mwMessage_free(MW_MESSAGE(msg)); } g_slist_free(chan->incoming_queue); chan->incoming_queue = NULL; for(l = chan->outgoing_queue; l; l = l->next) { struct mwMessage *msg = (struct mwMessage *) l->data; l->data = NULL; mwSession_send(chan->session, msg); mwMessage_free(msg); } g_slist_free(chan->outgoing_queue); chan->outgoing_queue = NULL; }
void * forward(void * ptr) { int err; msg_t tmp; channel_set s_chset, r_chset; s_chset.chan = chan_s; s_chset.events = CHANNEL_EVENT_READ|CHANNEL_EVENT_CLOSE; r_chset.chan = chan_r; r_chset.events = CHANNEL_EVENT_WRITE|CHANNEL_EVENT_CLOSE; while(n < MAX_FWD_MSG) { s_chset.revents = CHANNEL_EVENT_NOEVT; r_chset.revents = CHANNEL_EVENT_NOEVT; err = channel_select(&s_chset,1,CHANNEL_TIME_WAIT); if(err == -1) { perror("FWD - 1 channel_select()"); channel_close(chan_s); channel_close(chan_r); break; } else if(err == 0) continue; if(CHAN_READ_EVT(s_chset.revents)) { err = channel_recv(chan_s,&tmp); if(err == -1) { perror("FWD - error channel_recv"); channel_close(chan_s); channel_close(chan_r); break; } } else if(CHAN_CLOSE_EVT(s_chset.revents)) { channel_close(chan_r); break; } err = channel_select(&r_chset,1,CHANNEL_TIME_WAIT); if(err == -1) { perror("FWD - 1 channel_select()"); channel_close(chan_s); channel_close(chan_r); break; } else if(err == 0) continue; if(CHAN_WRITE_EVT(r_chset.revents)) { err = channel_send(chan_r,&tmp); if(err == -1) { perror("FWD - error channel_send"); channel_close(chan_s); channel_close(chan_r); break; } n += 1; if(n >= MAX_FWD_MSG) { //printf("n : %d OK \n",n); channel_close(chan_s); channel_close(chan_r); } } else if(CHAN_CLOSE_EVT(r_chset.revents)) { channel_close(chan_s); break; } } pthread_exit(NULL); }