Esempio n. 1
0
void iqueue_pop(void *queue, int *data)
{
    QUEUE *q = (QUEUE *)queue;
    QNODE *node = NULL;

    if(q)
    {
        MUTEX_LOCK(q->mutex);
        if((node = q->first))
        {
            *data = node->data;
            if((q->first = q->first->next) == NULL)
            {
                q->last = NULL;
            }
            node->next = q->left;
            q->left = node;
            --(q->total);
        }
        MUTEX_UNLOCK(q->mutex);
    } 
    return ;
}
Esempio n. 2
0
/* search the list of all policies bound to context @tspContext. If
 * one is found of type popup, return TRUE, else return FALSE. */
TSS_BOOL
obj_context_has_popups(TSS_HCONTEXT tspContext)
{
    struct tsp_object *obj;
    struct tr_policy_obj *policy;
    struct obj_list *list = &policy_list;
    TSS_BOOL ret = FALSE;

    MUTEX_LOCK(list->lock);

    for (obj = list->head; obj; obj = obj->next) {
        if (obj->tspContext == tspContext) {
            policy = (struct tr_policy_obj *)obj->data;
            if (policy->SecretMode == TSS_SECRET_MODE_POPUP)
                ret = TRUE;
            break;
        }
    }

    MUTEX_UNLOCK(list->lock);

    return ret;
}
Esempio n. 3
0
/* Buffer update thread (created and called by DART)
   This is a high-priority thread used to compute and update the audio stream,
   automatically created by the DART subsystem. We compute the next audio
   buffer and feed it to the waveaudio device. */
