static inline unsigned char do_cache2(struct cache2 *self)
{
    uint32_t current_serial;
    int change_detected;
    unsigned char c;

    if (pthread_mutex_trylock(&self->lock)) {
        /* We are willing to accept some race in this context */
        return self->evaluate(self);
    }

    change_detected = check_cache(&self->cache_persist)
                   || check_cache(&self->cache_ro);
    current_serial = __system_property_area_serial();
    if (current_serial != self->serial) {
        change_detected = 1;
    }
    if (change_detected) {
        refresh_cache(&self->cache_persist, self->key_persist);
        refresh_cache(&self->cache_ro, self->key_ro);
        self->serial = current_serial;
    }
    c = self->evaluate(self);

    pthread_mutex_unlock(&self->lock);

    return c;
}
Exemple #2
0
/* Creates an array of strings cooresponding to the users photosets.
 * Returns the number of photosets or negative for an error.
 *
 * IMPORTANT: Make sure you free(names) after you are done!
 */
unsigned int get_photoset_names(char ***names) {
    GHashTableIter iter;
    char *key;
    unsigned int size, i;

    if(!names)
        return 0;

    pthread_rwlock_rdlock(&cache_lock);
    if(check_cache()) {
        pthread_rwlock_unlock(&cache_lock);
        return 0;
    }

    /* We dont want to add the "" photoset (used for photos without a photoset) into this list */
    size = g_hash_table_size(photoset_ht) - 1;

    if(!(*names = (char **)malloc(sizeof(char *) * size))) {
        pthread_rwlock_unlock(&cache_lock);
        return 0;
    }

    /* Add each photoset to the list. We add the keys since the names may be duplicates/NULL */
    g_hash_table_iter_init(&iter, photoset_ht);
    i = 0;
    while(g_hash_table_iter_next(&iter, (gpointer)&key, NULL)) {
        if(key && strcmp(key, "")) {
            (*names)[i] = strdup(key);
            i++;
        }
    }
    pthread_rwlock_unlock(&cache_lock);
    return i;
}
Exemple #3
0
void *request_handler(void *ptr) {
    #ifdef DEBUG
    printf("enter request_handler\n");
    #endif

    int client_fd = ((Thread_Input*)ptr)->client_fd; 
    Request request;
    Response response;
    parse_request_header(client_fd, &request);
    modify_request_header(&request);
    
    if (check_cache(&request, &response)) {
        send_client(client_fd, &response);
    } else {
        if (forward_request(client_fd, &request, &response) < 0) {
            Close(client_fd);
            return NULL;
        } else {
            if (response.content_size <= MAX_OBJECT_SIZE)
                save_to_cache(&request, &response);
        }
    }
    free(ptr);
    Close(client_fd);
    #ifdef DEBUG
    printf("connection close\n\n");
    printf("leave request_handler\n");
    #endif
    return NULL; 
}
Exemple #4
0
LIBLOG_ABI_PRIVATE int __android_log_is_debuggable()
{
    static uint32_t serial;
    static struct cache_char tag_cache;
    static const char key[] = "ro.debuggable";
    int ret;

    if (tag_cache.c) { /* ro property does not change after set */
        ret = tag_cache.c == '1';
    } else if (lock()) {
        struct cache_char temp_cache = { { NULL, -1 }, '\0' };
        refresh_cache(&temp_cache, key);
        ret = temp_cache.c == '1';
    } else {
        int change_detected = check_cache(&tag_cache.cache);
        uint32_t current_serial = __system_property_area_serial();
        if (current_serial != serial) {
            change_detected = 1;
        }
        if (change_detected) {
            refresh_cache(&tag_cache, key);
            serial = current_serial;
        }
        ret = tag_cache.c == '1';

        unlock();
    }

    return ret;
}
Exemple #5
0
static AtkObject*
gail_notebook_ref_child (AtkObject      *obj,
                         gint           i)
{
  AtkObject *accessible = NULL;
  GailNotebook *gail_notebook;
  GtkNotebook *gtk_notebook;
  GtkWidget *widget;
 
  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
  if (widget == NULL)
    /*
     * State is defunct
     */
    return NULL;

  gail_notebook = GAIL_NOTEBOOK (obj);
  
  gtk_notebook = GTK_NOTEBOOK (widget);

  if (gail_notebook->page_count < gtk_notebook_get_n_pages (gtk_notebook))
    check_cache (gail_notebook, gtk_notebook);

  accessible = find_child_in_list (gail_notebook->page_cache, i);

  if (accessible != NULL)
    g_object_ref (accessible);

  return accessible;
}
Exemple #6
0
/*
 * ldap_search - initiate an ldap (and X.500) search operation.  Parameters:
 *
 *	ld		LDAP descriptor
 *	base		DN of the base object
 *	scope		the search scope - one of LDAP_SCOPE_BASE,
 *			    LDAP_SCOPE_ONELEVEL, LDAP_SCOPE_SUBTREE
 *	filter		a string containing the search filter
 *			(e.g., "(|(cn=bob)(sn=bob))")
 *	attrs		list of attribute types to return for matches
 *	attrsonly	1 => attributes only 0 => attributes and values
 *
 * Example:
 *	char	*attrs[] = { "mail", "title", 0 };
 *	msgid = ldap_search( ld, "c=us@o=UM", LDAP_SCOPE_SUBTREE, "cn~=bob",
 *	    attrs, attrsonly );
 */
int
ldap_search( LDAP *ld, char *base, int scope, char *filter,
	char **attrs, int attrsonly )
{
	BerElement	*ber;

	Debug( LDAP_DEBUG_TRACE, "ldap_search\n", 0, 0, 0 );

	if (( ber = ldap_build_search_req( ld, base, scope, filter, attrs,
	    attrsonly )) == NULLBER ) {
		return( -1 );
	}

#ifndef NO_CACHE
	if ( ld->ld_cache != NULL ) {
		if ( check_cache( ld, LDAP_REQ_SEARCH, ber ) == 0 ) {
			ber_free( ber, 1 );
			ld->ld_errno = LDAP_SUCCESS;
			return( ld->ld_msgid );
		}
		add_request_to_cache( ld, LDAP_REQ_SEARCH, ber );
	}
#endif /* NO_CACHE */

	/* send the message */
	return ( send_initial_request( ld, LDAP_REQ_SEARCH, base, ber ));
}
Exemple #7
0
void cacheex_timeout(ECM_REQUEST *er)
{
	if(er->cacheex_wait_time_expired)
		return;
	er->cacheex_wait_time_expired = 1;
	if(er->rc >= E_UNHANDLED)
	{
		cs_log_dbg(D_LB, "{client %s, caid %04X, prid %06X, srvid %04X} cacheex timeout! ",
					(check_client(er->client) ? er->client->account->usr : "******"), er->caid, er->prid, er->srvid);

		// if check_cw mode=0, first try to get cw from cache without check counter!
		CWCHECK check_cw = get_cwcheck(er);
		if(!check_cw.mode)
		{
			struct ecm_request_t *ecm = NULL;
			ecm = check_cache(er, er->client);

			if(ecm) // found in cache
			{
				struct s_write_from_cache *wfc = NULL;
				if(!cs_malloc(&wfc, sizeof(struct s_write_from_cache)))
				{
					NULLFREE(ecm);
					return;
				}
				wfc->er_new = er;
				wfc->er_cache = ecm;
				if(!add_job(er->client, ACTION_ECM_ANSWER_CACHE, wfc, sizeof(struct s_write_from_cache))) // write_ecm_answer_fromcache
					{ NULLFREE(ecm); }
				return;
			}
		}

		// check if "normal" readers selected, if not send NOT FOUND!
		// cacheex1-client (having always no "normal" reader),
		// or not-cacheex-1 client with no normal readers available (or filtered by LB)
		if((er->reader_count + er->fallback_reader_count - er->cacheex_reader_count) <= 0)
		{
			if(!cfg.wait_until_ctimeout)
			{
				er->rc = E_NOTFOUND;
				er->selected_reader = NULL;
				er->rcEx = 0;
				cs_log_dbg(D_LB, "{client %s, caid %04X, prid %06X, srvid %04X} cacheex timeout: NO \"normal\" readers... not_found! ",
							(check_client(er->client) ? er->client->account->usr : "******"), er->caid, er->prid, er->srvid);

				send_dcw(er->client, er);
				return;
			}
		}
		else
		{
			if(er->stage < 2)
			{
				debug_ecm(D_TRACE, "request for %s %s", username(er->client), buf);
				request_cw_from_readers(er, 0);
			}
		}
	}
}
Exemple #8
0
/*
 * ldap_compare - perform an ldap (and X.500) compare operation.  The dn
 * of the entry to compare to and the attribute and value to compare (in
 * attr and value) are supplied.  The msgid of the response is returned.
 *
 * Example:
 *	ldap_compare( ld, "c=us@cn=bob", "userPassword", "secret" )
 */
int
ldap_compare( LDAP *ld, char *dn, char *attr, char *value )
{
	BerElement	*ber;
	struct berval bv;
	int rv;
	
	/* The compare request looks like this:
	 *	CompareRequest ::= SEQUENCE {
	 *		entry	DistinguishedName,
	 *		ava	SEQUENCE {
	 *			type	AttributeType,
	 *			value	AttributeValue
	 *		}
	 *	}
	 * and must be wrapped in an LDAPMessage.
	 */

#ifdef _REENTRANT
        LOCK_LDAP(ld);
#endif
	Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 128, "ldap_compare\n"), 0, 0, 0 );

	bv.bv_val = value;
	bv.bv_len = strlen(value);
	
	if ((ber = ldap_build_compare_req(ld, dn, attr, &bv, NULL)) == NULLBER) {
#ifdef _REENTRANT
        UNLOCK_LDAP(ld);
#endif
		return (-1);
	}
	
