extern "C" void free(void *ptr) { if (fred_wrappers_initializing) { JASSERT(mem_allocated_for_initializing_wrappers); JASSERT(ptr == wrapper_init_buf); return; } void *return_addr = GET_RETURN_ADDRESS(); if ((!shouldSynchronize(return_addr) && !log_all_allocs) || ptr == NULL || jalib::Filesystem::GetProgramName() == "gdb") { _real_pthread_mutex_lock(&allocation_lock); _real_free(ptr); _real_pthread_mutex_unlock(&allocation_lock); return; } log_entry_t my_entry = create_free_entry(my_clone_id, free_event, ptr); void *retval = NULL; if (SYNC_IS_REPLAY) { waitForTurn(&my_entry, &free_turn_check); _real_pthread_mutex_lock(&allocation_lock); _real_free(ptr); _real_pthread_mutex_unlock(&allocation_lock); WRAPPER_REPLAY_END(free); } else if (SYNC_IS_RECORD) { // Not restart; we should be logging. _real_pthread_mutex_lock(&allocation_lock); _real_free(ptr); WRAPPER_LOG_WRITE_ENTRY(my_entry); _real_pthread_mutex_unlock(&allocation_lock); } }
extern "C" int pthread_detach(pthread_t thread) { int retval = 0; void *return_addr = GET_RETURN_ADDRESS(); if (!shouldSynchronize(return_addr)) { int retval = _real_pthread_detach(thread); if (retval == 0) { dmtcp::ThreadInfo::markDetached(thread); } return retval; } log_entry_t my_entry = create_pthread_detach_entry(my_clone_id, pthread_detach_event, thread); //FIXME: We don't need to log/replay this event. if (SYNC_IS_REPLAY) { WRAPPER_REPLAY(pthread_detach); } else if (SYNC_IS_RECORD) { retval = _real_pthread_detach(thread); WRAPPER_LOG_WRITE_ENTRY(pthread_detach); } if (retval == 0) { dmtcp::ThreadInfo::markDetached(thread); } return retval; }
extern "C" int pthread_join (pthread_t thread, void **value_ptr) { /* Reap Existing Threads */ //dmtcp::ThreadInfo::reapThreads(); /* We change things up a bit here. Since we don't allow the user's pthread_join() to have an effect, we don't call the mtcp "delete_thread_on_pthread_join()" function here unless we decide not to synchronize this call to pthread_join(). We DO need to call it from the thread reaper reapThread(), however, which is in pthreadwrappers.cpp. */ //if (!dmtcp::ThreadInfo::isUserJoinable(thread)) { //return EINVAL; //} void *return_addr = GET_RETURN_ADDRESS(); if (!shouldSynchronize(return_addr)) { int retval = _real_pthread_join(thread, value_ptr); if (retval == 0) { dmtcp::ThreadInfo::reapThread(thread); } return retval; } int retval = 0; log_entry_t my_entry = create_pthread_join_entry(my_clone_id, pthread_join_event, thread, value_ptr); if (SYNC_IS_REPLAY) { WRAPPER_REPLAY_START(pthread_join); int saved_retval = (long) RETVAL(my_entry, pthread_join); WRAPPER_REPLAY_END(pthread_join); retval = _real_pthread_join(thread, value_ptr); JASSERT(retval == saved_retval); if (value_ptr != NULL) { JASSERT(*value_ptr == GET_FIELD(my_entry, pthread_join, ret_value_ptr)); } } else if (SYNC_IS_RECORD) { WRAPPER_LOG_RESERVE_SLOT(pthread_join); retval = _real_pthread_join(thread, value_ptr); if (value_ptr != NULL) { SET_FIELD2(my_entry, pthread_join, ret_value_ptr, *value_ptr); } WRAPPER_LOG_UPDATE_ENTRY(pthread_join); } return retval; }
extern "C" int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void*), void *arg) { /* Reap Existing Threads */ dmtcp::ThreadInfo::reapThreads(); int retval; /* Here I've split apart WRAPPER_HEADER_RAW because we need to create the * reaper thread even if the current mode is SYNC_IS_NOOP. */ void *return_addr = GET_RETURN_ADDRESS(); if (!dmtcp_is_running_state() || !validAddress(return_addr) || isProcessGDB()) { retval = _real_pthread_create(thread, attr, start_routine, arg); } else if (SYNC_IS_NOOP) { struct create_arg *createArg = (struct create_arg*) JALLOC_HELPER_MALLOC(sizeof(*createArg)); createArg->fn = start_routine; createArg->thread_arg = arg; createArg->userStack = (void*) -1; // Make sure it is non-NULL if (attr != NULL) { createArg->attr = *attr; pthread_attr_getdetachstate(attr, &createArg->userDetachState); } else { createArg->userDetachState = PTHREAD_CREATE_JOINABLE; } dmtcp::ThreadInfo::prePthreadCreate(); retval = _real_pthread_create(thread, attr, start_wrapper, createArg); if (retval != 0) { dmtcp::ThreadInfo::postPthreadCreate(); } } else { retval = internal_pthread_create(thread, attr, start_routine, arg); } if (!pthread_cancel_initialized) { initialize_pthread_cancel(); } return retval; }
void EINT_Registration_and_mask(kal_uint8 eintno, kal_bool Dbounce_En, kal_bool ACT_Polarity, void (reg_hisr)(void), kal_bool auto_umask) { // PDN_CLR(PDN_GPIO); kal_uint32 savedMask; /* If EINT Number is out of range, get return address and send it to exception handler */ if(eintno >= EINT_TOTAL_CHANNEL) { kal_uint32 retaddr; GET_RETURN_ADDRESS(retaddr); kal_fatal_error_handler(KAL_ERROR_DRV_EINT_INVALID_INDEX, retaddr); } /*disable eint interrupt*/ eint_set_irqen(eintno, EINT_DISABLE); /*register LISR*/ /*dispatch for dedicated eint*/ if (eint_is_dedicated & (1<<eintno)) { switch(eint_is_dedicated_map[eintno]) { case DEDICATED_EINT0: { eint_set_l1_eint_enable(DEDICATED_EINT0, EINT_DISABLE); IRQ_Register_LISR(DEDICATED_EINT_IRQ0, DEINT0_LISR, "DEINT0 handler"); } break; case DEDICATED_EINT1: { eint_set_l1_eint_enable(DEDICATED_EINT1, EINT_DISABLE); IRQ_Register_LISR(DEDICATED_EINT_IRQ1, DEINT1_LISR, "DEINT1 handler"); } break; case DEDICATED_EINT2: { eint_set_l1_eint_enable(DEDICATED_EINT2, EINT_DISABLE); IRQ_Register_LISR(DEDICATED_EINT_IRQ2, DEINT2_LISR, "DEINT2 handler"); } break; case DEDICATED_EINT3: { eint_set_l1_eint_enable(DEDICATED_EINT3, EINT_DISABLE); IRQ_Register_LISR(DEDICATED_EINT_IRQ3, DEINT3_LISR, "DEINT3 handler"); } break; default: break; } } else { IRQ_Register_LISR(IRQ_EIT_CODE, EINT_LISR, "EINT handler"); } /* Save and set MCU's I,F bits to disable interrupts */ // savedMask = LockIRQ(); /* Set external interrupt polarity */ EINT_Set_Polarity(eintno,ACT_Polarity); #if !defined(MT6290) gpio_set_eint_src(eintno,eint_src_map[eintno]); #endif if (Dbounce_En) { //eint_set_debounce_duration(eintno,EINT_DB_DUR_DEFAULT); eint_set_debounce_enable(eintno,EINT_ENABLE); } else { /*disable debounce */ eint_set_debounce_enable(eintno,EINT_DISABLE); } /* Save and set MCU's I,F bits to disable interrupts */ savedMask = SaveAndSetIRQMask(); /* Register external interrupt's HISR */ EINT_FUNC.eint_func[eintno] = reg_hisr; EINT_FUNC.eint_active[eintno] = KAL_FALSE; EINT_FUNC.eint_auto_umask[eintno] = auto_umask; if (eint_is_dedicated & (1<<eintno)) { /* register HISR */ DRV_Register_HISR(DRV_DEINT_HISR_ID, DEINT_HISR_Entry); EINT_L2_ACK(eintno); //EINT_UnMask(eintno); RestoreIRQMask(savedMask); } else { /* register HISR */ DRV_Register_HISR(DRV_EINT_HISR_ID, EINT_HISR_Entry); EINT_L2_ACK(eintno); //EINT_UnMask(eintno); IRQSensitivity( IRQ_EIT_CODE, LEVEL_SENSITIVE ); /* Enable external interrupt */ IRQUnmask( IRQ_EIT_CODE ); RestoreIRQMask(savedMask); } }