void Render_Widget::resolve_color_buffer(Buffer& buffer) { if (!buffer.color_is_resolved) { buffer.color_is_resolved = true; q::video::gles::Interface interf; interf.iglBindBuffer(q::video::gles::iGL_PIXEL_PACK_BUFFER, buffer.color_pbo); auto* ptr = static_cast<uint8_t*>(interf.iglMapBuffer(q::video::gles::iGL_PIXEL_PACK_BUFFER, q::video::gles::iGL_READ_ONLY)); QASSERT(ptr); size_t data_size = buffer.size.x * buffer.size.y * sizeof(uint32_t); QASSERT(data_size > 0); buffer.color_data.resize(data_size); //flip vertically size_t row_size = buffer.size.x * sizeof(uint32_t); for (size_t i = 0; i < buffer.size.y; i++) { memcpy(buffer.color_data.data() + (buffer.size.y - 1 - i) * row_size, ptr + i * row_size, row_size); } interf.iglUnmapBuffer(q::video::gles::iGL_PIXEL_PACK_BUFFER); interf.iglBindBuffer(q::video::gles::iGL_PIXEL_PACK_BUFFER, 0); } }
bool read_registers_uint16_le(uint8_t addr, uint8_t reg, uint16_t* data, uint8_t size) { QASSERT(s_is_initialized); QASSERT(s_is_locked); QASSERT(data && size > 0); if (!data || size == 0) { return 0; } uint8_t* data_ptr8 = reinterpret_cast<uint8_t*>(data) + 1; //the data_ptr8 will advance like this //1, 0, 3, 2, 5, 4, 7, 6, 9, 8 if (!_start()) goto error; if (!_send_address(SLA_W(addr))) goto error; if (!_send_byte(reg)) goto error; if (!_start()) goto error; if (!_send_address(SLA_R(addr))) goto error; { uint8_t i = size - 1; while (i > 0) { if (!_receive_byte_ack()) goto error; *data_ptr8 = TWDR; data_ptr8 -= 1; if (!_receive_byte_ack()) goto error; *data_ptr8 = TWDR; data_ptr8 += 3; --i; } } //last bytes { if (!_receive_byte_ack()) goto error; *data_ptr8 = TWDR; data_ptr8 -= 1; if (!_receive_byte()) goto error; *data_ptr8 = TWDR; //data_ptr8 += 3; } if (!_stop()) goto error; return true; error: s_lockup_count++; return false; }
void set_high_speed(bool active) { QASSERT(s_is_initialized); QASSERT(s_is_locked); if (active) { TWBR = ((CPU_FREQ / 400000) - 16) / 2; } else { TWBR = ((CPU_FREQ / 100000) - 16) / 2; } }
bool read_registers(uint8_t addr, uint8_t reg, uint8_t* data, uint8_t size) { QASSERT(s_is_initialized); QASSERT(s_is_locked); QASSERT(size > 0); if (size == 0) { return 0; } if (!_start()) goto error; if (!_send_address(SLA_W(addr))) goto error; if (!_send_byte(reg)) goto error; if (!_start()) goto error; if (!_send_address(SLA_R(addr))) goto error; if (data) { uint8_t i = size - 1; while (i > 0) { if (!_receive_byte_ack()) goto error; *data++ = TWDR; --i; } //last item { if (!_receive_byte()) goto error; *data = TWDR; } } else { uint8_t i = size - 1; while (i > 0) { if (!_receive_byte_ack()) goto error; s_i2c_null_sink = TWDR; --i; } //last item { if (!_receive_byte()) goto error; s_i2c_null_sink = TWDR; } } if (!_stop()) goto error; return true; error: s_lockup_count++; return false; }
void AIOP_PWM_Out::set_enabled_for_all(bool enabled) { QASSERT(m_is_initialized); if (enabled) { TCCR3A |= (1<<COM3A1); TCCR4A |= (1<<COM4A1); TCCR3A |= (1<<COM3B1); TCCR3A |= (1<<COM3C1); TCCR4A |= (1<<COM4B1); TCCR4A |= (1<<COM4C1); TCCR1A |= (1<<COM1A1); TCCR1A |= (1<<COM1B1); } else { TCCR3A &= ~(1<<COM3A1); TCCR4A &= ~(1<<COM4A1); TCCR3A &= ~(1<<COM3B1); TCCR3A &= ~(1<<COM3C1); TCCR4A &= ~(1<<COM4B1); TCCR4A &= ~(1<<COM4C1); TCCR1A &= ~(1<<COM1A1); TCCR1A &= ~(1<<COM1B1); } }
void AIOP_PWM_Out::set_frequency(uint8_t ch, uint16_t hz) { QASSERT(m_is_initialized); uint16_t icr = timer_period(hz); switch(ch) { case 0: case 1: case 2: ICR3 = icr; break; case 6: case 7: ICR1 = icr; break; case 3: case 4: case 5: ICR4 = icr; break; } }
void AIOP_PWM_Out::set_enabled(uint8_t ch, bool enabled) { QASSERT(m_is_initialized); if (enabled) { switch (ch) { case 0: TCCR3A |= (1<<COM3B1); break; case 1: TCCR3A |= (1<<COM3C1); break; case 2: TCCR3A |= (1<<COM3A1); break; case 3: TCCR4A |= (1<<COM4A1); break; case 4: TCCR4A |= (1<<COM4B1); break; case 5: TCCR4A |= (1<<COM4C1); break; case 6: TCCR1A |= (1<<COM1A1); break; case 7: TCCR1A |= (1<<COM1B1); break; } } else { switch (ch) { case 0: TCCR3A &= ~(1<<COM3B1); break; case 1: TCCR3A &= ~(1<<COM3C1); break; case 2: TCCR3A &= ~(1<<COM3A1); break; case 3: TCCR4A &= ~(1<<COM4A1); break; case 4: TCCR4A &= ~(1<<COM4B1); break; case 5: TCCR4A &= ~(1<<COM4C1); break; case 6: TCCR1A &= ~(1<<COM1A1); break; case 7: TCCR1A &= ~(1<<COM1B1); break; } } }
//-------------------------------------------------------------------------- void linux_debmod_t::tdb_enable_event(td_event_e event, internal_bpt *bp) { td_notify_t notify; td_err_e err = td_ta_event_addr(ta, event, ¬ify); DIE_IF_FAILED("td_ta_event_addr", err); bool ok = add_internal_bp(*bp, size_t(notify.u.bptaddr)); debdeb("%a: added BP for thread event %s\n", bp->bpt_addr, event == TD_CREATE ? "TD_CREATE" : "TD_DEATH"); QASSERT(ok); }
bool write(uint8_t addr, const uint8_t* data, uint8_t size) { QASSERT(s_is_initialized); QASSERT(s_is_locked); QASSERT(data && size > 0); if (!_start()) goto error; if (!_send_address(SLA_W(addr))) goto error; for (int8_t i = size; i > 0; i--) { if (!_send_byte(*data++)) goto error; } if (!_stop()) goto error; return true; error: s_lockup_count++; return false; }
void AIOP_PWM_Out::set_frequency_for_all(uint16_t hz) { QASSERT(m_is_initialized); for (uint8_t i = 0; i < MAX_CHANNEL_COUNT; i++) { set_frequency(i, hz); } }
bool read(uint8_t addr, uint8_t* data, uint8_t size) { QASSERT(s_is_initialized); QASSERT(s_is_locked); QASSERT(size > 0); if (size == 0) { return 0; } if (!_start()) goto error; if (!_send_address(SLA_R(addr))) goto error; if (data) { for (int8_t i = size - 1; i > 0; i--) //write size - 1 butes { if (!_receive_byte_ack()) goto error; *data++ = TWDR; } //last item { if (!_receive_byte()) goto error; *data = TWDR; } } else { for (int8_t i = size - 1; i > 0; i--) //write size - 1 butes { if (!_receive_byte_ack()) goto error; s_i2c_null_sink = TWDR; } //last item { if (!_receive_byte()) goto error; s_i2c_null_sink = TWDR; } } if (!_stop()) goto error; return true; error: s_lockup_count++; return false; }
//------------------------------------------------------------------------- // Converts IDC arguments to Python argument list or just one tuple // If 'decref' is NULL then 'pargs' will contain one element which is the tuple bool pyw_convert_idc_args( const idc_value_t args[], int nargs, ref_vec_t &pargs, bool as_tupple, char *errbuf, size_t errbufsize) { PYW_GIL_CHECK_LOCKED_SCOPE(); ref_t py_tuple; pargs.qclear(); if ( as_tupple ) { py_tuple = newref_t(PyTuple_New(nargs)); if ( py_tuple == NULL ) { if ( errbuf != 0 && errbufsize > 0 ) qstrncpy(errbuf, "Failed to create a new tuple to store arguments!", errbufsize); return false; } } for ( int i=0; i<nargs; i++ ) { ref_t py_obj; int cvt = idcvar_to_pyvar(args[i], &py_obj); if ( cvt < CIP_OK ) { if ( errbuf != 0 && errbufsize > 0 ) qsnprintf(errbuf, errbufsize, "arg#%d has wrong type %d", i, args[i].vtype); return false; } if ( as_tupple ) { // PyTuple_SetItem() steals the reference. py_obj.incref(); QASSERT(30412, PyTuple_SetItem(py_tuple.o, i, py_obj.o) == 0); } else { pargs.push_back(py_obj); } } // Add the tuple to the list of args only now. Doing so earlier will // cause the py_tuple.o->ob_refcnt to be 2 and not 1, and that will // cause 'PyTuple_SetItem()' to fail. if ( as_tupple ) pargs.push_back(py_tuple); return true; }
//-------------------------------------------------------------------------- // 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, int elc_flags) { 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 QASSERT(616, !handling_lowcnds.has(lc->ea)); handling_lowcnds.push_back(lc->ea); int code; if ( (elc_flags & ELC_KEEP_EIP) == 0 ) { regval_t rv; rv._set_int(lc->ea); code = dbg_write_register(event->tid, pc_idx, &rv); if ( code <= 0 ) { handling_lowcnds.del(lc->ea); return false; } } code = dbg_freeze_threads_except(event->tid); if ( code > 0 ) { int bptlen = lc->type == BPT_SOFT ? lc->orgbytes.size() : lc->size; code = dbg_del_bpt(lc->type, lc->ea, lc->orgbytes.begin(), bptlen); 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, bptlen) <= 0 ) { // if this fails, it may be because the breakpoint is invalid // at this time so we should notify IDA it isn't available // any more code = 0; dwarning("%a: could not restore deleted bpt\n", lc->ea); // odd } } if ( dbg_thaw_threads_except(event->tid) <= 0 ) { dwarning("%d: could not resume suspended threads\n", event->tid); // odd code = 0; } } handling_lowcnds.del(lc->ea); if ( code <= 0 || event->eid != STEP ) return false; // did not resume } if ( (elc_flags & ELC_KEEP_SUSP) != 0 ) return true; return dbg_continue_after_event(event) > 0; }
void unlock(vm_pagenum_t pagenum) { VM_page *found = searchhash(pagenum); QASSERT(found != NULL); if ( found->locked > 0 ) { found->locked--; if ( !found->locked ) locks++; } }
//-------------------------------------------------------------------------- void linux_debmod_t::new_thread(thrinfo_t *info) { int tid = info->ti_lid; threads_t::iterator p = threads.find(tid); if ( p == threads.end() ) // not found { #ifdef LDEB msg("thread %d is new\n", tid); ::display_thrinfo(*info); #endif td_err_e err; td_thr_events_t events; td_event_emptyset(&events); td_event_addset(&events, TD_CREATE); td_event_addset(&events, TD_DEATH); td_event_addset(&events, TD_CATCHSIG); err = td_thr_set_event(info->th_p, &events); DIE_IF_FAILED("td_thr_set_event", err); err = td_thr_event_enable(info->th_p, 1); COMPLAIN_IF_FAILED("td_thr_event_enable", err); if ( err != TD_OK ) { #ifdef LDEB msg("%d: thread dead already? not adding to list.\n", tid); #endif return; } sigset_t set; sigemptyset(&set); sigaddset(&set, SIGSTOP); td_thr_setsigpending(info->th_p, 1, &set); debug_event_t ev; ev.eid = THREAD_START; ev.pid = process_handle; ev.tid = tid; ev.ea = (ea_t)info->ti_startfunc; ev.handled = true; add_thread(tid); // attach to the thread and make is ready for debugging qptrace(PTRACE_ATTACH, tid, 0, 0); int status; int tid2 = waitpid(tid, &status, __WCLONE); // (must succeed) consume SIGSTOP QASSERT(tid2 != -1 && WIFSTOPPED(status) && WSTOPSIG(status) == SIGSTOP); get_thread(tid)->waiting_sigstop = false; enqueue_event(ev, IN_FRONT); } get_thread(tid)->thr = info->th_p; }
bool lock(vm_pagenum_t pagenum) { if ( locks > 0 ) { VM_page *found = searchhash(pagenum); QASSERT(found != NULL); if ( !found->locked ) locks--; found->locked++; return true; } return false; }
void SReqListener::request(const ReqMsg &msg) { SMutex::Autolock autoLock(mLock); if (mQueue->size() >= mQueue->maxSize()) { LOGVBS("%s: wait for queueing, current size: %llu", mName.c_str(), mQueue->size()); QASSERT(mQueue->size() == mQueue->maxSize()); mQueuePoped.wait(mLock); } mQueue->push(msg); mQueuePushed.signal(); }
void Acceleration_Calibration_Wizard::set_calibration_points(sz::calibration::Acceleration_Points const& data) { rapidjson::Document calibrationj; calibrationj.SetObject(); autojsoncxx::to_document(data, calibrationj); q::Path path("Calibration"); path += m_output.name; rapidjson::Document configj = jsonutil::clone_value(m_node->config); if (!jsonutil::remove_value(configj, path)) { QASSERT(0); return; } if (!jsonutil::add_value(configj, path, std::move(calibrationj), configj.GetAllocator())) { QASSERT(0); return; } m_hal.set_node_config(m_node, configj); }
void AIOP_PWM_Out::set_data_for_all(Data const& data) { QASSERT(m_is_initialized); int16_t pulse = static_cast<int16_t>(data.value * PULSE_RANGE_F); pulse = MIN_PULSE_WIDTH + math::clamp(pulse, int16_t(0), PULSE_RANGE); OCR3B = pulse; //2 OCR3C = pulse; //3 OCR3A = pulse; //5 OCR4A = pulse; //6 OCR4B = pulse; //7 OCR4C = pulse; //8 OCR1A = pulse;// d11 OCR1B = pulse;// d12 }
//-------------------------------------------------------------------------- // determine the future bpt size and read the original instruction from memory. // if necessary, the bpt address may be adjusted. // return the number of read bytes. // this function is overloaded in arm debugger subclasses. int debmod_t::read_bpt_orgbytes(ea_t *p_ea, int *p_len, uchar *buf, int bufsize) { int len = *p_len; if ( (debugger_flags & DBG_FLAG_CAN_CONT_BPT) == 0 ) { // we must save the original bytes before adding the bpt QASSERT(30017, bufsize >= len); if ( dbg_read_memory(*p_ea, buf, len) <= 0 ) return -1; } else { // if the debuger can itself continue from bpts, // orgbytes will not be used by the kernel. however // we must return something because non-empty orgbytes mean // that a soft bpt is active. we return zeroes in b->orgbytes. } return len; }
//-------------------------------------------------------------------------- bool debmod_t::check_input_file_crc32(uint32 orig_crc) { // take this opportunity to check that the derived class initialized // register related fields correctly QASSERT(30016, sp_idx != -1 && pc_idx != -1 && nregs > 0); if ( orig_crc == 0 ) return true; // the database has no crc linput_t *li = open_linput(input_file_path.c_str(), false); if ( li == NULL ) return false; uint32 crc = calc_file_crc32(li); close_linput(li); return crc == orig_crc; }
size_t JSON_Model::Tree_Item::get_row() const { if (!m_parent) { return 0; } auto it = std::find_if(m_parent->m_children.begin(), m_parent->m_children.end(), [this](std::unique_ptr<Tree_Item> const& c) { return c.get() == this; }); if (it != m_parent->m_children.end()) { return std::distance(m_parent->m_children.begin(), it); } QASSERT(0); return 0; }
void AIOP_PWM_Out::set_data(uint8_t ch, Data const& data) { QASSERT(m_is_initialized); int16_t pulse = static_cast<int16_t>(data.value * PULSE_RANGE_F); pulse = MIN_PULSE_WIDTH + math::clamp(pulse, int16_t(0), PULSE_RANGE); switch(ch) { case 0: OCR3B = pulse; break; //2 case 1: OCR3C = pulse; break; //3 case 2: OCR3A = pulse; break; //5 case 3: OCR4A = pulse; break; //6 case 4: OCR4B = pulse; break; //7 case 5: OCR4C = pulse; break; //8 case 6: OCR1A = pulse; break;// d11 case 7: OCR1B = pulse; break;// d12 } }
//-------------------------------------------------------------------------- bool debmod_t::evaluate_and_handle_lowcnd(debug_event_t *event, int elc_flags) { bool resume = false; if ( event->eid == BREAKPOINT ) { ea_t ea = event->bpt.kea != BADADDR ? event->bpt.kea : event->bpt.hea != BADADDR ? event->bpt.hea : event->ea; QASSERT(617, !handling_lowcnds.has(ea)); lowcnd_t *lc = get_failed_lowcnd(event->tid, ea); if ( lc != NULL ) { // condition is not satisfied, just make a single step and resume debdeb("%a: bptcnd yielded false\n", ea); event->handled = true; resume = handle_lowcnd(lc, event, elc_flags); } } return resume; }
//-------------------------------------------------------------------------- cpu_type_t macbase_debmod_t::get_process_cpu(pid_t _pid) { int mib[CTL_MAXNAME]; size_t mibLen = CTL_MAXNAME; int err = sysctlnametomib("sysctl.proc_cputype", mib, &mibLen); if ( err == 0 ) { QASSERT(895, mibLen < CTL_MAXNAME); mib[mibLen] = _pid; mibLen += 1; cpu_type_t cpu_type; size_t cpuTypeSize = sizeof(cpu_type); err = sysctl(mib, mibLen, &cpu_type, &cpuTypeSize, 0, 0); if ( err == 0 ) return cpu_type; } msg("error from sysctl: %s\n", strerror(errno)); return 0; }
int eb_get_pos(EditBuffer *b, int *line_ptr, int *col_ptr, int offset) { Page *p, *p_end; int line, col, line1, col1; QASSERT(offset >= 0); line = 0; col = 0; p = b->page_table; p_end = p + b->nb_pages; for (;;) { if (p >= p_end) goto the_end; if (offset < p->size) break; if (!(p->flags & PG_VALID_POS)) { p->flags |= PG_VALID_POS; get_pos(p->data, p->size, &p->nb_lines, &p->col, &b->charset_state); } line += p->nb_lines; if (p->nb_lines) col = 0; col += p->col; offset -= p->size; p++; } get_pos(p->data, offset, &line1, &col1, &b->charset_state); line += line1; if (line1) col = 0; col += col1; the_end: *line_ptr = line; *col_ptr = col; return line; }
/* return the number of lines and column position for a buffer */ static void get_pos(u8 *buf, int size, int *line_ptr, int *col_ptr, CharsetDecodeState *s) { u8 *p, *p1, *lp; int line, len, col, ch; QASSERT(size >= 0); line = 0; p = buf; lp = p; p1 = p + size; for (;;) { p = memchr(p, '\n', p1 - p); if (!p) break; p++; lp = p; line++; } /* now compute number of chars (XXX: potential problem if out of block, but for UTF8 it works) */ col = 0; while (lp < p1) { ch = s->table[*lp]; if (ch == ESCAPE_CHAR) { /* XXX: utf8 only is handled */ len = utf8_length[*lp]; lp += len; } else { lp++; } col++; } *line_ptr = line; *col_ptr = col; }
float Render_Widget::get_depth_at(const math::vec2u32& coords) { if (!m_flags.test(Flag::DEPTH_ACCESS)) { QASSERT(0); return 0; } if (m_buffers_full) { auto& buffer = m_buffers[m_read_buffer_idx]; std::lock_guard<std::mutex> lg(buffer.mutex); resolve_depth_buffer(buffer); auto c = math::min(coords, buffer.size - math::vec2u32(1, 1)); //convert from top-left origin to openGL bottom-left origin c.y = buffer.size.y - c.y - 1; return buffer.depth_data[c.y * buffer.size.x + c.x]; } return 0; }
//-------------------------------------------------------------------------- static const regval_t &idaapi arm_getreg(const char *name, const regval_t *regvals) { int idx = ssmod->get_regidx(name, NULL); QASSERT(30182, idx >= 0 && idx < ssmod->nregs); return regvals[idx]; }
//---------------------------------------------------------------------- static void process_operand(op_t &x,int isAlt,int isload) { switch ( x.type ) { case o_reg: case o_reglist: return; case o_imm: QASSERT(10090, isload); process_immediate_number(x.n); if ( op_adds_xrefs(uFlag, x.n) ) ua_add_off_drefs2(x, dr_O, calc_opimm_flags()); break; case o_phrase: case o_displ: process_immediate_number(x.n); if ( isAlt ) break; if ( op_adds_xrefs(uFlag, x.n) ) { ea_t ea = ua_add_off_drefs2(x, isload ? dr_R : dr_W, calc_opdispl_flags()); if ( ea != BADADDR ) { ua_dodata2(x.offb, ea, x.dtyp); if ( !isload ) doVar(ea); } } // create stack variables if required if ( x.type == o_displ && may_create_stkvars() && !isDefArg(uFlag, x.n) ) { func_t *pfn = get_func(cmd.ea); if ( pfn != NULL && (issp(x.phrase) || isbp(x.phrase) && (pfn->flags & FUNC_FRAME) != 0) ) { if ( ua_stkvar2(x, x.addr, STKVAR_VALID_SIZE) ) op_stkvar(cmd.ea, x.n); } } break; case o_near: case o_far: { cref_t ftype = x.type == o_near ? fl_JN : fl_JF; ea_t ea = calc_mem(x); if ( InstrIsSet(cmd.itype, CF_CALL) ) { if ( !func_does_return(ea) ) flow = false; ftype = x.type == o_near ? fl_CN : fl_CF; } ua_add_cref(x.offb, ea, ftype); } break; case o_mem: { ea_t ea = calc_mem(x); ua_add_dref(x.offb, ea, isload ? dr_R : dr_W); ua_dodata2(x.offb, ea, x.dtyp); if ( !isload ) doVar(ea); } break; default: INTERR(10091); } }