static LONG APIENTRY Dart_UpdateBuffers(ULONG ulStatus, PMCI_MIX_BUFFER pBuffer, ULONG ulFlags)
{
	/* sanity check */
	if (!pBuffer)
		return TRUE;
	
	/* if we have finished a buffer, we're ready to play a new one */
	if ((ulFlags == MIX_WRITE_COMPLETE) ||
		((ulFlags == (MIX_WRITE_COMPLETE | MIX_STREAM_ERROR)) &&
		 (ulStatus == ERROR_DEVICE_UNDERRUN))) {
		/* refill this audio buffer and feed it again */
		MUTEX_LOCK(vars);
		if (Player_Paused_internal())
			pBuffer->ulBufferLength =
					VC_SilenceBytes(pBuffer->pBuffer, BufferSize);
		else
			pBuffer->ulBufferLength =
					VC_WriteBytes(pBuffer->pBuffer, BufferSize);
		MUTEX_UNLOCK(vars);
		MixSetupParms.pmixWrite(MixSetupParms.ulMixHandle, pBuffer, 1);
	}
	return TRUE;
}
Esempio n. 4
0
static inline void mailstream_ssl_init(void)
{
#ifdef USE_SSL
    mailstream_ssl_init_lock();
    MUTEX_LOCK(&ssl_lock);
#ifndef USE_GNUTLS
    if (!openssl_init_done) {
#if defined (HAVE_PTHREAD_H) && !defined (WIN32) && defined (USE_SSL) && defined (LIBETPAN_REENTRANT)
        mailstream_openssl_reentrant_setup();
#endif

        SSL_load_error_strings();
        SSL_library_init();
        OpenSSL_add_all_algorithms();

        openssl_init_done = 1;
    }
#else
    gnutls_global_init();
#endif
    MUTEX_UNLOCK(&ssl_lock);
#endif
}
Esempio n. 5
0
//add nodeid to qleft
void mmtree64_qleft(void *x, int tnodeid)
{
    int z = 0;
    if(x)
    {
        MUTEX_LOCK(MMT(x)->mutex);
        memset(&(MMT(x)->map[tnodeid]), 0, sizeof(MTNODE64));
        if(MMT(x)->state->qleft == 0)
        {
            MMT(x)->state->qfirst = MMT(x)->state->qlast = tnodeid;
        }
        else
        {
            z = MMT(x)->state->qlast;
            MMT(x)->map[z].parent = tnodeid;
            MMT(x)->state->qlast = tnodeid;
        }
        MMT(x)->state->qleft++;
        MMT(x)->state->left++;
        MUTEX_UNLOCK(MMT(x)->mutex);
    }
    return ;
}
Esempio n. 6
0
/* pop */
int mmqueue_pop(MMQUEUE *mmq, int rootid, int64_t *data)
{
    int id = -1;

    if(mmq && rootid > 0 && rootid < MMQ_ROOT_MAX)
    {
        MUTEX_LOCK(mmq->mutex);
        if(mmq->state && mmq->nodes && mmq->state->roots[rootid].status > 0 
                && mmq->state->roots[rootid].total > 0 
                && (id = mmq->state->roots[rootid].first) > 0)
        {
            if(data) *data = mmq->nodes[id].data;    
            mmq->state->roots[rootid].first = mmq->nodes[id].next;
            mmq->state->roots[rootid].total--;
            if(mmq->state->roots[rootid].total == 0)
                mmq->state->roots[rootid].last = 0;
            mmq->nodes[id].next = mmq->state->qleft;
            mmq->state->qleft = id;
        }
        MUTEX_UNLOCK(mmq->mutex);
    }
    return id;
}
Esempio n. 7
0
MIKMODAPI CHAR* MikMod_InfoDriver(void)
{
	int t;
	size_t len=0;
	MDRIVER *l;
	CHAR *list=NULL;

	MUTEX_LOCK(lists);
	/* compute size of buffer */
	for(l=firstdriver;l;l=l->next)
		len+=4+(l->next?1:0)+strlen(l->Version);

	if(len)
		if((list=MikMod_malloc(len*sizeof(CHAR)))) {
			list[0]=0;
			/* list all registered device drivers : */
			for(t=1,l=firstdriver;l;l=l->next,t++)
				sprintf(list,(l->next)?"%s%2d %s\n":"%s%2d %s",
				    list,t,l->Version);
		}
	MUTEX_UNLOCK(lists);
	return list;
}
Esempio n. 8
0
static int validate_stream_params(struct cli_state *s, struct rxtx_data *rxtx,
                                  const char *argv0)
{
    int status = 0;
    MUTEX_LOCK(&rxtx->data_mgmt.lock);

    /* These items will have been checked when the parameter was set */
    assert(rxtx->data_mgmt.samples_per_buffer >= RXTX_SAMPLES_MIN);
    assert(rxtx->data_mgmt.samples_per_buffer % RXTX_SAMPLES_MIN == 0);
    assert(rxtx->data_mgmt.num_buffers >= RXTX_BUFFERS_MIN);

    if (rxtx->data_mgmt.num_transfers >= rxtx->data_mgmt.num_buffers) {
        cli_err(s, argv0,
                "The 'xfers' parameter (%u) must be < the 'buffers'"
                " parameter (%u).\n", rxtx->data_mgmt.num_transfers,
                rxtx->data_mgmt.num_buffers);

        status = CLI_RET_INVPARAM;
    }

    MUTEX_UNLOCK(&rxtx->data_mgmt.lock);
    return status;
};
asyncTask_t *JKG_Stack_Pop(jkg_stack_t *stack)
{
	asyncTask_t *task;

	// FIXME
	/*if(!stack && !stack->init)
	{
		return;
	}*/

	JKG_Assert(stack);
	JKG_Assert(stack->init);
	MUTEX_LOCK(stack);
	
	task = stack->head;			// Get the head item
	if (task) {					// If it's not NULL, there was an item
		stack->head = stack->head->next;	// Update the head item
		task->next = NULL;
		UNFLAGTASK(task);		// Unflag the task (debug only)
	}
	MUTEX_UNLOCK(stack);		// Unlock the mutex/CS
	return task;
}
Esempio n. 10
0
long eprom24x_core::update_error(eprom24x_exception rxp)
{
  MUTEX_LOCK(m_error_mutex);
  if (m_last_error_read) {
    m_error_source    = rxp.get_source();
    m_error_code      = rxp.get_code();
    m_last_error_read = false; // Latch last error until read
  }
  MUTEX_UNLOCK(m_error_mutex);

#ifdef DEBUG_PRINTS 
  switch(rxp.get_source()) {
  case EPROM24x_INTERNAL_ERROR:
    debug_internal_error();
    break;
  case EPROM24x_LINUX_ERROR:
    debug_linux_error();
    break;
  }
#endif

  return EPROM24x_FAILURE;
}
Esempio n. 11
0
void bytes2buf(void *dest, size_t done, buf_str *ctx) {
	size_t len;
	//FIXME if (done & 3)
	if (ctx->to <= done) { done = ctx->to; ctx->to = 0; }
	else { ctx->to -= done; }
	if (ctx->from >= done) { ctx->from -= done; return; }
	else if (ctx->from > 0) { done -= ctx->from; dest += ctx->from; ctx->from = 0; }
	while (done) {
		len = (ctx->p.period - ctx->cur_period) * CHANNELS * BITS / 8;
		if (len > done) len = done;
		memcpy(ctx->p.buf + (ctx->cur_id * ctx->p.period + ctx->cur_period) * CHANNELS * BITS / 8, dest, len);
		done -= len;
		dest += len;
		ctx->cur_period += len / (CHANNELS * BITS / 8);
		if (ctx->cur_period >= ctx->p.period) {
			ctx->cur_id++;
			ctx->cur_id = ctx->cur_id & ctx->p.buf_max;
			MUTEX_LOCK(ctx->p.mutex + ctx->cur_id);
			MUTEX_UNLOCK(ctx->p.mutex + ((ctx->cur_id - 1) & ctx->p.buf_max));
			ctx->cur_period = 0;
		}
	}
}
Esempio n. 12
0
void
remove_table_entry(TSS_HCONTEXT tspContext)
{
	struct host_table_entry *hte, *prev = NULL;

	MUTEX_LOCK(ht->lock);

	for (hte = ht->entries; hte; prev = hte, hte = hte->next) {
		if (hte->tspContext == tspContext) {
			if (prev != NULL)
				prev->next = hte->next;
			else
				ht->entries = hte->next;
			if (hte->hostname)
				free(hte->hostname);
			free(hte->comm.buf);
			free(hte);
			break;
		}
	}

	MUTEX_UNLOCK(ht->lock);
}
Esempio n. 13
0
static void XAudio2_Exit(void) {
	if (UpdateBufferHandle != NULL) {
		/* signal thread to exit and wait for the exit */
		if (threadInUse) {
			threadInUse = 0;
			MUTEX_UNLOCK(vars);
			SetEvent(hBufferEvent);
			WaitForSingleObject(UpdateBufferHandle, INFINITE);
			MUTEX_LOCK(vars);
		}
		CloseHandle(UpdateBufferHandle);
		UpdateBufferHandle = NULL;
	}
	IXAudio2SourceVoice_Stop(pSourceVoice, 0, 0);
	if (pSourceVoice) {
		IXAudio2SourceVoice_DestroyVoice(pSourceVoice);
		pSourceVoice = NULL;
	}
	if (pMasterVoice) {
		IXAudio2MasteringVoice_DestroyVoice(pMasterVoice);
		pMasterVoice = NULL;
	}
	if (pXAudio2) {
		IXAudio2_Release(pXAudio2);
		pXAudio2 = NULL;
	}
#ifndef __cplusplus
	if (hBufferEvent != NULL) {
		CloseHandle(hBufferEvent);
		hBufferEvent = NULL;
	}
#endif
#ifndef _XBOX
	CoUninitialize();
#endif
	VC_Exit();
}
Esempio n. 14
0
int 
USBDevice_Write(LPSKYETEK_DEVICE device,
		unsigned char* buffer,
		unsigned int length,
    unsigned int timeout)
{
	unsigned char* ptr;
	unsigned char writeSize;
	LPUSB_DEVICE usbDevice;
	
	if((device == NULL) || (buffer == NULL) || (device->user == NULL) )
		return 0;

	usbDevice = (LPUSB_DEVICE)device->user;

	ptr = buffer;

	MUTEX_LOCK(&usbDevice->sendBufferMutex);
	while(length > 0)
	{
		writeSize = usbDevice->endOfSendBuffer - (unsigned int)usbDevice->sendBufferWritePtr;

		writeSize = (length > writeSize) ? writeSize : length;

		memcpy(usbDevice->sendBufferWritePtr, ptr, writeSize);
		
		usbDevice->sendBufferWritePtr += writeSize;
		ptr += writeSize;
		length -= writeSize;

		if((unsigned int)usbDevice->sendBufferWritePtr == usbDevice->endOfSendBuffer)
			USBDevice_internalFlush(device, 0);
	}
	MUTEX_UNLOCK(&usbDevice->sendBufferMutex);

	return (ptr - buffer);
}
Esempio n. 15
0
TSS_RESULT
tcs_wrap_ReadCurrentTicks(struct tcsd_thread_data *data)
{
    TCS_CONTEXT_HANDLE hContext;
    UINT32 pulCurrentTime;
    BYTE *prgbCurrentTime;
    TSS_RESULT result;

    if (getData(TCSD_PACKET_TYPE_UINT32, 0, &hContext, 0, &data->comm))
        return TCSERR(TSS_E_INTERNAL_ERROR);

    LogDebugFn("thread %ld context %x", THREAD_ID, hContext);

    MUTEX_LOCK(tcsp_lock);

    result = TCSP_ReadCurrentTicks_Internal(hContext, &pulCurrentTime, &prgbCurrentTime);

    MUTEX_UNLOCK(tcsp_lock);

    if (result == TSS_SUCCESS) {
        initData(&data->comm, 2);
        if (setData(TCSD_PACKET_TYPE_UINT32, 0, &pulCurrentTime, 0, &data->comm)) {
            free(prgbCurrentTime);
            return TCSERR(TSS_E_INTERNAL_ERROR);
        }
        if (setData(TCSD_PACKET_TYPE_PBYTE, 1, prgbCurrentTime, pulCurrentTime,
                    &data->comm)) {
            free(prgbCurrentTime);
            return TCSERR(TSS_E_INTERNAL_ERROR);
        }
        free(prgbCurrentTime);
    } else
        initData(&data->comm, 0);

    data->comm.hdr.u.result = result;
    return TSS_SUCCESS;
}
Esempio n. 16
0
TSS_RESULT
tcs_wrap_GetTestResult(struct tcsd_thread_data *data)
{
	TCS_CONTEXT_HANDLE hContext;
	TSS_RESULT result;
	UINT32 resultDataSize;
	BYTE *resultData = NULL;

	if (getData(TCSD_PACKET_TYPE_UINT32, 0, &hContext, 0, &data->comm))
		return TCSERR(TSS_E_INTERNAL_ERROR);

	LogDebugFn("thread %zd context %x", THREAD_ID, hContext);

	MUTEX_LOCK(tcsp_lock);

	result = TCSP_GetTestResult_Internal(hContext, &resultDataSize, &resultData);

	MUTEX_UNLOCK(tcsp_lock);

	if (result == TSS_SUCCESS) {
		initData(&data->comm, 2);
		if (setData(TCSD_PACKET_TYPE_UINT32, 0, &resultDataSize, 0, &data->comm)) {
			free(resultData);
			return TCSERR(TSS_E_INTERNAL_ERROR);
		}
		if (setData(TCSD_PACKET_TYPE_PBYTE, 1, resultData, resultDataSize, &data->comm)) {
			free(resultData);
			return TCSERR(TSS_E_INTERNAL_ERROR);
		}
		free(resultData);
	} else
		initData(&data->comm, 0);


	data->comm.hdr.u.result = result;
	return TSS_SUCCESS;
}
Esempio n. 17
0
int bladerf_set_bandwidth(struct bladerf *dev, bladerf_module module,
                          unsigned int bandwidth,
                          unsigned int *actual)
{
    int status;
    lms_bw bw;

    MUTEX_LOCK(&dev->ctrl_lock);

    if (bandwidth < BLADERF_BANDWIDTH_MIN) {
        bandwidth = BLADERF_BANDWIDTH_MIN;
        log_info("Clamping bandwidth to %dHz\n", bandwidth);
    } else if (bandwidth > BLADERF_BANDWIDTH_MAX) {
        bandwidth = BLADERF_BANDWIDTH_MAX;
        log_info("Clamping bandwidth to %dHz\n", bandwidth);
    }

    bw = lms_uint2bw(bandwidth);

    status = lms_lpf_enable(dev, module, true);
    if (status != 0) {
        goto out;
    }

    status = lms_set_bandwidth(dev, module, bw);
    if (actual != NULL) {
        if (status == 0) {
            *actual = lms_bw2uint(bw);
        } else {
            *actual = 0;
        }
    }

out:
    MUTEX_UNLOCK(&dev->ctrl_lock);
    return status;
}
Esempio n. 18
0
/* Require a 10% margin on the sample rate to ensure we can keep up, and
 * warn if this margin is violated.
 *
 * We effectively ensuring:
 *
 * Min sample rate > (xfers / timeout period) * samples / buffer
 *                    ^
 *  1 xfer = buffer --'
 */