#ifndef NO_CACHE
	if ( ld->ld_cache != NULL ) {
		if ( check_cache( ld, LDAP_REQ_COMPARE, ber ) == 0 ) {
			ber_free( ber, 1 );
			ld->ld_errno = LDAP_SUCCESS;
#ifdef _REENTRANT
			UNLOCK_LDAP(ld);
#endif
			return( ld->ld_msgid );
		}
		add_request_to_cache( ld, LDAP_REQ_COMPARE, ber );
	}
#endif /* NO_CACHE */

	/* send the message */
	rv = send_initial_request( ld, LDAP_REQ_COMPARE, dn, ber );
#ifdef _REENTRANT
        UNLOCK_LDAP(ld);
#endif
	return (rv);
}
Exemple #9
0
/*
 * Internal method to get the cached_photo of
 * a particular photo.
 * Assumes there is a lock initiated
 */
static cached_photo *get_photo(const char *photoset, const char *photo) {
    cached_photoset *cps;

    if(check_cache())
        return NULL;

    if(!(cps = g_hash_table_lookup(photoset_ht, photoset)))
        return NULL;

    if(check_photoset_cache(cps))
        return NULL;

    return g_hash_table_lookup(cps->photo_ht, photo);
}
static 
void configure_caches(cache_t* I1c, cache_t* D1c, cache_t* L2c)
{
#define DEFINED(L)   (-1 != L.size  || -1 != L.assoc || -1 != L.line_size)

   Int n_clos = 0;

   // Count how many were defined on the command line.
   if (DEFINED(clo_I1_cache)) { n_clos++; }
   if (DEFINED(clo_D1_cache)) { n_clos++; }
   if (DEFINED(clo_L2_cache)) { n_clos++; }

   // Set the cache config (using auto-detection, if supported by the
   // architecture)
   VG_(configure_caches)( I1c, D1c, L2c, (3 == n_clos) );

   // Then replace with any defined on the command line.
   if (DEFINED(clo_I1_cache)) { *I1c = clo_I1_cache; }
   if (DEFINED(clo_D1_cache)) { *D1c = clo_D1_cache; }
   if (DEFINED(clo_L2_cache)) { *L2c = clo_L2_cache; }

   // Then check values and fix if not acceptable.
   check_cache(I1c, "I1");
   check_cache(D1c, "D1");
   check_cache(L2c, "L2");

   if (VG_(clo_verbosity) > 1) {
      VG_(message)(Vg_UserMsg, "Cache configuration used:");
      VG_(message)(Vg_UserMsg, "  I1: %dB, %d-way, %dB lines",
                               I1c->size, I1c->assoc, I1c->line_size);
      VG_(message)(Vg_UserMsg, "  D1: %dB, %d-way, %dB lines",
                               D1c->size, D1c->assoc, D1c->line_size);
      VG_(message)(Vg_UserMsg, "  L2: %dB, %d-way, %dB lines",
                               L2c->size, L2c->assoc, L2c->line_size);
   }
#undef CMD_LINE_DEFINED
}
Exemple #11
0
/* Looks for the photoset specified in the argument.
 * Returns pointer to the stored cached_information
 * or 0 if not found.
 */
cached_information *photoset_lookup(const char *photoset) {
    cached_photoset *cps;
    cached_information *ci_copy = NULL;

    pthread_rwlock_rdlock(&cache_lock);
    if(check_cache())
        goto fail;

    cps = g_hash_table_lookup(photoset_ht, photoset);
    if(cps)
        ci_copy = copy_cached_info(&(cps->ci));

fail: pthread_rwlock_unlock(&cache_lock);
    return ci_copy;
}
Exemple #12
0
/***************************************
* install the cache memory
* the largest available memory block must be size bytes
* return actual amount of memory available,
* ie size of largest available block
*/
uint32 install_cache( uint32 size )
{
register uint32 s = size;
uint32   a = MemAvail();	/* available memory */

   assert( head_mem == NULL );	/* must not already be installed !! */

   /* restrict size to range 60k .. (mem available - 60k) */
   if( s == 0 ) s = a/4;	/* default value */
   if( s < 60000 ) s = 60000;	/* min size */
   if( 60000+s > a ) s = a/2;	/* too big ==> use 50% available memory */

   s = ((s+3)&~3)+sizeof(tMemHdr);	/* round up to exact number of longs */
   assert( (sizeof(tMemHdr)&3) == 0 );	/* exact nr longs */

   head_free = head_mem = (tMemHdr*)hi_malloc( s );

   if( head_mem == NULL ) {
      /* pathological case ... */
      nr_blocks = 0;
      total_size = 0;
   }
   else {
      total_size = head_mem->size = s - sizeof(tMemHdr);
      #ifndef NDEBUG
      head_free->magic = MAGIC;
      head_free->data[0] = -1;
      #endif
      head_free->pbase = NULL;
      head_free->next_mem = NULL;
      head_free->prev_mem = NULL;
      head_free->next_list = NULL;
      head_free->prev_list = NULL;
      head_data = tail_data = NULL;
      nr_blocks = 1;
   } /* if */

   total_used = 0;
   total_free = total_size;

   assert( total_free + total_used + (nr_blocks-1)*sizeof(tMemHdr) == total_size );
   assert( check_block(head_free) );
   assert( check_cache() );

   return total_size;

} /* install_cache() */
Exemple #13
0
/******************************************
* refresh a block of memory by moving it to the tail of the data chain
* called by user to refresh a block of memory
* NB: p0 is pointer to the data, need to find pointer to MemHdr first
*/
void use_mem( void *const p0 )
{
register tMemHdr *const p = ((tMemHdr*)( (uint32)p0 - offsetof(tMemHdr, data) )); /* <<< size_t */
register tMemHdr *t0 = p->prev_list;
register tMemHdr *t1 = p->next_list;

   assert( head_mem != NULL );	/* there must be a cache !! */

   assert( p->magic == MAGIC );
   assert( check_block(p) );
   assert( ISDATA(p) );

   assert( head_data != NULL );
   assert( tail_data != NULL );
   assert( t1 != NULL || p == tail_data );
   assert( t0 != NULL || p == head_data );

   if( t1 != NULL ) {

      /** not already at the end, remove block from chain **/

      assert( head_data->next_list != NULL );	/* must be at least 2 blocks - this one & the one at the end */

      t1->prev_list = t0;
      if( t0 != NULL ) {
         t0->next_list = t1;
      }
      else {
         head_data = t1;
      } /* if */

      /** append p to current end of data chain */
      p->prev_list = tail_data;
      tail_data->next_list = p;
      p->next_list = NULL;
      tail_data = p;

   } /* if */

   assert( check_cache() );
   assert( tail_data->data == p0 );

} /* use_mem() */
Exemple #14
0
/* Creates an array of strings cooresponding to  the users photos
 * of a certain photoset. Returns the number of photos in the
 * photoset or negative signaling an error.
 *
 * IMPORTANT: Make sure you free(names) (but not the strings within)
 * after you are done!
 */
unsigned int get_photo_names(const char *photoset, char ***names) {
    GHashTableIter iter;
    char *key;
    cached_photoset *cps;
    cached_photo *cp;
    unsigned int i, size;

    if(!names || !photoset)
        return 0;

    pthread_rwlock_rdlock(&cache_lock);
    if(check_cache())
        goto fail;

    /* If the photoset is not found in the cache, return */
    if(!(cps = g_hash_table_lookup(photoset_ht, photoset)))
        goto fail;

    if(check_photoset_cache(cps))
        goto fail;

    size = g_hash_table_size(cps->photo_ht);

    if(!(*names = (char **)malloc(sizeof(char *) * size)))
        goto fail;

    /* Add each photo to the list. We add the keys since the names may be duplicates/NULL */
    g_hash_table_iter_init(&iter, cps->photo_ht);
    for(i = 0; g_hash_table_iter_next(&iter, (gpointer)&key, (gpointer)&cp); i++)
    {
        (*names)[i] = strdup(key);
    }

    pthread_rwlock_unlock(&cache_lock);
    return size;

fail:   pthread_rwlock_unlock(&cache_lock);
    return 0;
}
Exemple #15
0
/* Decide where to begin the acquisition process. */
static krb5_error_code
begin(krb5_context context, krb5_tkt_creds_context ctx)
{
    krb5_error_code code;

    code = check_cache(context, ctx);
    if (code != 0 || ctx->state == STATE_COMPLETE)
        return code;

    /* If the server realm is unspecified, start with the client realm. */
    if (krb5_is_referral_realm(&ctx->server->realm)) {
        krb5_free_data_contents(context, &ctx->server->realm);
        code = krb5int_copy_data_contents(context, &ctx->client->realm,
                                          &ctx->server->realm);
        TRACE_TKT_CREDS_REFERRAL_REALM(context, ctx->server);
        if (code != 0)
            return code;
    }

    /* Obtain a TGT for the service realm. */
    ctx->getting_tgt_for = STATE_REFERRALS;
    return begin_get_tgt(context, ctx);
}
Exemple #16
0
/* 
 * request_handler - general function to handler each client request 
 */
