ssize_t DevPty::handle_read(struct anvil_read_msg *msg, anvil_msginfo_t *msg_info, size_t nbyte, off_t offset) { //anvil_syslog(0, "Ptm::handle_read() n=%d a=%d\n", nbyte, get_pts()->chars_avail()); size_t avail = get_pts()->chars_avail(); if (avail) { size_t amount_to_read = std::min(nbyte, avail); msg_poke(msg_info->pid, msg_info->tid, get_pts()->get_chars_ptr(), amount_to_read, 0); get_pts()->erase_chars(amount_to_read); msg_reply(msg_info->pid, msg_info->tid, amount_to_read, NULL, 0); //anvil_syslog(0, "Ptm::handle_read() got %d chars\n", amount_to_read); msg_send(m_master_pid, ANVIL_POLL_READY, (void *)(uintptr_t)12345, 4); } else { // Reply with no chars msg_reply(msg_info->pid, msg_info->tid, 0, NULL, 0); // Queue the process until there are chars // m_output_waiter = *msg_info; // m_output_waiter_size = msg->nbyte; // anvil_syslog(0, "Ptm::handle_read() got no chars\n"); } return 0; }
static int do_open(void *msg, anvil_msginfo_t *msg_info) { struct anvil_open_msg *openmsg; char name[1024]; file_struct *pfile; int found; fcb_t *fcb; #if 0 openmsg = (struct anvil_open_msg *)msg; if (openmsg->pathlen > 1023) { msg_reply(msg_info->pid, msg_info->tid, ENAMETOOLONG, NULL, 0); return -1; } msg_peek(msg_info->pid, msg_info->tid, name, openmsg->pathlen, sizeof(struct anvil_open_msg)); name[openmsg->pathlen] = 0; anvil_syslog(0, "INITRD: do_open file <%s>\n", name); pfile = (file_struct *)dlist_peek_head(&filelist); found = 0; while (pfile) { if (!strcmp(pfile->filename, name)) { anvil_syslog(0, "*** INITRD: Found file %s\n", pfile->filename); found = 1; break; /* Break so that pfile is valid */ } pfile = (file_struct *)dlist_peek_next(&filelist, (dlist_item_t *)pfile); } if (!found) { anvil_syslog(0, "INITRD: do_open couldn't find %s\n", name); msg_reply(msg_info->pid, msg_info->tid, ENOENT, NULL, 0); return -1; } fcb = (fcb_t *)malloc(sizeof(fcb_t)); fcb->fs = pfile; fcb->pos = 0; fcb->data = pfile->addr; //anvil_syslog(0, "INITRD: do_open file <%s> fcb=%016lx\n", name, fcb); msg_port_allow(msg_info->pid, msg_info->tid, (void *)fcb, NULL); msg_reply(msg_info->pid, msg_info->tid, 0, NULL, 0); #endif return 0; }
static void *usbdev_cdc_acm(void *arg) { msg_t msg, reply, msg_q[8]; msg_init_queue(msg_q, 8); usbdev_t *dev = arg; while (true) { msg_receive(&msg); reply.type = msg.type; usb_ep_t ep = msg.content.value; switch (msg.type) { case USBDEV_EVENT_OUT: usbdev_acm_evt_out(dev); break; case USBDEV_EVENT_IN: if (ep == ENDPOINT_ADDR_IN(USBDEV_ACM_EP_BULKIN)) { usbdev_acm_evt_in(dev); } break; case USBDEV_EVENT_SOF: if (ep_configured(dev, ENDPOINT_ADDR_IN(USBDEV_ACM_EP_BULKIN))) { usbdev_acm_sof_event(dev); } break; case USBDEV_EVENT_REQUEST_CLASS_SETUP: reply.content.value = usbdev_setup_request_class(dev); msg_reply(&msg, &reply); break; case USBDEV_EVENT_REQUEST_CLASS_OUT: reply.content.value = usbdev_request_class_out(dev); msg_reply(&msg, &reply); break; case USBDEV_EVENT_RESET: usbdev_acm_reset(); break; default: break; } } return NULL; }
/* * namer_wstat() * Allow writing of supported stat messages */ void namer_wstat(struct msg *m, struct file *f) { char *field, *val; struct node *n = f->f_node; /* * See if common handling code can do it */ if (do_wstat(m, &n->n_prot, f->f_mode, &field, &val) == 0) return; /* * Set/clear "node pending deletion" flag */ if (!strcmp(field, "deleted")) { n->n_deleted = (val && val[0] && (val[0] != '0')); m->m_arg = m->m_arg1 = m->m_nseg = 0; msg_reply(m->m_sender, m); return; } /* * Not a field we support... */ msg_err(m->m_sender, EINVAL); }
static void *_event_loop(void *arg) { msg_t reply, msg_queue[GNRC_NETTEST_MSG_QUEUE_SIZE]; (void)arg; msg_init_queue(msg_queue, GNRC_NETTEST_MSG_QUEUE_SIZE); reply.type = GNRC_NETAPI_MSG_TYPE_ACK; while (1) { msg_t msg; gnrc_netapi_opt_t *opt; msg_receive(&msg); switch (msg.type) { case GNRC_NETAPI_MSG_TYPE_GET: opt = (gnrc_netapi_opt_t *)msg.content.ptr; reply.content.value = _get_set_opt(_opt_cbs[opt->opt].get, opt->context, opt->data, opt->data_len); break; case GNRC_NETAPI_MSG_TYPE_SET: opt = (gnrc_netapi_opt_t *)msg.content.ptr; reply.content.value = _get_set_opt(_opt_cbs[opt->opt].set, opt->context, opt->data, opt->data_len); break; } msg_reply(&msg, &reply); } return NULL; }
/* * nvram_wstat() * Allow writing of supported stat messages */ void nvram_wstat(struct msg *m, struct file *f) { char *field, *val; int sz = 0; /* * See if common handling code can do it */ if (do_wstat(m, &nvram_prot, f->f_flags, &field, &val) == 0) { return; } /* * Process each kind of field we can write */ if (!strcmp(field, "gen")) { /* * Set access-generation field */ if (val) { nvram_accgen = atoi(val); } else { nvram_accgen += 1; } f->f_gen = nvram_accgen; } else if (!strcmp(field, "size")) { /* * Are we addressing the "all" node? If not reject the request */ if (f->f_node != ALL_INO) { msg_err(m->m_sender, EINVAL); return; } /* * Set usable NVRAM size */ if (val) { sz = atoi(val); } if ((sz < MIN_NVRAM_BYTES) || (sz > MAX_NVRAM_BYTES)) { msg_err(m->m_sender, EINVAL); return; } nvram_bytes = sz; } else { /* * Not a field we support... */ msg_err(m->m_sender, EINVAL); return; } /* * Return success */ m->m_buflen = m->m_nseg = m->m_arg = m->m_arg1 = 0; msg_reply(m->m_sender, m); }
void *udp_packet_handler(void *arg) { (void) arg; msg_t m_recv_ip, m_send_ip, m_recv_udp, m_send_udp; socket_internal_t *udp_socket = NULL; msg_init_queue(udp_msg_queue, UDP_PKT_RECV_BUF_SIZE); while (1) { msg_receive(&m_recv_ip); ipv6_hdr_t *ipv6_header = ((ipv6_hdr_t *)m_recv_ip.content.ptr); udp_hdr_t *udp_header = ((udp_hdr_t *)(m_recv_ip.content.ptr + IPV6_HDR_LEN)); uint16_t chksum = ipv6_csum(ipv6_header, (uint8_t*) udp_header, NTOHS(udp_header->length), IPPROTO_UDP); if (chksum == 0xffff) { udp_socket = get_udp_socket(udp_header); if (udp_socket != NULL) { m_send_udp.content.ptr = (char *)ipv6_header; msg_send_receive(&m_send_udp, &m_recv_udp, udp_socket->recv_pid); } else { printf("Dropped UDP Message because no thread ID was found for delivery!\n"); } } else { printf("Wrong checksum (%x)!\n", chksum); } msg_reply(&m_recv_ip, &m_send_ip); } }
/* * dup_client() * Duplicate current file access onto new session */ static void dup_client(struct msg *m, struct file *fold) { struct file *f; /* * Get data structure */ if ((f = malloc(sizeof(struct file))) == 0) { msg_err(m->m_sender, strerror()); return; } /* * Fill in fields. Simply duplicate old file. */ *f = *fold; /* * Hash under the sender's handle */ if (hash_insert(filehash, m->m_arg, f)) { free(f); msg_err(m->m_sender, ENOMEM); return; } /* * Return acceptance */ m->m_arg = m->m_arg1 = m->m_buflen = m->m_nseg = 0; msg_reply(m->m_sender, m); }
void kernel_footprint(void) { init(); // generate code for process struct Process *p = proc_new(proc1_main, 0, sizeof(proc1_stack), proc1_stack); proc_setPri(p, 5); proc_yield(); // generate code for msg Msg msg; msg_initPort(&in_port, event_createSignal(p, SIG_USER1)); msg_put(&in_port, &msg); msg_peek(&in_port); Msg *msg_re = msg_get(&in_port); msg_reply(msg_re); // generate code for signals sig_send(p, SIG_USER0); // generate code for msg Semaphore sem; sem_init(&sem); sem_obtain(&sem); sem_release(&sem); sig_wait(SIG_USER0); }
int32_t destiny_socket_recvfrom(int s, void *buf, uint32_t len, int flags, sockaddr6_t *from, uint32_t *fromlen) { if (isUDPSocket(s)) { msg_t m_recv, m_send; ipv6_hdr_t *ipv6_header; udp_hdr_t *udp_header; uint8_t *payload; get_socket(s)->recv_pid = thread_getpid(); msg_receive(&m_recv); ipv6_header = ((ipv6_hdr_t *)m_recv.content.ptr); udp_header = ((udp_hdr_t *)(m_recv.content.ptr + IPV6_HDR_LEN)); payload = (uint8_t *)(m_recv.content.ptr + IPV6_HDR_LEN + UDP_HDR_LEN); memset(buf, 0, len); memcpy(buf, payload, udp_header->length - UDP_HDR_LEN); memcpy(&from->sin6_addr, &ipv6_header->srcaddr, 16); from->sin6_family = AF_INET6; from->sin6_flowinfo = 0; from->sin6_port = udp_header->src_port; *fromlen = sizeof(sockaddr6_t); msg_reply(&m_recv, &m_send); return udp_header->length - UDP_HDR_LEN; } else if (is_tcp_socket(s)) { return destiny_socket_recv(s, buf, len, flags); } else { printf("Socket Type not supported!\n"); return -1; } }
void udp_packet_handler(void) { msg_t m_recv_ip, m_send_ip, m_recv_udp, m_send_udp; ipv6_hdr_t *ipv6_header; udp_hdr_t *udp_header; uint8_t *payload; socket_internal_t *udp_socket = NULL; uint16_t chksum; while (1) { msg_receive(&m_recv_ip); ipv6_header = ((ipv6_hdr_t *)m_recv_ip.content.ptr); udp_header = ((udp_hdr_t *)(m_recv_ip.content.ptr + IPV6_HDR_LEN)); payload = (uint8_t *)(m_recv_ip.content.ptr + IPV6_HDR_LEN + UDP_HDR_LEN); chksum = udp_csum(ipv6_header, udp_header); if (chksum == 0xffff) { udp_socket = get_udp_socket(ipv6_header, udp_header); if (udp_socket != NULL) { m_send_udp.content.ptr = (char *)ipv6_header; msg_send_receive(&m_send_udp, &m_recv_udp, udp_socket->recv_pid); } else { printf("Dropped UDP Message because no thread ID was found for delivery!\n"); } } else { printf("Wrong checksum (%x)!\n", chksum); } msg_reply(&m_recv_ip, &m_send_ip); } }
ssize_t DevPty::handle_write(struct anvil_write_msg *msg, anvil_msginfo_t *msg_info, size_t nbyte, off_t offset) { //anvil_syslog(0, "Ptm::handle_write()\n"); // Put the bytes in the ring buffer uint8_t buf[WRITE_BUF_SIZE+1]; size_t still_to_write = nbyte; size_t total_written = 0; while (still_to_write) { size_t peek_amount = std::min(still_to_write, (size_t)WRITE_BUF_SIZE); if (peek_amount <= 0) { break; } msg_peek(msg_info->pid, msg_info->tid, buf, peek_amount, total_written + sizeof(struct anvil_write_msg)); still_to_write -= peek_amount; total_written += peek_amount; for (int i=0; i<peek_amount; ++i) { //anvil_syslog(0, "Ptm %c (%02x)\n", isprint(buf[i])?buf[i]:'-', buf[i]); get_pts()->push_char(buf[i]); } } msg_reply(msg_info->pid, msg_info->tid, total_written, NULL, 0); return total_written; }
int32_t udp_recvfrom(int s, void *buf, uint32_t len, int flags, sockaddr6_t *from, uint32_t *fromlen) { (void) flags; msg_t m_recv, m_send; ipv6_hdr_t *ipv6_header; udp_hdr_t *udp_header; uint8_t *payload; socket_base_get_socket(s)->recv_pid = thread_getpid(); msg_receive(&m_recv); ipv6_header = ((ipv6_hdr_t *)m_recv.content.ptr); udp_header = ((udp_hdr_t *)(m_recv.content.ptr + IPV6_HDR_LEN)); payload = (uint8_t *)(m_recv.content.ptr + IPV6_HDR_LEN + UDP_HDR_LEN); memset(buf, 0, len); /* cppcheck: the memset sets parts of the buffer to 0 even though it will * be overwritten by the next memcpy. However without the memset the buffer * could contain stale data (if the copied data is less then the buffer * length) and setting just the left over part of the buffer to 0 would * introduce overhead (calculation how much needs to be zeroed). */ /* cppcheck-suppress redundantCopy */ memcpy(buf, payload, NTOHS(udp_header->length) - UDP_HDR_LEN); memcpy(&from->sin6_addr, &ipv6_header->srcaddr, 16); from->sin6_family = AF_INET6; from->sin6_flowinfo = 0; from->sin6_port = udp_header->src_port; *fromlen = sizeof(sockaddr6_t); msg_reply(&m_recv, &m_send); return NTOHS(udp_header->length) - UDP_HDR_LEN; }
static void *_slip(void *args) { gnrc_slip_dev_t *dev = _SLIP_DEV(args); msg_t msg, reply, msg_q[_SLIP_MSG_QUEUE_SIZE]; msg_init_queue(msg_q, _SLIP_MSG_QUEUE_SIZE); dev->slip_pid = thread_getpid(); gnrc_netif_add(dev->slip_pid); DEBUG("slip: SLIP runs on UART_%d\n", dev->uart); while (1) { DEBUG("slip: waiting for incoming messages\n"); msg_receive(&msg); switch (msg.type) { case _SLIP_MSG_TYPE: DEBUG("slip: incoming message of size %" PRIu32 " from UART_%d in buffer\n", msg.content.value, dev->uart); _slip_receive(dev, (size_t)msg.content.value); break; case GNRC_NETAPI_MSG_TYPE_SND: DEBUG("slip: GNRC_NETAPI_MSG_TYPE_SND received\n"); _slip_send(dev, (gnrc_pktsnip_t *)msg.content.ptr); break; case GNRC_NETAPI_MSG_TYPE_GET: DEBUG("slip: GNRC_NETAPI_MSG_TYPE_GET received\n"); reply.type = GNRC_NETAPI_MSG_TYPE_ACK; reply.content.value = (uint32_t)_slip_get((gnrc_netapi_opt_t *)msg.content.ptr); msg_reply(&msg, &reply); break; case GNRC_NETAPI_MSG_TYPE_SET: DEBUG("slip: GNRC_NETAPI_MSG_TYPE_SET received\n"); reply.type = GNRC_NETAPI_MSG_TYPE_ACK; reply.content.value = (uint32_t)(-ENOTSUP); DEBUG("slip: I don't support this but have to reply.\n"); msg_reply(&msg, &reply); break; } } /* should be never reached */ return NULL; }
/* * sc_wstat() * Handle FS_WSTAT of "select" and "unselect" messages * * Returns 0 if it's handled here, 1 if not. * NOTE: we "handle" it here even if it's an error for one of our * message types. */ int sc_wstat(struct msg *m, struct selclient *scp, char *field, char *val) { if (!strcmp(field, "select")) { extern port_t path_open(); if (scp->sc_mask) { msg_err(m->m_sender, EBUSY); return(0); } if (parse(val, &scp->sc_mask, &scp->sc_clid, &scp->sc_fd, &scp->sc_key) || (!scp->sc_mask)) { msg_err(m->m_sender, EINVAL); return(0); } /* * Protect against any unsupported bits */ if (scp->sc_nosupp & scp->sc_mask) { scp->sc_mask = 0; msg_err(m->m_sender, ENOTSUP); return(0); } /* * TBD: use hostname for clustered case */ if (selfs_port < 0) { selfs_port = path_open("//fs/select", 0); } if (selfs_port < 0) { scp->sc_mask = 0; msg_err(m->m_sender, strerror()); return(0); } scp->sc_needsel = 1; scp->sc_iocount = 0; /* * Client no longer uses select() on this connection */ } else if (!strcmp(field, "unselect")) { sc_done(scp); } else { /* * Not a message *we* handle... */ return(1); } /* * Success */ m->m_arg = m->m_arg1 = m->m_buflen = m->m_nseg = 0; msg_reply(m->m_sender, m); return(0); }
static int do_seek(void *msg, anvil_msginfo_t *msg_info) { struct anvil_seek_msg *seekmsg; int leng; int remaining; char *pdata; fcb_t *fcb; int64_t new_pos; seekmsg = (struct anvil_seek_msg *)msg; fcb = (fcb_t *)msg_info->cookie; //anvil_syslog(0, "do_seek FCB=%016lx\n", fcb); switch (seekmsg->whence) { case SEEK_SET: new_pos = seekmsg->offset; break; case SEEK_CUR: new_pos = fcb->pos + seekmsg->offset; break; case SEEK_END: new_pos = fcb->fs->size + seekmsg->offset; break; default: msg_reply(msg_info->pid, msg_info->tid, -EINVAL, NULL, 0); break; } if (new_pos < 0) { msg_reply(msg_info->pid, msg_info->tid, -EINVAL, NULL, 0); return -1; } fcb->pos = new_pos; msg_reply(msg_info->pid, msg_info->tid, new_pos, NULL, 0); return 0; }
/** * Get next byte from stdin in gbk encoding (if conversion is needed). */ int terminal_getchar(void) { int ch = do_terminal_getchar(); while ((RMSG || msg_num) && session_status() != ST_LOCKSCREEN) { msg_reply(ch); ch = do_terminal_getchar(); } return ch; }
/* * tmpfs_write() * Write to an open file */ void tmpfs_write(struct msg *m, struct file *f) { struct openfile *o = f->f_file; uint x, cnt, err; /* * Can only write to a true file, and only if open for writing. */ if (!o || !(f->f_perm & ACC_WRITE)) { msg_err(m->m_sender, EPERM); return; } /* * Walk each segment of the message */ err = cnt = 0; for (x = 0; x < m->m_nseg; ++x) { seg_t *s; /* * Write it */ s = &m->m_seg[x]; if (do_write(o, f->f_pos, s->s_buf, s->s_buflen)) { err = 1; break; } /* * Update position and count */ f->f_pos += s->s_buflen; cnt += s->s_buflen; /* * If we've extended the file, update the * file length. */ if (f->f_pos > o->o_len) { o->o_len = f->f_pos; } } /* * Done. Return count of stuff written. */ if ((cnt == 0) && err) { msg_err(m->m_sender, strerror()); } else { m->m_arg = cnt; m->m_arg1 = m->m_nseg = 0; msg_reply(m->m_sender, m); } }
void second_thread(void) { printf("second_thread starting.\n"); msg_t m; while(1) { msg_receive(&m); printf("2nd: got msg from %i\n", m.sender_pid); m.content.value++; msg_reply(&m, &m); } }
/* * namer_seek() * Set file position */ static void namer_seek(struct msg *m, struct file *f) { if (m->m_arg < 0) { msg_err(m->m_sender, EINVAL); return; } f->f_pos = m->m_arg; m->m_buflen = m->m_arg = m->m_arg1 = m->m_nseg = 0; msg_reply(m->m_sender, m); }
static void *_event_loop(void *args) { msg_t msg, reply; (void)args; msg_init_queue(_msg_q, GNRC_RPL_MSG_QUEUE_SIZE); /* preinitialize ACK */ reply.type = GNRC_NETAPI_MSG_TYPE_ACK; trickle_t *trickle; /* start event loop */ while (1) { DEBUG("RPL: waiting for incoming message.\n"); msg_receive(&msg); switch (msg.type) { case GNRC_RPL_MSG_TYPE_LIFETIME_UPDATE: DEBUG("RPL: GNRC_RPL_MSG_TYPE_LIFETIME_UPDATE received\n"); _update_lifetime(); break; case GNRC_RPL_MSG_TYPE_TRICKLE_INTERVAL: DEBUG("RPL: GNRC_RPL_MSG_TYPE_TRICKLE_INTERVAL received\n"); trickle = msg.content.ptr; if (trickle && (trickle->callback.func != NULL)) { trickle_interval(trickle); } break; case GNRC_RPL_MSG_TYPE_TRICKLE_CALLBACK: DEBUG("RPL: GNRC_RPL_MSG_TYPE_TRICKLE_CALLBACK received\n"); trickle = msg.content.ptr; if (trickle && (trickle->callback.func != NULL)) { trickle_callback(trickle); } break; case GNRC_NETAPI_MSG_TYPE_RCV: DEBUG("RPL: GNRC_NETAPI_MSG_TYPE_RCV received\n"); _receive(msg.content.ptr); break; case GNRC_NETAPI_MSG_TYPE_SND: break; case GNRC_NETAPI_MSG_TYPE_GET: case GNRC_NETAPI_MSG_TYPE_SET: DEBUG("RPL: reply to unsupported get/set\n"); reply.content.value = -ENOTSUP; msg_reply(&msg, &reply); break; default: break; } } return NULL; }
void second_thread(void) { //printf("2nd thread started, pid: %i\n", thread_getpid()); msg_t m; while (1) { msg_receive(&m); //printf("2nd: Got msg from %i\n", m.sender_pid); m.content.value++; msg_reply(&m, &m); } }
static void *_event_loop(void *args) { msg_t msg, reply, msg_q[GNRC_SIXLOWPAN_MSG_QUEUE_SIZE]; gnrc_netreg_entry_t me_reg = GNRC_NETREG_ENTRY_INIT_PID(GNRC_NETREG_DEMUX_CTX_ALL, sched_active_pid); (void)args; msg_init_queue(msg_q, GNRC_SIXLOWPAN_MSG_QUEUE_SIZE); /* register interest in all 6LoWPAN packets */ gnrc_netreg_register(GNRC_NETTYPE_SIXLOWPAN, &me_reg); /* preinitialize ACK */ reply.type = GNRC_NETAPI_MSG_TYPE_ACK; /* start event loop */ while (1) { DEBUG("6lo: waiting for incoming message.\n"); msg_receive(&msg); switch (msg.type) { case GNRC_NETAPI_MSG_TYPE_RCV: DEBUG("6lo: GNRC_NETDEV_MSG_TYPE_RCV received\n"); _receive(msg.content.ptr); break; case GNRC_NETAPI_MSG_TYPE_SND: DEBUG("6lo: GNRC_NETDEV_MSG_TYPE_SND received\n"); _send(msg.content.ptr); break; case GNRC_NETAPI_MSG_TYPE_GET: case GNRC_NETAPI_MSG_TYPE_SET: DEBUG("6lo: reply to unsupported get/set\n"); reply.content.value = -ENOTSUP; msg_reply(&msg, &reply); break; #ifdef MODULE_GNRC_SIXLOWPAN_FRAG case GNRC_SIXLOWPAN_MSG_FRAG_SND: DEBUG("6lo: send fragmented event received\n"); gnrc_sixlowpan_frag_send(msg.content.ptr); break; #endif default: DEBUG("6lo: operation not supported\n"); break; } } return NULL; }
int DevPty::handle_ioctl(struct anvil_ioctl_msg *msg, anvil_msginfo_t *msg_info) { //anvil_syslog(0, "Ask::TtyDevice::handle_ioctl %08x %08x %08x\n", msg->request, msg->flags, msg->size); switch (msg->request) { case TIOCSWINSZ: { //anvil_syslog(0, "DevPty::handle_ioctl setwinsz()\n"); struct winsize ws; msg_peek(msg_info->pid, msg_info->tid, &ws, sizeof(ws), sizeof(struct anvil_ioctl_msg)); m_pts.set_size(ws.ws_col, ws.ws_row); msg_reply(msg_info->pid, msg_info->tid, 0, NULL, 0); break; } default: msg_reply(msg_info->pid, msg_info->tid, -EINVAL, NULL, 0); //anvil_syslog(0, "DevPty::handle_default\n"); break; } return 0; }
void thread2(void) { puts("THREAD 2\n"); for (int i = 0;; ++i) { msg_t msg, reply; msg_receive(&msg); //printf("T2 got %" PRIu32 " (i=%d)\n", msg.content.value, i); reply.content.value = msg.content.value; msg_reply(&msg, &reply); } }
void attack(void) { object_t *objp = (object_t *)random(); object_t obj = (object_t)random(); char *name = (char *)random(); void *msg = (void *)random(); size_t size = (size_t)random(); task_t self = task_self(); void *addr = (void *)random(); int attr = random() & 7; thread_t t = (thread_t)random(); thread_t *tp = (thread_t *)random(); object_create(NULL, NULL); object_create(NULL, objp); object_create(name, NULL); object_create(name, objp); object_destroy(0); object_destroy(obj); object_lookup(NULL, objp); object_lookup(name, NULL); object_lookup(name, objp); msg_send(0, msg, size); msg_send(obj, NULL, size); msg_send(obj, msg, 0); msg_send(0, msg, 0); msg_send(0, NULL, size); msg_send(obj, msg, size); msg_receive(0, msg, size); msg_receive(obj, NULL, size); msg_receive(obj, msg, 0); msg_receive(0, msg, 0); msg_receive(0, NULL, size); msg_receive(obj, msg, size); msg_reply(0, msg, size); msg_reply(obj, NULL, size); msg_reply(obj, msg, 0); msg_reply(0, msg, 0); msg_reply(0, NULL, size); msg_reply(obj, msg, size); vm_allocate(self, addr, size, 1); vm_allocate(self, &addr, size, 1); vm_free(self, addr); vm_attribute(self, addr, attr); vm_map(self, addr, size, &addr); thread_create(self, tp); thread_suspend(t); thread_terminate(t); }
void Pts::wakeup_driver() { if (m_ptm.m_output_waiter.pid && m_output_queue.size()) { //anvil_syslog(0, "Ask::TtyDevice::wakeup_driver() found waiter %d\n", m_ptm.m_output_waiter.pid); // There's a reader, wait him up size_t amount_to_read = std::min(m_ptm.m_output_waiter_size, m_output_queue.size()); msg_poke(m_ptm.m_output_waiter.pid, m_ptm.m_output_waiter.tid, &m_output_queue[0], amount_to_read, 0); m_output_queue.erase(m_output_queue.begin(), m_output_queue.begin() + amount_to_read); msg_reply(m_ptm.m_output_waiter.pid, m_ptm.m_output_waiter.tid, amount_to_read, NULL, 0); m_ptm.m_output_waiter.pid = 0; } msg_send(m_ptm.m_master_pid, ANVIL_POLL_READY, (void *)(uintptr_t)12345, 4); }
static void *_event_loop(void *args) { msg_t msg, reply, msg_q[NG_SIXLOWPAN_MSG_QUEUE_SIZE]; ng_netreg_entry_t me_reg; (void)args; msg_init_queue(msg_q, NG_SIXLOWPAN_MSG_QUEUE_SIZE); me_reg.demux_ctx = NG_NETREG_DEMUX_CTX_ALL; me_reg.pid = thread_getpid(); /* register interest in all 6LoWPAN packets */ ng_netreg_register(NG_NETTYPE_SIXLOWPAN, &me_reg); /* preinitialize ACK */ reply.type = NG_NETAPI_MSG_TYPE_ACK; /* start event loop */ while (1) { DEBUG("6lo: waiting for incoming message.\n"); msg_receive(&msg); switch (msg.type) { case NG_NETAPI_MSG_TYPE_RCV: DEBUG("6lo: NG_NETDEV_MSG_TYPE_RCV received\n"); _receive((ng_pktsnip_t *)msg.content.ptr); break; case NG_NETAPI_MSG_TYPE_SND: DEBUG("6lo: NG_NETDEV_MSG_TYPE_SND received\n"); _send((ng_pktsnip_t *)msg.content.ptr); break; case NG_NETAPI_MSG_TYPE_GET: case NG_NETAPI_MSG_TYPE_SET: DEBUG("6lo: reply to unsupported get/set\n"); reply.content.value = -ENOTSUP; msg_reply(&msg, &reply); break; default: DEBUG("6lo: operation not supported\n"); break; } } return NULL; }
int do_close(void *msg, anvil_msginfo_t *msg_info) { fcb_t *fcb; int fd_ret; int pid; anvil_syslog(0, "do_close pid=%d fd=%d FCB=%016lx\n", msg_info->pid, fcb); fcb = (fcb_t *)msg_info->cookie; //++fcb->ref_cnt; msg_reply(msg_info->pid, msg_info->tid, 0, NULL, 0); return 0; }
void TermBox::writech(unsigned char ch) { int pid, tid; getWaiter(pid, tid); if (pid) { char buf[100]; memcpy(buf, m_fcb->line_disc.getKeyBuf(), m_fcb->line_disc.getKeyCnt()); buf[m_fcb->line_disc.getKeyCnt()] = 0; anvil_syslog(0, "TERM-SVR: do_read un-blocking %d keys\n", m_fcb->line_disc.getKeyCnt()); //anvil_syslog(0, "TERM-SVR: REPLYING %s\n", buf); msg_reply(pid, tid, 1, m_fcb->line_disc.getKeyBuf(), 1); m_fcb->line_disc.clearBuf(1); setWaiter(0, 0); } }