Exemple #1
0
static int tpmfront_probe(struct xenbus_device *dev,
		const struct xenbus_device_id *id)
{
	struct tpm_private *priv;
	int rv;

	priv = kzalloc(sizeof(*priv), GFP_KERNEL);
	if (!priv) {
		xenbus_dev_fatal(dev, -ENOMEM, "allocating priv structure");
		return -ENOMEM;
	}

	rv = setup_chip(&dev->dev, priv);
	if (rv) {
		kfree(priv);
		return rv;
	}

	rv = setup_ring(dev, priv);
	if (rv) {
		ring_free(priv);
		return rv;
	}

	tpm_get_timeouts(priv->chip);

	return tpm_chip_register(priv->chip);
}
Exemple #2
0
static
struct chring *chring_tx_to_chring(struct chring_tx *ct)
{
    struct chring *ring;
    int err = 0, i;

    ring = ring_alloc(ct->nr, ct->group);
    if (IS_ERR(ring)) {
        hvfs_err(xnet, "ring_alloc failed w/ %ld\n",
                 PTR_ERR(ring));
        return ring;
    }

    /* ok, let's copy the array to chring */
    for (i = 0; i < ct->nr; i++) {
        err = ring_add_point_nosort(&ct->array[i], ring);
        if (err) {
            hvfs_err(xnet, "ring add point failed w/ %d\n", err);
            goto out;
        }
    }
    /* sort it */
    ring_resort_nolock(ring);

    /* calculate the checksum of the CH ring */
    lib_md5_print(ring->array, ring->alloc * sizeof(struct chp), "CHRING");

    return ring;
out:
    ring_free(ring);
    return ERR_PTR(err);
}
Exemple #3
0
static int tpmfront_remove(struct xenbus_device *dev)
{
	struct tpm_chip *chip = dev_get_drvdata(&dev->dev);
	struct tpm_private *priv = dev_get_drvdata(&chip->dev);
	tpm_chip_unregister(chip);
	ring_free(priv);
	dev_set_drvdata(&chip->dev, NULL);
	return 0;
}
static int tpmfront_remove(struct xenbus_device *dev)
{
	struct tpm_chip *chip = dev_get_drvdata(&dev->dev);
	struct tpm_private *priv = TPM_VPRIV(chip);
	tpm_remove_hardware(&dev->dev);
	ring_free(priv);
	TPM_VPRIV(chip) = NULL;
	return 0;
}
Exemple #5
0
void db_worker_stop() {
    if (!db_enabled) {
        return;
    }
    mtx_lock(&mtx);
    ring_put_exit(&ring);
    cnd_signal(&cnd);
    mtx_unlock(&mtx);
    thrd_join(thrd, NULL);
    cnd_destroy(&cnd);
    mtx_destroy(&mtx);
    ring_free(&ring);
}
Exemple #6
0
RING_API void ring_state_free ( void *pState,void *pMemory )
{
	#if RING_USEPOOLMANAGER
	/* Use Pool Manager */
	if ( pState != NULL ) {
		#if RING_TRACKALLOCATIONS
		((RingState *) pState)->vPoolManager.nFreeCount++ ;
		#endif
		ring_poolmanager_free(((RingState *) pState),pMemory);
		return ;
	}
	#endif
	ring_free(pMemory);
}
Exemple #7
0
void client_free(client c) {
	dlist_node_t node;

	remove_from_monitors(c);
	remove_from_clients(c);
	if (c->flags & CLIENT_CLOSE_ASAP && (node = dlist_find(clients_to_close, c)))
		dlist_remove(clients_to_close, node);
	delete_file_event(el, c->fd, EVENT_READABLE);
	delete_file_event(el, c->fd, EVENT_WRITABLE);
	ring_free(&c->reply);
	client_reset(c);
	FREE(c->argv);
	pthread_spin_destroy(&c->lock);
	close(c->fd);
	xcb_log(XCB_LOG_NOTICE, "Client '%p' got freed", c);
	FREE(c);
}
Exemple #8
0
void ring_poolmanager_free ( RingState *pRingState,void *pMemory )
{
	PoolData *pPoolData  ;
	if ( pRingState != NULL ) {
		if ( pRingState->vPoolManager.pBlockStart != NULL ) {
			if ( (pMemory >= pRingState->vPoolManager.pBlockStart) && (pMemory <= pRingState->vPoolManager.pBlockEnd ) ) {
				pPoolData = (PoolData *) pMemory ;
				pPoolData->pNext = pRingState->vPoolManager.pCurrentItem ;
				pRingState->vPoolManager.pCurrentItem = pPoolData ;
				#if RING_TRACKALLOCATIONS
				pRingState->vPoolManager.nSmallFreeCount++ ;
				#endif
				return ;
			}
		}
	}
	ring_free(pMemory);
}
Exemple #9
0
/** Advance the simulation time by 1 tick.
 * This is called by the core simulator every simulated 1ms.
 * The purpose is to invoke functions that would normally be done
 * by hardware on a periodic basis.
 */
