static int read_packet (int fd, unsigned int header_bytes, char* buf, size_t buf_size) { char header[header_bytes]; unsigned char *tmp; size_t len = 0; if (read_exact (fd, header, header_bytes) != header_bytes) { return -1; } for (tmp = (unsigned char *) header; header_bytes > 0; --header_bytes, ++tmp) { len <<= 8; len |= *tmp; } if (len > buf_size) { fprintf (stderr, "driver2pipe: read_packet: packet too large: %lx\n", (long) len); return -1; } return (read_exact (fd, buf, len) == len) ? (ssize_t) len : -1; }
ssize_t handler_tcp_read(int fd, char *buff, size_t len) { ssize_t rlen; struct ct_proto *hdr = (struct ct_proto *) buff; if (!buff || !len) return 0; /* May exit on EAGAIN if 0 Byte read */ rlen = read_exact(fd, buff, sizeof(struct ct_proto), 1); if (rlen < 0) return rlen; if (unlikely(ntohs(hdr->payload) > len - sizeof(struct ct_proto))) { errno = ENOMEM; return 1; /* Force server to close connection */ } /* May not exit on EAGAIN if 0 Byte read */ rlen = read_exact(fd, buff + sizeof(struct ct_proto), ntohs(hdr->payload), 0); if (rlen < 0) return rlen; return sizeof(struct ct_proto) + rlen; }
/* * Read and validate the Image and Domain headers. */ static int read_headers(struct xc_sr_context *ctx) { xc_interface *xch = ctx->xch; struct xc_sr_ihdr ihdr; struct xc_sr_dhdr dhdr; if ( read_exact(ctx->fd, &ihdr, sizeof(ihdr)) ) { PERROR("Failed to read Image Header from stream"); return -1; } ihdr.id = ntohl(ihdr.id); ihdr.version = ntohl(ihdr.version); ihdr.options = ntohs(ihdr.options); if ( ihdr.marker != IHDR_MARKER ) { ERROR("Invalid marker: Got 0x%016"PRIx64, ihdr.marker); return -1; } else if ( ihdr.id != IHDR_ID ) { ERROR("Invalid ID: Expected 0x%08x, Got 0x%08x", IHDR_ID, ihdr.id); return -1; } else if ( ihdr.version != IHDR_VERSION ) { ERROR("Invalid Version: Expected %d, Got %d", ihdr.version, IHDR_VERSION); return -1; } else if ( ihdr.options & IHDR_OPT_BIG_ENDIAN ) { ERROR("Unable to handle big endian streams"); return -1; } ctx->restore.format_version = ihdr.version; if ( read_exact(ctx->fd, &dhdr, sizeof(dhdr)) ) { PERROR("Failed to read Domain Header from stream"); return -1; } ctx->restore.guest_type = dhdr.type; ctx->restore.guest_page_size = (1U << dhdr.page_shift); if ( dhdr.xen_major == 0 ) { IPRINTF("Found %s domain, converted from legacy stream format", dhdr_type_to_str(dhdr.type)); DPRINTF(" Legacy conversion script version %u", dhdr.xen_minor); } else IPRINTF("Found %s domain from Xen %u.%u", dhdr_type_to_str(dhdr.type), dhdr.xen_major, dhdr.xen_minor); return 0; }
/* only called for live migration, must be called after suspend */ int xc_tmem_restore_extra(xc_interface *xch, int dom, int io_fd) { uint32_t pool_id; struct xen_tmem_oid oid; uint32_t index; int count = 0; int checksum = 0; while ( read_exact(io_fd, &pool_id, sizeof(pool_id)) == 0 && pool_id != -1 ) { if ( read_exact(io_fd, &oid, sizeof(oid)) ) return -1; if ( read_exact(io_fd, &index, sizeof(index)) ) return -1; if ( xc_tmem_control_oid(xch, pool_id, XEN_SYSCTL_TMEM_OP_RESTORE_FLUSH_PAGE, dom, 0,index,oid,NULL) <= 0 ) return -1; count++; checksum += pool_id + oid.oid[0] + oid.oid[1] + oid.oid[2] + index; } if ( pool_id != -1 ) return -1; if ( count ) DPRINTF("invalidated %d tmem pages, check=%d\n",count,checksum); return 0; }
static int xc_ia64_recv_vcpumap(const xc_dominfo_t *info, int io_fd, uint64_t **vcpumapp) { uint64_t max_virt_cpus; unsigned long vcpumap_size; uint64_t *vcpumap = NULL; *vcpumapp = NULL; if (read_exact(io_fd, &max_virt_cpus, sizeof(max_virt_cpus))) { ERROR("error reading max_virt_cpus"); return -1; } if (max_virt_cpus < info->max_vcpu_id) { ERROR("too large max_virt_cpus %i < %i\n", max_virt_cpus, info->max_vcpu_id); return -1; } vcpumap_size = (max_virt_cpus + 1 + sizeof(vcpumap[0]) - 1) / sizeof(vcpumap[0]); vcpumap = malloc(vcpumap_size); if (vcpumap == NULL) { ERROR("memory alloc for vcpumap"); return -1; } memset(vcpumap, 0, vcpumap_size); if (read_exact(io_fd, vcpumap, vcpumap_size)) { ERROR("read vcpumap"); free(vcpumap); return -1; } *vcpumapp = vcpumap; return 0; }
void scp_send( struct scp_handle *scp, uint8_t cmd, void *dat, uint8_t len) { uint8_t *buf = memalloc(len + 3); unsigned int i; buf[0] = cmd; buf[1] = len; memcpy(buf + 2, dat, len); buf[len + 2] = 0x4a; for (i = 0; i < len + 2; i++) buf[len + 2] += buf[i]; write_exact(scp->fd, buf, len + 3); if (cmd == SCPCMD_SENDRAM_USB) read_exact(scp->fd, dat, 512*1024); read_exact(scp->fd, buf, 2); if (buf[0] != cmd) errx(1, "Mismatch command echo: sent %02x (%s), received %02x (%s)", cmd, scp_cmdstr(cmd), buf[0], scp_cmdstr(buf[0])); if (buf[1] != 0x4f) errx(1, "Command %02x (%s) failed: %02x (%s)", cmd, scp_cmdstr(cmd), buf[1], scp_errstr(buf[1])); memfree(buf); }
int read_qemu(struct xc_sr_context *ctx) { xc_interface *xch = ctx->xch; char qemusig[21]; uint32_t qlen; void *qbuf = NULL; int rc = -1; if ( read_exact(ctx->fd, qemusig, sizeof(qemusig)) ) { PERROR("Error reading QEMU signature"); goto out; } if ( !memcmp(qemusig, "DeviceModelRecord0002", sizeof(qemusig)) ) { if ( read_exact(ctx->fd, &qlen, sizeof(qlen)) ) { PERROR("Error reading QEMU record length"); goto out; } qbuf = malloc(qlen); if ( !qbuf ) { PERROR("no memory for device model state"); goto out; } if ( read_exact(ctx->fd, qbuf, qlen) ) { PERROR("Error reading device model state"); goto out; } } else { ERROR("Invalid device model state signature '%*.*s'", (int)sizeof(qemusig), (int)sizeof(qemusig), qemusig); goto out; } /* With Remus, this could be read many times */ if ( ctx->x86_hvm.restore.qbuf ) free(ctx->x86_hvm.restore.qbuf); ctx->x86_hvm.restore.qbuf = qbuf; ctx->x86_hvm.restore.qlen = qlen; rc = 0; out: if (rc) free(qbuf); return rc; }
static void epcap_send(EPCAP_STATE *ep) { const int fd = STDIN_FILENO; ssize_t n = 0; unsigned char buf[SNAPLEN] = {0}; u_int16_t len = 0; for ( ; ; ) { if (child_exited) return; n = read_exact(fd, buf, sizeof(len)); if (n != sizeof(len)) { VERBOSE(1, "epcap_send: header len != %lu: %ld", (unsigned long)sizeof(len), (long)n); return; } len = (buf[0] << 8) | buf[1]; VERBOSE(2, "epcap_send: packet len = %u", len); if (len >= sizeof(buf)) return; n = read_exact(fd, buf, len); if (n != len) { VERBOSE(1, "epcap_send: len = %u, read = %ld", len, (long)n); return; } if (ep->opt & EPCAP_OPT_INJECT) { n = pcap_inject(ep->p, buf, len); if (n < 0) { VERBOSE(0, "epcap_send: %s", pcap_geterr(ep->p)); return; } else if (n != len) { VERBOSE(1, "epcap_send: len = %u, sent = %ld", len, (long)n); } } else { VERBOSE(2, "epcap_send: ignoring: len = %u", len); } } }
static struct container *eadf_open(struct disk *d) { struct disk_header dhdr; struct track_header thdr; struct disk_info *di; struct track_info *ti; unsigned int i; lseek(d->fd, 0, SEEK_SET); read_exact(d->fd, &dhdr, sizeof(dhdr)); if (strncmp(dhdr.sig, "UAE-1ADF", sizeof(dhdr.sig))) return NULL; d->di = di = memalloc(sizeof(*di)); di->nr_tracks = be16toh(dhdr.nr_tracks); di->track = memalloc(di->nr_tracks * sizeof(struct track_info)); for (i = 0; i < di->nr_tracks; i++) { ti = &di->track[i]; read_exact(d->fd, &thdr, sizeof(thdr)); thdr.type = be16toh(thdr.type); if (thdr.type != 1) { warnx("Bad track type %u in Ext-ADF", thdr.type); goto cleanup_error; } init_track_info(ti, TRKTYP_raw); ti->len = be32toh(thdr.len); if (ti->len == 0) { init_track_info(ti, TRKTYP_unformatted); ti->total_bits = TRK_WEAK; } else { ti->dat = memalloc(ti->len); ti->total_bits = be32toh(thdr.bitlen); } } for (i = 0; i < di->nr_tracks; i++) { ti = &di->track[i]; read_exact(d->fd, ti->dat, ti->len); } return &container_eadf; cleanup_error: for (i = 0; i < di->nr_tracks; i++) memfree(di->track[i].dat); memfree(di->track); memfree(di); d->di = NULL; return NULL; }
/* * Get the list of PFNs that are not in the psuedo-phys map. * Although we allocate pages on demand, balloon driver may * decreased simaltenously. So we have to free the freed * pages here. */ static int xc_ia64_recv_unallocated_list(int xc_handle, int io_fd, uint32_t dom, struct xen_ia64_p2m_table *p2m_table) { int rc = -1; unsigned int i; unsigned int count; unsigned long *pfntab = NULL; unsigned int nr_frees; if (read_exact(io_fd, &count, sizeof(count))) { ERROR("Error when reading pfn count"); goto out; } pfntab = malloc(sizeof(unsigned long) * count); if (pfntab == NULL) { ERROR("Out of memory"); goto out; } if (read_exact(io_fd, pfntab, sizeof(unsigned long)*count)) { ERROR("Error when reading pfntab"); goto out; } nr_frees = 0; for (i = 0; i < count; i++) { if (xc_ia64_p2m_allocated(p2m_table, pfntab[i])) { pfntab[nr_frees] = pfntab[i]; nr_frees++; } } if (nr_frees > 0) { if (xc_domain_memory_decrease_reservation(xc_handle, dom, nr_frees, 0, pfntab) < 0) { PERROR("Could not decrease reservation"); goto out; } else DPRINTF("Decreased reservation by %d / %d pages\n", nr_frees, count); } rc = 0; out: if (pfntab != NULL) free(pfntab); return rc; }
int read_cmd(byte **buf) { unsigned int len; unsigned char tmp[4]; if ((len = read_exact(tmp,4)) != 4) { return(-1); } len = ntohl(*((unsigned int *)tmp)); debug("read_cmd got len %u", len); *buf = malloc(len*sizeof(byte)); read_exact(*buf,len); }
// This function is the hook for Q.931. For now, it prints out // data and tries to establish a data link. static void dump_incoming_lapd(int data_socket) { short length; GTH_lapd_rx_su su; send_dl_establish_req(data_socket); for (;;) { length = 0; read_exact(data_socket, (char *)&length, 2); length = ntohs(length); read_exact(data_socket, (char *)&su, length); switch (su.opcode) { case Q921_DL_ESTABLISH_IND: printf("dl-establish-ind received, data link is up\n"); break; case Q921_DL_ESTABLISH_CONFIRM: printf("dl-establish-conf received, data link is up, sending data\n"); send_dl_data_req(data_socket); break; case Q921_DL_RELEASE_IND: printf("got dl-release-ind, resending dl_establish_req\n"); send_dl_establish_req(data_socket); break; case Q921_MDL_ERROR_IND: printf("got MDL-error-ind(%c)\n", su.payload[0]); break; case Q921_DL_DATA_IND: printf("got LAPD payload data, len=%d, hexdump=%2x %2x %2x %2x %2x (%c%c%c%c%c)\n", length - 6, su.payload[0], su.payload[1], su.payload[2], su.payload[3], su.payload[4], su.payload[0], su.payload[1], su.payload[2], su.payload[3], su.payload[4]); break; default: printf("unexpected LAPD data, tag=%d flags=0x%x opcode=%d len=%d\n", su.tag, su.flags, su.opcode, length); break; } } }
/* * Reads a record from the stream, and fills in the record structure. * * Returns 0 on success and non-0 on failure. * * On success, the records type and size shall be valid. * - If size is 0, data shall be NULL. * - If size is non-0, data shall be a buffer allocated by malloc() which must * be passed to free() by the caller. * * On failure, the contents of the record structure are undefined. */ static int read_record(struct xc_sr_context *ctx, struct xc_sr_record *rec) { xc_interface *xch = ctx->xch; struct xc_sr_rhdr rhdr; size_t datasz; if ( read_exact(ctx->fd, &rhdr, sizeof(rhdr)) ) { PERROR("Failed to read Record Header from stream"); return -1; } else if ( rhdr.length > REC_LENGTH_MAX ) { ERROR("Record (0x%08x, %s) length %#x exceeds max (%#x)", rhdr.type, rec_type_to_str(rhdr.type), rhdr.length, REC_LENGTH_MAX); return -1; } datasz = ROUNDUP(rhdr.length, REC_ALIGN_ORDER); if ( datasz ) { rec->data = malloc(datasz); if ( !rec->data ) { ERROR("Unable to allocate %zu bytes for record data (0x%08x, %s)", datasz, rhdr.type, rec_type_to_str(rhdr.type)); return -1; } if ( read_exact(ctx->fd, rec->data, datasz) ) { free(rec->data); rec->data = NULL; PERROR("Failed to read %zu bytes of data for record (0x%08x, %s)", datasz, rhdr.type, rec_type_to_str(rhdr.type)); return -1; } } else rec->data = NULL; rec->type = rhdr.type; rec->length = rhdr.length; return 0; };
static Cmd *read_cmd() { Cmd * cmd; uint32_t packetlen; size_t n; size_t offset = 2 * sizeof(char*) + sizeof(uint32_t); n = fread(&packetlen, sizeof(uint32_t), 1, stdin); switch (n) { case 0: exit(0); case 1: break; default: perror("fread"); exit(1); } packetlen = ntohl(packetlen); cmd = (Cmd*)calloc(1, packetlen + offset); cmd->passwd = ((char*)cmd + 2 * sizeof(char*)) + sizeof(cmd->hdr); read_exact((char*)cmd+offset, packetlen); cmd->hdr.packetlen = packetlen; cmd->hdr.passwdlen = ntohl(cmd->hdr.passwdlen); cmd->hdr.saltlen = ntohl(cmd->hdr.saltlen); cmd->hdr.N = ntohl(cmd->hdr.N); cmd->hdr.r = ntohl(cmd->hdr.r); cmd->hdr.p = ntohl(cmd->hdr.p); cmd->hdr.buflen = ntohl(cmd->hdr.buflen); cmd->salt = cmd->passwd + cmd->hdr.passwdlen; return cmd; }
int username_msg(char *username, size_t len, char *dst, size_t dlen) { int fd; ssize_t ret; uint32_t salt; unsigned char h[crypto_hash_sha512_BYTES]; struct username_struct *us = (struct username_struct *) dst; char *uname; size_t uname_len; if (dlen < sizeof(struct username_struct)) return -ENOMEM; uname_len = 512; uname = xzmalloc(uname_len); fd = open_or_die("/dev/random", O_RDONLY); ret = read_exact(fd, &salt, sizeof(salt), 0); if (ret != sizeof(salt)) panic("Cannot read from /dev/random!\n"); close(fd); slprintf(uname, uname_len, "%s%u", username, salt); crypto_hash_sha512(h, (unsigned char *) uname, strlen(uname)); us->salt = htonl(salt); memcpy(us->hash, h, sizeof(us->hash)); xfree(uname); return 0; }
static int xc_ia64_recv_vcpu_context(int xc_handle, int io_fd, uint32_t dom, uint32_t vcpu, vcpu_guest_context_any_t *ctxt_any) { vcpu_guest_context_t *ctxt = &ctxt_any->c; if (read_exact(io_fd, ctxt, sizeof(*ctxt))) { ERROR("Error when reading ctxt"); return -1; } fprintf(stderr, "ip=%016lx, b0=%016lx\n", ctxt->regs.ip, ctxt->regs.b[0]); /* Initialize and set registers. */ ctxt->flags = VGCF_EXTRA_REGS | VGCF_SET_CR_IRR | VGCF_online; if (xc_vcpu_setcontext(xc_handle, dom, vcpu, ctxt_any) != 0) { ERROR("Couldn't set vcpu context"); return -1; } /* Just a check. */ ctxt->flags = 0; if (xc_vcpu_getcontext(xc_handle, dom, vcpu, ctxt_any)) { ERROR("Could not get vcpu context"); return -1; } return 0; }
void scp_printinfo(struct scp_handle *scp) { uint8_t info[2]; scp_send(scp, SCPCMD_SCPINFO, NULL, 0); read_exact(scp->fd, info, 2); printf("Supercard Pro: Hardware v%u.%u; Firmware v%u.%u\n", info[0] >> 4, info[0] & 15, info[1] >> 4, info[1] & 15); }
static void tapdisk_lio_ack_event(struct tqueue *queue) { struct lio *lio = queue->tio_data; uint64_t val; if (lio->flags & LIO_FLAG_EVENTFD) read_exact(lio->event_fd, &val, sizeof(val)); }
evtchn_port_or_error_t xenevtchn_pending(xenevtchn_handle *xce) { int fd = xce->fd; evtchn_port_t port; if ( read_exact(fd, (char *)&port, sizeof(port)) == -1 ) return -1; return port; }
evtchn_port_or_error_t xc_evtchn_pending(int xce_handle) { evtchn_port_t port; if ( read_exact(xce_handle, (char *)&port, sizeof(port)) == -1 ) return -1; return port; }
static evtchn_port_or_error_t netbsd_evtchn_pending(xc_evtchn *xce, xc_osdep_handle h) { int fd = (int)h; evtchn_port_t port; if ( read_exact(fd, (char *)&port, sizeof(port)) == -1 ) return -1; return port; }
static void *worker(void *self) { int fd, old_state; ssize_t ret; size_t blen = TUNBUFF_SIZ; //FIXME const struct worker_struct *ws = self; struct pollfd fds; char *buff; fds.fd = ws->efd[0]; fds.events = POLLIN; ret = curve25519_alloc_or_maybe_die(ws->c); if (ret < 0) syslog_panic("Cannot init curve25519!\n"); buff = xmalloc_aligned(blen, 64); syslog(LOG_INFO, "curvetun thread on CPU%u up!\n", ws->cpu); pthread_cleanup_push(xfree_func, ws->c); pthread_cleanup_push(curve25519_free, ws->c); pthread_cleanup_push(xfree_func, buff); while (likely(!sigint)) { poll(&fds, 1, -1); if ((fds.revents & POLLIN) != POLLIN) continue; pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &old_state); while ((ret = read_exact(ws->efd[0], &fd, sizeof(fd), 1)) > 0) { if (ret != sizeof(fd)) { sched_yield(); continue; } ret = ws->handler(fd, ws, buff, blen); if (ret) write_exact(ws->parent.refd, &fd, sizeof(fd), 1); } pthread_setcancelstate(old_state, NULL); } syslog(LOG_INFO, "curvetun thread on CPU%u down!\n", ws->cpu); pthread_cleanup_pop(1); pthread_cleanup_pop(1); pthread_cleanup_pop(1); pthread_exit((void *) ((long) ws->cpu)); }
int read_cmd(byte **buf, int *size) { int len; if (read_exact(*buf, 4) != 4) return(-1); len = ((*buf)[0] << 24) | \ ((*buf)[1] << 16) | \ ((*buf)[2] << 8) | \ (*buf)[3]; if (len > *size) { byte* tmp = (byte*)realloc((void*)*buf, len); if (tmp == NULL) return -1; else *buf = tmp; *size = len; } return read_exact(*buf, len); }
int read_erlang(byte *buff) { /* 1. read first two btyes from erlang which contain lenths bytes using read_stdin; MSB first 2. extract length 3. read this number of bytes from stdin using read_stdin */ int len; /* hold result of converting length bytes */ check((read_exact(stdinfd,buff,2) == 2), "Error reading message header"); len = get_16bit(buff); check((read_exact(stdinfd,buff,len) == len), "Error reading message body:"); // mesglen = len; return len; error: return -1; }
int main(void) { char msg[100]; int msg_len; #ifdef __WIN32__ _setmode(_fileno( stdin), _O_BINARY); _setmode(_fileno( stdout), _O_BINARY); #endif msg_len = read_exact(msg, 100); write_exact("Content-type: text/plain\r\n\r\n", 28); write_exact(msg, msg_len); exit(EXIT_SUCCESS); }
static struct container *adf_open(struct disk *d) { struct track_info *ti; struct disk_info *di; unsigned int i, j, k; char sig[8]; off_t sz; read_exact(d->fd, sig, sizeof(sig)); if (!strncmp(sig, "UAE-1ADF", sizeof(sig))) return container_eadf.open(d); sz = lseek(d->fd, 0, SEEK_END); if (sz != 160*512*11) { warnx("ADF file bad size: %lu bytes", (unsigned long)sz); return NULL; } lseek(d->fd, 0, SEEK_SET); adf_init(d); di = d->di; for (i = 0; i < di->nr_tracks; i++) { ti = &di->track[i]; read_exact(d->fd, ti->dat, ti->len); for (j = 0; j < ti->nr_sectors; j++) { unsigned char *p = ti->dat + j*ti->bytes_per_sector; for (k = 0; k < ti->bytes_per_sector/4; k++) if (memcmp(p+k*4, "NDOS", 4)) break; if (k != ti->bytes_per_sector/4) set_sector_valid(ti, j); } } return &container_adf; }
static int read_page(int xc_handle, int io_fd, uint32_t dom, unsigned long pfn) { void *mem; mem = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE, PROT_READ|PROT_WRITE, pfn); if (mem == NULL) { ERROR("cannot map page"); return -1; } if (read_exact(io_fd, mem, PAGE_SIZE)) { ERROR("Error when reading from state file (5)"); munmap(mem, PAGE_SIZE); return -1; } munmap(mem, PAGE_SIZE); return 0; }
static struct stream *caps_open(const char *name, unsigned int data_rpm) { int fd; char sig[4]; /* Simple signature check */ if ((fd = file_open(name, O_RDONLY)) == -1) return NULL; read_exact(fd, sig, 4); close(fd); if (strncmp(sig, "CAPS", 4)) return NULL; w("CAPS/IPF image is detected, but support is not enabled.\n"); w("Support must be enabled at compile time (e.g., 'caps=y make')\n"); w("Download the library at http://www.softpres.org/download\n"); w("Respect the SPS Freeware License Agreement!\n"); return NULL; }
static gboolean read_line(struct sipe_file_transfer_private *ft_private, guchar *data, gsize size) { gsize pos = 0; if (size < 2) return FALSE; memset(data, 0, size--); do { if (!read_exact(ft_private, data + pos, 1)) return FALSE; } while ((data[pos] != '\n') && (++pos < size)); /* Buffer too short? */ if ((pos == size) && (data[pos - 1] != '\n')) { return FALSE; } return TRUE; }
/* Read shared info. */ static int xc_ia64_recv_shared_info(int xc_handle, int io_fd, uint32_t dom, unsigned long shared_info_frame, unsigned long *start_info_pfn) { unsigned int i; /* The new domain's shared-info frame. */ shared_info_t *shared_info; /* Read shared info. */ shared_info = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE, PROT_READ|PROT_WRITE, shared_info_frame); if (shared_info == NULL) { ERROR("cannot map page"); return -1; } if (read_exact(io_fd, shared_info, PAGE_SIZE)) { ERROR("Error when reading shared_info page"); munmap(shared_info, PAGE_SIZE); return -1; } /* clear any pending events and the selector */ memset(&(shared_info->evtchn_pending[0]), 0, sizeof (shared_info->evtchn_pending)); for (i = 0; i < MAX_VIRT_CPUS; i++) shared_info->vcpu_info[i].evtchn_pending_sel = 0; if (start_info_pfn != NULL) *start_info_pfn = shared_info->arch.start_info_pfn; munmap (shared_info, PAGE_SIZE); return 0; }