void *request_handler(int client_fd) {
    #ifdef DEBUG
    printf("enter request_handler\n");
    #endif

    Request request;
    Response response;
    parse_request_header(client_fd, &request);
    modify_request_header(&request);
    
    if (check_cache(&request, &response)) {
        #ifdef DEBUG
        printf("in cache ! \n");
        #endif
        send_client(client_fd, &response);
    } else {
        #ifdef DEBUG
        printf("not in cache !\n");
        #endif
        if (forward_request(client_fd, &request, &response) < 0) {
            close(client_fd);
            return NULL;
        } else {
            /* save to cache if status code 2XX and < max size */
            if (response.content_size <= MAX_OBJECT_SIZE &&
                    response.header[state_ofs] == '2')
                save_to_cache(&request, &response);
        }
    }

    close(client_fd);
    #ifdef DEBUG
    printf("connection close\n");
    printf("leave request_handler\n");
    #endif
    return NULL; 
}
Exemple #17
0
static void
gail_notebook_real_notify_gtk (GObject           *obj,
                               GParamSpec        *pspec)
{
  GtkWidget *widget;
  AtkObject* atk_obj;

  widget = GTK_WIDGET (obj);
  atk_obj = gtk_widget_get_accessible (widget);

  if (strcmp (pspec->name, "page") == 0)
    {
      gint page_num, old_page_num;
      gint focus_page_num = 0;
      gint old_focus_page_num;
      GailNotebook *gail_notebook;
      GtkNotebook *gtk_notebook;
     
      gail_notebook = GAIL_NOTEBOOK (atk_obj);
      gtk_notebook = GTK_NOTEBOOK (widget);
     
      if (gail_notebook->page_count < gtk_notebook_get_n_pages (gtk_notebook))
       check_cache (gail_notebook, gtk_notebook);
      /*
       * Notify SELECTED state change for old and new page
       */
      old_page_num = gail_notebook->selected_page;
      page_num = gtk_notebook_get_current_page (gtk_notebook);
      gail_notebook->selected_page = page_num;
      gail_notebook->focus_tab_page = page_num;
      old_focus_page_num = gail_notebook->focus_tab_page;

      if (page_num != old_page_num)
        {
          AtkObject *obj;

          if (old_page_num != -1)
            {
              obj = gail_notebook_ref_child (atk_obj, old_page_num);
              if (obj)
                {
                  atk_object_notify_state_change (obj,
                                                  ATK_STATE_SELECTED,
                                                  FALSE);
                  g_object_unref (obj);
                }
            }
          obj = gail_notebook_ref_child (atk_obj, page_num);
          if (obj)
            {
              atk_object_notify_state_change (obj,
                                              ATK_STATE_SELECTED,
                                              TRUE);
              g_object_unref (obj);
              /*
               * The page which is being displayed has changed but there is
               * no need to tell the focus tracker as the focus page will also 
               * change or a widget in the page will receive focus if the
               * Notebook does not have tabs.
               */
            }
          g_signal_emit_by_name (atk_obj, "selection_changed");
          g_signal_emit_by_name (atk_obj, "visible_data_changed");
        }
      if (gtk_notebook_get_show_tabs (gtk_notebook) &&
         (focus_page_num != old_focus_page_num))
        {
          if (gail_notebook->idle_focus_id)
            g_source_remove (gail_notebook->idle_focus_id);
          gail_notebook->idle_focus_id = gdk_threads_add_idle (gail_notebook_check_focus_tab, atk_obj);
        }
    }
  else
    GAIL_WIDGET_CLASS (gail_notebook_parent_class)->notify_gtk (obj, pspec);
}
Exemple #18
0
static void *chkcache_process(void)
{
    set_thread_name(__func__);

    time_t timeout;
    struct ecm_request_t *er, *ecm;
#ifdef CS_CACHEEX
    uint8_t add_hitcache_er;
    struct s_reader *cl_rdr;
    struct s_reader *rdr;
    struct s_ecm_answer *ea;
    struct s_client *cex_src=NULL;
#endif
    struct s_write_from_cache *wfc=NULL;

    while(1)
    {
        cs_readlock(&ecmcache_lock);
        for(er = ecmcwcache; er; er = er->next)
        {
            timeout = time(NULL)-((cfg.ctimeout+500)/1000+1);
            if(er->tps.time < timeout)
            {
                break;
            }

            if(er->rc<E_UNHANDLED || er->readers_timeout_check)  //already answered
            {
                continue;
            }

            //********  CHECK IF FOUND ECM IN CACHE
            ecm = check_cache(er, er->client);
            if(ecm)     //found in cache
            {

#ifdef CS_CACHEEX
                //check for add_hitcache
                if(ecm->cacheex_src)   //cw from cacheex
                {
                    if((er->cacheex_wait_time && !er->cacheex_wait_time_expired) || !er->cacheex_wait_time)   //only when no wait_time expires (or not wait_time)
                    {

                        //add_hitcache already called, but we check if we have to call it for these (er) caid|prid|srvid
                        if(ecm->prid!=er->prid || ecm->srvid!=er->srvid)
                        {
                            cex_src = ecm->cacheex_src && is_valid_client(ecm->cacheex_src) && !ecm->cacheex_src->kill ?  ecm->cacheex_src : NULL; //here we should be sure cex client has not been freed!
                            if(cex_src) { //add_hitcache only if client is really active
                                add_hitcache_er=1;
                                cl_rdr = cex_src->reader;
                                if(cl_rdr && cl_rdr->cacheex.mode == 2)
                                {
                                    for(ea = er->matching_rdr; ea; ea = ea->next)
                                    {
                                        rdr = ea->reader;
                                        if(cl_rdr == rdr && ((ea->status & REQUEST_ANSWERED) == REQUEST_ANSWERED))
                                        {
                                            cs_debug_mask(D_CACHEEX|D_CSP|D_LB,"{client %s, caid %04X, prid %06X, srvid %04X} [CACHEEX] skip ADD self request!", (check_client(er->client)?er->client->account->usr:"******"),er->caid, er->prid, er->srvid);
                                            add_hitcache_er=0; //don't add hit cache, reader requested self
                                        }
                                    }
                                }

                                if(add_hitcache_er)
                                {
                                    add_hitcache(cex_src, er);    //USE cacheex client (to get correct group) and ecm from requesting client (to get correct caid|prid|srvid)!!!
                                }
                            }
                        }

                    }
                    else
                    {
                        //add_hitcache already called, but we have to remove it because cacheex not coming before wait_time
                        if(ecm->prid==er->prid && ecm->srvid==er->srvid)
                        {
                            del_hitcache(ecm);
                        }
                    }
                }
                //END check for add_hitcache
#endif

                if(check_client(er->client))
                {

                    wfc=NULL;
                    if(!cs_malloc(&wfc, sizeof(struct s_write_from_cache)))
                    {
                        NULLFREE(ecm);
                        continue;
                    }

                    wfc->er_new=er;
                    wfc->er_cache=ecm;

                    if(!add_job(er->client, ACTION_ECM_ANSWER_CACHE, wfc, sizeof(struct s_write_from_cache)))   //write_ecm_answer_fromcache
                    {
                        NULLFREE(ecm);
                        continue;
                    }
                }
                else
                {
                    NULLFREE(ecm);
                }
            }
        }
        cs_readunlock(&ecmcache_lock);

        cs_sleepms(10);
    }

    return NULL;
}
static cid_data_t *do_lookup(switch_memory_pool_t *pool, switch_event_t *event, const char *num, switch_bool_t skipurl, switch_bool_t skipcitystate)
{
	char *number = NULL;
	char *name = NULL;
	char *url_query = NULL;
	cid_data_t *cid = NULL;
	cid_data_t *cidtmp = NULL;
	switch_bool_t save_cache = SWITCH_FALSE;

	cid = switch_core_alloc(pool, sizeof(cid_data_t));
	switch_assert(cid);

	number = string_digitsonly(pool, num);
	switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "caller_id_number", number);

	/* database always wins */
	if (switch_odbc_available() && globals.odbc_dsn && globals.sql) {
		name = do_db_lookup(pool, event, number, globals.sql);
		if (name) {
			cid->name = name;
			cid->src = "phone_database";
			goto done;
		}
	}

	if (globals.cache) {
		cidtmp = check_cache(pool, number);
		if (cidtmp) {
			cid = cidtmp;
			cid->src = switch_core_sprintf(pool, "%s (cache)", cid->src);
			goto done;
		}
	}

	if (!skipurl && globals.whitepages_apikey) {
		cid = do_whitepages_lookup(pool, event, number);
		if (cid && cid->name) {	/* only cache if we have a name */
			save_cache = SWITCH_TRUE;
			goto done;
		}
	}

	if (!skipurl && globals.url) {
		url_query = switch_event_expand_headers(event, globals.url);
		do_lookup_url(pool, event, &name, url_query, NULL, NULL, 0);
		if (name) {
			cid->name = name;
			cid->src = "url";

			save_cache = SWITCH_TRUE;
		}
		if (url_query != globals.url) {
			switch_safe_free(url_query);
		}
	}

  done:
	if (!cid) {
		cid = switch_core_alloc(pool, sizeof(cid_data_t));
		switch_assert(cid);
	}
	/* append area if we can */
	if (!cid->area && !skipcitystate && strlen(number) == 11 && number[0] == '1' && switch_odbc_available() && globals.odbc_dsn && globals.citystate_sql) {

		/* yes, this is really area */
		name = do_db_lookup(pool, event, number, globals.citystate_sql);
		if (name) {
			cid->area = name;
			if (cid->src) {
				cid->src = switch_core_sprintf(pool, "%s,%s", cid->src, "npanxx_database");
			} else {
				cid->src = "npanxx_database";
			}
		}
	}

	if (!cid->area) {
		cid->area = "UNKNOWN";
	}
	if (!cid->name) {
		if (skipcitystate) {
			if (strlen(number) == 11 && number[0] == '1') {
				int a, b, c;
				sscanf(number, "1%3d%3d%4d", &a, &b, &c);
				cid->name = switch_core_sprintf(pool, "%03d-%03d-%04d", a, b, c);
			} else {
				cid->name = number;
			}
		} else {
			cid->name = cid->area;
		}
	}
	if (!cid->src) {
		cid->src = "UNKNOWN";
	}

	if (globals.cache && save_cache) {
		set_cache(pool, number, cid);
	}


	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG10, "cidlookup source: %s\n", cid->src);
	return cid;
}
Exemple #20
0
/*
 * handle_mo() returns NULL if invalid MO found.
 */