void sim_time_step (void)
{
	struct time_handler *elem, *elem_next, *periodic;

	/* Atomically get and clear the list of timers to
	 * be executed on this tick */
	elem = time_handler_ring[ring_now];
	time_handler_ring[ring_now] = NULL;

	/* Call each timer function */
	while (elem != NULL)
	{
		(*elem->fn) (elem->data);

		if (elem->periodicity)
		{
			/* If periodic, just requeue it rather than free/alloc */
			elem_next = elem->next;


			periodic = time_handler_ring[ring_later (elem->periodicity)];
			if (!periodic)
			{
				time_handler_ring[ring_later (elem->periodicity)] = elem;
			}
			else
			{
				while (periodic->next != NULL)
					periodic = periodic->next;
				periodic->next = elem;
			}
			elem->next = NULL;
			elem = elem_next;
		}
		else
		{
			elem_next = elem->next;
			ring_free (elem);
			elem = elem_next;
		}
	}
	ring_now = ring_later (1);
}
Exemple #10
0
void test_ring() {
  int size;
  unsigned char *buf = malloc(sizeof(unsigned char) * BUF_SIZE);
  Ring *ring = ring_malloc(BUF_SIZE);
  RingReader *reader = reader_malloc(ring);

  size = reader_read(reader, buf);
  assert(0 == size);  
  
  printf("one write and one read\n");
  ring_write(ring, "11", 2);
  size = reader_read(reader, buf);
  assert(2 == size);
  assert(0 == memcmp(buf, "11", 2));

  printf("two writes and one read due to overflow\n");
  ring_write(ring, "22", 2);
  ring_write(ring, "33", 2);
  size = reader_read(reader, buf);
  assert(-1 == size);
  size = reader_read(reader, buf);
  assert(2 == size);
  assert(0 == memcmp(buf, "33", 2));
  
  printf("two small writes and two reads\n");
  ring_write(ring, "4", 1);
  ring_write(ring, "5", 1);
  size = reader_read(reader, buf);
  assert(1 == size);
  assert(0 == memcmp(buf, "4", 1));
  size = reader_read(reader, buf);
  assert(1 == size);
  assert(0 == memcmp(buf, "5", 1));  

  printf("fill once again\n");
  ring_write(ring, "123456", 6);
  size = reader_read(reader, buf);
  assert(6 == size);
  assert(0 == memcmp(buf, "123456", 6));

  ring_free(ring);
}
Exemple #11
0
void test_raw() {
  Ring *ring = ring_malloc(BUF_SIZE);
  unsigned char *buf = malloc(sizeof(unsigned char) * BUF_SIZE);
  unsigned char *reference = malloc(sizeof(unsigned char) * BUF_SIZE);
  int i;
  for (i=0; i < BUF_SIZE; i++) {
    reference[i] = i;
  }

  // raw write entire buffer and verify
  ring_raw_write(ring, 0, reference, BUF_SIZE);
  ring_raw_read(ring, buf, 0, BUF_SIZE);
  assert(0 == memcmp(reference, buf, BUF_SIZE));

  // raw write entire buffer from middle and verify
  ring_raw_write(ring, BUF_SIZE / 2, reference, BUF_SIZE);
  ring_raw_read(ring, buf, BUF_SIZE / 2, BUF_SIZE);
  assert(0 == memcmp(reference, buf, BUF_SIZE));
  
  ring_free(ring);
}