static void check_samplerate(struct cli_state *s, struct rxtx_data *rxtx)
{
    int status;
    uint64_t samplerate_min;        /* Min required sample rate */
    unsigned int samplerate_dev;    /* Device's current sample rate */
    unsigned int n_xfers, samp_per_buf, timeout_ms;

    MUTEX_LOCK(&rxtx->data_mgmt.lock);
    n_xfers = (unsigned int)rxtx->data_mgmt.num_transfers;
    samp_per_buf = (unsigned int)rxtx->data_mgmt.samples_per_buffer;
    timeout_ms = rxtx->data_mgmt.timeout_ms;
    MUTEX_UNLOCK(&rxtx->data_mgmt.lock);

    samplerate_min = (uint64_t)n_xfers * samp_per_buf * 1000 / timeout_ms;
    samplerate_min += (samplerate_min + 9) / 10;

    status = bladerf_get_sample_rate(s->dev, rxtx->module, &samplerate_dev);
    if (status < 0) {
        cli_err(s, "Error", "Failed read device's current sample rate. "
                            "Unable to perform sanity check.\n");
    } else if (samplerate_dev < samplerate_min) {
        if (samplerate_min <= 40000000) {
            printf("\n");
            printf("    Warning: The current sample rate may be too low. For %u transfers,\n"
                   "    %u samples per buffer, and a %u ms timeout, a sample rate\n"
                   "    over %"PRIu64" Hz may be required. Alternatively, the 'timeout'\n"
                   "    parameter could be increased, but may yield underruns.\n\n",
                   n_xfers, samp_per_buf, timeout_ms, samplerate_min);
        } else {
            printf("\n");
            printf("    Warning: The current configuraion with %u transfers,\n"
                   "    %u samples per buffer, and a %u ms timeout requires a\n"
                   "    sample rate above 40MHz. Timeouts may occur with these settings.\n\n",
                   n_xfers, samp_per_buf, timeout_ms);
        }
    }
}
Esempio n. 19
0
TSS_RESULT
tcs_wrap_CMK_SetRestrictions(struct tcsd_thread_data *data)
{
	TCS_CONTEXT_HANDLE hContext;
	TSS_CMK_DELEGATE restriction;
	TPM_AUTH ownerAuth;
	TSS_RESULT result;

	if (getData(TCSD_PACKET_TYPE_UINT32, 0, &hContext, 0, &data->comm))
		return TCSERR(TSS_E_INTERNAL_ERROR);

	LogDebugFn("thread %ld context %x", THREAD_ID, hContext);

	if (getData(TCSD_PACKET_TYPE_UINT32, 1, &restriction, 0, &data->comm))
		return TCSERR(TSS_E_INTERNAL_ERROR);

	if (getData(TCSD_PACKET_TYPE_AUTH, 2, &ownerAuth, 0, &data->comm))
		return TCSERR(TSS_E_INTERNAL_ERROR);

	MUTEX_LOCK(tcsp_lock);

	result = TCSP_CMK_SetRestrictions_Internal(hContext, restriction, &ownerAuth);

	MUTEX_UNLOCK(tcsp_lock);

	if (result == TSS_SUCCESS) {
		initData(&data->comm, 1);
		if (setData(TCSD_PACKET_TYPE_AUTH, 0, &ownerAuth, 0, &data->comm))
			return TCSERR(TSS_E_INTERNAL_ERROR);
	} else
		initData(&data->comm, 0);

	data->comm.hdr.u.result = result;

	return TSS_SUCCESS;
}
Esempio n. 20
0
void
_stage_2_ ()
{
  MUTEX_DECL (_stage_2_series_block_stmt_28_c_mutex_);
  MUTEX_LOCK (_stage_2_series_block_stmt_28_c_mutex_);
  _stage_2_inner_inarg_prep_macro__;
  _stage_2_branch_block_stmt_29_c_export_decl_macro_;
  {
// merge  file ShiftRegister.aa, line 41
    _stage_2_merge_stmt_30_c_preamble_macro_;
    _stage_2_merge_stmt_30_c_postamble_macro_;
//              tval := ($bitcast ($uint<16>) midpipe )// bits of buffering = 16 
    _stage_2_assign_stmt_34_c_macro_;
//              outpipe := tval// bits of buffering = 16 
    _stage_2_assign_stmt_37_c_macro_;
// $report (stage_2 sent                 output tval )
    _stage_2_stmt_39_c_macro_;
/* 		$place[loopback]
*/ goto loopback_29;
    _stage_2_branch_block_stmt_29_c_export_apply_macro_;
  }
  _stage_2_inner_outarg_prep_macro__;
  MUTEX_UNLOCK (_stage_2_series_block_stmt_28_c_mutex_);
}
Esempio n. 21
0
/* insert new root */
int mmtree64_new_tree(void *x)
{
    int id = 0, i = 0;
    if(x)
    {
        MUTEX_LOCK(MMT(x)->mutex);
        if(MMT(x)->state->nroots == 0) MMT(x)->state->nroots = 1;
        if(MMT(x)->state && MMT(x)->state->nroots < MMTREE64_ROOT_MAX)
        {
            for(i = 1; i < MMTREE64_ROOT_MAX; i++)
            {
                if(MMT(x)->state->roots[i].status == 0)
                {
                    MMT(x)->state->roots[i].status = 1;
                    MMT(x)->state->nroots++;
                    id = i;
                    break;
                }
            }
        }
        MUTEX_UNLOCK(MMT(x)->mutex);
    }
    return id;
}
Esempio n. 22
0
/* new queue */
int mmqueue_new(MMQUEUE *mmq)
{
    int rootid = -1, i = 0;

    if(mmq)
    {
        MUTEX_LOCK(mmq->mutex);
        if(mmq->state && mmq->map && mmq->state->nroots < MMQ_ROOT_MAX)
        {
            i = 1;
            while(mmq->state->roots[i].status && i < MMQ_ROOT_MAX) ++i;
            if(i < MMQ_ROOT_MAX && mmq->state->roots[i].status == 0)
            {
                mmq->state->roots[i].status = 1;
                mmq->state->nroots++;
                mmq->state->roots[i].total = 0;
                mmq->state->roots[i].first = mmq->state->roots[i].last = 0;
                rootid = i;
            }
        }
        MUTEX_UNLOCK(mmq->mutex);
    }
    return rootid;
}
Esempio n. 23
0
/* Assumes buffer lock is held */
static int advance_tx_buffer(struct bladerf_sync *s, struct buffer_mgmt *b)
{
    int status;

    log_verbose("%s: Marking buf[%u] full\n", __FUNCTION__, b->prod_i);
    b->status[b->prod_i] = SYNC_BUFFER_IN_FLIGHT;

    /* This call may block and it results in a per-stream lock being held, so
     * the buffer lock must be dropped.
     *
     * A callback may occur in the meantime, but this will not touch the status
     * for this this buffer, or the producer index.
     */
    MUTEX_UNLOCK(&b->lock);
    status = async_submit_stream_buffer(s->worker->stream,
                                        b->buffers[b->prod_i],
                                        s->stream_config.timeout_ms);
    MUTEX_LOCK(&b->lock);

    if (status == 0) {
        b->prod_i = (b->prod_i + 1) % b->num_buffers;

        /* Go handle the next buffer, if we have one available.  Otherwise,
         * check up on the worker's state and restart it if needed. */
        if (b->status[b->prod_i] == SYNC_BUFFER_EMPTY) {
            s->state = SYNC_STATE_BUFFER_READY;
        } else {
            s->state = SYNC_STATE_CHECK_WORKER;
        }
    } else {
        log_debug("%s: Failed to advance buffer: %s\n",
                  __FUNCTION__, bladerf_strerror(status));
    }

    return status;
}
Esempio n. 24
0
/*
 * Pushs a list_entry_t at the end of a list
 */