char *
handle_mo(struct msg_pack *mp)
{
	int	fd;
	char	*result;
	struct stat64	statbuf;
	Msg_node	*mnp;
	Gettext_t	*gt = global_gt;

#define	CONNECT_ENTRY	\
	mnp->next = gt->m_node; \
	gt->m_node = mnp; \
	gt->c_m_node = mnp

#ifdef GETTEXT_DEBUG
	gprintf(0, "*************** handle_mo(0x%p)\n", (void *)mp);
	printmp(mp, 1);
#endif

	mnp = check_cache(mp);

	if (mnp != NULL) {
		/* cache found */
		return (handle_type_mo(mnp, mp));
	}

	/*
	 * Valid entry not found in the cache
	 */
	mnp = calloc(1, sizeof (Msg_node));
	if (mnp == NULL) {
		DFLTMSG(result, mp->msgid1, mp->msgid2, mp->n, mp->plural);
		return (result);
	}
	mnp->hashid = mp->hash_domain;
	mnp->path = strdup(mp->msgfile);
	if (mnp->path == NULL) {
		free(mnp);
		DFLTMSG(result, mp->msgid1, mp->msgid2, mp->n, mp->plural);
		return (result);
	}

	fd = nls_safe_open(mp->msgfile, &statbuf, &mp->trusted, !mp->nlsp);
	if ((fd == -1) || (statbuf.st_size > LONG_MAX)) {
		if (fd != -1)
			(void) close(fd);
		mnp->type = T_ILL_MO;
		CONNECT_ENTRY;
		return (NULL);
	}
	mp->fsz = (size_t)statbuf.st_size;
	mp->addr = mmap(NULL, mp->fsz, PROT_READ, MAP_SHARED, fd, 0);
	(void) close(fd);

	if (mp->addr == MAP_FAILED) {
		free(mnp->path);
		free(mnp);
		DFLTMSG(result, mp->msgid1, mp->msgid2, mp->n, mp->plural);
		return (result);
	}

	if (setmsg(mnp, (char *)mp->addr, mp->fsz) == -1) {
		free(mnp->path);
		free(mnp);
		(void) munmap(mp->addr, mp->fsz);
		DFLTMSG(result, mp->msgid1, mp->msgid2, mp->n, mp->plural);
		return (result);
	}
	mnp->trusted = mp->trusted;
	CONNECT_ENTRY;

	return (handle_type_mo(mnp, mp));
}
/* 
------------------------------------------------------------------------------------------------------------------
Function name:	main()
------------------------------------------------------------------------------------------------------------------
Arguments passed:	void
Return argunemts:	void

Description:	Controls the flow from extracting arguments from input trace file to implementing simulator logic
				and once the execution is completed, it gives out the statistics of how many clock cycles did it
				take to complete the whole execution, hit count, miss count, read count, write count, etc.
*/
void main (void)
{
	// Local variable declarations
	char arg[16], addr[16];
	bool hit_flag = FALSE;
	bool empty_flag = FALSE;
	bool version_flag = FALSE, debug_flag = FALSE, trace_flag = FALSE;
	uint_8 line_num = 0;

	// Temporary variable declarations
	uint_32 mem_addr;
	uint_32 temp_tag, temp_index, temp_offset;
	
	// File pointers
	FILE *fp;
	FILE *fp_out;
	
	// Counts for different categories to calculate efficiency
	uint_64 clock_cycles = 0;
	uint_64 read_hits = 0, write_hits = 0, read_misses = 0, write_misses = 0, reads = 0, writes = 0;
	uint_64 accesses = 0, hits = 0, misses = 0, write_backs = 0;
	
	// Opening input trace file in read mode and output trace file in writing mode
	fp = fopen(INPUT_TRACE, "r");
	fp_out = fopen("Output.txt", "w");
	
	// Initialize Cache to 0s
	for (uint_32 temp_li1 = 0; temp_li1 < NO_OF_SETS; temp_li1 ++)
	{
		for (uint_32 temp_li2 = 0; temp_li2 < NO_OF_LINES; temp_li2 ++)
		{
			l1cache[temp_li1][temp_li2].tag = 0;
			l1cache[temp_li1][temp_li2].lru = 0;
			l1cache[temp_li1][temp_li2].valid = FALSE;
			for(uint_8 temp_li3 = 0; temp_li3 < SIZE_OF_LINE; temp_li3 ++)
				l1cache[temp_li1][temp_li2].data[temp_li3] = 0;
		}
	}
		
	// Main Logic to read the trace and perform required modifications
	while (fscanf(fp, "%s", arg) != EOF)					// reads arguments like 'r', 'w', "-v", "-t" and "-d"
	{
		// Handling "-v", "-t" and "-d" arguments and making sure arg contains either 'r' or 'w' only.
		while (arg[0] == '-') 
		{
			switch (arg[1])
			{
				case 'v':
				case 'V':	version_flag = TRUE;
							break;
				case 't':
				case 'T':	trace_flag = TRUE;
							break;
				case 'd':
				case 'D':	debug_flag = TRUE;
							break;
			}
			
			// If input trace file ends with "-v", "-t" and "-d", it will end the execution
			if (fscanf(fp, "%s", arg) == EOF)
			{
				break;
			}
		}
		
		fscanf(fp, "%s", addr);						// getting address of 'r' or 'w' argument
		// If version_flag is set, print version and exit execution.
		if (version_flag)
		{
			printf("Version %.1f\n", VERSION);
			break;
		}
		// Echo input command if trace flag is set.
		if (trace_flag)
		{
			printf("%s %s\n", arg, addr);
			if (TRACE_OUT)
				fprintf(fp_out, "%s %s\n", arg, addr);
		}
		accesses ++;
		
		// Seperating tag, index and offset fields from the address field.
		mem_addr 	= (uint_32) strtol (addr, NULL, 0);
		temp_tag 	= (mem_addr & TAG_MSK) >> TAG_VAL;
		temp_index 	= (mem_addr & INDEX_MSK) >> INDEX_VAL;
		temp_offset = mem_addr & OFFSET_MSK;
		line_num 	= check_cache(temp_tag, temp_index, &hit_flag, &empty_flag);
		clock_cycles++;					// increment a clock cycle for every cache visit.
		if (hit_flag)	// cache hit
		{
			hits ++;
			if ((arg[0] == 'r') || (arg[0] == 'R'))
			{
				if(debug_flag)				// if debug_flag is set, dump relevent information
				{
					printf("cache read hit to line %d\n", line_num);
					if (TRACE_OUT)			// to write the same dumped information in an output trace file
						fprintf(fp_out, "cache read hit to line %d\n", line_num);
				}
				read_hits ++;
				reads ++;
			}
			else if ((arg[0] == 'w') || (arg[0] == 'W'))
			{
				if(debug_flag)				// if debug_flag is set, dump relevent information
				{
					printf("cache write hit to line %d\n", line_num);
					if (TRACE_OUT)
						fprintf(fp_out, "cache write hit to line %d\n", line_num);
				}
				write_hits ++;
				writes ++;
				l1cache[temp_index][line_num].dirty = TRUE;				// if cache hit and is a write, then set dirty bit
			}
		}
		else		// cache miss
		{
			misses ++;
			if ((arg[0] == 'r') || (arg[0] == 'R'))
			{
				if(debug_flag)				// if debug_flag is set, dump relevent information
				{
					printf("cache read miss to line %d\n", line_num);
					if (TRACE_OUT)
						fprintf(fp_out, "cache read miss to line %d\n", line_num);
				}
				read_misses ++;
				reads ++;
			}
			else if ((arg[0] == 'w') || (arg[0] == 'W'))
			{
				if(debug_flag)				// if debug_flag is set, dump relevent information
				{
					printf("cache write miss to line %d\n", line_num);
					if (TRACE_OUT)
						fprintf(fp_out, "cache write miss to line %d\n", line_num);
				}
				write_misses++;
				writes ++;
			}
			
			// If dirty bit is set, write back cache line to main memory and reset dirty bit to false
			if (l1cache[temp_index][line_num].dirty == TRUE)
			{
				write_backs ++;
				if(debug_flag)				// if debug_flag is set, dump relevent information
				{
					printf("Dirty bit is set. So writing back line %d of set: %d to main memory\n", line_num, temp_index);
					if (TRACE_OUT)
						fprintf(fp_out, "Dirty bit is set. So writing back line %d of set: %d to main memory\n", line_num, temp_index);
				}
				clock_cycles += 50;			// memory access time to replace the cache line to memory
				l1cache[temp_index][line_num].dirty = FALSE;			// reset dirty bit
			}
			
			clock_cycles += 50;				// cache miss penalty(memory access to get cache line)
			l1cache[temp_index][line_num].tag = temp_tag;			// write tag field when new cache line is replaced
		}
		
		// now set the LRU field for the recently accessed line of a set
		set_lru(line_num, temp_index, &hit_flag, &empty_flag);
		
		// print the accessed set information 
		if(debug_flag)				// if debug_flag is set, dump relevent information
		{
			printf("\t\t\tSet: %d\n", temp_index);
			if (TRACE_OUT)
				fprintf(fp_out, "\t\t\tSet: %d\n", temp_index);
			for (uint_8 temp = 0; temp < NO_OF_LINES; temp ++)
			{
				printf("Line: %d\tTag: 0x%05X\tLRU: %d\tValid: %d\tDirty: %d\n", temp, l1cache[temp_index][temp].tag, l1cache[temp_index][temp].lru, l1cache[temp_index][temp].valid, l1cache[temp_index][temp].dirty);
				if (TRACE_OUT)
					fprintf(fp_out, "Line: %d\tTag: 0x%5X\tLRU: %d\tValid: %d\tDirty: %d\n", temp, l1cache[temp_index][temp].tag, l1cache[temp_index][temp].lru, l1cache[temp_index][temp].valid, l1cache[temp_index][temp].dirty);
			}
		}
	}
	
	// print statistics.
	printf("Total number of clockcycles = %ld\naccesses = %ld; hits = %ld; misses = %ld; reads = %ld; writes = %ld;\nread hits = %ld; write hits = %ld; read misses = %ld; write misses = %ld; write backs = %ld\n", clock_cycles, accesses, hits, misses, reads, writes, read_hits, write_hits, read_misses, write_misses, write_backs);
	printf("Miss ratio = %.4f, Average cycles per instruction = %.4f\n", ((float) misses / accesses), ((float) clock_cycles / accesses)); 
	if (TRACE_OUT)
	{
		fprintf(fp_out, "Total number of clockcycles = %ld\naccesses = %ld; hits = %ld; misses = %ld; reads = %ld; writes = %ld;\nread hits = %ld; write hits = %ld; read misses = %ld; write misses = %ld; write backs = %ld\n", clock_cycles, accesses, hits, misses, reads, writes, read_hits, write_hits, read_misses, write_misses, write_backs);
		fprintf(fp_out, "Miss ratio = %.4f, Average cycles per instruction = %.4f\n", ((float) misses / accesses), ((float) clock_cycles / accesses)); 
	}
	
	// closing all the opened files
	fclose(fp);
	fclose(fp_out);
}
Exemple #22
0
/*********************************************************
 * Core Memory Management Operation
 *********************************************************/
