/* returns the non-garbage block corresponding to the asked var. */ static ENV_VAR* GetEnvBlockByName(const char *var) { ENV_VAR* pVar; int index = IsPreDefinedVar(var); int i; for(i = 0; i < MaxEnvVarsNum; i++) { if( !(pVar = GetEnvBlockByNumber(i)) ) return NULL; enter_critical_section(); if(index) { /* Pre-defined environment variables */ if(pVar->varNum == index) { exit_critical_section(); return pVar; } } else { /* Dynamic environment variables */ if(!strcmp(var, pVar->data)) { exit_critical_section(); return pVar; } } exit_critical_section(); } return NULL; }
/* Gives the nth non-garbage environment block. Indexed starting ZERO */ static ENV_VAR* GetEnvBlockByNumber(int index) { ENV_VAR* pVar; int count = 0; unsigned int end_address, size; pVar = (ENV_VAR*)GetEnvBaseAndSize(&size); end_address = ( int ) pVar + size; /* skip first block */ pVar++; enter_critical_section(); for(;( ( int )pVar < end_address ) && pVar->varNum!=0xFF; pVar = EnvGetNextBlock(pVar)) { if(!IsEnvGarbage(pVar)) { if(count == index){ exit_critical_section(); return pVar; } else count++; } } exit_critical_section(); return NULL; }
int nvram_get_var(const char* name) { enter_critical_section(); NvramVar* var = nvram_find_var(name); if(var == NULL) { puts("unable to find nvram entry\n\n"); exit_critical_section(); return -1; } printf("%s = %s\n", var->name, var->string); exit_critical_section(); return 0; }
/** * @brief Signal an event * * Signals an event. If EVENT_FLAG_AUTOUNSIGNAL is set in the event * object's flags, only one waiting thread is allowed to proceed. Otherwise, * all waiting threads are allowed to proceed until such time as * event_unsignal() is called. * * @param e Event object * @param reschedule If true, waiting thread(s) are executed immediately, * and the current thread resumes only after the * waiting threads have been satisfied. If false, * waiting threads are placed at the end of the run * queue. * * @return Returns NO_ERROR on success. */ status_t event_signal(event_t *e, bool reschedule) { enter_critical_section(); #if EVENT_CHECK ASSERT(e->magic == EVENT_MAGIC); #endif if (!e->signalled) { if (e->flags & EVENT_FLAG_AUTOUNSIGNAL) { /* try to release one thread and leave unsignalled if successful */ if (wait_queue_wake_one(&e->wait, reschedule, NO_ERROR) <= 0) { /* * if we didn't actually find a thread to wake up, go to * signalled state and let the next call to event_wait * unsignal the event. */ e->signalled = true; } } else { /* release all threads and remain signalled */ e->signalled = true; wait_queue_wake_all(&e->wait, reschedule, NO_ERROR); } } exit_critical_section(); return NO_ERROR; }
/** * @brief Wait for event to be signaled * * If the event has already been signaled, this function * returns immediately. Otherwise, the current thread * goes to sleep until the event object is signaled, * the timeout is reached, or the event object is destroyed * by another thread. * * @param e Event object * @param timeout Timeout value, in ms * * @return 0 on success, ERR_TIMED_OUT on timeout, * other values on other errors. */ status_t event_wait_timeout(event_t *e, time_t timeout) { status_t ret = NO_ERROR; enter_critical_section(); #if EVENT_CHECK ASSERT(e->magic == EVENT_MAGIC); #endif if (e->signalled) { /* signalled, we're going to fall through */ if (e->flags & EVENT_FLAG_AUTOUNSIGNAL) { /* autounsignal flag lets one thread fall through before unsignalling */ e->signalled = false; } } else { /* unsignalled, block here */ ret = wait_queue_block(&e->wait, timeout); if (ret < 0) goto err; } err: exit_critical_section(); return ret; }
status_t platform_set_periodic_timer(platform_timer_callback callback, void *arg, lk_time_t interval) { LTRACEF("callback %p, arg %p, interval %lu\n", callback, arg, interval); enter_critical_section(); t_callback = callback; /* disable the timer */ ARM64_WRITE_SYSREG(CNTP_CTL_EL0, 0); /* set the countdown register to max */ ARM64_WRITE_SYSREG(CNTP_TVAL_EL0, INT32_MAX); /* calculate the compare delta and set the comparison register */ interval_delta = (uint64_t)timer_freq * interval / 1000U; last_compare = read_counter() + interval_delta; ARM64_WRITE_SYSREG(CNTP_CVAL_EL0, last_compare); ARM64_WRITE_SYSREG(CNTP_CTL_EL0, 1); unmask_interrupt(INT_PPI_NSPHYS_TIMER); exit_critical_section(); return NO_ERROR; }
static void JNICALL callbackSingleStep(jvmtiEnv * const jvmti_env, JNIEnv * const jni_env, const jthread thread, const jmethodID method, const jlocation location) { (void) jvmti_env; (void) jni_env; (void) thread; (void) location; (void) method; #ifdef DETAILED_RESULTS enter_critical_section(jvmti); if (last_jmethod != method) { last_jmethod = method; if (hashmap_get(map, (map_key_t) method, (void *) &cur_method_stat) == MAP_MISSING) { cur_method_stat = NEW(method_stat_t); cur_method_stat->id = method; (void)hashmap_put(map, (map_key_t) method, cur_method_stat); } } cur_method_stat->counter++; num_instructions_proccessed++; exit_critical_section(jvmti); #else __sync_fetch_and_add(&num_instructions_proccessed, 1); #endif }
/* Callback for JVMTI_EVENT_VM_INIT */ static void JNICALL cbVMInit(jvmtiEnv *jvmti, JNIEnv *env, jthread thread) { enter_critical_section(jvmti); { jclass klass; jfieldID field; /* Register Natives for class whose methods we use */ klass = (*env)->FindClass(env, STRING(MINST_class)); if ( klass == NULL ) { fatal_error("ERROR: JNI: Cannot find %s with FindClass\n", STRING(MINST_class)); } /* Engage calls. */ field = (*env)->GetStaticFieldID(env, klass, STRING(MINST_engaged), "I"); if ( field == NULL ) { fatal_error("ERROR: JNI: Cannot get field from %s\n", STRING(MINST_class)); } (*env)->SetStaticIntField(env, klass, field, 1); } exit_critical_section(jvmti); }
status_t platform_set_periodic_timer( platform_timer_callback callback, void *arg, time_t interval) { #ifdef PLATFORM_MSM7X30 unsigned val = 0; unsigned mask = (0x1 << 28); //Check for the hardware revision val = readl(HW_REVISION_NUMBER); if(val & mask) writel(1, DGT_CLK_CTL); #endif enter_critical_section(); timer_callback = callback; timer_arg = arg; timer_interval = interval; writel(timer_interval * (DGT_HZ / 1000), DGT_MATCH_VAL); writel(0, DGT_CLEAR); writel(DGT_ENABLE_EN | DGT_ENABLE_CLR_ON_MATCH_EN, DGT_ENABLE); register_int_handler(INT_DEBUG_TIMER_EXP, timer_irq, 0); unmask_interrupt(INT_DEBUG_TIMER_EXP); exit_critical_section(); return 0; }
static enum handler_return msm_i2c_isr(void *arg) { enter_critical_section(); msm_i2c_interrupt_locked(); exit_critical_section(); return INT_RESCHEDULE; }
status_t platform_set_oneshot_timer (platform_timer_callback callback, void *arg, lk_time_t interval) { LTRACEF("callback %p, arg %p, timeout %lu\n", callback, arg, interval); uint64_t ticks = u64_mul_u64_fp32_64(interval, timer_freq_msec_conversion); if (unlikely(ticks == 0)) ticks = 1; if (unlikely(ticks > 0xffffffff)) ticks = 0xffffffff; enter_critical_section(); t_callback = callback; oneshot_interval = interval; // disable timer TIMREG(TIMER_CONTROL) = 0; TIMREG(TIMER_LOAD) = ticks; TIMREG(TIMER_CONTROL) = (1<<2) | (1<<0) | (1<<0); // irq enable, oneshot, enable exit_critical_section(); return NO_ERROR; }
/* Java Native Method for exit */ static void MTRACE_native_exit(JNIEnv *env, jclass klass, jobject thread, jint cnum, jint mnum) { enter_critical_section(gdata->jvmti); { /* It's possible we get here right after VmDeath event, be careful */ if ( !gdata->vm_is_dead ) { ClassInfo *cp; MethodInfo *mp; if ( cnum >= gdata->ccount ) { fatal_error("ERROR: Class number out of range\n"); } cp = gdata->classes + cnum; if ( mnum >= cp->mcount ) { fatal_error("ERROR: Method number out of range\n"); } mp = cp->methods + mnum; if ( interested((char*)cp->name, (char*)mp->name, gdata->include, gdata->exclude) ) { mp->returns++; } } } exit_critical_section(gdata->jvmti); }
/** * @brief Acquire a mutex; wait if needed. * * This function waits for a mutex to become available. It * may wait forever if the mutex never becomes free. * * @return NO_ERROR on success, other values on error */ status_t mutex_acquire(mutex_t *m) { status_t ret = NO_ERROR; #if MUTEX_CHECK ASSERT(m->magic == MUTEX_MAGIC); if (current_thread == m->holder) panic("mutex_acquire: thread %p (%s) tried to acquire mutex %p it already owns.\n", current_thread, current_thread->name, m); #endif enter_critical_section(); if (unlikely(++m->count > 1)) { /* * block on the wait queue. If it returns an error, it was likely destroyed * out from underneath us, so make sure we dont scribble thread ownership * on the mutex. */ ret = wait_queue_block(&m->wait, INFINITE_TIME); if (ret < 0) goto err; } #if MUTEX_CHECK m->holder = current_thread; #endif err: exit_critical_section(); return ret; }
void task_sleep(unsigned long delay) { timer_t *timer; dbg("start sleep ...\n"); #ifdef DEBUG scheduler->dump(); #endif timer = (timer_t *)kmalloc(sizeof(*timer)); if (NULL == timer) { error("%s: alloc timer failled\n"); } init_timer_value(timer); enter_critical_section(); oneshot_timer_add(timer, delay, (timer_function)task_sleep_function, (void *)current_task); current_task->state = SLEEPING; scheduler->dequeue_task(current_task, 0); task_schedule(); exit_critical_section(); }
void dex_power_off(void) { unsigned num; if (halt_done) { dprintf(CRITICAL, "%s: poweroff already done\n", __func__); return; } enter_critical_section(); halt_done = true; /* 1. dex 0x14 without interupts (disable irq + write 0x14 to smem)*/ writeb(DEX_POWER_OFF, (unsigned)(MSM_SHARED_BASE + 0xfc100)); /* 2. dex counter ++ */ num = readl((unsigned)(MSM_SHARED_BASE + 0xfc108)) + 1; writel(num, (unsigned)(MSM_SHARED_BASE + 0xfc108)); /* 3. A2M = -1 */ writel(-1, MSM_A2M_INT(4)); /* 4. sleep 5s */ mdelay(500); /* 5. set smem sign 0x55AA00FF */ writel(0x55AA00FF,(unsigned)(MSM_SHARED_BASE + 0xfc08C)); mdelay(500); /* 6. gpio reset */ writel(readl(MSM_GPIOCFG2_BASE + 0x504) | (1 << 9), MSM_GPIOCFG2_BASE + 0x504); mdelay(50); gpio_set(25,0); exit_critical_section(); for (;;); }
lk_bigtime_t current_time_hires(void) { uint64_t tusec; uint32_t count1, count2; uint32_t reload = SysTick->LOAD & SysTick_LOAD_RELOAD_Msk; // The tick count can roll over while we read the counter, // so try to prevent that. do { count1 = (volatile uint32_t)SysTick->VAL; enter_critical_section(); count2 = (volatile uint32_t)SysTick->VAL; tusec = (volatile uint64_t)ticks; exit_critical_section(); } while (count2 > count1); tusec = tusec * 1000; RCC_ClocksTypeDef clocks; RCC_GetClocksFreq(&clocks); uint32_t clk_mhz = clocks.SYSCLK_Frequency / 1000000; count1 = reload - count1; count1 /= clk_mhz; return tusec + count1; }
/** * @brief Release mutex */ status_t mutex_release(mutex_t *m) { #if MUTEX_CHECK ASSERT(m->magic == MUTEX_MAGIC); if (current_thread != m->holder) panic("mutex_release: thread %p (%s) tried to release mutex %p it doesn't own. owned by %p (%s)\n", current_thread, current_thread->name, m, m->holder, m->holder ? m->holder->name : "none"); #endif enter_critical_section(); #if MUTEX_CHECK m->holder = 0; #endif if (unlikely(--m->count >= 1)) { /* release a thread */ wait_queue_wake_one(&m->wait, true, NO_ERROR); } exit_critical_section(); return NO_ERROR; }
/* Callback for JVMTI_EVENT_VM_INIT */ static void JNICALL cbVMInit(jvmtiEnv *jvmti, JNIEnv *env, jthread thread) { enter_critical_section(jvmti); { char tname[MAX_THREAD_NAME_LENGTH]; static jvmtiEvent events[] = { JVMTI_EVENT_THREAD_START, JVMTI_EVENT_THREAD_END }; int i; /* The VM has started. */ get_thread_name(jvmti, thread, tname, sizeof(tname)); stdout_message("VMInit %s\n", tname); /* The VM is now initialized, at this time we make our requests * for additional events. */ for( i=0; i < (int)(sizeof(events)/sizeof(jvmtiEvent)); i++) { jvmtiError error; /* Setup event notification modes */ error = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE, events[i], (jthread)NULL); check_jvmti_error(jvmti, error, "Cannot set event notification"); } } exit_critical_section(jvmti); }
size_t cbuf_read_char(cbuf_t *cbuf, char *c, bool block) { DEBUG_ASSERT(cbuf); DEBUG_ASSERT(c); enter_critical_section(); if (block) event_wait(&cbuf->event); // see if there's data available size_t ret = 0; if (cbuf->tail != cbuf->head) { *c = cbuf->buf[cbuf->tail]; cbuf->tail = INC_POINTER(cbuf, cbuf->tail, 1); if (cbuf->tail == cbuf->head) { // we've emptied the buffer, unsignal the event event_unsignal(&cbuf->event); } ret = 1; } exit_critical_section(); return ret; }
static void JNICALL dataDumpRequest(jvmtiEnv *jvmti) { enter_critical_section(jvmti); { printf("%s\n", gdata->classname); if ( !gdata->dumpInProgress ) { gdata->dumpInProgress = JNI_TRUE; gdata->klassTag = 1; gdata->jvmti->SetTag(gdata->klass, gdata->klassTag); jint count = 0; void* user_data = NULL; jvmti->IterateOverReachableObjects(&heap_root_callback, &stack_ref_callback, &object_ref_callback, user_data); // print ref paths RefPaths* list = ref_paths; int max = gdata->max_count; printf("Reference paths of instances of %s ....\n", gdata->classname); while ((list != NULL) && (max >= 0) ) { ObjectInfo* object = (ObjectInfo*)list->path; printf("\n\nReference Path:"); dfsPrintRefPaths(object); list = list->next; max--; } //unset tags jvmti->IterateOverReachableObjects(&heap_root_callback, &stack_ref_callback, &object_ref_clean_callback, user_data); //delete object info list ObjectInfoList* list1 = objList; while (list1) { ObjectInfoList* node = list1; list1 = list1->next; DeallocateObject(node->obj); delete(node); } objList = NULL; //delete ref paths list list = ref_paths; RefPaths* path; while (list != NULL) { path = list; list = list->next; delete(path); } ref_paths = NULL; gdata->klassTag = 1; gdata->dumpInProgress = JNI_FALSE; } } exit_critical_section(jvmti); }
void menu_putc(char c) { struct fbcon_config *config = fbcon_display(); static int in_putc = 0; if(in_putc) return; // lock if(is_initialized && !in_critical_section()) mutex_acquire(&logbuf_mutex); else enter_critical_section(); in_putc = 1; // automatic line break int cwidth = pf2font_get_cwidth(c); if(logbuf_posx+cwidth>config->width) { logbuf_row++; logbuf_col = 0; logbuf_posx = 0; display_server_refresh(); } // scroll down while(logbuf_row>ARRAY_SIZE(logbuf)-1) { unsigned i; for(i=1; i<ARRAY_SIZE(logbuf); i++) { memcpy(logbuf[i-1], logbuf[i], ARRAY_SIZE(logbuf[0])); } logbuf_row--; } // write char logbuf[logbuf_row][logbuf_col++] = c=='\n'?'\0':c; // expression start static int in_expr = 0; if(!in_expr && c=='\e') in_expr = 1; if(!in_expr) { logbuf_posx+=cwidth; } // expression end else if(in_expr && c=='m') in_expr = 0; // line break if(logbuf_col==ARRAY_SIZE(logbuf[logbuf_row]) || c=='\n') { logbuf_row++; logbuf_col = 0; logbuf_posx = 0; display_server_refresh(); } // unlock in_putc = 0; if(is_initialized && !in_critical_section()) mutex_release(&logbuf_mutex); else exit_critical_section(); }
void initial_task_func(void) { int ret; exit_critical_section(); ret = current_task->entry(current_task->args); task_exit(ret); }
timer_ticks_t timer_get_ticks() { enter_critical_section(); timer_ticks_t ticks = timer_ticks; exit_critical_section(); return ticks; }
void dump_frame(void *frame) { enter_critical_section(); // disable ints #if ARCH_ARM dump_fault_frame((struct arm_fault_frame *)frame); #endif exit_critical_section(); // disable ints }
/* Callback for JVMTI_EVENT_VM_START */ static void JNICALL cbVMStart(jvmtiEnv *jvmti, JNIEnv *env) { enter_critical_section(jvmti); { /* Indicate VM has started */ gdata->vm_is_started = JNI_TRUE; } exit_critical_section(jvmti); }
static int FormatEnvBlock(void) { unsigned int size, i; unsigned char* pFlash = GetEnvBaseAndSize(&size); #ifdef ENV_SPACE_SIZE char *pExtraSpace; if(!(pExtraSpace = _malloc(env_size - size))) { return SBL_EFAILURE; } memset(pExtraSpace, 0xFF, env_size - size); memcpy(pExtraSpace, (char*)env_base + ENV_SPACE_SIZE, env_size - size); #endif enter_critical_section(); /* If Erase returns 0 => Flash has gone bad. Return error */ if(FWBErase((unsigned int)pFlash, size, 0) == 0) { exit_critical_section(); return SBL_EFAILURE; } FWBOpen((int)pFlash); for (i = 0; i <= strlen(envVersion) ;i++) { FWBWriteByte( (int)(pFlash++), envVersion[i]); } #ifdef ENV_SPACE_SIZE pFlash = (char*)env_base + ENV_SPACE_SIZE; for (i = 0; i < env_size - size ;i++) { FWBWriteByte( (int)(pFlash++), pExtraSpace[i]); } _free(pExtraSpace); #endif FWBClose(); exit_critical_section(); return SBL_SUCCESS; }
/* Register interrupt handler */ void register_int_handler(unsigned int vector, int_handler func, void *arg) { ASSERT(vector < NR_IRQS); enter_critical_section(); handler[vector].func = func; handler[vector].arg = arg; exit_critical_section(); }
static void l2_inv_all(void) { /* invalidate all ways */ enter_critical_section(); PL310_L2CC->InvalidateByWay = way_mask; while (PL310_L2CC->InvalidateByWay & way_mask); PL310_L2CC->CacheSync = 0; exit_critical_section(); }
void nvram_display_list() { NvramVar* var = (NvramVar*) gNvramList->next; enter_critical_section(); while(var != (void*) gNvramList) { printf("0x%08x: %s = %s\n", var, var->name, var->string); var = var->next; } printf("\n"); exit_critical_section(); }
void register_int_handler(unsigned int vector, int_handler func, void *arg) { if (vector >= NR_IRQS) return; enter_critical_section(); handler[vector].func = func; handler[vector].arg = arg; exit_critical_section(); }