static void check_coarse_timers_dowork (struct context *c) { const struct timeval save = c->c2.timeval; c->c2.timeval.tv_sec = BIG_TIMEOUT; c->c2.timeval.tv_usec = 0; process_coarse_timers (c); c->c2.coarse_timer_wakeup = now + c->c2.timeval.tv_sec; dmsg (D_INTERVAL, "TIMER: coarse timer wakeup %d seconds", (int) c->c2.timeval.tv_sec); /* Is the coarse timeout NOT the earliest one? */ if (c->c2.timeval.tv_sec > save.tv_sec) c->c2.timeval = save; }
/* true if at least one free buffer available */ bool reliable_can_get (const struct reliable *rel) { struct gc_arena gc = gc_new (); int i; for (i = 0; i < rel->size; ++i) { const struct reliable_entry *e = &rel->array[i]; if (!e->active) return true; } dmsg (D_REL_LOW, "ACK no free receive buffer available: %s", reliable_print_ids (rel, &gc)); gc_free (&gc); return false; }
static int plugin_call_item (const struct plugin *p, void *per_client_context, const int type, const struct argv *av, struct openvpn_plugin_string_list **retlist, const char **envp) { int status = OPENVPN_PLUGIN_FUNC_SUCCESS; /* clear return list */ if (retlist) *retlist = NULL; if (p->plugin_handle && (p->plugin_type_mask & OPENVPN_PLUGIN_MASK (type))) { struct gc_arena gc = gc_new (); struct argv a = argv_insert_head (av, p->so_pathname); dmsg (D_PLUGIN_DEBUG, "PLUGIN_CALL: PRE type=%s", plugin_type_name (type)); plugin_show_args_env (D_PLUGIN_DEBUG, (const char **)a.argv, envp); /* * Call the plugin work function */ if (p->func2) status = (*p->func2)(p->plugin_handle, type, (const char **)a.argv, envp, per_client_context, retlist); else if (p->func1) status = (*p->func1)(p->plugin_handle, type, (const char **)a.argv, envp); else ASSERT (0); msg (D_PLUGIN, "PLUGIN_CALL: POST %s/%s status=%d", p->so_pathname, plugin_type_name (type), status); if (status == OPENVPN_PLUGIN_FUNC_ERROR) msg (M_WARN, "PLUGIN_CALL: plugin function %s failed with status %d: %s", plugin_type_name (type), status, p->so_pathname); argv_reset (&a); gc_free (&gc); } return status; }
static void lz4v2_decompress(struct buffer *buf, struct buffer work, struct compress_context *compctx, const struct frame *frame) { size_t zlen_max = EXPANDED_SIZE(frame); uint8_t c; /* flag indicating whether or not our peer compressed */ if (buf->len <= 0) { return; } ASSERT(buf_init(&work, FRAME_HEADROOM(frame))); /* do unframing/swap (assumes buf->len > 0) */ uint8_t *head = BPTR(buf); c = *head; /* Not compressed */ if (c != COMP_ALGV2_INDICATOR_BYTE) { return; } /* Packet to short to make sense */ if (buf->len <= 1) { buf->len = 0; return; } c = head[1]; if (c == COMP_ALGV2_LZ4_BYTE) /* packet was compressed */ { buf_advance(buf,2); do_lz4_decompress(zlen_max, &work, buf, compctx); } else if (c == COMP_ALGV2_UNCOMPRESSED_BYTE) { buf_advance(buf,2); } else { dmsg(D_COMP_ERRORS, "Bad LZ4v2 decompression header byte: %d", c); buf->len = 0; } }
/* * Write to an OpenSSL BIO in non-blocking mode. */ static int bio_write (BIO *bio, const uint8_t *data, int size, const char *desc) { int i; int ret = 0; ASSERT (size >= 0); if (size) { /* * Free the L_TLS lock prior to calling BIO routines * so that foreground thread can still call * tls_pre_decrypt or tls_pre_encrypt, * allowing tunnel packet forwarding to continue. */ #ifdef BIO_DEBUG bio_debug_data ("write", bio, data, size, desc); #endif i = BIO_write (bio, data, size); if (i < 0) { if (BIO_should_retry (bio)) { ; } else { msg (D_TLS_ERRORS | M_SSL, "TLS ERROR: BIO write %s error", desc); ret = -1; ERR_clear_error (); } } else if (i != size) { msg (D_TLS_ERRORS | M_SSL, "TLS ERROR: BIO write %s incomplete %d/%d", desc, i, size); ret = -1; ERR_clear_error (); } else { /* successful write */ dmsg (D_HANDSHAKE_VERBOSE, "BIO write %s %d bytes", desc, i); ret = 1; } } return ret; }
static void replay_bind_cont(void *st, errval_t err, struct replay_binding *b) { static int slavenum = 0; struct slave *sl = &SlState.slaves[slavenum]; slavenum++; dmsg("ENTER\n"); //printf("%s:%s MY TASKGRAPH IS %p\n", __FILE__, __FUNCTION__, &TG); assert(err_is_ok(err)); sl->b = b; b->rx_vtbl = replay_vtbl; b->st = &TG; bound = true; /* printf("assigned binding to %p\n", sl); */ }
/** * @brief Order loading of a new instrument. * * The request will go into a queue waiting to be processed by the * class internal task thread. This method will immediately return and * the instrument will be loaded in the background. * * @param Filename - file name of the instrument * @param uiInstrumentIndex - index of the instrument within the file * @param pEngineChannel - engine channel on which the instrument should be loaded */ void InstrumentManagerThread::StartNewLoad(String Filename, uint uiInstrumentIndex, EngineChannel* pEngineChannel) { dmsg(1,("Scheduling '%s' (Index=%d) to be loaded in background (if not loaded yet).\n",Filename.c_str(),uiInstrumentIndex)); // already tell the engine which instrument to load pEngineChannel->PrepareLoadInstrument(Filename.c_str(), uiInstrumentIndex); command_t cmd; cmd.type = command_t::DIRECT_LOAD; cmd.pEngineChannel = pEngineChannel; mutex.Lock(); queue.push_back(cmd); mutex.Unlock(); StartThread(); // ensure thread is running conditionJobsLeft.Set(true); // wake up thread }
/* schedule all pending packets for immediate retransmit */ void reliable_schedule_now (struct reliable *rel) { int i; dmsg (D_REL_DEBUG, "ACK reliable_schedule_now"); rel->hold = false; for (i = 0; i < rel->size; ++i) { struct reliable_entry *e = &rel->array[i]; if (e->active) { e->next_try = now; e->timeout = rel->initial_timeout; } } }
bool save_preferences (void) { FILE* fs; dmsg (D_MISC, "save preferences to %s", preferences_file ()); fs = fopen (preferences_file (), "wt"); if (fs == 0) { wmsg ("cannot save preferences to %s", preferences_file ()); dperror ("fopen"); return true; } output_preferences (fs); fclose (fs); return false; }
static void start_threads(void) { int i; tinfo = calloc(nb_thread, sizeof(struct thread_info_s)); if (tinfo == NULL) handle_error("calloc"); for( i=0; i < nb_thread; i++) { tinfo[i].thread_num = i; if(pthread_create(&tinfo[i].thread_id, NULL, mr_map, &tinfo[i])) handle_error("thread create"); dmsg("Thread number %d launched\n", i); } }
void AudioThread::CacheInitialSamples(gig::Sample* pSample) { if (!pSample || pSample->GetCache().Size) return; if (pSample->SamplesTotal <= NUM_RAM_PRELOAD_SAMPLES) { // Sample is too short for disk streaming, so we load the whole // sample into RAM and place 'pAudioIO->FragmentSize << MAX_PITCH' // number of '0' samples (silence samples) behind the official buffer // border, to allow the interpolator do it's work even at the end of // the sample. gig::buffer_t buf = pSample->LoadSampleDataWithNullSamplesExtension(pAudioIO->FragmentSize << MAX_PITCH); dmsg(("Cached %d Bytes, %d silence bytes.\n", buf.Size, buf.NullExtensionSize)); } else { // we only cache NUM_RAM_PRELOAD_SAMPLES and stream the other sample points from disk pSample->LoadSampleData(NUM_RAM_PRELOAD_SAMPLES); } if (!pSample->GetCache().Size) std::cerr << "Unable to cache sample - maybe memory full!" << std::endl << std::flush; }
void semaphore_open (struct semaphore *s, const char *name) { struct security_attributes sa; s->locked = false; s->name = name; s->hand = NULL; if (init_security_attributes_allow_all (&sa)) s->hand = CreateSemaphore(&sa.sa, 1, 1, name); if (s->hand == NULL) msg (M_WARN|M_ERRNO, "WARNING: Cannot create Win32 semaphore '%s'", name); else dmsg (D_SEMAPHORE, "Created Win32 semaphore '%s'", s->name); }
void process_incoming_tun (struct context *c) { struct gc_arena gc = gc_new (); perf_push (PERF_PROC_IN_TUN); if (c->c2.buf.len > 0) c->c2.tun_read_bytes += c->c2.buf.len; #ifdef LOG_RW if (c->c2.log_rw && c->c2.buf.len > 0) fprintf (stderr, "r"); #endif /* Show packet content */ dmsg (D_TUN_RW, "TUN READ [%d]", BLEN (&c->c2.buf)); if (c->c2.buf.len > 0) { if ((c->options.mode == MODE_POINT_TO_POINT) && (!c->options.allow_recursive_routing)) drop_if_recursive_routing (c, &c->c2.buf); /* * The --passtos and --mssfix options require * us to examine the IP header (IPv4 or IPv6). */ process_ip_header (c, PIPV4_PASSTOS|PIP_MSSFIX|PIPV4_CLIENT_NAT, &c->c2.buf); #ifdef PACKET_TRUNCATION_CHECK /* if (c->c2.buf.len > 1) --c->c2.buf.len; */ ipv4_packet_size_verify (BPTR (&c->c2.buf), BLEN (&c->c2.buf), TUNNEL_TYPE (c->c1.tuntap), "PRE_ENCRYPT", &c->c2.n_trunc_pre_encrypt); #endif encrypt_sign (c, true); } else { buf_reset (&c->c2.to_link); } perf_pop (); gc_free (&gc); }
static void modmult(Bignum r1, Bignum r2, Bignum modulus, Bignum result) { Bignum temp = newbn(modulus[0]+1); Bignum tmp2 = newbn(modulus[0]+1); int i; int bit, bits, digit, smallbit; enter((">modmult\n")); debug(r1); debug(r2); debug(modulus); for (i=1; i<=result[0]; i++) result[i] = 0; /* result := 0 */ for (i=1; i<=temp[0]; i++) temp[i] = (i > r2[0] ? 0 : r2[i]); /* temp := r2 */ bits = 1+msb(r1); for (bit = 0; bit < bits; bit++) { digit = 1 + bit / 16; smallbit = bit % 16; debug(temp); if (digit <= r1[0] && (r1[digit] & (1<<smallbit))) { dmsg(("bit %d\n", bit)); add(temp, result, tmp2); if (ge(tmp2, modulus)) sub(tmp2, modulus, result); else add(tmp2, Zero, result); debug(result); } add(temp, temp, tmp2); if (ge(tmp2, modulus)) sub(tmp2, modulus, temp); else add(tmp2, Zero, temp); } freebn(temp); freebn(tmp2); debug(result); leave(("<modmult\n")); }
void adjust_volume (void) { if (opt.music) md_musicvolume = (13 - opt.music_volume) * 128 / 13; else md_musicvolume = 0; dmsg (D_SOUND_TRACK, "set volume to %d/128", md_musicvolume); /* This doesn't want to work. I'm changing the volume of each sample as a work around, see event_sfX() in sfx.c. if (opt.sfx) md_sndfxvolume = (13 - opt.sfx_volume) * 128 / 13; else md_sndfxvolume = 0; */ }
void DirectoryScanner::Scan(String DbDir, String FsDir, bool Flat, bool insDir, ScanProgress* pProgress) { dmsg(2,("DirectoryScanner: Scan(DbDir=%s,FsDir=%s,Flat=%d,insDir=%d)\n", DbDir.c_str(), FsDir.c_str(), Flat, insDir)); if (DbDir.empty() || FsDir.empty()) throw Exception("Directory expected"); this->DbDir = DbDir; this->FsDir = FsDir; this->insDir = insDir; if (DbDir.at(DbDir.length() - 1) != '/') { this->DbDir.append("/"); } if (FsDir.at(FsDir.length() - 1) != File::DirSeparator) { this->FsDir.push_back(File::DirSeparator); } this->Flat = Flat; this->pProgress = pProgress; File::WalkDirectoryTree(FsDir, this); }
static int proxy_connection_io_recv (struct proxy_connection *pc) { /* recv data from socket */ const int status = recv (pc->sd, BPTR(&pc->buf), BCAP(&pc->buf), MSG_NOSIGNAL); if (status < 0) { return (errno == EAGAIN) ? IOSTAT_EAGAIN_ON_READ : IOSTAT_READ_ERROR; } else { if (!status) return IOSTAT_READ_ERROR; dmsg (D_PS_PROXY_DEBUG, "PORT SHARE PROXY: read[%d] %d", (int)pc->sd, status); pc->buf.len = status; } return IOSTAT_GOOD; }
void prng_init (const char *md_name, const int nonce_secret_len_parm) { prng_uninit (); nonce_md = md_name ? md_kt_get (md_name) : NULL; if (nonce_md) { ASSERT (nonce_secret_len_parm >= NONCE_SECRET_LEN_MIN && nonce_secret_len_parm <= NONCE_SECRET_LEN_MAX); nonce_secret_len = nonce_secret_len_parm; { const int size = md_kt_size(nonce_md) + nonce_secret_len; dmsg (D_CRYPTO_DEBUG, "PRNG init md=%s size=%d", md_kt_name(nonce_md), size); nonce_data = (uint8_t*) malloc (size); check_malloc_return (nonce_data); prng_reset_nonce(); } } }
/* * We want to wake up in delay microseconds. If timeval is larger * than delay, set timeval to delay. */ bool shaper_soonest_event(struct timeval *tv, int delay) { bool ret = false; if (delay < 1000000) { if (tv->tv_sec) { tv->tv_sec = 0; tv->tv_usec = delay; ret = true; } else if (delay < tv->tv_usec) { tv->tv_usec = delay; ret = true; } } else { const int sec = delay / 1000000; const int usec = delay % 1000000; if (sec < tv->tv_sec) { tv->tv_sec = sec; tv->tv_usec = usec; ret = true; } else if (sec == tv->tv_sec) { if (usec < tv->tv_usec) { tv->tv_usec = usec; ret = true; } } } #ifdef SHAPER_DEBUG dmsg(D_SHAPER_DEBUG, "SHAPER shaper_soonest_event sec=%d usec=%d ret=%d", (int)tv->tv_sec, (int)tv->tv_usec, (int)ret); #endif return ret; }
static ssize_t UsbMenuSel_switch_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { dmsg("buf=%s\n", buf); #ifdef _SUPPORT_SAMSUNG_AUTOINSTALLER_ if (strncmp(buf, "KIES_REAL", 9) == 0) { //UsbMenuSelStore(0); usb_switch_select(USBSTATUS_SAMSUNG_KIES_REAL); } else #endif if (strncmp(buf, "KIES", 4) == 0) { UsbMenuSelStore(0); usb_switch_select(USBSTATUS_SAMSUNG_KIES); } if (strncmp(buf, "MTP", 3) == 0) { UsbMenuSelStore(1); usb_switch_select(USBSTATUS_MTPONLY); } if (strncmp(buf, "UMS", 3) == 0) { UsbMenuSelStore(2); usb_switch_select(USBSTATUS_UMS); } #if !defined(CONFIG_TARGET_LOCALE_NTT) // disable tethering xmoondash if (strncmp(buf, "VTP", 3) == 0) { UsbMenuSelStore(3); usb_switch_select(USBSTATUS_VTP); } #endif if (strncmp(buf, "ASKON", 5) == 0) { UsbMenuSelStore(4); usb_switch_select(USBSTATUS_ASKON); } return size; }
//-------------------------------------------------------------------------- // returns true-lowcnd was false, resumed the application // nb: recursive calls to this function are not handled in any special way! bool debmod_t::handle_lowcnd(lowcnd_t *lc, debug_event_t *event) { if ( (debugger_flags & DBG_FLAG_CAN_CONT_BPT) == 0 ) { // difficult case: we have to reset pc, remove the bpt, single step, and resume the app handling_lowcnd = true; regval_t rv; rv._set_int(lc->ea); int code = dbg_write_register(event->tid, pc_idx, &rv); if ( code <= 0 ) { handling_lowcnd = false; return false; } code = dbg_freeze_threads_except(event->tid); if ( code > 0 ) { code = dbg_del_bpt(lc->type, lc->ea, lc->orgbytes.begin(), lc->orgbytes.size()); if ( code > 0 ) { code = dbg_perform_single_step(event, lc->cmd); if ( code <= 0 ) dmsg("%a: failed to single step\n", event->ea); // may happen if ( dbg_add_bpt(lc->type, lc->ea, lc->orgbytes.size()) <= 0 ) { code = 0; dwarning("%a: could not restore deleted bpt\n", lc->cmd.ea); // odd } } if ( dbg_thaw_threads_except(event->tid) <= 0 ) { dwarning("%d: could not resume suspended threads\n", event->tid); // odd code = 0; } } handling_lowcnd = false; if ( code <= 0 || event->eid != STEP ) return false; // did not resume } return dbg_continue_after_event(event); }
/* make sure that incoming packet ID won't deadlock the receive buffer */ bool reliable_wont_break_sequentiality (const struct reliable *rel, packet_id_type id) { struct gc_arena gc = gc_new (); int ret; if ((int)id < (int)rel->packet_id + rel->size) { ret = true; } else { dmsg (D_REL_LOW, "ACK " packet_id_format " breaks sequentiality: %s", (packet_id_print_type)id, reliable_print_ids (rel, &gc)); ret = false; } gc_free (&gc); return ret; }
int key_des_num_cblocks (const EVP_CIPHER *kt) { int ret = 0; const char *name = OBJ_nid2sn (EVP_CIPHER_nid (kt)); if (name) { if (!strncmp (name, "DES-", 4)) { ret = EVP_CIPHER_key_length (kt) / sizeof (DES_cblock); } else if (!strncmp (name, "DESX-", 5)) { ret = 1; } } dmsg (D_CRYPTO_DEBUG, "CRYPTO INFO: n_DES_cblocks=%d", ret); return ret; }
void RAD::poweredOn() { #ifdef DEBUG dmsg("powered ON"); #endif ibus.sendMessage(DEVICE_RAD,DEVICE_LOC,0x36, 0xA1); // source tuner/tape delay(1000); switchToSource(source); muteOff(); sendVolume(); updateTONE(); dspc.powerOn(); displayMenu(); displaySource(); powerOnDelay=0; }
void DiskThread::DeleteStream(delete_command_t& Command) { if (Command.pStream) Command.pStream->Kill(); else { // the stream wasn't created by disk thread or picked up by audio thread yet // if stream was created but not picked up yet Stream* pStream = pCreatedStreams[Command.OrderID]; if (pStream && pStream != SLOT_RESERVED) { pStream->Kill(); pCreatedStreams[Command.OrderID] = NULL; // free slot for new order return; } // the stream was not created yet if (GhostQueue->write_space() > 0) { GhostQueue->push(&Command.hStream); } else dmsg(1,("DiskThread: GhostQueue full!\n")); } }
static bool multi_tcp_process_outgoing_link(struct multi_context *m, bool defer, const unsigned int mpp_flags) { struct multi_instance *mi = multi_process_outgoing_link_pre(m); bool ret = true; if (mi) { if (defer || mbuf_defined(mi->tcp_link_out_deferred)) { /* save to queue */ struct buffer *buf = &mi->context.c2.to_link; if (BLEN(buf) > 0) { struct mbuf_buffer *mb = mbuf_alloc_buf(buf); struct mbuf_item item; set_prefix(mi); dmsg(D_MULTI_TCP, "MULTI TCP: queuing deferred packet"); item.buffer = mb; item.instance = mi; mbuf_add_item(mi->tcp_link_out_deferred, &item); mbuf_free_buf(mb); buf_reset(buf); ret = multi_process_post(m, mi, mpp_flags); if (!ret) { mi = NULL; } clear_prefix(); } } else { ret = multi_process_outgoing_link_dowork(m, mi, mpp_flags); if (!ret) { mi = NULL; } } } return ret; }
/* read a packet ID acknowledgement record from buf into ack */ bool reliable_ack_read (struct reliable_ack * ack, struct buffer * buf, const struct session_id * sid) { struct gc_arena gc = gc_new (); int i; uint8_t count; packet_id_type net_pid; packet_id_type pid; struct session_id session_id_remote; if (!buf_read (buf, &count, sizeof (count))) goto error; for (i = 0; i < count; ++i) { if (!buf_read (buf, &net_pid, sizeof (net_pid))) goto error; if (ack->len >= RELIABLE_ACK_SIZE) goto error; pid = ntohpid (net_pid); ack->packet_id[ack->len++] = pid; } if (count) { if (!session_id_read (&session_id_remote, buf)) goto error; if (!session_id_defined (&session_id_remote) || !session_id_equal (&session_id_remote, sid)) { dmsg (D_REL_LOW, "ACK read BAD SESSION-ID FROM REMOTE, local=%s, remote=%s", session_id_print (sid, &gc), session_id_print (&session_id_remote, &gc)); goto error; } } gc_free (&gc); return true; error: gc_free (&gc); return false; }
int key_des_num_cblocks(const mbedtls_cipher_info_t *kt) { int ret = 0; if (kt->type == MBEDTLS_CIPHER_DES_CBC) { ret = 1; } if (kt->type == MBEDTLS_CIPHER_DES_EDE_CBC) { ret = 2; } if (kt->type == MBEDTLS_CIPHER_DES_EDE3_CBC) { ret = 3; } dmsg(D_CRYPTO_DEBUG, "CRYPTO INFO: n_DES_cblocks=%d", ret); return ret; }
static ssize_t KiesStatus_switch_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { dmsg("buf=%s\n", buf); if (strncmp(buf, "START", 5) == 0) { kies_status = 1; } else if (strncmp(buf, "STOP", 4) == 0) { kies_status = 2; UsbIndicator(2); } else if (strncmp(buf, "INIT", 4) == 0 ) { kies_status = 0; } return size; }
/* * Should we ping the remote? */ void check_ping_send_dowork (struct context *c) { c->c2.buf = c->c2.buffers->aux_buf; ASSERT (buf_init (&c->c2.buf, FRAME_HEADROOM (&c->c2.frame))); ASSERT (buf_safe (&c->c2.buf, MAX_RW_SIZE_TUN (&c->c2.frame))); ASSERT (buf_write (&c->c2.buf, ping_string, sizeof (ping_string))); /* * We will treat the ping like any other outgoing packet, * encrypt, sign, etc. */ encrypt_sign (c, true); dmsg (D_PING, "SENT PING"); }