static int access_page(pid_t pid, char mode, addr_t address, addr_t *physical_addr) {
    frame_t frame;
    int ret;
	
    /*
     * Check for a context switch
     */
    if(last_pid != pid ) {
        last_pid = pid;
        stats.num_context_switch++;
		//stats.num_procs++;
		stats.pid_list[stats.num_procs++] = pid;
    }

    /*
     * Check for valid page reference
     */
    if( 0 != check_address(address) ) {
        /*printf("%s: Fault! Invalid Address Reference!\n", current_ref);*/
        stats.num_errors++;
        return -1;
    }

    /*
     * Check the Cache
     * - Success: Load page!
     * - Failure: Check TLB
     * Return:
     *  > 0: Resolved in cache
     *  = 0: Not resolved in cache
     *  < 0: Error!
     */
    ret = check_cache(pid, mode, address, &frame);
    if( ret < 0 ) {
        fprintf(stderr, "Error: Cache lookup failed!\n");
        stats.num_errors++;
        return -1;
    }
    else if( ret > 0 ) {
        /*printf("%s: Cache Hit!\n", current_ref);*/
        stats.cache_hit++;
        *physical_addr = frame*PAGE_SIZE + GET_OFFSET(address);
        return 0;
    }
    stats.cache_miss++;
    printf("%s: Cache Miss...\n", current_ref);

    /*
     * Check the TLB
     * - Success: Access page from RAM, update cache
     * - Failure: Look in Page Table
     *
     * Return:
     *  > 0: Resolved in TLB
     *  = 0: Not resolved in TLB
     *  < 0: Error!
     */
    ret = check_tlb(pid, mode, address, &frame);
    if( ret < 0 ) {
        fprintf(stderr, "Error: TLB lookup failed!\n");
        stats.num_errors++;
        return -1;
    }
    else if( ret > 0 ) {
        printf("%s: TLB Hit!\n", current_ref);
        stats.tlb_hit++;
        *physical_addr = frame*PAGE_SIZE + GET_OFFSET(address);
        return 0;
    }
    stats.tlb_miss++;
    printf("%s: TLB Miss...\n", current_ref);

    /*
     * Check the Page Table
     * - In RAM:
     *   - Access Page from RAM
     *   - Update TLB, Cache
     * - In Swap:
     *   - Find a frame to replace
     *   - Page-Fault
     *   - Update Page Table
     *   - Update TLB, Cache
     */
    //ret = check_page_table(pid, mode, address, &frame);
    ret = check_page_dir(pid, mode, address, &frame);
    if( ret < 0 ) {
        fprintf(stderr, "Error: Page Table lookup failed!\n");
        stats.num_errors++;
        return -1;
    }
    else if( ret > 0 ) {
        *physical_addr = frame*PAGE_SIZE + GET_OFFSET(address);
        return 0;
    }

    fprintf(stderr, "%s: Error: Page Table Miss! This should never happen\n", current_ref);
    exit(-1);

    return -1;
}
/** 
 * Main loop to rewrite packets
 */
int
rewrite_packets(tcpedit_t *tcpedit, pcap_t *pin, pcap_dumper_t *pout)
{
    tcpr_dir_t cache_result = TCPR_DIR_C2S;     /* default to primary */
    struct pcap_pkthdr pkthdr, *pkthdr_ptr;     /* packet header */
    const u_char *pktconst = NULL;              /* packet from libpcap */
    u_char **pktdata = NULL;
    static u_char *pktdata_buff;
    static char *frag = NULL;
    COUNTER packetnum = 0;
    int rcode, frag_len, i, proto;

    pkthdr_ptr = &pkthdr;

    if (pktdata_buff == NULL)
        pktdata_buff = (u_char *)safe_malloc(MAXPACKET);

    pktdata = &pktdata_buff;

    if (frag == NULL)
        frag = (char *)safe_malloc(MAXPACKET);

    /* MAIN LOOP 
     * Keep sending while we have packets or until
     * we've sent enough packets
     */
    while ((pktconst = pcap_next(pin, pkthdr_ptr)) != NULL) {
        packetnum++;
        dbgx(2, "packet " COUNTER_SPEC " caplen %d", packetnum, pkthdr.caplen);

        /* 
         * copy over the packet so we can pad it out if necessary and
         * because pcap_next() returns a const ptr
         */
        memcpy(*pktdata, pktconst, pkthdr.caplen);

#ifdef ENABLE_VERBOSE
        if (options.verbose)
            tcpdump_print(&tcpdump, pkthdr_ptr, *pktdata);
#endif

        /* Dual nic processing? */
        if (options.cachedata != NULL) {
            cache_result = check_cache(options.cachedata, packetnum);
        }

        /* sometimes we should not send the packet, in such cases
         * no point in editing this packet at all, just write it to the
         * output file (note, we can't just remove it, or the tcpprep cache
         * file will loose it's indexing
         */

        if (cache_result == TCPR_DIR_NOSEND)
            goto WRITE_PACKET; /* still need to write it so cache stays in sync */

        if ((rcode = tcpedit_packet(tcpedit, &pkthdr_ptr, pktdata, cache_result)) == TCPEDIT_ERROR) {
            return -1;
        } else if ((rcode == TCPEDIT_SOFT_ERROR) && HAVE_OPT(SKIP_SOFT_ERRORS)) {
            /* don't write packet */
            dbgx(1, "Packet " COUNTER_SPEC " is suppressed from being written due to soft errors", packetnum);
            continue;
        }


WRITE_PACKET:
#ifdef ENABLE_FRAGROUTE
        if (options.frag_ctx == NULL) {
            /* write the packet when there's no fragrouting to be done */
            pcap_dump((u_char *)pout, pkthdr_ptr, *pktdata);
        } else {
            /* get the L3 protocol of the packet */
            proto = tcpedit_l3proto(tcpedit, AFTER_PROCESS, *pktdata, pkthdr_ptr->caplen);

            /* packet is IPv4/IPv6 AND needs to be fragmented */
            if ((proto ==  ETHERTYPE_IP || proto == ETHERTYPE_IP6) &&
                ((options.fragroute_dir == FRAGROUTE_DIR_BOTH) ||
                 (cache_result == TCPR_DIR_C2S && options.fragroute_dir == FRAGROUTE_DIR_C2S) ||
                 (cache_result == TCPR_DIR_S2C && options.fragroute_dir == FRAGROUTE_DIR_S2C))) {

                if (fragroute_process(options.frag_ctx, *pktdata, pkthdr_ptr->caplen) < 0)
                    errx(-1, "Error processing packet via fragroute: %s", options.frag_ctx->errbuf);

                i = 0;
                while ((frag_len = fragroute_getfragment(options.frag_ctx, &frag)) > 0) {
                    /* frags get the same timestamp as the original packet */
                    dbgx(1, "processing packet " COUNTER_SPEC " frag: %u (%d)", packetnum, i++, frag_len);
                    pkthdr_ptr->caplen = frag_len;
                    pkthdr_ptr->len = frag_len;
                    pcap_dump((u_char *)pout, pkthdr_ptr, (u_char *)frag);
                }
            } else {
                /* write the packet without fragroute */
                pcap_dump((u_char *)pout, pkthdr_ptr, *pktdata);
            }
        }
#else
    /* write the packet when there's no fragrouting to be done */
    pcap_dump((u_char *)pout, pkthdr_ptr, *pktdata);

#endif
    } /* while() */
    return 0;
}
Exemple #24
0
/*
 * handle_lang
 *
 * take care of the LANGUAGE specification
 */
