/** * @brief BTRecordFile::readRecordFromDiskTest * @param pDisk * @param pRecordID * Hace la lectura de un registro en la RAM */ void BTRecordFile::readRecordFromDiskTest(Disk pDisk, unsigned short pRecordID) { const char *padre = pDisk.read(this->_metadataPtr->getFirstRecordPos(), 7); const char *hizq = pDisk.read(this->_metadataPtr->getFirstRecordPos() + 8, 7); const char *hder = pDisk.read(this->_metadataPtr->getFirstRecordPos() + 16, 7); std::string father(padre); // obtiene el padre std::string HI(hizq); // obtiene el hijo izq std::string HD(hder); // obtiene el hijo der unsigned short _sizeCounter = this->_metadataPtr->getFirstRecordPos() + 24; // inicio de la data DLL<IRecordDataType*> *tmp1 = _metadataPtr->getRecordStruct(); DLLNode<IRecordDataType*> *tmp = tmp1->getHeadPtr(); const char *data; cout << "Binario " << father << " " << HI << " " << HD << endl; std::string P = _conversion->binaryToDecimal(father); std::string PHI = _conversion->binaryToDecimal(HI); std::string PHD = _conversion->binaryToDecimal(HD); cout << P << " " << PHI << " " << PHD << " "; while (tmp != nullptr) { data = (dynamic_cast<RecordDataType<char>*>(tmp->getData()))->getDataPtr(); const char *DATO = pDisk.read(_sizeCounter, 7); std::string DATOSTR(DATO); // obtiene el padre _sizeCounter += 8; cout << sortUserDataFromDisk(DATOSTR, *data) << endl; tmp = tmp->getNextPtr(); } }
static void map_dma(unsigned int i, unsigned int j) { unsigned int data_len = 0; unsigned int k, pci_dir; int count; struct scatterlist *sg; struct mscp *cpp; struct scsi_cmnd *SCpnt; cpp = &HD(j)->cp[i]; SCpnt = cpp->SCpnt; pci_dir = SCpnt->sc_data_direction; if (SCpnt->sense_buffer) cpp->sense_addr = H2DEV(pci_map_single(HD(j)->pdev, SCpnt->sense_buffer, SCSI_SENSE_BUFFERSIZE, PCI_DMA_FROMDEVICE)); cpp->sense_len = SCSI_SENSE_BUFFERSIZE; if (scsi_bufflen(SCpnt)) { count = scsi_dma_map(SCpnt); BUG_ON(count < 0); scsi_for_each_sg(SCpnt, sg, count, k) { cpp->sglist[k].address = H2DEV(sg_dma_address(sg)); cpp->sglist[k].num_bytes = H2DEV(sg_dma_len(sg)); data_len += sg->length; } cpp->sg = TRUE; cpp->use_sg = scsi_sg_count(SCpnt); cpp->data_address = H2DEV(pci_map_single(HD(j)->pdev, cpp->sglist, cpp->use_sg * sizeof(struct sg_list), pci_dir)); cpp->data_len = H2DEV(data_len); } else {
static int getentropy_fallback(void *buf, size_t len) { uint8_t results[SHA512_DIGEST_LENGTH]; int save_errno = errno, e, pgs = sysconf(_SC_PAGESIZE), faster = 0, repeat; static int cnt; struct timespec ts; struct timeval tv; perfstat_cpu_total_t cpustats; #ifdef _AIX61 perfstat_cpu_total_wpar_t cpustats_wpar; #endif perfstat_partition_total_t lparstats; perfstat_disk_total_t diskinfo; perfstat_netinterface_total_t netinfo; struct rusage ru; sigset_t sigset; struct stat st; SHA512_CTX ctx; static pid_t lastpid; pid_t pid; size_t i, ii, m; char *p; pid = getpid(); if (lastpid == pid) { faster = 1; repeat = 2; } else { faster = 0; lastpid = pid; repeat = REPEAT; } for (i = 0; i < len; ) { int j; SHA512_Init(&ctx); for (j = 0; j < repeat; j++) { HX((e = gettimeofday(&tv, NULL)) == -1, tv); if (e != -1) { cnt += (int)tv.tv_sec; cnt += (int)tv.tv_usec; } HX(perfstat_cpu_total(NULL, &cpustats, sizeof(cpustats), 1) == -1, cpustats); #ifdef _AIX61 HX(perfstat_cpu_total_wpar(NULL, &cpustats_wpar, sizeof(cpustats_wpar), 1) == -1, cpustats_wpar); #endif HX(perfstat_partition_total(NULL, &lparstats, sizeof(lparstats), 1) == -1, lparstats); HX(perfstat_disk_total(NULL, &diskinfo, sizeof(diskinfo), 1) == -1, diskinfo); HX(perfstat_netinterface_total(NULL, &netinfo, sizeof(netinfo), 1) == -1, netinfo); for (ii = 0; ii < sizeof(cl)/sizeof(cl[0]); ii++) HX(clock_gettime(cl[ii], &ts) == -1, ts); HX((pid = getpid()) == -1, pid); HX((pid = getsid(pid)) == -1, pid); HX((pid = getppid()) == -1, pid); HX((pid = getpgid(0)) == -1, pid); HX((e = getpriority(0, 0)) == -1, e); if (!faster) { ts.tv_sec = 0; ts.tv_nsec = 1; (void) nanosleep(&ts, NULL); } HX(sigpending(&sigset) == -1, sigset); HX(sigprocmask(SIG_BLOCK, NULL, &sigset) == -1, sigset); HF(getentropy); /* an addr in this library */ HF(printf); /* an addr in libc */ p = (char *)&p; HD(p); /* an addr on stack */ p = (char *)&errno; HD(p); /* the addr of errno */ if (i == 0) { struct sockaddr_storage ss; struct statvfs stvfs; struct termios tios; socklen_t ssl; off_t off; /* * Prime-sized mappings encourage fragmentation; * thus exposing some address entropy. */ struct mm { size_t npg; void *p; } mm[] = { { 17, MAP_FAILED }, { 3, MAP_FAILED }, { 11, MAP_FAILED }, { 2, MAP_FAILED }, { 5, MAP_FAILED }, { 3, MAP_FAILED }, { 7, MAP_FAILED }, { 1, MAP_FAILED }, { 57, MAP_FAILED }, { 3, MAP_FAILED }, { 131, MAP_FAILED }, { 1, MAP_FAILED }, }; for (m = 0; m < sizeof mm/sizeof(mm[0]); m++) { HX(mm[m].p = mmap(NULL, mm[m].npg * pgs, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, -1, (off_t)0), mm[m].p); if (mm[m].p != MAP_FAILED) { size_t mo; /* Touch some memory... */ p = mm[m].p; mo = cnt % (mm[m].npg * pgs - 1); p[mo] = 1; cnt += (int)((long)(mm[m].p) / pgs); } /* Check cnts and times... */ for (ii = 0; ii < sizeof(cl)/sizeof(cl[0]); ii++) { HX((e = clock_gettime(cl[ii], &ts)) == -1, ts); if (e != -1) cnt += (int)ts.tv_nsec; } HX((e = getrusage(RUSAGE_SELF, &ru)) == -1, ru); if (e != -1) { cnt += (int)ru.ru_utime.tv_sec; cnt += (int)ru.ru_utime.tv_usec; } } for (m = 0; m < sizeof mm/sizeof(mm[0]); m++) { if (mm[m].p != MAP_FAILED) munmap(mm[m].p, mm[m].npg * pgs); mm[m].p = MAP_FAILED; } HX(stat(".", &st) == -1, st); HX(statvfs(".", &stvfs) == -1, stvfs); HX(stat("/", &st) == -1, st); HX(statvfs("/", &stvfs) == -1, stvfs); HX((e = fstat(0, &st)) == -1, st); if (e == -1) { if (S_ISREG(st.st_mode) || S_ISFIFO(st.st_mode) || S_ISSOCK(st.st_mode)) { HX(fstatvfs(0, &stvfs) == -1, stvfs); HX((off = lseek(0, (off_t)0, SEEK_CUR)) < 0, off); } if (S_ISCHR(st.st_mode)) { HX(tcgetattr(0, &tios) == -1, tios); } else if (S_ISSOCK(st.st_mode)) { memset(&ss, 0, sizeof ss); ssl = sizeof(ss); HX(getpeername(0, (void *)&ss, &ssl) == -1, ss); } } HX((e = getrusage(RUSAGE_CHILDREN, &ru)) == -1, ru); if (e != -1) { cnt += (int)ru.ru_utime.tv_sec; cnt += (int)ru.ru_utime.tv_usec; } } else { /* Subsequent hashes absorb previous result */ HD(results); } HX((e = gettimeofday(&tv, NULL)) == -1, tv); if (e != -1) { cnt += (int)tv.tv_sec; cnt += (int)tv.tv_usec; } HD(cnt); } SHA512_Final(results, &ctx); memcpy((char *)buf + i, results, min(sizeof(results), len - i)); i += min(sizeof(results), len - i); } explicit_bzero(&ctx, sizeof ctx); explicit_bzero(results, sizeof results); if (gotdata(buf, len) == 0) { errno = save_errno; return 0; /* satisfied */ } errno = EIO; return -1; }
/*ARGSUSED*/ static int d_uberdata(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) { uberdata_t uberdata; int i; if (argc != 0) return (DCMD_USAGE); if (!(flags & DCMD_ADDRSPEC) && (addr = uberdata_addr()) == NULL) return (DCMD_ERR); if (mdb_vread(&uberdata, sizeof (uberdata), addr) != sizeof (uberdata)) { mdb_warn("failed to read uberdata at 0x%p", addr); return (DCMD_ERR); } mdb_printf("%#a\n", addr); HD("&link_lock &ld_lock &fork_lock"); mdb_printf(OFFSTR "%s %s %s\n", OFFSET(link_lock), prt_addr((void *)(addr + OFFSET(link_lock)), 1), prt_addr((void *)(addr + OFFSET(ld_lock)), 1), prt_addr((void *)(addr + OFFSET(fork_lock)), 0)); HD("&atfork_lock &callout_lock &tdb_hash_lock"); mdb_printf(OFFSTR "%s %s %s\n", OFFSET(atfork_lock), prt_addr((void *)(addr + OFFSET(atfork_lock)), 1), prt_addr((void *)(addr + OFFSET(callout_lock)), 1), prt_addr((void *)(addr + OFFSET(tdb_hash_lock)), 0)); HD("&tdb_hash_lock_stats &siguaction[0]"); mdb_printf(OFFSTR "%s %s\n", OFFSET(tdb_hash_lock_stats), prt_addr((void *)(addr + OFFSET(tdb_hash_lock_stats)), 1), prt_addr((void *)(addr + OFFSET(siguaction)), 0)); HD("&bucket free_list chunks"); for (i = 0; i < NBUCKETS; i++) { mdb_printf(OFFSTR "%s %s %ld\n", OFFSET(bucket[i]), prt_addr((void *)(addr + OFFSET(bucket[i])), 1), prt_addr(uberdata.bucket[i].free_list, 1), uberdata.bucket[i].chunks); } HD("&atexit_root head exit_frame_monitor"); mdb_printf(OFFSTR "%s %s %s\n", OFFSET(atexit_root), prt_addr((void *)(addr + OFFSET(atexit_root.exitfns_lock)), 1), prt_addr(uberdata.atexit_root.head, 1), prt_addr(uberdata.atexit_root.exit_frame_monitor, 0)); HD("&tsd_metadata tsdm_nkeys tsdm_nused tsdm_destro"); mdb_printf(OFFSTR "%s %-10d %-10d %s\n", OFFSET(tsd_metadata), prt_addr((void *)(addr + OFFSET(tsd_metadata.tsdm_lock)), 1), uberdata.tsd_metadata.tsdm_nkeys, uberdata.tsd_metadata.tsdm_nused, prt_addr((void *)uberdata.tsd_metadata.tsdm_destro, 0)); HD("&tls_metadata tls_modinfo.data tls_modinfo.size"); mdb_printf(OFFSTR "%s %s %ld\n", OFFSET(tls_metadata), prt_addr((void *)(addr + OFFSET(tls_metadata.tls_lock)), 1), prt_addr(uberdata.tls_metadata.tls_modinfo.tls_data, 1), uberdata.tls_metadata.tls_modinfo.tls_size); HD(" static_tls.data static_tls.size"); mdb_printf(OFFSTR "%s %s %ld\n", OFFSET(tls_metadata.static_tls), " ", prt_addr(uberdata.tls_metadata.static_tls.tls_data, 1), uberdata.tls_metadata.static_tls.tls_size); HD("primary_ma bucket_ini uflags.mt uflags.pad uflags.trs uflags.ted"); mdb_printf(OFFSTR "%-10d %-10d %-10d %-10d %-10d %d\n", OFFSET(primary_map), uberdata.primary_map, uberdata.bucket_init, uberdata.uberflags.uf_x.x_mt, uberdata.uberflags.uf_x.x_pad, uberdata.uberflags.uf_x.x_tdb_register_sync, uberdata.uberflags.uf_x.x_thread_error_detection); HD("queue_head thr_hash_table hash_size hash_mask"); mdb_printf(OFFSTR "%s %s %-10d 0x%x\n", OFFSET(queue_head), prt_addr(uberdata.queue_head, 1), prt_addr(uberdata.thr_hash_table, 1), uberdata.hash_size, uberdata.hash_mask); HD("ulwp_one all_lwps all_zombies"); mdb_printf(OFFSTR "%s %s %s\n", OFFSET(ulwp_one), prt_addr(uberdata.ulwp_one, 1), prt_addr(uberdata.all_lwps, 1), prt_addr(uberdata.all_zombies, 0)); HD("nthreads nzombies ndaemons pid sigacthandler"); mdb_printf(OFFSTR "%-10d %-10d %-10d %-10d %s\n", OFFSET(nthreads), uberdata.nthreads, uberdata.nzombies, uberdata.ndaemons, (int)uberdata.pid, prt_addr((void *)uberdata.sigacthandler, 0)); HD("lwp_stacks lwp_laststack nfreestack stk_cache"); mdb_printf(OFFSTR "%s %s %-10d %d\n", OFFSET(lwp_stacks), prt_addr(uberdata.lwp_stacks, 1), prt_addr(uberdata.lwp_laststack, 1), uberdata.nfreestack, uberdata.thread_stack_cache); HD("ulwp_freelist ulwp_lastfree ulwp_replace_free"); mdb_printf(OFFSTR "%s %s %s\n", OFFSET(ulwp_freelist), prt_addr(uberdata.ulwp_freelist, 1), prt_addr(uberdata.ulwp_lastfree, 1), prt_addr(uberdata.ulwp_replace_free, 0)); HD("ulwp_replace_last atforklist"); mdb_printf(OFFSTR "%s %s\n", OFFSET(ulwp_replace_last), prt_addr(uberdata.ulwp_replace_last, 1), prt_addr(uberdata.atforklist, 0)); HD("robustlocks robustlist progname"); mdb_printf(OFFSTR "%s %s %s\n", OFFSET(robustlocks), prt_addr(uberdata.robustlocks, 1), prt_addr(uberdata.robustlist, 1), prt_addr(uberdata.progname, 0)); HD("tdb_bootstrap tdb_sync_addr_hash tdb_'count tdb_'fail"); mdb_printf(OFFSTR "%s %s %-10d %d\n", OFFSET(tdb_bootstrap), prt_addr(uberdata.tdb_bootstrap, 1), prt_addr(uberdata.tdb.tdb_sync_addr_hash, 1), uberdata.tdb.tdb_register_count, uberdata.tdb.tdb_hash_alloc_failed); HD("tdb_sync_addr_free tdb_sync_addr_last tdb_sync_alloc"); mdb_printf(OFFSTR "%s %s %ld\n", OFFSET(tdb.tdb_sync_addr_free), prt_addr(uberdata.tdb.tdb_sync_addr_free, 1), prt_addr(uberdata.tdb.tdb_sync_addr_last, 1), uberdata.tdb.tdb_sync_alloc); HD("tdb_ev_global_mask tdb_events"); mdb_printf(OFFSTR "0x%08x 0x%08x %s\n", OFFSET(tdb.tdb_ev_global_mask), uberdata.tdb.tdb_ev_global_mask.event_bits[0], uberdata.tdb.tdb_ev_global_mask.event_bits[1], prt_addr((void *)uberdata.tdb.tdb_events, 0)); return (DCMD_OK); }
/*ARGSUSED*/ static int d_ulwp(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) { ulwp_t ulwp; if (argc != 0 || !(flags & DCMD_ADDRSPEC)) return (DCMD_USAGE); if (mdb_vread(&ulwp, sizeof (ulwp), addr) != sizeof (ulwp) && (bzero(&ulwp, sizeof (ulwp)), mdb_vread(&ulwp, REPLACEMENT_SIZE, addr)) != REPLACEMENT_SIZE) { mdb_warn("failed to read ulwp at 0x%p", addr); return (DCMD_ERR); } mdb_printf("%#a\n", addr); HD("self uberdata"); mdb_printf(OFFSTR "%s %s\n", OFFSET(ul_self), prt_addr(ulwp.ul_self, 1), prt_addr(ulwp.ul_uberdata, 0)); HD("tlsent ntlsent"); mdb_printf(OFFSTR "%s %ld\n", OFFSET(ul_tlsent), prt_addr(ulwp.ul_tlsent, 1), ulwp.ul_ntlsent); HD("forw back next"); mdb_printf(OFFSTR "%s %s %s\n", OFFSET(ul_forw), prt_addr(ulwp.ul_forw, 1), prt_addr(ulwp.ul_back, 1), prt_addr(ulwp.ul_next, 0)); HD("hash rval stk"); mdb_printf(OFFSTR "%s %s %s\n", OFFSET(ul_hash), prt_addr(ulwp.ul_hash, 1), prt_addr(ulwp.ul_rval, 1), prt_addr(ulwp.ul_stk, 0)); HD("mapsiz guardsize stktop stksiz"); mdb_printf(OFFSTR "%-10ld %-10ld %s %ld\n", OFFSET(ul_mapsiz), ulwp.ul_mapsiz, ulwp.ul_guardsize, prt_addr((void *)ulwp.ul_stktop, 1), ulwp.ul_stksiz); HD("ustack.ss_sp ustack.ss_size ustack.ss_flags"); mdb_printf(OFFSTR "%s %-21ld %s\n", OFFSET(ul_ustack.ss_sp), prt_addr(ulwp.ul_ustack.ss_sp, 1), ulwp.ul_ustack.ss_size, stack_flags(&ulwp.ul_ustack)); HD("ix lwpid pri epri policy cid"); mdb_printf(OFFSTR "%-10d %-10d %-10d %-10d %-10d %d\n", OFFSET(ul_ix), ulwp.ul_ix, ulwp.ul_lwpid, ulwp.ul_pri, ulwp.ul_epri, ulwp.ul_policy, ulwp.ul_cid); HD("cursig pleasestop stop signalled dead unwind"); mdb_printf(OFFSTR "%-10d ", OFFSET(ul_cursig), ulwp.ul_cursig); mdb_printf(ulwp.ul_pleasestop? "0x%-8x " : "%-10d ", ulwp.ul_pleasestop); mdb_printf(ulwp.ul_stop? "0x%-8x " : "%-10d ", ulwp.ul_stop); mdb_printf("%-10d %-10d %d\n", ulwp.ul_signalled, ulwp.ul_dead, ulwp.ul_unwind); HD("detached writer stopping can'prolog preempt savpreempt"); mdb_printf(OFFSTR "%-10d %-10d %-10d %-10d %-10d %d\n", OFFSET(ul_detached), ulwp.ul_detached, ulwp.ul_writer, ulwp.ul_stopping, ulwp.ul_cancel_prologue, ulwp.ul_preempt, ulwp.ul_savpreempt); HD("sigsuspend main fork primarymap m'spinners d'noreserv"); mdb_printf(OFFSTR "%-10d %-10d %-10d %-10d %-10d %d\n", OFFSET(ul_sigsuspend), ulwp.ul_sigsuspend, ulwp.ul_main, ulwp.ul_fork, ulwp.ul_primarymap, ulwp.ul_max_spinners, ulwp.ul_door_noreserve); HD("queue_fifo c'w'defer e'detect' async_safe rt rtqueued"); mdb_printf(OFFSTR "%-10d %-10d %-10d %-10d %-10d %d\n", OFFSET(ul_queue_fifo), ulwp.ul_queue_fifo, ulwp.ul_cond_wait_defer, ulwp.ul_error_detection, ulwp.ul_async_safe, ulwp.ul_rt, ulwp.ul_rtqueued); HD("misaligned adapt'spin queue_spin critical sigdefer vfork"); mdb_printf(OFFSTR "%-10d %-10d %-10d %-10d %-10d %d\n", OFFSET(ul_misaligned), ulwp.ul_misaligned, ulwp.ul_adaptive_spin, ulwp.ul_queue_spin, ulwp.ul_critical, ulwp.ul_sigdefer, ulwp.ul_vfork); HD("cancelable c'pending c'disabled c'async save_async mutator"); mdb_printf(OFFSTR "%-10d %-10d %-10d %-10d %-10d %d\n", OFFSET(ul_cancelable), ulwp.ul_cancelable, ulwp.ul_cancel_pending, ulwp.ul_cancel_disabled, ulwp.ul_cancel_async, ulwp.ul_save_async, ulwp.ul_mutator); HD("created replace nocancel errno errnop"); mdb_printf(OFFSTR "%-10d %-10d %-10d %-10d %s\n", OFFSET(ul_created), ulwp.ul_created, ulwp.ul_replace, ulwp.ul_nocancel, ulwp.ul_errno, prt_addr(ulwp.ul_errnop, 0)); HD("clnup_hdr schedctl_called schedctl"); mdb_printf(OFFSTR "%s %s %s\n", OFFSET(ul_clnup_hdr), prt_addr(ulwp.ul_clnup_hdr, 1), prt_addr(ulwp.ul_schedctl_called, 1), prt_addr((void *)ulwp.ul_schedctl, 0)); HD("bindflags libc_locks stsd &ftsd"); mdb_printf(OFFSTR, OFFSET(ul_bindflags)); mdb_printf(ulwp.ul_bindflags? "0x%-8x " : "%-10d ", ulwp.ul_bindflags); mdb_printf("%-10d ", ulwp.ul_libc_locks); mdb_printf("%s %s\n", prt_addr(ulwp.ul_stsd, 1), prt_addr((void *)(addr + OFFSET(ul_ftsd[0])), 0)); HD("eventmask[0..1] eventnum eventdata"); mdb_printf(OFFSTR "0x%08x 0x%08x %-21d %s\n", OFFSET(ul_td_evbuf.eventmask.event_bits[0]), ulwp.ul_td_evbuf.eventmask.event_bits[0], ulwp.ul_td_evbuf.eventmask.event_bits[1], ulwp.ul_td_evbuf.eventnum, prt_addr(ulwp.ul_td_evbuf.eventdata, 0)); HD("td'enable sync'reg qtype cv_wake rtld usropts"); mdb_printf(OFFSTR "%-10d %-10d %-10d %-10d %-10d ", OFFSET(ul_td_events_enable), ulwp.ul_td_events_enable, ulwp.ul_sync_obj_reg, ulwp.ul_qtype, ulwp.ul_cv_wake, ulwp.ul_rtld); mdb_printf(ulwp.ul_usropts? "0x%x\n" : "%d\n", ulwp.ul_usropts); HD("startpc startarg wchan"); mdb_printf(OFFSTR "%s %s %s\n", OFFSET(ul_startpc), prt_addr((void *)ulwp.ul_startpc, 1), prt_addr(ulwp.ul_startarg, 1), prt_addr(ulwp.ul_wchan, 0)); HD("link sleepq cvmutex"); mdb_printf(OFFSTR "%s %s %s\n", OFFSET(ul_link), prt_addr(ulwp.ul_link, 1), prt_addr(ulwp.ul_sleepq, 1), prt_addr(ulwp.ul_cvmutex, 0)); HD("mxchain save_state"); mdb_printf(OFFSTR "%s %d\n", OFFSET(ul_mxchain), prt_addr(ulwp.ul_mxchain, 1), ulwp.ul_save_state); HD("rdlockcnt rd_rwlock rd_count"); mdb_printf(OFFSTR "%-21d %s %d\n", OFFSET(ul_rdlockcnt), ulwp.ul_rdlockcnt, prt_addr(ulwp.ul_readlock.single.rd_rwlock, 1), ulwp.ul_readlock.single.rd_count); HD("heldlockcnt heldlocks tpdp"); mdb_printf(OFFSTR "%-21d %s %s\n", OFFSET(ul_heldlockcnt), ulwp.ul_heldlockcnt, prt_addr(ulwp.ul_heldlocks.single, 1), prt_addr(ulwp.ul_tpdp, 0)); HD("siglink s'l'spin s'l'spin2 s'l'sleep s'l'wakeup"); mdb_printf(OFFSTR "%s %-10d %-10d %-10d %d\n", OFFSET(ul_siglink), prt_addr(ulwp.ul_siglink, 1), ulwp.ul_spin_lock_spin, ulwp.ul_spin_lock_spin2, ulwp.ul_spin_lock_sleep, ulwp.ul_spin_lock_wakeup); HD("&queue_root rtclassid pilocks"); mdb_printf(OFFSTR "%s %-10d %d\n", OFFSET(ul_queue_root), prt_addr((void *)(addr + OFFSET(ul_queue_root)), 1), ulwp.ul_rtclassid, ulwp.ul_pilocks); /* * The remainder of the ulwp_t structure * is invalid if this is a replacement. */ if (ulwp.ul_replace) return (DCMD_OK); HD("sigmask[0..3]"); mdb_printf(OFFSTR "0x%08x 0x%08x 0x%08x 0x%08x\n", OFFSET(ul_sigmask.__sigbits[0]), ulwp.ul_sigmask.__sigbits[0], ulwp.ul_sigmask.__sigbits[1], ulwp.ul_sigmask.__sigbits[2], ulwp.ul_sigmask.__sigbits[3]); HD("tmpmask[0..3]"); mdb_printf(OFFSTR "0x%08x 0x%08x 0x%08x 0x%08x\n", OFFSET(ul_tmpmask.__sigbits[0]), ulwp.ul_tmpmask.__sigbits[0], ulwp.ul_tmpmask.__sigbits[1], ulwp.ul_tmpmask.__sigbits[2], ulwp.ul_tmpmask.__sigbits[3]); HD("&siginfo &spinlock &fpuenv"); mdb_printf(OFFSTR "%s %s %s\n", OFFSET(ul_siginfo), prt_addr((void *)(addr + OFFSET(ul_siginfo)), 1), prt_addr((void *)(addr + OFFSET(ul_spinlock)), 1), prt_addr((void *)(addr + OFFSET(ul_fpuenv)), 0)); HD("tmem.size &tmem.roots"); mdb_printf(OFFSTR "%-21H %s\n", OFFSET(ul_tmem), ulwp.ul_tmem.tm_size, prt_addr((void *)(addr + OFFSET(ul_tmem) + sizeof (size_t)), 0)); return (DCMD_OK); }
static int getentropy_fallback(void *buf, size_t len) { uint8_t results[SHA512_DIGEST_LENGTH]; int save_errno = errno, e, pgs = getpagesize(), faster = 0, repeat; static int cnt; struct timespec ts; struct timeval tv; struct rusage ru; sigset_t sigset; struct stat st; SHA512_CTX ctx; static pid_t lastpid; pid_t pid; size_t i, ii, m; char *p; struct tcpstat tcpstat; struct udpstat udpstat; struct ipstat ipstat; u_int64_t mach_time; unsigned int idata; void *addr; pid = getpid(); if (lastpid == pid) { faster = 1; repeat = 2; } else { faster = 0; lastpid = pid; repeat = REPEAT; } for (i = 0; i < len; ) { int j; SHA512_Init(&ctx); for (j = 0; j < repeat; j++) { HX((e = gettimeofday(&tv, NULL)) == -1, tv); if (e != -1) { cnt += (int)tv.tv_sec; cnt += (int)tv.tv_usec; } mach_time = mach_absolute_time(); HD(mach_time); ii = sizeof(addr); HX(sysctl(kmib, sizeof(kmib) / sizeof(kmib[0]), &addr, &ii, NULL, 0) == -1, addr); ii = sizeof(idata); HX(sysctl(hwmib, sizeof(hwmib) / sizeof(hwmib[0]), &idata, &ii, NULL, 0) == -1, idata); ii = sizeof(tcpstat); HX(sysctl(tcpmib, sizeof(tcpmib) / sizeof(tcpmib[0]), &tcpstat, &ii, NULL, 0) == -1, tcpstat); ii = sizeof(udpstat); HX(sysctl(udpmib, sizeof(udpmib) / sizeof(udpmib[0]), &udpstat, &ii, NULL, 0) == -1, udpstat); ii = sizeof(ipstat); HX(sysctl(ipmib, sizeof(ipmib) / sizeof(ipmib[0]), &ipstat, &ii, NULL, 0) == -1, ipstat); HX((pid = getpid()) == -1, pid); HX((pid = getsid(pid)) == -1, pid); HX((pid = getppid()) == -1, pid); HX((pid = getpgid(0)) == -1, pid); HX((e = getpriority(0, 0)) == -1, e); if (!faster) { ts.tv_sec = 0; ts.tv_nsec = 1; (void) nanosleep(&ts, NULL); } HX(sigpending(&sigset) == -1, sigset); HX(sigprocmask(SIG_BLOCK, NULL, &sigset) == -1, sigset); HF(getentropy); /* an addr in this library */ HF(printf); /* an addr in libc */ p = (char *)&p; HD(p); /* an addr on stack */ p = (char *)&errno; HD(p); /* the addr of errno */ if (i == 0) { struct sockaddr_storage ss; struct statvfs stvfs; struct termios tios; struct statfs stfs; socklen_t ssl; off_t off; /* * Prime-sized mappings encourage fragmentation; * thus exposing some address entropy. */ struct mm { size_t npg; void *p; } mm[] = { { 17, MAP_FAILED }, { 3, MAP_FAILED }, { 11, MAP_FAILED }, { 2, MAP_FAILED }, { 5, MAP_FAILED }, { 3, MAP_FAILED }, { 7, MAP_FAILED }, { 1, MAP_FAILED }, { 57, MAP_FAILED }, { 3, MAP_FAILED }, { 131, MAP_FAILED }, { 1, MAP_FAILED }, }; for (m = 0; m < sizeof mm/sizeof(mm[0]); m++) { HX(mm[m].p = mmap(NULL, mm[m].npg * pgs, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, -1, (off_t)0), mm[m].p); if (mm[m].p != MAP_FAILED) { size_t mo; /* Touch some memory... */ p = mm[m].p; mo = cnt % (mm[m].npg * pgs - 1); p[mo] = 1; cnt += (int)((long)(mm[m].p) / pgs); } /* Check cnts and times... */ mach_time = mach_absolute_time(); HD(mach_time); cnt += (int)mach_time; HX((e = getrusage(RUSAGE_SELF, &ru)) == -1, ru); if (e != -1) { cnt += (int)ru.ru_utime.tv_sec; cnt += (int)ru.ru_utime.tv_usec; } } for (m = 0; m < sizeof mm/sizeof(mm[0]); m++) { if (mm[m].p != MAP_FAILED) munmap(mm[m].p, mm[m].npg * pgs); mm[m].p = MAP_FAILED; } HX(stat(".", &st) == -1, st); HX(statvfs(".", &stvfs) == -1, stvfs); HX(statfs(".", &stfs) == -1, stfs); HX(stat("/", &st) == -1, st); HX(statvfs("/", &stvfs) == -1, stvfs); HX(statfs("/", &stfs) == -1, stfs); HX((e = fstat(0, &st)) == -1, st); if (e == -1) { if (S_ISREG(st.st_mode) || S_ISFIFO(st.st_mode) || S_ISSOCK(st.st_mode)) { HX(fstatvfs(0, &stvfs) == -1, stvfs); HX(fstatfs(0, &stfs) == -1, stfs); HX((off = lseek(0, (off_t)0, SEEK_CUR)) < 0, off); } if (S_ISCHR(st.st_mode)) { HX(tcgetattr(0, &tios) == -1, tios); } else if (S_ISSOCK(st.st_mode)) { memset(&ss, 0, sizeof ss); ssl = sizeof(ss); HX(getpeername(0, (void *)&ss, &ssl) == -1, ss); } } HX((e = getrusage(RUSAGE_CHILDREN, &ru)) == -1, ru); if (e != -1) { cnt += (int)ru.ru_utime.tv_sec; cnt += (int)ru.ru_utime.tv_usec; } } else { /* Subsequent hashes absorb previous result */ HD(results); } HX((e = gettimeofday(&tv, NULL)) == -1, tv); if (e != -1) { cnt += (int)tv.tv_sec; cnt += (int)tv.tv_usec; } HD(cnt); } SHA512_Final(results, &ctx); memcpy((char *)buf + i, results, min(sizeof(results), len - i)); i += min(sizeof(results), len - i); } explicit_bzero(&ctx, sizeof ctx); explicit_bzero(results, sizeof results); if (gotdata(buf, len) == 0) { errno = save_errno; return (0); /* satisfied */ } errno = EIO; return (-1); }
static int getentropy_fallback(void *buf, size_t len) { uint8_t results[SHA512_DIGEST_LENGTH]; int save_errno = errno, e, pgs = getpagesize(), faster = 0, repeat; static int cnt; struct timespec ts; struct timeval tv; struct rusage ru; sigset_t sigset; struct stat st; SHA512_CTX ctx; static pid_t lastpid; pid_t pid; size_t i, ii, m; char *p; pid = getpid(); if (lastpid == pid) { faster = 1; repeat = 2; } else { faster = 0; lastpid = pid; repeat = REPEAT; } for (i = 0; i < len; ) { int j; SHA512_Init(&ctx); for (j = 0; j < repeat; j++) { HX((e = gettimeofday(&tv, NULL)) == -1, tv); if (e != -1) { cnt += (int)tv.tv_sec; cnt += (int)tv.tv_usec; } dl_iterate_phdr(getentropy_phdr, &ctx); for (ii = 0; ii < sizeof(cl)/sizeof(cl[0]); ii++) HX(clock_gettime(cl[ii], &ts) == -1, ts); HX((pid = getpid()) == -1, pid); HX((pid = getsid(pid)) == -1, pid); HX((pid = getppid()) == -1, pid); HX((pid = getpgid(0)) == -1, pid); HX((e = getpriority(0, 0)) == -1, e); if (!faster) { ts.tv_sec = 0; ts.tv_nsec = 1; (void) nanosleep(&ts, NULL); } HX(sigpending(&sigset) == -1, sigset); HX(sigprocmask(SIG_BLOCK, NULL, &sigset) == -1, sigset); #if 0 HF(main); /* an addr in program */ #endif HF(getentropy); /* an addr in this library */ HF(printf); /* an addr in libc */ p = (char *)&p; HD(p); /* an addr on stack */ p = (char *)&errno; HD(p); /* the addr of errno */ if (i == 0) { struct sockaddr_storage ss; struct statvfs stvfs; struct termios tios; struct statfs stfs; socklen_t ssl; off_t off; /* * Prime-sized mappings encourage fragmentation; * thus exposing some address entropy. */ struct mm { size_t npg; void *p; } mm[] = { { 17, MAP_FAILED }, { 3, MAP_FAILED }, { 11, MAP_FAILED }, { 2, MAP_FAILED }, { 5, MAP_FAILED }, { 3, MAP_FAILED }, { 7, MAP_FAILED }, { 1, MAP_FAILED }, { 57, MAP_FAILED }, { 3, MAP_FAILED }, { 131, MAP_FAILED }, { 1, MAP_FAILED }, }; for (m = 0; m < sizeof mm/sizeof(mm[0]); m++) { HX(mm[m].p = mmap(NULL, mm[m].npg * pgs, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, -1, (off_t)0), mm[m].p); if (mm[m].p != MAP_FAILED) { size_t mo; /* Touch some memory... */ p = mm[m].p; mo = cnt % (mm[m].npg * pgs - 1); p[mo] = 1; cnt += (int)((long)(mm[m].p) / pgs); } /* Check cnts and times... */ for (ii = 0; ii < sizeof(cl)/sizeof(cl[0]); ii++) { HX((e = clock_gettime(cl[ii], &ts)) == -1, ts); if (e != -1) cnt += (int)ts.tv_nsec; } HX((e = getrusage(RUSAGE_SELF, &ru)) == -1, ru); if (e != -1) { cnt += (int)ru.ru_utime.tv_sec; cnt += (int)ru.ru_utime.tv_usec; } } for (m = 0; m < sizeof mm/sizeof(mm[0]); m++) { if (mm[m].p != MAP_FAILED) munmap(mm[m].p, mm[m].npg * pgs); mm[m].p = MAP_FAILED; } HX(stat(".", &st) == -1, st); HX(statvfs(".", &stvfs) == -1, stvfs); HX(statfs(".", &stfs) == -1, stfs); HX(stat("/", &st) == -1, st); HX(statvfs("/", &stvfs) == -1, stvfs); HX(statfs("/", &stfs) == -1, stfs); HX((e = fstat(0, &st)) == -1, st); if (e == -1) { if (S_ISREG(st.st_mode) || S_ISFIFO(st.st_mode) || S_ISSOCK(st.st_mode)) { HX(fstatvfs(0, &stvfs) == -1, stvfs); HX(fstatfs(0, &stfs) == -1, stfs); HX((off = lseek(0, (off_t)0, SEEK_CUR)) < 0, off); } if (S_ISCHR(st.st_mode)) { HX(tcgetattr(0, &tios) == -1, tios); } else if (S_ISSOCK(st.st_mode)) { memset(&ss, 0, sizeof ss); ssl = sizeof(ss); HX(getpeername(0, (void *)&ss, &ssl) == -1, ss); } } HX((e = getrusage(RUSAGE_CHILDREN, &ru)) == -1, ru); if (e != -1) { cnt += (int)ru.ru_utime.tv_sec; cnt += (int)ru.ru_utime.tv_usec; } } else { /* Subsequent hashes absorb previous result */ HD(results); } HX((e = gettimeofday(&tv, NULL)) == -1, tv); if (e != -1) { cnt += (int)tv.tv_sec; cnt += (int)tv.tv_usec; } HD(cnt); } #ifdef HAVE_GETAUXVAL #ifdef AT_RANDOM /* Not as random as you think but we take what we are given */ p = (char *) getauxval(AT_RANDOM); if (p) HR(p, 16); #endif #ifdef AT_SYSINFO_EHDR p = (char *) getauxval(AT_SYSINFO_EHDR); if (p) HR(p, pgs); #endif #ifdef AT_BASE p = (char *) getauxval(AT_BASE); if (p) HD(p); #endif #endif SHA512_Final(results, &ctx); memcpy((char *)buf + i, results, min(sizeof(results), len - i)); i += min(sizeof(results), len - i); } memset(results, 0, sizeof results); if (gotdata(buf, len) == 0) { errno = save_errno; return 0; /* satisfied */ } errno = EIO; return -1; }
static int port_detect \ (unsigned long port_base, unsigned int j, struct scsi_host_template *tpnt) { unsigned char irq, dma_channel, subversion, i; unsigned char in_byte; char *bus_type, dma_name[16]; /* Allowed BIOS base addresses (NULL indicates reserved) */ unsigned long bios_segment_table[8] = { 0, 0xc4000, 0xc8000, 0xcc000, 0xd0000, 0xd4000, 0xd8000, 0xdc000 }; /* Allowed IRQs */ unsigned char interrupt_table[4] = { 15, 14, 11, 10 }; /* Allowed DMA channels for ISA (0 indicates reserved) */ unsigned char dma_channel_table[4] = { 5, 6, 7, 0 }; /* Head/sector mappings */ struct { unsigned char heads; unsigned char sectors; } mapping_table[4] = { { 16, 63 }, { 64, 32 }, { 64, 63 }, { 64, 32 } }; struct config_1 { #if defined(__BIG_ENDIAN_BITFIELD) unsigned char dma_channel: 2, interrupt:2, removable_disks_as_fixed:1, bios_segment: 3; #else unsigned char bios_segment: 3, removable_disks_as_fixed: 1, interrupt: 2, dma_channel: 2; #endif } config_1; struct config_2 { #if defined(__BIG_ENDIAN_BITFIELD) unsigned char tfr_port: 2, bios_drive_number: 1, mapping_mode: 2, ha_scsi_id: 3; #else unsigned char ha_scsi_id: 3, mapping_mode: 2, bios_drive_number: 1, tfr_port: 2; #endif } config_2; char name[16]; sprintf(name, "%s%d", driver_name, j); if (!request_region(port_base, REGION_SIZE, driver_name)) { #if defined(DEBUG_DETECT) printk("%s: address 0x%03lx in use, skipping probe.\n", name, port_base); #endif goto fail; } spin_lock_irq(&driver_lock); if (inb(port_base + REG_PRODUCT_ID1) != PRODUCT_ID1) goto freelock; in_byte = inb(port_base + REG_PRODUCT_ID2); if ((in_byte & 0xf0) != PRODUCT_ID2) goto freelock; *(char *)&config_1 = inb(port_base + REG_CONFIG1); *(char *)&config_2 = inb(port_base + REG_CONFIG2); irq = interrupt_table[config_1.interrupt]; dma_channel = dma_channel_table[config_1.dma_channel]; subversion = (in_byte & 0x0f); /* Board detected, allocate its IRQ */ if (request_irq(irq, do_interrupt_handler, IRQF_DISABLED | ((subversion == ESA) ? IRQF_SHARED : 0), driver_name, (void *) &sha[j])) { printk("%s: unable to allocate IRQ %u, detaching.\n", name, irq); goto freelock; } if (subversion == ISA && request_dma(dma_channel, driver_name)) { printk("%s: unable to allocate DMA channel %u, detaching.\n", name, dma_channel); goto freeirq; } if (have_old_firmware) tpnt->use_clustering = DISABLE_CLUSTERING; spin_unlock_irq(&driver_lock); sh[j] = scsi_register(tpnt, sizeof(struct hostdata)); spin_lock_irq(&driver_lock); if (sh[j] == NULL) { printk("%s: unable to register host, detaching.\n", name); goto freedma; } sh[j]->io_port = port_base; sh[j]->unique_id = port_base; sh[j]->n_io_port = REGION_SIZE; sh[j]->base = bios_segment_table[config_1.bios_segment]; sh[j]->irq = irq; sh[j]->sg_tablesize = MAX_SGLIST; sh[j]->this_id = config_2.ha_scsi_id; sh[j]->can_queue = MAX_MAILBOXES; sh[j]->cmd_per_lun = MAX_CMD_PER_LUN; #if defined(DEBUG_DETECT) { unsigned char sys_mask, lcl_mask; sys_mask = inb(sh[j]->io_port + REG_SYS_MASK); lcl_mask = inb(sh[j]->io_port + REG_LCL_MASK); printk("SYS_MASK 0x%x, LCL_MASK 0x%x.\n", sys_mask, lcl_mask); } #endif /* Probably a bogus host scsi id, set it to the dummy value */ if (sh[j]->this_id == 0) sh[j]->this_id = -1; /* If BIOS is disabled, force enable interrupts */ if (sh[j]->base == 0) outb(CMD_ENA_INTR, sh[j]->io_port + REG_SYS_MASK); memset(HD(j), 0, sizeof(struct hostdata)); HD(j)->heads = mapping_table[config_2.mapping_mode].heads; HD(j)->sectors = mapping_table[config_2.mapping_mode].sectors; HD(j)->subversion = subversion; HD(j)->pdev = NULL; HD(j)->board_number = j; if (have_old_firmware) sh[j]->sg_tablesize = MAX_SAFE_SGLIST; if (HD(j)->subversion == ESA) { sh[j]->unchecked_isa_dma = FALSE; sh[j]->dma_channel = NO_DMA; sprintf(BN(j), "U34F%d", j); bus_type = "VESA"; } else { unsigned long flags; sh[j]->unchecked_isa_dma = TRUE; flags=claim_dma_lock(); disable_dma(dma_channel); clear_dma_ff(dma_channel); set_dma_mode(dma_channel, DMA_MODE_CASCADE); enable_dma(dma_channel); release_dma_lock(flags); sh[j]->dma_channel = dma_channel; sprintf(BN(j), "U14F%d", j); bus_type = "ISA"; } sh[j]->max_channel = MAX_CHANNEL - 1; sh[j]->max_id = MAX_TARGET; sh[j]->max_lun = MAX_LUN; if (HD(j)->subversion == ISA && !board_inquiry(j)) { HD(j)->board_id[40] = 0; if (strcmp(&HD(j)->board_id[32], "06000600")) { printk("%s: %s.\n", BN(j), &HD(j)->board_id[8]); printk("%s: firmware %s is outdated, FW PROM should be 28004-006.\n", BN(j), &HD(j)->board_id[32]); sh[j]->hostt->use_clustering = DISABLE_CLUSTERING; sh[j]->sg_tablesize = MAX_SAFE_SGLIST; } } if (dma_channel == NO_DMA) sprintf(dma_name, "%s", "BMST"); else sprintf(dma_name, "DMA %u", dma_channel); spin_unlock_irq(&driver_lock); for (i = 0; i < sh[j]->can_queue; i++) HD(j)->cp[i].cp_dma_addr = pci_map_single(HD(j)->pdev, &HD(j)->cp[i], sizeof(struct mscp), PCI_DMA_BIDIRECTIONAL); for (i = 0; i < sh[j]->can_queue; i++) if (! ((&HD(j)->cp[i])->sglist = kmalloc( sh[j]->sg_tablesize * sizeof(struct sg_list), (sh[j]->unchecked_isa_dma ? GFP_DMA : 0) | GFP_ATOMIC))) { printk("%s: kmalloc SGlist failed, mbox %d, detaching.\n", BN(j), i); goto release; } if (max_queue_depth > MAX_TAGGED_CMD_PER_LUN) max_queue_depth = MAX_TAGGED_CMD_PER_LUN; if (max_queue_depth < MAX_CMD_PER_LUN) max_queue_depth = MAX_CMD_PER_LUN; if (tag_mode != TAG_DISABLED && tag_mode != TAG_SIMPLE) tag_mode = TAG_ORDERED; if (j == 0) { printk("UltraStor 14F/34F: Copyright (C) 1994-2003 Dario Ballabio.\n"); printk("%s config options -> of:%c, tm:%d, lc:%c, mq:%d, et:%c.\n", driver_name, YESNO(have_old_firmware), tag_mode, YESNO(linked_comm), max_queue_depth, YESNO(ext_tran)); } printk("%s: %s 0x%03lx, BIOS 0x%05x, IRQ %u, %s, SG %d, MB %d.\n", BN(j), bus_type, (unsigned long)sh[j]->io_port, (int)sh[j]->base, sh[j]->irq, dma_name, sh[j]->sg_tablesize, sh[j]->can_queue); if (sh[j]->max_id > 8 || sh[j]->max_lun > 8) printk("%s: wide SCSI support enabled, max_id %u, max_lun %u.\n", BN(j), sh[j]->max_id, sh[j]->max_lun); for (i = 0; i <= sh[j]->max_channel; i++) printk("%s: SCSI channel %u enabled, host target ID %d.\n", BN(j), i, sh[j]->this_id); return TRUE; freedma: if (subversion == ISA) free_dma(dma_channel); freeirq: free_irq(irq, &sha[j]); freelock: spin_unlock_irq(&driver_lock); release_region(port_base, REGION_SIZE); fail: return FALSE; release: u14_34f_release(sh[j]); return FALSE; }
static int board_inquiry(unsigned int j) { struct mscp *cpp; dma_addr_t id_dma_addr; unsigned int limit = 0; unsigned long time; id_dma_addr = pci_map_single(HD(j)->pdev, HD(j)->board_id, sizeof(HD(j)->board_id), PCI_DMA_BIDIRECTIONAL); cpp = &HD(j)->cp[0]; cpp->cp_dma_addr = pci_map_single(HD(j)->pdev, cpp, sizeof(struct mscp), PCI_DMA_BIDIRECTIONAL); memset(cpp, 0, sizeof(struct mscp) - CP_TAIL_SIZE); cpp->opcode = OP_HOST_ADAPTER; cpp->xdir = DTD_IN; cpp->data_address = H2DEV(id_dma_addr); cpp->data_len = H2DEV(sizeof(HD(j)->board_id)); cpp->cdb_len = 6; cpp->cdb[0] = HA_CMD_INQUIRY; if (wait_on_busy(sh[j]->io_port, MAXLOOP)) { printk("%s: board_inquiry, adapter busy.\n", BN(j)); return TRUE; } HD(j)->cp_stat[0] = IGNORE; /* Clear the interrupt indication */ outb(CMD_CLR_INTR, sh[j]->io_port + REG_SYS_INTR); /* Store pointer in OGM address bytes */ outl(H2DEV(cpp->cp_dma_addr), sh[j]->io_port + REG_OGM); /* Issue OGM interrupt */ outb(CMD_OGM_INTR, sh[j]->io_port + REG_LCL_INTR); spin_unlock_irq(&driver_lock); time = jiffies; while ((jiffies - time) < HZ && limit++ < 20000) udelay(100L); spin_lock_irq(&driver_lock); if (cpp->adapter_status || HD(j)->cp_stat[0] != FREE) { HD(j)->cp_stat[0] = FREE; printk("%s: board_inquiry, err 0x%x.\n", BN(j), cpp->adapter_status); return TRUE; } pci_unmap_single(HD(j)->pdev, cpp->cp_dma_addr, sizeof(struct mscp), PCI_DMA_BIDIRECTIONAL); pci_unmap_single(HD(j)->pdev, id_dma_addr, sizeof(HD(j)->board_id), PCI_DMA_BIDIRECTIONAL); return FALSE; }
int HttpClient::_go( const char * command , string url , const char * body , Result * result ) { bool ssl = false; if ( url.find( "https://" ) == 0 ) { ssl = true; url = url.substr( 8 ); } else { uassert( 10271 , "invalid url" , url.find( "http://" ) == 0 ); url = url.substr( 7 ); } string host , path; if ( url.find( "/" ) == string::npos ) { host = url; path = "/"; } else { host = url.substr( 0 , url.find( "/" ) ); path = url.substr( url.find( "/" ) ); } HD( "host [" << host << "]" ); HD( "path [" << path << "]" ); string server = host; int port = ssl ? 443 : 80; string::size_type idx = host.find( ":" ); if ( idx != string::npos ) { server = host.substr( 0 , idx ); string t = host.substr( idx + 1 ); port = atoi( t.c_str() ); } HD( "server [" << server << "]" ); HD( "port [" << port << "]" ); string req; { stringstream ss; ss << command << " " << path << " HTTP/1.1\r\n"; ss << "Host: " << host << "\r\n"; ss << "Connection: Close\r\n"; ss << "User-Agent: mongodb http client\r\n"; if ( body ) { ss << "Content-Length: " << strlen( body ) << "\r\n"; } ss << "\r\n"; if ( body ) { ss << body; } req = ss.str(); } SockAddr addr( server.c_str() , port ); HD( "addr: " << addr.toString() ); Socket sock; if ( ! sock.connect( addr ) ) return -1; if ( ssl ) { #ifdef MONGO_SSL _checkSSLManager(); sock.secure( _sslManager.get() ); #else uasserted( 15862 , "no ssl support" ); #endif } { const char * out = req.c_str(); int toSend = req.size(); sock.send( out , toSend, "_go" ); } char buf[4096]; int got = sock.unsafe_recv( buf , 4096 ); buf[got] = 0; int rc; char version[32]; assert( sscanf( buf , "%s %d" , version , &rc ) == 2 ); HD( "rc: " << rc ); StringBuilder sb; if ( result ) sb << buf; while ( ( got = sock.unsafe_recv( buf , 4096 ) ) > 0) { if ( result ) sb << buf; } if ( result ) { result->_init( rc , sb.str() ); } return rc; }