void WFStartupSendNop::EventCallback(int32 eventType, WFStartupEventCallbackParameter* param) { // Send a NOP message to server and see if comes back, this way we // can test the internet connection without having to authenticate // the client agains the server, used for wayfinder id. isab::Buffer *buf = new isab::Buffer( 10 ); isab::NParamBlock params; isab::Buffer tmpbuf( 128 ); std::vector<byte> bbuf; params.writeParams(bbuf, NSC_PROTO_VER, false /* NO GZIP */); tmpbuf.writeNextByteArray( &bbuf.front(), bbuf.size() ); const uint8* data = tmpbuf.accessRawData(); uint32 size = tmpbuf.getLength(); buf->writeNextUnaligned16bit(isab::navRequestType::NAV_NOP_REQ); class isab::DataGuiMess mess(isab::GuiProtEnums::GUI_TO_NGP_DATA, buf->getLength(), buf->accessRawData(), size, data); m_sender->SendMessage(mess, this); delete buf; }
/* * Allocate an empty _disk cache_ buffer. We use this when dealing with file * holes. It would be nice if this API could go way and readi just use uzero() * * This won't be able to use tmpbuf if we split disk and temporary buffers. */ void *zerobuf(void) { void *b = tmpbuf(); memset(b, 0, 512); return b; }
char *zerobuf(void) { char *b; char *tmpbuf(); b = tmpbuf(); bzero(b, 512); return (b); }
void scan_find(const class scanner_params &sp,const recursion_control_block &rcb) { assert(sp.sp_version==scanner_params::CURRENT_SP_VERSION); if(sp.phase==scanner_params::PHASE_STARTUP) { assert(sp.info->si_version==scanner_info::CURRENT_SI_VERSION); sp.info->name = "find"; sp.info->author = "Simson Garfinkel"; sp.info->description = "Simple search for patterns"; sp.info->scanner_version= "1.1"; sp.info->flags = scanner_info::SCANNER_FIND_SCANNER; sp.info->feature_names.insert("find"); sp.info->histogram_defs.insert(histogram_def("find","","histogram",HistogramMaker::FLAG_LOWERCASE)); return; } if(sp.phase==scanner_params::PHASE_SHUTDOWN) return; if (scanner_params::PHASE_INIT == sp.phase) { for (std::vector<std::string>::const_iterator itr(FindOpts.Patterns.begin()); itr != FindOpts.Patterns.end(); ++itr) { add_find_pattern(*itr); } for (std::vector<std::string>::const_iterator itr(FindOpts.Files.begin()); itr != FindOpts.Files.end(); ++itr) { process_find_file(itr->c_str()); } } if(sp.phase==scanner_params::PHASE_SCAN) { /* The current regex library treats \0 as the end of a string. * So we make a copy of the current buffer to search that's one bigger, and the copy has a \0 at the end. */ feature_recorder *f = sp.fs.get_name("find"); managed_malloc<u_char> tmpbuf(sp.sbuf.bufsize+1); if(!tmpbuf.buf) return; // no memory for searching memcpy(tmpbuf.buf,sp.sbuf.buf,sp.sbuf.bufsize); tmpbuf.buf[sp.sbuf.bufsize]=0; for(size_t pos = 0; pos < sp.sbuf.pagesize && pos < sp.sbuf.bufsize;) { /* Now see if we can find a string */ std::string found; size_t offset=0; size_t len = 0; if(find_list.check((const char *)tmpbuf.buf+pos,&found,&offset,&len)) { if(len == 0) { len+=1; continue; } f->write_buf(sp.sbuf,pos+offset,len); pos += offset+len; } else { /* nothing was found; skip past the first \0 and repeat. */ const u_char *eos = (const u_char *)memchr(tmpbuf.buf+pos,'\000',sp.sbuf.bufsize-pos); if(eos) pos=(eos-tmpbuf.buf)+1; // skip 1 past the \0 else pos=sp.sbuf.bufsize; // skip to the end of the buffer } } } }
void mbr_parse(char letter) { boot_record_t *br; uint8_t i,k = 0; uint32_t tstart; uint32_t tlen; kprintf("hd%c: ", letter); /* allocate temporary memory */ br = (boot_record_t *)tmpbuf(); blk_op.is_read = true; blk_op.is_user = false; blk_op.addr = (uint8_t *)br; blk_op.lba = 0; blk_op.nblock = 1; /* FIX: should also check table's CRC */ if(!blk_op.blkdev->transfer() || br->magic != MBR_SIGNATURE){ kputs("No CCPT"); return; } /* add each entry to blkops struct */ /* This adds paritions as it finds good ones? */ for(i=0; i<MBR_ENTRY_COUNT; i++){ if( ! br->partition[i].flags ){ continue; } /* if valid entry, then adjust offset/len to blocks*/ else{ tstart = br->partition[i].start; tlen = br->partition[i].len; if( !br->secz ){ tstart >>= 1; tlen >>= 1; } else{ tstart <<= (br->secz-1); tlen <<= (br->secz-1); } blk_op.blkdev->lba_first[k] = tstart; blk_op.blkdev->lba_count[k] = tlen; kprintf("hd%c%d ", letter, k+1); k++; }
void filename(char *userspace_upath, char *name) { char *buf; char *ptr; buf = tmpbuf(); if(ugets(userspace_upath, buf, 512)) { brelse(buf); *name = '\0'; return; /* An access violation reading the name */ } ptr = buf; while(*ptr) ++ptr; /* Special case for "...name.../" */ while(*ptr != '/' && ptr-- > buf); ptr++; memcpy(name, ptr, FILENAME_LEN); brelse(buf); }
void merge(Iterator begin, Iterator mid, Iterator end, Comparable cmp) { if( !cmp(*(mid+1), *mid) ) return; TemporaryBuffer<Iterator> tmpbuf(begin, end); typename TemporaryBuffer<Iterator>::iterator auxBegin = tmpbuf.begin(); typename TemporaryBuffer<Iterator>::iterator auxEnd = tmpbuf.end(); typename TemporaryBuffer<Iterator>::iterator auxMid = auxBegin + (mid - begin); typename TemporaryBuffer<Iterator>::iterator it1 = auxBegin, it2 = auxMid+1; while(it1 < auxMid+1 && it2 < auxEnd) { if( cmp(*it1, *it2) ) *(begin++) = *(it1++); else *(begin++) = *(it2++); } while(it1 < auxMid+1) *(begin++) = *(it1++); while(it2 < auxEnd) *(begin++) = *(it2++); }
void mbr_parse(char letter) { boot_record_t *br; uint8_t i,k = 0; kprintf("hd%c: ", letter); /* allocate temporary memory */ br = (boot_record_t *)tmpbuf(); blk_op.is_read = true; blk_op.is_user = false; blk_op.addr = br; blk_op.lba = 0; blk_op.nblock = 1; /* FIX: should also check table's CRC */ if(!blk_op.blkdev->transfer() || br->magic != MBR_SIGNATURE){ kputs("No CCPT"); return; } /* add each entry to blkops struct */ /* This adds paritions as it finds good ones? */ for(i=0; i<MBR_ENTRY_COUNT; i++){ if( ! br->partition[i].flags ){ continue; } else{ blk_op.blkdev->lba_first[k] = br->partition[i].start; blk_op.blkdev->lba_count[k] = br->partition[i].len; kprintf("hd%c%d ", letter, k+1); k++; } } /* release temporary memory */ brelse((bufptr)br); }
inoptr n_open(char *uname, inoptr *parent) { inoptr r; char *tb; tb = (char*)tmpbuf(); /* temporary memory to hold kernel's copy of the filename */ if (ugets(uname, tb, 512) == -1) { *parent = NULLINODE; return NULLINODE; } #ifdef DEBUG kprintf("n_open(\"%s\")\n", tb); #endif r = kn_open(tb, parent); brelse(tb); return r; }
arg_t _execve(void) { /* Not ideal on stack */ struct binfmt_flat binflat; inoptr ino; char **nargv; /* In user space */ char **nenvp; /* In user space */ struct s_argblk *abuf, *ebuf; int argc; uint32_t bin_size; /* Will need to be bigger on some cpus */ uaddr_t progbase, top; uaddr_t go; uint32_t true_brk; if (!(ino = n_open_lock(name, NULLINOPTR))) return (-1); if (!((getperm(ino) & OTH_EX) && (ino->c_node.i_mode & F_REG) && (ino->c_node.i_mode & (OWN_EX | OTH_EX | GRP_EX)))) { udata.u_error = EACCES; goto nogood; } setftime(ino, A_TIME); udata.u_offset = 0; udata.u_count = sizeof(struct binfmt_flat); udata.u_base = (void *)&binflat; udata.u_sysio = true; readi(ino, 0); if (udata.u_done != sizeof(struct binfmt_flat)) { udata.u_error = ENOEXEC; goto nogood; } /* FIXME: ugly - save this as valid_hdr modifies it */ true_brk = binflat.bss_end; /* Hard coded for our 68K format. We don't quite use the ucLinux names, we don't want to load a ucLinux binary in error! */ if (memcmp(binflat.magic, "bFLT", 4) || !valid_hdr(ino, &binflat)) { udata.u_error = ENOEXEC; goto nogood2; } /* Memory needed */ bin_size = binflat.bss_end + binflat.stack_size; /* Overflow ? */ if (bin_size < binflat.bss_end) { udata.u_error = ENOEXEC; goto nogood2; } /* Gather the arguments, and put them in temporary buffers. */ abuf = (struct s_argblk *) tmpbuf(); /* Put environment in another buffer. */ ebuf = (struct s_argblk *) tmpbuf(); /* Read args and environment from process memory */ if (rargs(argv, abuf) || rargs(envp, ebuf)) goto nogood3; /* This must be the last test as it makes changes if it works */ /* FIXME: need to update this to support split code/data and to fix stack handling nicely */ /* FIXME: ENOMEM fix needs to go to 16bit ? */ if ((udata.u_error = pagemap_realloc(0, bin_size, 0)) != 0) goto nogood3; /* Core dump and ptrace permission logic */ #ifdef CONFIG_LEVEL_2 /* Q: should uid == 0 mean we always allow core */ if ((!(getperm(ino) & OTH_RD)) || (ino->c_node.i_mode & (SET_UID | SET_GID))) udata.u_flags |= U_FLAG_NOCORE; else udata.u_flags &= ~U_FLAG_NOCORE; #endif udata.u_codebase = progbase = pagemap_base(); /* From this point on we are commmited to the exec() completing so we can start writing over the old program */ uput(&binflat, (uint8_t *)progbase, sizeof(struct binfmt_flat)); /* setuid, setgid if executable requires it */ if (ino->c_node.i_mode & SET_UID) udata.u_euid = ino->c_node.i_uid; if (ino->c_node.i_mode & SET_GID) udata.u_egid = ino->c_node.i_gid; top = progbase + bin_size; udata.u_top = top; udata.u_ptab->p_top = top; // kprintf("user space at %p\n", progbase); // kprintf("top at %p\n", progbase + bin_size); bin_size = binflat.reloc_start + 4 * binflat.reloc_count; go = (uint32_t)progbase + binflat.entry; close_on_exec(); /* * Read in the rest of the program, block by block. We rely upon * the optimization path in readi to spot this is a big move to user * space and move it directly. */ if (bin_size > sizeof(struct binfmt_flat)) { /* We copied the header already */ bin_size -= sizeof(struct binfmt_flat); udata.u_base = (uint8_t *)progbase + sizeof(struct binfmt_flat); udata.u_count = bin_size; udata.u_sysio = false; readi(ino, 0); if (udata.u_done != bin_size) goto nogood4; } /* Header isn't counted in relocations */ relocate(&binflat, progbase, bin_size); /* This may wipe the relocations */ uzero((uint8_t *)progbase + binflat.data_end, binflat.bss_end - binflat.data_end + binflat.stack_size); /* Use of brk eats into the stack allocation */ /* Use the temporary we saved (hack) as we mangled bss_end */ udata.u_break = udata.u_codebase + true_brk; /* Turn off caught signals */ memset(udata.u_sigvec, 0, sizeof(udata.u_sigvec)); /* place the arguments, environment and stack at the top of userspace memory. */ /* Write back the arguments and the environment */ nargv = wargs(((char *) top - 4), abuf, &argc); nenvp = wargs((char *) (nargv), ebuf, NULL); /* Fill in udata.u_name with Program invocation name */ uget((void *) ugetl(nargv, NULL), udata.u_name, 8); memcpy(udata.u_ptab->p_name, udata.u_name, 8); tmpfree(abuf); tmpfree(ebuf); i_unlock_deref(ino); /* Shove argc and the address of argv just below envp */ uputl((uint32_t) nargv, nenvp - 1); uputl((uint32_t) argc, nenvp - 2); // Set stack pointer for the program udata.u_isp = nenvp - 2; /* * Sort of - it's a good way to deal with all the stupidity of * random 68K platforms we will have to handle, and a nice place * to stuff the signal trampoline 8) */ install_vdso(); // kprintf("Go = %p ISP = %p\n", go, udata.u_isp); doexec(go); nogood4: /* Must not run userspace */ ssig(udata.u_ptab, SIGKILL); nogood3: tmpfree(abuf); tmpfree(ebuf); nogood2: nogood: i_unlock_deref(ino); return (-1); }
int main(int argc, char *argv[]) { char *outfile=NULL, buf[256]; struct stat statbuf; int nbytes,nread,nsamples; std::string tmpbuf(""); int i=0,j; if ((argc < 2) || (argc > 3)) { fprintf(stderr,"%s infile [outfile]\n",argv[0]); exit(1); } char *infile=argv[1]; if (argc==3) { outfile=argv[2]; } FILE *in=fopen(infile,"r"); FILE *out; if (outfile) { out=fopen(outfile,"w"); } else { out=stdout; } stat(infile,&statbuf); nbytes=statbuf.st_size; fseek(in,0,SEEK_SET); tmpbuf.reserve(nbytes); // read entire file into a buffer. while ((nread=(int)fread(buf,1,sizeof(buf),in))) { tmpbuf+=std::string(&(buf[0]),nread); } // parse the header header.parse_xml(tmpbuf); // decode the data std::vector<unsigned char> datav( xml_decode_field<unsigned char>(tmpbuf,"data") ); tmpbuf.clear(); nsamples=header.group_info->data_desc.nsamples; nbytes=nsamples*header.group_info->recorder_cfg->bits_per_sample/8; if (datav.size() < nbytes) { fprintf(stderr,"Data size does not match number of samples\n"); exit(1); } // convert the data to floating point sah_complex *fpdata=(sah_complex *)calloc(nsamples,sizeof(sah_complex)); sah_complex *fpout=(sah_complex *)calloc(2048,sizeof(sah_complex)); sah_complex *tmpb=(sah_complex *)calloc(1024,sizeof(sah_complex)); if (!fpdata || !fpout) { fprintf(stderr,"Memory allocation failure\n"); exit(1); } bits_to_floats(&(datav[0]),fpdata,nsamples); datav.clear(); sah_complex workbuf[2048]; fftwf_plan reverse=fftwf_plan_dft_1d(2048,workbuf,fpout,FFTW_BACKWARD,FFTW_MEASURE); fftwf_plan forward=fftwf_plan_dft_1d(1024,tmpb,workbuf,FFTW_FORWARD,FFTW_MEASURE|FFTW_PRESERVE_INPUT); while (i<nsamples) { // Do the forward transform. fftwf_execute_dft(forward, fpdata+i, workbuf); // shift 64 frequency bins memmove((void *)(workbuf+64), (void *)workbuf, 1024*sizeof(sah_complex)); // now move the upper 64 into the low bins memmove((void *)workbuf,(void *)(workbuf+1024),64*sizeof(sah_complex)); // clear the upper range memset((void *)(workbuf+1024),0,64*sizeof(sah_complex)); // Do the reverse transform fftwf_execute_dft(reverse,workbuf,fpout); // for (j=0; j<2048; j++) { fprintf(out,"%f\n",fpout[j][0]/1024.0); } i+=1024; } exit(0); }
void devide_init_drive(uint8_t drive) { blkdev_t *blk; uint8_t *buffer, select; switch(drive){ case 0: select = 0xE0; break; case 1: select = 0xF0; break; default: return; } kprintf("IDE drive %d: ", drive); #ifdef IDE_8BIT_ONLY /* set 8-bit mode -- mostly only supported by CF cards */ devide_writeb(ide_reg_devhead, select); if(!devide_wait(IDE_STATUS_READY)) return; devide_writeb(ide_reg_features, 0x01); /* Enable 8-bit PIO transfer mode (CFA feature set only) */ devide_writeb(ide_reg_command, IDE_CMD_SET_FEATURES); #endif /* confirm drive has LBA support */ if(!devide_wait(IDE_STATUS_READY)) return; /* send identify command */ devide_writeb(ide_reg_devhead, select); devide_writeb(ide_reg_command, IDE_CMD_IDENTIFY); /* allocate temporary sector buffer memory */ buffer = (uint8_t *)tmpbuf(); if(!devide_wait(IDE_STATUS_DATAREQUEST)) goto failout; blk_op.is_user = false; blk_op.addr = buffer; blk_op.nblock = 1; devide_read_data(); if(!(buffer[99] & 0x02)){ kputs("LBA unsupported.\n"); goto failout; } blk = blkdev_alloc(); if(!blk) goto failout; blk->transfer = devide_transfer_sector; blk->flush = devide_flush_cache; blk->driver_data = drive & DRIVE_NR_MASK; if( !(((uint16_t*)buffer)[82] == 0x0000 && ((uint16_t*)buffer)[83] == 0x0000) || (((uint16_t*)buffer)[82] == 0xFFFF && ((uint16_t*)buffer)[83] == 0xFFFF) ){ /* command set notification is supported */ if(buffer[164] & 0x20){ /* write cache is supported */ blk->driver_data |= FLAG_WRITE_CACHE; } } /* read out the drive's sector count */ blk->drive_lba_count = le32_to_cpu(*((uint32_t*)&buffer[120])); /* done with our temporary memory */ brelse((bufptr)buffer); /* scan partitions */ blkdev_scan(blk, SWAPSCAN); return; failout: brelse((bufptr)buffer); return; }
arg_t _execve(void) { /* We aren't re-entrant where this matters */ uint8_t hdr[16]; staticfast inoptr ino; char **nargv; /* In user space */ char **nenvp; /* In user space */ struct s_argblk *abuf, *ebuf; int argc; uint16_t progptr; uint16_t progload; staticfast uint16_t top; uint16_t bin_size; /* Will need to be bigger on some cpus */ uint16_t bss; top = ramtop; if (!(ino = n_open_lock(name, NULLINOPTR))) return (-1); if (!((getperm(ino) & OTH_EX) && (ino->c_node.i_mode & F_REG) && (ino->c_node.i_mode & (OWN_EX | OTH_EX | GRP_EX)))) { udata.u_error = EACCES; goto nogood; } setftime(ino, A_TIME); udata.u_offset = 0; udata.u_count = 16; udata.u_base = hdr; udata.u_sysio = true; readi(ino, 0); if (udata.u_done != 16) { udata.u_error = ENOEXEC; goto nogood; } if (!header_ok(hdr)) { udata.u_error = ENOEXEC; goto nogood2; } progload = hdr[7] << 8; if (progload == 0) progload = PROGLOAD; top = *(uint16_t *)(hdr + 8); if (top == 0) /* Legacy 'all space' binary */ top = ramtop; else /* Requested an amount, so adjust for the base */ top += progload; bss = *(uint16_t *)(hdr + 14); /* Binary doesn't fit */ /* FIXME: review overflows */ bin_size = ino->c_node.i_size; progptr = bin_size + 1024 + bss; if (progload < PROGLOAD || top - progload < progptr || progptr < bin_size) { udata.u_error = ENOMEM; goto nogood2; } udata.u_ptab->p_status = P_NOSLEEP; /* If we made pagemap_realloc keep hold of some defined area we could in theory just move the arguments up or down as part of the process - that would save us all this hassle but replace it with new hassle */ /* Gather the arguments, and put them in temporary buffers. */ abuf = (struct s_argblk *) tmpbuf(); /* Put environment in another buffer. */ ebuf = (struct s_argblk *) tmpbuf(); /* Read args and environment from process memory */ if (rargs(argv, abuf) || rargs(envp, ebuf)) goto nogood3; /* SN */ /* This must be the last test as it makes changes if it works */ /* FIXME: once we sort out chmem we can make stack and data two elements. We never allocate 'code' as there is no split I/D */ /* This is only safe from deadlocks providing pagemap_realloc doesn't sleep */ if (pagemap_realloc(0, top - MAPBASE, 0)) goto nogood3; /* From this point on we are commmited to the exec() completing */ /* Core dump and ptrace permission logic */ #ifdef CONFIG_LEVEL_2 /* Q: should uid == 0 mean we always allow core */ if ((!(getperm(ino) & OTH_RD)) || (ino->c_node.i_mode & (SET_UID | SET_GID))) udata.u_flags |= U_FLAG_NOCORE; else udata.u_flags &= ~U_FLAG_NOCORE; #endif udata.u_top = top; udata.u_ptab->p_top = top; /* setuid, setgid if executable requires it */ if (ino->c_node.i_mode & SET_UID) udata.u_euid = ino->c_node.i_uid; if (ino->c_node.i_mode & SET_GID) udata.u_egid = ino->c_node.i_gid; /* FIXME: In the execve case we may on some platforms have space below PROGLOAD to clear... */ /* We are definitely going to succeed with the exec, * so we can start writing over the old program */ uput(hdr, (uint8_t *)progload, 16); /* At this point, we are committed to reading in and * executing the program. This call must not block. */ close_on_exec(); /* * Read in the rest of the program, block by block. We rely upon * the optimization path in readi to spot this is a big move to user * space and move it directly. */ progptr = progload + 16; if (bin_size > 16) { bin_size -= 16; udata.u_base = (uint8_t *)progptr; /* We copied the first block already */ udata.u_count = bin_size; udata.u_sysio = false; readi(ino, 0); if (udata.u_done != bin_size) goto nogood4; progptr += bin_size; } /* Wipe the memory in the BSS. We don't wipe the memory above that on 8bit boxes, but defer it to brk/sbrk() */ uzero((uint8_t *)progptr, bss); /* Set initial break for program */ udata.u_break = (int)ALIGNUP(progptr + bss); /* Turn off caught signals */ memset(udata.u_sigvec, 0, sizeof(udata.u_sigvec)); // place the arguments, environment and stack at the top of userspace memory, // Write back the arguments and the environment nargv = wargs(((char *) top - 2), abuf, &argc); nenvp = wargs((char *) (nargv), ebuf, NULL); // Fill in udata.u_name with program invocation name uget((void *) ugetw(nargv), udata.u_name, 8); memcpy(udata.u_ptab->p_name, udata.u_name, 8); tmpfree(abuf); tmpfree(ebuf); i_deref(ino); /* Shove argc and the address of argv just below envp FIXME: should flip them in crt0.S of app for R2L setups so we can get rid of the ifdefs */ #ifdef CONFIG_CALL_R2L /* Arguments are stacked the 'wrong' way around */ uputw((uint16_t) nargv, nenvp - 2); uputw((uint16_t) argc, nenvp - 1); #else uputw((uint16_t) nargv, nenvp - 1); uputw((uint16_t) argc, nenvp - 2); #endif /* Set stack pointer for the program */ udata.u_isp = nenvp - 2; /* Start execution (never returns) */ udata.u_ptab->p_status = P_RUNNING; doexec(progload); /* tidy up in various failure modes */ nogood4: /* Must not run userspace */ ssig(udata.u_ptab, SIGKILL); nogood3: udata.u_ptab->p_status = P_RUNNING; tmpfree(abuf); tmpfree(ebuf); nogood2: nogood: i_unlock_deref(ino); return (-1); }
// on success, swi.data points to malloced data. int seti_parse_data(FILE* f, ANALYSIS_STATE& state) { unsigned long nbytes, nsamples,samples_per_byte; sah_complex *data; unsigned long i; char *p, buf[256]; sah_complex *bin_data=0; int retval=0; FORCE_FRAME_POINTER; nsamples = swi.nsamples; samples_per_byte=(8/swi.bits_per_sample); data = (sah_complex *)malloc_a(nsamples*sizeof(sah_complex), MEM_ALIGN); bin_data = (sah_complex *)malloc_a(nsamples*sizeof(sah_complex), MEM_ALIGN); if (!data) SETIERROR(MALLOC_FAILED, "!data"); if (!bin_data) SETIERROR(MALLOC_FAILED, "!bin_data"); switch(swi.data_type) { case DATA_ASCII: for (i=0; i<nsamples; i++) { p = fgets(buf, 256, f); if (!p) { SETIERROR(READ_FAILED,"in seti_parse_data"); } sscanf(buf, "%f%f", &data[i][0], &data[i][1]); } break; case DATA_ENCODED: case DATA_SUN_BINARY: try { int nread; std::string tmpbuf(""); fseek(f,0,SEEK_SET); nbytes = (nsamples/samples_per_byte); tmpbuf.reserve(nbytes*3/2); while ((nread=(int)fread(buf,1,sizeof(buf),f))) { tmpbuf+=std::string(&(buf[0]),nread); } std::vector<unsigned char> datav( xml_decode_field<unsigned char>(tmpbuf,"data") ); memcpy(bin_data,&(datav[0]),datav.size()); if (datav.size() < nbytes) throw BAD_DECODE; } catch (int i) { retval=i; if (data) free_a(data); if (bin_data) free_a(bin_data); SETIERROR(i,"in seti_parse_data()"); } bits_to_floats((unsigned char *)bin_data, data, nsamples); memcpy(bin_data,data,nsamples*sizeof(sah_complex)); state.savedWUData = bin_data; break; /* #if 0 nbytes = (nsamples/4); bin_data = (unsigned char*)malloc_a((nbytes+2)*sizeof(unsigned char), MEM_ALIGN); if (!bin_data) SETIERROR(MALLOC_FAILED, "!bin_data"); retval = read_bin_data(bin_data, nbytes, f); if (retval) { if (data) free_a(data); if (bin_data) free_a(bin_data); SETIERROR(retval,"from read_bin_data()"); } bits_to_floats(bin_data, data, nsamples); state.savedWUData = bin_data; break; #endif */ } state.npoints = nsamples; state.data = data; #ifdef BOINC_APP_GRAPHICS if (sah_graphics) { strlcpy(sah_graphics->wu.receiver_name,swi.receiver_cfg.name,255); sah_graphics->wu.s4_id = swi.receiver_cfg.s4_id; sah_graphics->wu.time_recorded = swi.time_recorded; sah_graphics->wu.subband_base = swi.subband_base; sah_graphics->wu.start_ra = swi.start_ra; sah_graphics->wu.start_dec = swi.start_dec; sah_graphics->wu.subband_sample_rate = swi.subband_sample_rate; sah_graphics->ready = true; } #endif return 0; }
void CommGraphWriter::writeFullGraphToTextStream( size_t record_number, std::ostream& os) const { /* * Gather graph data on d_root_rank and write out. */ TBOX_ASSERT(record_number < d_records.size()); const Record& record = d_records[record_number]; MessageStream ostr; for (size_t inodev = 0; inodev < record.d_node_values.size(); ++inodev) { const NodeValue& nodev = record.d_node_values[inodev]; ostr << nodev.d_value; } for (size_t iedge = 0; iedge < record.d_edges.size(); ++iedge) { const Edge& edge = record.d_edges[iedge]; ostr << edge.d_value << edge.d_dir << edge.d_other_node; } std::vector<char> tmpbuf(record.d_mpi.getRank() == d_root_rank ? ostr.getCurrentSize() * record.d_mpi.getSize() : 0); if (ostr.getCurrentSize() > 0) { record.d_mpi.Gather( (void *)ostr.getBufferStart(), int(ostr.getCurrentSize()), MPI_CHAR, (record.d_mpi.getRank() == d_root_rank ? &tmpbuf[0] : 0), int(record.d_mpi.getRank() == d_root_rank ? ostr.getCurrentSize() : 0), MPI_CHAR, d_root_rank); } os.setf(std::ios_base::fmtflags(0), std::ios_base::floatfield); os.precision(8); std::vector<NodeValue> max_nodev(record.d_node_values.size()); std::vector<Edge> max_edge(record.d_edges.size()); if (record.d_mpi.getRank() == d_root_rank) { os << "\nCommGraphWriter begin record number " << record_number << '\n'; os << "# proc" << '\t' << "dir" << '\t' << "remote" << '\t' << "value" << '\t' << "label\n"; if (!tmpbuf.empty()) { MessageStream istr(tmpbuf.size(), MessageStream::Read, &tmpbuf[0], false); for (int src_rank = 0; src_rank < record.d_mpi.getSize(); ++src_rank) { NodeValue tmpnodev; for (size_t inodev = 0; inodev < record.d_node_values.size(); ++inodev) { istr >> tmpnodev.d_value; os << src_rank << '\t' << tmpnodev.d_value << '\t' << record.d_node_values[inodev].d_label << '\n'; if (max_nodev[inodev].d_value < tmpnodev.d_value) { max_nodev[inodev] = tmpnodev; } } Edge tmpedge; for (size_t iedge = 0; iedge < record.d_edges.size(); ++iedge) { istr >> tmpedge.d_value >> tmpedge.d_dir >> tmpedge.d_other_node; os << src_rank << '\t' << (tmpedge.d_dir == FROM ? "<-" : "->") << '\t' << tmpedge.d_other_node << '\t' << tmpedge.d_value << '\t' << record.d_edges[iedge].d_label << '\n'; if (max_edge[iedge].d_value < tmpedge.d_value) { max_edge[iedge] = tmpedge; } } } }
void mbr_parse(char letter) { boot_record_t *br; uint8_t i, seen = 0; uint32_t ep_offset = 0, br_offset = 0; uint8_t next = 0; kprintf("hd%c: ", letter); /* allocate temporary memory */ br = (boot_record_t *)tmpbuf(); blk_op.is_read = true; blk_op.is_user = false; blk_op.addr = (uint8_t *)br; blk_op.lba = 0; do{ blk_op.nblock = 1; if(!blk_op.blkdev->transfer() || le16_to_cpu(br->signature) != MBR_SIGNATURE){ #ifdef CONFIG_MBR_OFFSET if (blk_op.lba == 0) { /* failed to find MBR on block 0. Go round again but this time look at the fall-back location for this badly-behaved media */ blk_op.lba = CONFIG_MBR_OFFSET; continue; } #endif break; } /* avoid an infinite loop where extended boot records form a loop */ if(seen >= 50) break; if(seen == 1){ /* we just loaded the first extended boot record */ ep_offset = blk_op.lba; next = 4; kputs("< "); } br_offset = blk_op.lba; blk_op.lba = 0; for(i=0; i<MBR_ENTRY_COUNT && next < MAX_PARTITIONS; i++){ switch(br->partition[i].type_chs_last[0]){ #ifdef CONFIG_GPT case MBR_GPT_PROTECTED_TYPE: // TODO assert next is zero (unless hybrid...) parse_gpt((uint8_t *) br, i); goto out; #endif case 0: break; case 0x05: case 0x0f: case 0x85: /* Extended boot record, or chained table; in principle a drive should contain at most one extended partition so this code is OK even for parsing the MBR. Chained EBR addresses are relative to the start of the extended partiton. */ blk_op.lba = ep_offset + le32_to_cpu(br->partition[i].lba_first); if(next >= 4) break; /* we include all primary partitions but we deliberately knobble the size in order to prevent catastrophic accidents */ br->partition[i].lba_count = cpu_to_le32(2L); /* fall through */ default: /* Regular partition: In EBRs these are relative to the EBR (not the disk, nor the extended partition) */ blk_op.blkdev->lba_first[next] = br_offset + le32_to_cpu(br->partition[i].lba_first); blk_op.blkdev->lba_count[next] = le32_to_cpu(br->partition[i].lba_count); next++; kprintf("hd%c%d ", letter, next); } } seen++; }while(blk_op.lba); if(ep_offset && next >= 4) kputs("> "); out: /* release temporary memory */ tmpfree(br); }
char *pathbuf(void) { return tmpbuf(); }
IDL_VPTR readwu(int argc, IDL_VPTR argv[], char *argk) { IDL_VPTR filename=NULL; static IDL_VARIABLE rv; rv.type=IDL_TYP_INT; rv.flags=IDL_V_CONST|IDL_V_NULL; rv.value.i=-1; char *outfile=NULL, buf[256]; struct stat statbuf; int nbytes,nread,nsamples; std::string tmpbuf(""); int i=0,j; if (argc != 1) { fprintf(stderr,"argc=%d\n",argc); fprintf(stderr,"array=readwu(wufile_name)\n"); return &rv; } IDL_STRING *infile=NULL; if (argv[0]->type != IDL_TYP_STRING) { IDL_MessageFromBlock(readwu_msg_block,0,IDL_MSG_RET,"Parameter 1 must be type STRING"); } else { infile=(IDL_STRING *)(&argv[0]->value.s); } FILE *in=fopen(infile->s,"r"); if (!in) { IDL_MessageFromBlock(readwu_msg_block,0,IDL_MSG_RET,"File not found"); return &rv; } stat(infile->s,&statbuf); nbytes=statbuf.st_size; fseek(in,0,SEEK_SET); tmpbuf.reserve(nbytes); // read entire file into a buffer. while ((nread=(int)fread(buf,1,sizeof(buf),in))) { tmpbuf+=std::string(&(buf[0]),nread); } // parse the header header.parse_xml(tmpbuf); // decode the data std::vector<unsigned char> datav( xml_decode_field<unsigned char>(tmpbuf,"data") ); tmpbuf.clear(); nsamples=header.group_info->data_desc.nsamples; nbytes=nsamples*header.group_info->recorder_cfg->bits_per_sample/8; if (datav.size() < nbytes) { fprintf(stderr,"Data size does not match number of samples\n"); return &rv; } // convert the data to floating point sah_complex *fpdata=(sah_complex *)IDL_MemAlloc(nsamples*sizeof(sah_complex),0,IDL_MSG_RET); if (!fpdata) { fprintf(stderr,"Unable to allocate memory!\r\n"); return &rv; } bits_to_floats(&(datav[0]),fpdata,nsamples); datav.clear(); IDL_MEMINT dims[]={nsamples}; return IDL_ImportArray(1,dims,IDL_TYP_COMPLEX,(UCHAR *)fpdata,NULL,NULL); }
void devide_init_drive(uint_fast8_t drive) { blkdev_t *blk; uint8_t *buffer; uint_fast8_t select; select = (drive & 1) ? 0xF0 : 0xE0; ide_select(drive); devide_writeb(ide_reg_devhead, select); kprintf("IDE drive %d: ", drive); #ifdef IDE_8BIT_ONLY if (IDE_IS_8BIT(drive)) { /* set 8-bit mode -- mostly only supported by CF cards */ if (!devide_wait(IDE_STATUS_READY)) goto out; devide_writeb(ide_reg_devhead, select); if (!devide_wait(IDE_STATUS_READY)) goto out; devide_writeb(ide_reg_features, 0x01); /* Enable 8-bit PIO transfer mode (CFA feature set only) */ devide_writeb(ide_reg_command, IDE_CMD_SET_FEATURES); } #endif /* confirm drive has LBA support */ if (!devide_wait(IDE_STATUS_READY)) goto out; /* send identify command */ devide_writeb(ide_reg_devhead, select); devide_writeb(ide_reg_command, IDE_CMD_IDENTIFY); /* allocate temporary sector buffer memory */ buffer = (uint8_t *)tmpbuf(); if (!devide_wait(IDE_STATUS_DATAREQUEST)) goto failout; blk_op.is_user = false; blk_op.addr = buffer; blk_op.nblock = 1; devide_read_data(); #ifdef CONFIG_IDE_BSWAP if(!(buffer[98] & 0x02)) { #else if(!(buffer[99] & 0x02)) { #endif kputs("LBA unsupported.\n"); goto failout; } blk = blkdev_alloc(); if(!blk) goto failout; blk->transfer = devide_transfer_sector; blk->flush = devide_flush_cache; blk->driver_data = drive & IDE_DRIVE_NR_MASK; if( !(((uint16_t*)buffer)[82] == 0x0000 && ((uint16_t*)buffer)[83] == 0x0000) || (((uint16_t*)buffer)[82] == 0xFFFF && ((uint16_t*)buffer)[83] == 0xFFFF) ){ /* command set notification is supported */ if(buffer[164] & 0x20){ /* write cache is supported */ blk->driver_data |= FLAG_WRITE_CACHE; } } /* read out the drive's sector count */ blk->drive_lba_count = le32_to_cpu(*((uint32_t*)&buffer[120])); /* done with our temporary memory */ tmpfree(buffer); /* Deselect the IDE, as we will re-select it in the partition scan and it may not recursively stack de-selections */ ide_deselect(); /* scan partitions */ blkdev_scan(blk, SWAPSCAN); return; failout: tmpfree(buffer); out: ide_deselect(); return; } void devide_init(void) { uint_fast8_t d; #ifdef IDE_HAS_RESET devide_reset(); #endif for(d=0; d < IDE_DRIVE_COUNT; d++) devide_init_drive(d); }