char *
handle_lang(struct cache_pack *cp, struct msg_pack *mp)
{
	Gettext_t *gt = global_gt;
	struct stat64	statbuf;
	const char	*p, *op, *q;
	char	*locale = NULL, *olocale, *result;
	unsigned int	hash_locale;
	size_t	locale_len, olocale_len = 0;
	int	gnu_mo_found = 0;
	int	fd;
	int	ret;

#ifdef GETTEXT_DEBUG
	(void) printf("*************** handle_lang(0x%p, 0x%p)\n",
		(void *)cp, (void *)mp);
	printcp(cp, 0);
	printmp(mp, 0);
#endif

	p = mp->language;

	while (*p) {
		op = p;
		q = strchr(p, ':');
		if (!q) {
			locale_len = strlen(p);
			p += locale_len;
		} else {
			locale_len = q - p;
			p += locale_len + 1;
		}
		if ((locale_len >= MAXPATHLEN) ||
			(locale_len == 0)) {
			/* illegal locale name */
			continue;
		}
		if (olocale_len < locale_len) {
			olocale = locale;
			locale = (char *)realloc(locale, locale_len + 1);
			if (!locale) {
				if (olocale)
					free(olocale);
				DFLTMSG(result, mp->msgid1, mp->msgid2,
					mp->n, mp->plural);
				return (result);
			}
			olocale_len = locale_len;
		}
		(void) memcpy(locale, op, locale_len);
		locale[locale_len] = '\0';
		hash_locale = get_hashid(locale, NULL);
		mp->locale = locale;
		mp->hash_locale = hash_locale;
		mp->locale_len = locale_len;
#ifdef GETTEXT_DEBUG
		*mp->msgfile = '\0';
#endif
		if (mk_msgfile(mp) == NULL) {
			/* illegal locale name */
			continue;
		}

		cp->node_hash = NULL;

		ret = check_cache(cp, mp);
		if (ret) {
			/*
			 * found in cache
			 */
			switch (cp->mnp->type) {
			case T_ILL_MO:
				/* invalid MO */
				continue;
			case T_SUN_MO:
				/* Solaris MO */
				goto out_loop;
			case T_GNU_MO:
				/* GNU MO */
				gnu_mo_found = 1;
				result = handle_gnu_mo(cp, mp, gt);
				if (result) {
					free(locale);
					return (result);
				}
				continue;
			}
			/* NOTREACHED */
		}
		/*
		 * not found in cache
		 */
		fd = nls_safe_open(mp->msgfile, &statbuf, &mp->trusted, 1);
		if ((fd == -1) || (statbuf.st_size > LONG_MAX)) {
			if (connect_invalid_entry(cp, mp) == -1) {
				DFLTMSG(result, mp->msgid1, mp->msgid2,
					mp->n, mp->plural);
				free(locale);
				return (result);
			}
			continue;
		}
		mp->fsz = (size_t)statbuf.st_size;
		mp->addr = mmap(0, mp->fsz, PROT_READ, MAP_SHARED, fd, 0);
		(void) close(fd);

		if (mp->addr == (caddr_t)-1) {
			if (connect_invalid_entry(cp, mp) == -1) {
				DFLTMSG(result, mp->msgid1, mp->msgid2,
					mp->n, mp->plural);
				free(locale);
				return (result);
			}
			continue;
		}

		cp->mnp = create_mnp(mp);
		if (!cp->mnp) {
			free(locale);
			free_mnp_mp(cp->mnp, mp);
			DFLTMSG(result, mp->msgid1, mp->msgid2, mp->n,
				mp->plural);
			return (result);
		}

		if (setmsg(cp->mnp, (char *)mp->addr, mp->fsz) == -1) {
			free(locale);
			free_mnp_mp(cp->mnp, mp);
			DFLTMSG(result, mp->msgid1, mp->msgid2, mp->n,
				mp->plural);
			return (result);
		}
		if (!cp->cacheline) {
			cp->cnp = create_cnp(cp->mnp, mp);
			if (!cp->cnp) {
				free(locale);
				free_mnp_mp(cp->mnp, mp);
				DFLTMSG(result, mp->msgid1, mp->msgid2,
					mp->n, mp->plural);
				return (result);
			}
		}
		cp->mnp->trusted = mp->trusted;
		connect_entry(cp);

		switch (cp->mnp->type) {
		case T_ILL_MO:
			/* invalid MO */
			continue;
		case T_SUN_MO:
			/* Solaris MO */
			goto out_loop;
		case T_GNU_MO:
			/* GNU MO */
			gnu_mo_found = 1;

			result = handle_gnu_mo(cp, mp, gt);
			if (result) {
				free(locale);
				return (result);
			}
			continue;
		}
		/* NOTREACHED */
	}

out_loop:
	if (gnu_mo_found) {
		DFLTMSG(result, mp->msgid1, mp->msgid2, mp->n, mp->plural);
		free(locale);
		return (result);
	}
	if (locale)
		free(locale);
	return (NULL);
}
Exemple #25
0
/*
  lookup a mangled name, returning the original long name if present
  in the cache
*/
char *pvfs_mangled_lookup(struct pvfs_state *pvfs, TALLOC_CTX *mem_ctx, 
			  const char *name)
{
	return check_cache(pvfs->mangle_ctx, mem_ctx, name);
}
Exemple #26
0
/*************************************************************
* move a block of memory from the data chain to the free chain
* merge with next & previous blocks if possible
*/
static void release_block( register tMemHdr *tr )
{
register tMemHdr *t0;
register tMemHdr *t1;
   assert( tr == NULL || tr->next_mem == NULL || tr->next_mem->prev_mem == tr );
   assert( tr == NULL || tr->prev_mem == NULL || tr->prev_mem->next_mem == tr );
   assert( tr == NULL || tr->next_list == NULL || tr->next_list->prev_list == tr );
   assert( tr == NULL || tr->prev_list == NULL || tr->prev_list->next_list == tr );
   assert( check_block(tr) );
   assert( ISDATA(tr) );
   total_free += tr->size;
   total_used -= tr->size;
   *tr->pbase = NULL;       /* tell application this block has been released */
   tr->pbase = NULL;        /* flag this block as free */
   t0 = tr->prev_list;
   t1 = tr->next_list;
   if( t0 == NULL ) {
      head_data = t1;
   }
   else {
      t0->next_list = t1;
   } /* if */
   if( t1 == NULL ) {
      tail_data = t0;
   }
   else {
      t1->prev_list = t0;
   } /* if */

   /** block removed from data chain, now try merge with next, previous **/

   t1 = tr->next_mem;
   if( t1 != NULL && ISFREE(t1) ) {

      /** we can absorb the next mem block **/
      #ifdef TEST
      merged_next++;
      dprintf(( "merging block(%ld, size %ld) & following(%ld, size %ld)\n", (long)tr->data[0], (long)tr->size, (long)tr->next_mem->data[0], (long)tr->next_mem->size ));
      #endif

      rem_free( t1 );    /** remove next from free list **/

      /** remove tr->next_mem from memory list **/
      tr->size += t1->size + sizeof(tMemHdr);
      tr->next_mem = t0 = t1->next_mem;
      if( t0 != NULL ) {
         t0->prev_mem = tr;
      } /* if */

      assert( tr->next_mem == NULL || tr->next_mem->prev_mem == tr );
      assert( tr->next_mem == NULL || (uint32)tr + sizeof(tMemHdr) + tr->size == (uint32)tr->next_mem );

      dprintf(( "size of merged block is %ld\n", (long)tr->size ));
      total_free += sizeof( tMemHdr );
      nr_blocks--;
   } /* if */
   assert( total_free + total_used + (nr_blocks-1)*sizeof(tMemHdr) == total_size );

   t0 = tr->prev_mem;
   if( t0 != NULL && ISFREE(t0) ) {

      /** we can merge into the prev mem block **/

      #ifdef TEST
      dprintf(( "merging block(%ld, size %ld) & previous(%ld, size %ld)\n", (long)tr->data[0], (long)tr->size, (long)tr->prev_mem->data[0], (long)tr->prev_mem->size ));
      merged_prev++;
      #endif

      rem_free( t0 );     /** remove prev from free list **/

      /** remove tr from memory list **/
      t1 = t0->next_mem = tr->next_mem;
      if( t1 != NULL ) {
         t1->prev_mem = t0;
      } /* if */
      assert( t0->next_mem == NULL || t0->next_mem->prev_mem == t0 );
      assert( t1 == NULL || t1->prev_mem->next_mem == t1 );

      t0->size += tr->size + sizeof( tMemHdr );
      total_free += sizeof( tMemHdr );
      nr_blocks--;

      tr = t0;	/* tr is adr of merged block */
      dprintf(( "size of merged block is %ld\n", (long)tr->size ));
      assert( tr->next_mem == NULL || (uint32)tr + sizeof(tMemHdr) + tr->size == (uint32)tr->next_mem );
      assert( tr->next_mem == NULL || tr->next_mem->prev_mem == tr);
   } /* if */

   assert( total_free + total_used + (nr_blocks-1)*sizeof(tMemHdr) == total_size );

   add_free( tr );
   assert( check_cache() );
} /* release_block() */
static int __android_log_level(const char *tag, int default_prio)
{
    /* sizeof() is used on this array below */
    static const char log_namespace[] = "persist.log.tag.";
    static const size_t base_offset = 8; /* skip "persist." */
    /* calculate the size of our key temporary buffer */
    const size_t taglen = (tag && *tag) ? strlen(tag) : 0;
    /* sizeof(log_namespace) = strlen(log_namespace) + 1 */
    char key[sizeof(log_namespace) + taglen]; /* may be > PROPERTY_KEY_MAX */
    char *kp;
    size_t i;
    char c = 0;
    /*
     * Single layer cache of four properties. Priorities are:
     *    log.tag.<tag>
     *    persist.log.tag.<tag>
     *    log.tag
     *    persist.log.tag
     * Where the missing tag matches all tags and becomes the
     * system global default. We do not support ro.log.tag* .
     */
    static char last_tag[PROP_NAME_MAX];
    static uint32_t global_serial;
    /* some compilers erroneously see uninitialized use. !not_locked */
    uint32_t current_global_serial = 0;
    static struct cache tag_cache[2];
    static struct cache global_cache[2];
    int change_detected;
    int global_change_detected;
    int not_locked;

    strcpy(key, log_namespace);

    global_change_detected = change_detected = not_locked = lock();

    if (!not_locked) {
        /*
         *  check all known serial numbers to changes.
         */
        for (i = 0; i < (sizeof(tag_cache) / sizeof(tag_cache[0])); ++i) {
            if (check_cache(&tag_cache[i])) {
                change_detected = 1;
            }
        }
        for (i = 0; i < (sizeof(global_cache) / sizeof(global_cache[0])); ++i) {
            if (check_cache(&global_cache[i])) {
                global_change_detected = 1;
            }
        }

        current_global_serial = __system_property_area_serial();
        if (current_global_serial != global_serial) {
            change_detected = 1;
            global_change_detected = 1;
        }
    }

    if (taglen) {
        int local_change_detected = change_detected;
        if (!not_locked) {
            if (!last_tag[0]
                    || (last_tag[0] != tag[0])
                    || strncmp(last_tag + 1, tag + 1, sizeof(last_tag) - 1)) {
                /* invalidate log.tag.<tag> cache */
                for (i = 0; i < (sizeof(tag_cache) / sizeof(tag_cache[0])); ++i) {
                    tag_cache[i].pinfo = NULL;
                    tag_cache[i].c = '\0';
                }
                last_tag[0] = '\0';
                local_change_detected = 1;
            }
            if (!last_tag[0]) {
                strncpy(last_tag, tag, sizeof(last_tag));
            }
        }
        strcpy(key + sizeof(log_namespace) - 1, tag);

        kp = key;
        for (i = 0; i < (sizeof(tag_cache) / sizeof(tag_cache[0])); ++i) {
            struct cache *cache = &tag_cache[i];
            struct cache temp_cache;

            if (not_locked) {
                temp_cache.pinfo = NULL;
                temp_cache.c = '\0';
                cache = &temp_cache;
            }
            if (local_change_detected) {
                refresh_cache(cache, kp);
            }

            if (cache->c) {
                c = cache->c;
                break;
            }

            kp = key + base_offset;
        }
    }

    switch (toupper(c)) { /* if invalid, resort to global */
    case 'V':
    case 'D':
    case 'I':
    case 'W':
    case 'E':
    case 'F': /* Not officially supported */
    case 'A':
    case 'S':
    case BOOLEAN_FALSE: /* Not officially supported */
        break;
    default:
        /* clear '.' after log.tag */
        key[sizeof(log_namespace) - 2] = '\0';

        kp = key;
        for (i = 0; i < (sizeof(global_cache) / sizeof(global_cache[0])); ++i) {
            struct cache *cache = &global_cache[i];
            struct cache temp_cache;

            if (not_locked) {
                temp_cache = *cache;
                if (temp_cache.pinfo != cache->pinfo) { /* check atomic */
                    temp_cache.pinfo = NULL;
                    temp_cache.c = '\0';
                }
                cache = &temp_cache;
            }
            if (global_change_detected) {
                refresh_cache(cache, kp);
            }

            if (cache->c) {
                c = cache->c;
                break;
            }

            kp = key + base_offset;
        }
        break;
    }

    if (!not_locked) {
        global_serial = current_global_serial;
        unlock();
    }

    switch (toupper(c)) {
    case 'V': return ANDROID_LOG_VERBOSE;
    case 'D': return ANDROID_LOG_DEBUG;
    case 'I': return ANDROID_LOG_INFO;
    case 'W': return ANDROID_LOG_WARN;
    case 'E': return ANDROID_LOG_ERROR;
    case 'F': /* FALLTHRU */ /* Not officially supported */
    case 'A': return ANDROID_LOG_FATAL;
    case BOOLEAN_FALSE: /* FALLTHRU */ /* Not Officially supported */
    case 'S': return -1; /* ANDROID_LOG_SUPPRESS */
    }
    return default_prio;
}
Exemple #28
0
static int32_t ecm_ratelimit_findspace(struct s_reader *reader, ECM_REQUEST *er, struct ecmrl rl, int32_t reader_mode)
{

	int32_t h, foundspace = -1;
	int32_t maxecms = MAXECMRATELIMIT; // init maxecms
	int32_t totalecms = 0; // init totalecms
	struct timeb actualtime;
	cs_ftime(&actualtime);
	for(h = 0; h < MAXECMRATELIMIT; h++)    // release slots with srvid that are overtime, even if not called from reader module to maximize available slots!
	{
		if(reader->rlecmh[h].last.time == -1) { continue; }
		int32_t gone = comp_timeb(&actualtime, &reader->rlecmh[h].last);
		if( gone >= (reader->rlecmh[h].ratelimittime + reader->rlecmh[h].srvidholdtime) || gone < 0) // gone <0 fixup for bad systemtime on dvb receivers while changing transponders
		{
			cs_debug_mask(D_CLIENT, "ratelimiter srvid %04X released from slot #%d/%d of reader %s (%d>=%d ratelimit ms + %d ms srvidhold!)",
						  reader->rlecmh[h].srvid, h + 1, MAXECMRATELIMIT, reader->label, gone,
						  reader->rlecmh[h].ratelimittime, reader->rlecmh[h].srvidholdtime);
			reader->rlecmh[h].last.time = -1;
			reader->rlecmh[h].srvid = -1;
			reader->rlecmh[h].kindecm = 0;
		}
		if(reader->rlecmh[h].last.time == -1) { continue; }
		if(reader->rlecmh[h].ratelimitecm < maxecms) { maxecms = reader->rlecmh[h].ratelimitecm; }  // we found a more critical ratelimit srvid
		totalecms++;
	}

	cs_debug_mask(D_CLIENT, "ratelimiter found total of %d srvid for reader %s most critical is limited to %d requests", totalecms, reader->label, maxecms);

	if(reader->cooldown[0] && reader->cooldownstate != 1) { maxecms = MAXECMRATELIMIT; }  // dont apply ratelimits if cooldown isnt in use or not in effect

	for(h = 0; h < MAXECMRATELIMIT; h++)    // check if srvid is already in a slot
	{
		if(reader->rlecmh[h].last.time == -1) { continue; }
		if(reader->rlecmh[h].srvid == er->srvid && reader->rlecmh[h].caid == rl.caid && reader->rlecmh[h].provid == rl.provid
				&& (!reader->rlecmh[h].chid || (reader->rlecmh[h].chid == rl.chid)))
		{
			int32_t gone = comp_timeb(&actualtime, &reader->rlecmh[h].last);
			cs_debug_mask(D_CLIENT, "ratelimiter found srvid %04X for %d ms in slot #%d/%d of reader %s", er->srvid,
						  gone, h + 1, MAXECMRATELIMIT, reader->label);

			// check ecmunique if enabled and ecmunique time is done
			if(reader_mode && reader->ecmunique)
			{
				gone = comp_timeb(&actualtime, &reader->rlecmh[h].last);
				if(gone < reader->ratelimittime)
				{
					if(memcmp(reader->rlecmh[h].ecmd5, er->ecmd5, CS_ECMSTORESIZE))
					{
						if(er->ecm[0] == reader->rlecmh[h].kindecm)
						{
							char ecmd5[17 * 3];
							cs_hexdump(0, reader->rlecmh[h].ecmd5, 16, ecmd5, sizeof(ecmd5));
							cs_debug_mask(D_CLIENT, "ratelimiter ecm %s in this slot for next %d ms!", ecmd5,
										  (int)(reader->rlecmh[h].ratelimittime - gone));

							struct ecm_request_t *erold = NULL;
							if(!cs_malloc(&erold, sizeof(struct ecm_request_t)))
								{ return -2; }
							memcpy(erold, er, sizeof(struct ecm_request_t)); // copy ecm all
							memcpy(erold->ecmd5, reader->rlecmh[h].ecmd5, CS_ECMSTORESIZE); // replace md5 hash
							struct ecm_request_t *ecm = NULL;
							ecm = check_cache(erold, erold->client); //CHECK IF FOUND ECM IN CACHE
							NULLFREE(erold);
							if(ecm)   //found in cache
								{ write_ecm_answer(reader, er, ecm->rc, ecm->rcEx, ecm->cw, NULL); }
							else
								{ write_ecm_answer(reader, er, E_NOTFOUND, E2_RATELIMIT, NULL, "Ratelimiter: no slots free!"); }

							NULLFREE(ecm);
							return -2;
						}
						continue;
					}
				}
				if((er->ecm[0] == reader->rlecmh[h].kindecm)
						&& (gone <= (reader->ratelimittime + reader->srvidholdtime)))
				{

					cs_debug_mask(D_CLIENT, "ratelimiter srvid %04X ecm type %s, only allowing %s for next %d ms in slot #%d/%d of reader %s -> skipping this slot!", reader->rlecmh[h].srvid, (reader->rlecmh[h].kindecm == 0x80 ? "even" : "odd"), (reader->rlecmh[h].kindecm == 0x80 ? "odd" : "even"),
								  (int)(reader->rlecmh[h].ratelimittime + reader->rlecmh[h].srvidholdtime - gone),
								  h + 1, maxecms, reader->label);
					continue;
				}
			}

			if(h > 0)
			{
				for(foundspace = 0; foundspace < h; foundspace++)    // check for free lower slot
				{
					if(reader->rlecmh[foundspace].last.time == -1)
					{
						reader->rlecmh[foundspace] = reader->rlecmh[h]; // replace ecm request info
						reader->rlecmh[h].srvid = -1;
						reader->rlecmh[h].last.time = -1;
						if(foundspace < maxecms)
						{
							cs_debug_mask(D_CLIENT, "ratelimiter moved srvid %04X to slot #%d/%d of reader %s", er->srvid, foundspace + 1, maxecms, reader->label);
							return foundspace; // moving to lower free slot!
						}
						else
						{
							cs_debug_mask(D_CLIENT, "ratelimiter removed srvid %04X from slot #%d/%d of reader %s", er->srvid, foundspace + 1, maxecms, reader->label);
							reader->rlecmh[foundspace].last.time = -1; // free this slot since we are over ratelimit!
							return -1; // sorry, ratelimit!
						}
					}
				}
			}
			if(h < maxecms)    // found but cant move to lower position!
			{
				return h; // return position if within ratelimits!
			}
			else
			{
				reader->rlecmh[h].last.time = -1; // free this slot since we are over ratelimit!
				cs_debug_mask(D_CLIENT, "ratelimiter removed srvid %04X from slot #%d/%d of reader %s", er->srvid, h + 1, maxecms, reader->label);
				return -1; // sorry, ratelimit!
			}
		}
	}

	// srvid not found in slots!

	if((reader->cooldown[0] && reader->cooldownstate == 1) || !reader->cooldown[0])
	{
		; // do we use cooldown at all, are we in cooldown fase?

		// we are in cooldown or no cooldown configured!
		if(totalecms + 1 > maxecms || totalecms + 1 > rl.ratelimitecm)  // check if this channel fits in!
		{
			cs_debug_mask(D_CLIENT, "ratelimiter for reader %s has no free slots!", reader->label);
			return -1;
		}
	}
	else
	{
		maxecms = MAXECMRATELIMIT; // no limits right now!
	}

	for(h = 0; h < maxecms; h++)    // check for free slot
	{
		if(reader->rlecmh[h].last.time == -1)
		{
			if(reader_mode) { cs_debug_mask(D_CLIENT, "ratelimiter added srvid %04X to slot #%d/%d of reader %s", er->srvid, h + 1, maxecms, reader->label); }
			return h; // free slot found -> assign it!
		}
		else { 
			int32_t gone = comp_timeb(&actualtime, &reader->rlecmh[h].last);
		cs_debug_mask(D_CLIENT, "ratelimiter srvid %04X for %d ms present in slot #%d/%d of reader %s", reader->rlecmh[h].srvid, gone , h + 1,
			maxecms, reader->label); }  //occupied slots
	}

#ifdef HAVE_DVBAPI
	/* Overide ratelimit priority for dvbapi request */

	foundspace = -1;
	int32_t gone = 0;
	if((cfg.dvbapi_enabled == 1) && streq(er->client->account->usr, cfg.dvbapi_usr))
	{
		if(reader->lastdvbapirateoverride.time == 0) { // fixup for first run!
			gone = comp_timeb(&actualtime, &reader->lastdvbapirateoverride);
		}
		if(gone > reader->ratelimittime)
		{
			struct timeb minecmtime = actualtime;
			for(h = 0; h < MAXECMRATELIMIT; h++)
			{
				gone = comp_timeb(&minecmtime, &reader->rlecmh[h].last);
				if(gone > 0)
				{
					minecmtime = reader->rlecmh[h].last;
					foundspace = h;
				}
			}
			reader->lastdvbapirateoverride = actualtime;
			cs_debug_mask(D_CLIENT, "prioritizing DVBAPI user %s over other watching client", er->client->account->usr);
			cs_debug_mask(D_CLIENT, "ratelimiter forcing srvid %04X into slot #%d/%d of reader %s", er->srvid, foundspace + 1, maxecms, reader->label);
			return foundspace;
		}
		else cs_debug_mask(D_CLIENT, "DVBAPI User %s is switching too fast for ratelimit and can't be prioritized!",
							   er->client->account->usr);
	}

#endif

	return (-1); // no slot found
}
Exemple #29
0
/* LDAPv3 API extensions */
int ldap_compare_ext(LDAP *ld, char *dn, char *attr, struct berval *bvalue,
					 LDAPControl ** serverctrls, LDAPControl **clientctrls, int *msgidp)
{
	BerElement	*ber;
	struct berval bv;
	int rv;
	
	/* The compare request looks like this:
	 *	CompareRequest ::= SEQUENCE {
	 *		entry	DistinguishedName,
	 *		ava	SEQUENCE {
	 *			type	AttributeType,
	 *			value	AttributeValue
	 *		}
	 *	}
	 * and must be wrapped in an LDAPMessage.
	 */

#ifdef _REENTRANT
        LOCK_LDAP(ld);
#endif
	Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 128, "ldap_compare\n"), 0, 0, 0 );

	if ((ber = ldap_build_compare_req(ld, dn, attr, bvalue, NULL)) == NULLBER) {
		rv = ld->ld_errno;
		if (rv == LDAP_SUCCESS)
			rv = LDAP_OTHER;
#ifdef _REENTRANT
        UNLOCK_LDAP(ld);
#endif
		return (rv);
	}
	