static inline int
push_entry(linked_list_t *list, list_entry_t *entry)
{
    list_entry_t *p;
    if(!entry)
        return -1;
    MUTEX_LOCK(list->lock);
    if(list->length == 0)
    {
        list->head = list->tail = entry;
    }
    else
    {
        p = list->tail;
        p->next = entry;
        entry->prev = p;
        entry->next = NULL;
        list->tail = entry;
    }
    list->length++;
    entry->list = list;
    MUTEX_UNLOCK(list->lock);
    return 0;
}
Esempio n. 25
0
TSS_RESULT
tcs_wrap_OIAP(struct tcsd_thread_data *data)
{
	TCS_CONTEXT_HANDLE hContext;
	TCS_AUTHHANDLE authHandle;
	TCPA_NONCE n0;
	TSS_RESULT result;

	if (getData(TCSD_PACKET_TYPE_UINT32, 0, &hContext, 0, &data->comm))
		return TCSERR(TSS_E_INTERNAL_ERROR);

	if ((result = ctx_verify_context(hContext)))
		goto done;

	LogDebugFn("thread %ld context %x", THREAD_ID, hContext);

	MUTEX_LOCK(tcsp_lock);

	result = auth_mgr_oiap(hContext, &authHandle, &n0);

	MUTEX_UNLOCK(tcsp_lock);

	if (result == TSS_SUCCESS) {
		initData(&data->comm, 2);
		if (setData(TCSD_PACKET_TYPE_UINT32, 0, &authHandle, 0, &data->comm)) {
			return TCSERR(TSS_E_INTERNAL_ERROR);
		}
		if (setData(TCSD_PACKET_TYPE_NONCE, 1, &n0, 0, &data->comm)) {
			return TCSERR(TSS_E_INTERNAL_ERROR);
		}
	} else
done:		initData(&data->comm, 0);

	data->comm.hdr.u.result = result;
	return TSS_SUCCESS;
}
Esempio n. 26
0
TSS_RESULT
tcs_wrap_Extend(struct tcsd_thread_data *data)
{
	TCS_CONTEXT_HANDLE hContext;
	UINT32 pcrIndex;
	TCPA_DIGEST inDigest;
	TSS_RESULT result;
	TCPA_DIGEST outDigest;

	if (getData(TCSD_PACKET_TYPE_UINT32, 0, &hContext, 0, &data->comm))
		return TCSERR(TSS_E_INTERNAL_ERROR);

	LogDebugFn("thread %ld context %x", THREAD_ID, hContext);

	if (getData(TCSD_PACKET_TYPE_UINT32, 1, &pcrIndex, 0, &data->comm))
		return TCSERR(TSS_E_INTERNAL_ERROR);
	if (getData(TCSD_PACKET_TYPE_DIGEST, 2, &inDigest, 0, &data->comm))
		return TCSERR(TSS_E_INTERNAL_ERROR);

	MUTEX_LOCK(tcsp_lock);

	result = TCSP_Extend_Internal(hContext, pcrIndex, inDigest, &outDigest);

	MUTEX_UNLOCK(tcsp_lock);

	if (result == TSS_SUCCESS) {
		initData(&data->comm, 1);
		if (setData(TCSD_PACKET_TYPE_DIGEST, 0, &outDigest, 0, &data->comm)) {
			return TCSERR(TSS_E_INTERNAL_ERROR);
		}
	} else
		initData(&data->comm, 0);

	data->comm.hdr.u.result = result;
	return TSS_SUCCESS;
}
Esempio n. 27
0
static BOOL peer_info(RTP *rtp)
{
int addrlen;
struct sockaddr_in cli_addr, *cli_addrp;
struct hostent *hp;
static CHAR *fid = "peer_info";

    addrlen = sizeof(cli_addr);
    cli_addrp = &cli_addr;
    if (getpeername(rtp->sd, (struct sockaddr *)cli_addrp, &addrlen) != 0) {
        rtp_log(RTP_ERR, "%s: getpeername: %s", fid, strerror(errno));
        return FALSE;
    }
    rtp->addr = (CHAR *) strdup(inet_ntoa(cli_addrp->sin_addr));
    MUTEX_LOCK(&mutex);
        hp = gethostbyaddr(
            (char *) &cli_addrp->sin_addr,
            sizeof(struct in_addr),
            cli_addrp->sin_family
        );
        if (hp != NULL) {
            rtp->peer = (CHAR *) strdup(hp->h_name);
        } else {
            rtp->peer = (CHAR *) strdup(rtp->addr);
        }
    MUTEX_UNLOCK(&mutex);

    if (rtp->peer == (CHAR *) NULL) {
        rtp_log(RTP_ERR, "%s: strdup: %s", fid, strerror(errno));
        return FALSE;
    }

    rtp->port = (UINT16) ntohs(cli_addr.sin_port);

    return TRUE;
}
Esempio n. 28
0
/* check meta */
int xmap_check_meta(XMAP *xmap, int qid, int *status, XMSETS *xsets)
{
    int ret = -1, n = 0, k = 0;

    if(xmap && xsets && qid > 0)
    {
        MUTEX_LOCK(xmap->mutex);
        if(qid <= xmap->state->id_max && (ret = n = xmap->metas[qid].count) > 0)
        {
            *status = xmap->metas[qid].status;
            while(--n >= 0)
            {
                if((k = xmap->metas[qid].disks[n]) > 0 && k <= xmap->state->disk_id_max)
                {
                    xsets->lists[n].ip = xmap->disks[k].ip;
                    xsets->lists[n].port = xmap->disks[k].port;
                    xsets->lists[n].gid = xmap->disks[k].groupid;
                }
            }
        }
        MUTEX_UNLOCK(xmap->mutex);
    }
    return ret;
}
Esempio n. 29
0
int
mgcfifo_out(struct mgcfifo *pfifo, char *destbuff) //拷贝长度为一�?elements
{
  int ret = 0;
  static UINT16 i = 0;

  if (pfifo->fifo_size == 0)
    {
      while (1)
        mprintf("err fifosize == 0!\r\n");
    }

  MUTEX_LOCK ( pfifo->mutex );

  if (pfifo->nvalid == 0)
    {
      ret = -1;
      goto out;
    }

  DEBUG_FIFO("fifo out %d:", i++);
  (void) DEBUG_FIFO_ARRAY(pfifo->tail + pfifo->buff, pfifo->element_size);
  DEBUG_FIFO("\r\n");
  (void) memcpy(destbuff, pfifo->tail + pfifo->buff, pfifo->element_size);
//  if( pfifo->nvalid > 1)
  if (pfifo->tail != pfifo->head)
    {
      mgcfifo_tailinc(pfifo);
    }

  pfifo->nvalid--;

  ret = pfifo->nvalid;
  out: MUTEX_UNLOCK ( pfifo->mutex );
  return ret;
}
bool VDAgent::write_clipboard(VDAgentMessage* msg, uint32_t size)
{
    uint32_t pos = 0;
    bool ret = true;

    ASSERT(msg && size);
    //FIXME: do it smarter - no loop, no memcopy
    MUTEX_LOCK(_message_mutex);
    while (pos < size) {
        DWORD n = MIN(sizeof(VDIChunk) + size - pos, VD_AGENT_MAX_DATA_SIZE);
        VDIChunk* chunk = new_chunk(n);
        if (!chunk) {
            ret = false;
            break;
        }
        chunk->hdr.port = VDP_CLIENT_PORT;
        chunk->hdr.size = n - sizeof(VDIChunk);
        memcpy(chunk->data, (char*)msg + pos, n - sizeof(VDIChunk));
        enqueue_chunk(chunk);
        pos += (n - sizeof(VDIChunk));
    }
    MUTEX_UNLOCK(_message_mutex);
    return ret;
}