#ifndef NO_CACHE
	if ( ld->ld_cache != NULL ) {
		if ( check_cache( ld, LDAP_REQ_COMPARE, ber ) == 0 ) {
			ber_free( ber, 1 );
			ld->ld_errno = LDAP_SUCCESS;
			*msgidp = ld->ld_msgid;
#ifdef _REENTRANT
			UNLOCK_LDAP(ld);
#endif
			return( LDAP_SUCCESS );
		}
		add_request_to_cache( ld, LDAP_REQ_COMPARE, ber );
	}
#endif /* NO_CACHE */

	/* send the message */
	rv = send_initial_request( ld, LDAP_REQ_COMPARE, dn, ber );
	if (rv == -1) {
		rv = ld->ld_errno;
		if (rv == LDAP_SUCCESS){
			rv = LDAP_OTHER;
		}
#ifdef  _REENTRANT
		UNLOCK_LDAP(ld);
#endif	
		return (rv);
	}
	
	*msgidp = rv;
#ifdef _REENTRANT
	UNLOCK_LDAP(ld);
#endif
	return (LDAP_SUCCESS);
}
Exemple #30
0
int
main (int argc, char *argv[])
{
  mpfr_t x;
  int p;
  mpfr_rnd_t rnd;

  tests_start_mpfr ();

  p = (argc>1) ? atoi(argv[1]) : 53;
  rnd = (argc>2) ? (mpfr_rnd_t) atoi(argv[2]) : MPFR_RNDZ;

  mpfr_init (x);

  check (2, 1000);

  /* check precision of 2 bits */
  mpfr_set_prec (x, 2);
  mpfr_const_log2 (x, MPFR_RNDN);
  if (mpfr_cmp_ui_2exp(x, 3, -2)) /* 3*2^-2 */
    {
      printf ("mpfr_const_log2 failed for prec=2, rnd=MPFR_RNDN\n"
              "expected 0.75, got ");
      mpfr_out_str(stdout, 10, 0, x, MPFR_RNDN);
      putchar('\n');
      exit (1);
    }

  if (argc>=2)
    {
      mpfr_set_prec (x, p);
      mpfr_const_log2 (x, rnd);
      printf ("log(2)=");
      mpfr_out_str (stdout, 10, 0, x, rnd);
      puts ("");
    }

  mpfr_set_prec (x, 53);
  mpfr_const_log2 (x, MPFR_RNDZ);
  if (mpfr_cmp_str1 (x, "6.9314718055994530941e-1") )
    {
      printf ("mpfr_const_log2 failed for prec=53\n");
      exit (1);
    }

  mpfr_set_prec (x, 32);
  mpfr_const_log2 (x, MPFR_RNDN);
  if (mpfr_cmp_str1 (x, "0.69314718060195446"))
    {
      printf ("mpfr_const_log2 failed for prec=32\n");
      exit (1);
    }

  mpfr_clear(x);

  check_large();
  check_cache ();

  test_generic (2, 200, 1);

  tests_end_mpfr ();
  return 0;
}