Exemple #1
0
void ai_journal(const void* base, const void* dst, const void* src, unsigned int size)
{
  ai_journal_save(dst, size);
  // TODO: copy and hash at same time
  int index0 = (intptr_t)dst - (intptr_t)base; // use buffer offset as part of CRC
  current_hash ^= compute_hash(src, size, index0) ^ compute_hash(dst, size, index0);
  JDEBUG("%d -> %x\n", index0, current_hash);
  memcpyfast((void*)dst, src, size);
}
Exemple #2
0
void unlock(grt_word_t key1, grt_word_t key2) {
  hash_t hash1 = compute_hash(key1);
  hash_t hash2 = compute_hash(key2);
  if (hash1.proc == hash2.proc &&
      hash1.offset == hash2.offset) {
    hash_map_unlock(hash1.proc, hash1.offset);
  } else {
    hash_map_unlock(hash1.proc, hash1.offset);
    hash_map_unlock(hash2.proc, hash2.offset);
  }
}
    const char* compute_segment_name()
    {      
      std::sprintf(
        segment_name,
        "boost_flyweight_intermodule_holder_segment_"
        "%ld_%u_%u",
        (long)detail::process_id(),
        (unsigned)compute_hash(typeid(C).name(),0),
        (unsigned)compute_hash(typeid(C).name(),1));

      return segment_name;
    }
AstIdentifierList::AstIdentifierList(AstIdentifier* id)
{
	ids.push_back(id);
	this->et = AST_IDENTIFIER_LIST;
	compute_hash();

}
grt_bool_t hashtable_insert(grt_word_t val) {
  unsigned i;
  hash_t hash = compute_hash(val);
  WRITE_LOCK;
  node_t **head = &table[hash.proc][hash.offset];
  node_t *p = (node_t*) grt_read(hash.proc, (grt_word_t*) head);
  node_t *q = find_node(hash.proc, val, p);
  if (q) {
    UNLOCK;
    return GRT_TRUE;
  }
  q = (node_t*) grt_alloc(hash.proc, sizeof(node_t));
#if NB
  gasnet_put_nbi(hash.proc, (grt_word_t*) &q->next, &p,
		 sizeof(grt_word_t));
  gasnet_put_nbi(hash.proc, &q->val, &val, sizeof(grt_word_t));
  gasnet_put_nbi(hash.proc, (grt_word_t*) head, (grt_word_t*) &q,
		 sizeof(grt_word_t));
  gasnet_wait_syncnbi_puts();
#else
  grt_write(hash.proc, (grt_word_t) p, (grt_word_t*) &q->next);
  grt_write(hash.proc, val, &q->val);
  grt_write(hash.proc, (grt_word_t) q, (grt_word_t*) head);
#endif
  UNLOCK;
  return GRT_FALSE;
}
Exemple #6
0
void lock(grt_word_t key1, grt_word_t key2,
	  grt_lock_state_t *state1,
	  grt_lock_state_t *state2) {
  hash_t hash1 = compute_hash(key1), 
    hash2 = compute_hash(key2);
  if (hash1.proc == hash2.proc &&
      hash1.offset == hash2.offset) {
    hash_map_lock(hash1.proc, hash1.offset, WRITE, state1);
  } else if (key1 < key2) {
    hash_map_lock(hash1.proc, hash1.offset, WRITE, state1);
    hash_map_lock(hash2.proc, hash2.offset, WRITE, state2);
  } else {
    hash_map_lock(hash2.proc, hash2.offset, WRITE, state2);
    hash_map_lock(hash1.proc, hash1.offset, WRITE, state1);
  }
}
Exemple #7
0
bool verify_file(struct file *file, char *filename)
{
	struct file *local = calloc(1, sizeof(struct file));

	if (local == NULL) {
		abort();
	}

	local->filename = file->filename;
	local->use_xattrs = true;

	populate_file_struct(local, filename);
	if (compute_hash(local, filename) != 0) {
		free(local);
		return false;
	}

	/* Check if manifest hash matches local file hash */
	if (hash_equal(file->hash, local->hash)) {
		free(local);
		return true;
	} else {
		free(local);
		return false;
	}
}
Exemple #8
0
chordID write_block(char *buf, int len) {
  chordID ID = compute_hash(buf, len);
  dhash->insert (ID, buf, len, wrap(&insert_cb));
  inflight++;

  return ID;
}
void
dhashclient::insert (const char *buf, size_t buflen, cbinsertgw_t cb,
                     ptr<option_block> options)
{
  bigint key = compute_hash (buf, buflen);
  insert (key, buf, buflen, cb, options, DHASH_CONTENTHASH);
}
void Dictionary::reorder_dictionary() {

  // Copy all the dictionary entries into a single master list.

  DictionaryEntry* master_list = NULL;
  for (int i = 0; i < table_size(); ++i) {
    DictionaryEntry* p = bucket(i);
    while (p != NULL) {
      DictionaryEntry* tmp;
      tmp = p->next();
      p->set_next(master_list);
      master_list = p;
      p = tmp;
    }
    set_entry(i, NULL);
  }

  // Add the dictionary entries back to the list in the correct buckets.
  while (master_list != NULL) {
    DictionaryEntry* p = master_list;
    master_list = master_list->next();
    p->set_next(NULL);
    Symbol* class_name = InstanceKlass::cast((Klass*)(p->klass()))->name();
    // Since the null class loader data isn't copied to the CDS archive,
    // compute the hash with NULL for loader data.
    unsigned int hash = compute_hash(class_name, NULL);
    int index = hash_to_index(hash);
    p->set_hash(hash);
    p->set_loader_data(NULL);   // loader_data isn't copied to CDS
    p->set_next(bucket(index));
    set_entry(index, p);
  }
}
AstExpressionList::AstExpressionList(Expression* e) {
	exps.push_back(e);
	this->et = AST_EXPRESSION_LIST;

	compute_hash();

}
dc_t* get_code_from_hash(h_entry_t* hash, unsigned int hash_size, char* domain)
{
	int hash_entry;
	unsigned int dhash;
	entry_t* it;
	
	if(!hash || hash_size>MAX_HASH_SIZE)
		return NULL;
	
	dhash = compute_hash(domain);
	hash_entry = get_hash_entry(dhash, hash_size);

	lock_get(&hash[hash_entry].lock);
	
	/* parsing the list */
	it = hash[hash_entry].e;
	while(it!=NULL && it->dc->dhash<=dhash)
	{
		if(it->dc->dhash == dhash && strcasecmp(it->dc->domain, domain)==0)
		{
			lock_release(&hash[hash_entry].lock);
			return it->dc;
		}
		it = it->n;
	}

	lock_release(&hash[hash_entry].lock);

	return NULL;
}
Exemple #13
0
int main(int argc, char **argv)
{
        FILE * handle;
        uint64_t myhash;
        char filename[100];

	if(argc < 2){
        printf("Usage: ./hash \"file_name\""); 
	   exit (-1);
	}
     
        handle = fopen(argv[1], "rb");
        
        if (!handle) 
        {
                printf("Error openning file!");
                return 1;
        }

        myhash = compute_hash(handle);  
        printf("%x", myhash);

        fclose(handle);
        return 0;
}
/* return a new cell stored in share memory for this domain */
dc_t* new_cell(char* domain, code_t code)
{
	dc_t* cell = NULL; 
	
	if(!domain)
		return NULL;
	
	/* the cell is in share memory */
	cell = (dc_t*)shm_malloc(sizeof(dc_t));
    
	/* if there is no space return just NULL */
	if(!cell)
		return NULL;
	
	/* otherwise, fill in the structure fields */
	/* domain name */
	cell->domain = (char*)shm_malloc((1+strlen(domain))*sizeof(char));
	strcpy(cell->domain, domain);

	/* domain code */
	cell->code = code; 

	cell->dhash = compute_hash(domain);
    
	/* return the newly alocated in share memory cell */
	return cell;
}
Exemple #15
0
grt_bool_t hash_map_find(grt_word_t key, grt_word_t *val) {
  find_result_t result;
  hash_t hash = compute_hash(key);
  grt_on(hash.proc, find_handler_id, find_local, 
	 &key, sizeof(grt_word_t), &result, sizeof(find_result_t));
  if (val && (result.found == GRT_TRUE)) *val = result.val;
  return result.found;
}
Exemple #16
0
grt_bool_t hashtable_find(grt_word_t val) {
  hash_t hash = compute_hash(val);
  READ_LOCK;
  node_t *p = (node_t*) grt_read(hash.proc, (void*) &table[hash.proc][hash.offset]);
  grt_bool_t result =  find_node(hash.proc, val, p) == 0 ? GRT_FALSE : GRT_TRUE;
  UNLOCK;
  return result;
}
Exemple #17
0
static void
fill_hash_bucket (void)
{
  basic_block bb;
  rtx insn;
  void **slot;
  p_hash_bucket bucket;
  struct hash_bucket_def tmp_bucket;
  p_hash_elem elem;
  unsigned long insn_idx;

  insn_idx = 0;
  FOR_EACH_BB (bb)
    {
      FOR_BB_INSNS_REVERSE (bb, insn)
        {
          if (!ABSTRACTABLE_INSN_P (insn))
            continue;

          /* Compute hash value for INSN.  */
          tmp_bucket.hash = compute_hash (insn);

          /* Select the hash group.  */
          bucket = (p_hash_bucket) htab_find (hash_buckets, &tmp_bucket);

          if (!bucket)
            {
              /* Create a new hash group.  */
              bucket = (p_hash_bucket) xcalloc (1,
                                        sizeof (struct hash_bucket_def));
              bucket->hash = tmp_bucket.hash;
              bucket->seq_candidates = NULL;

              slot = htab_find_slot (hash_buckets, &tmp_bucket, INSERT);
              *slot = bucket;
            }

          /* Create new list for storing sequence candidates.  */
          if (!bucket->seq_candidates)
              bucket->seq_candidates = htab_create (HASH_INIT,
                                                    htab_hash_elem,
                                                    htab_eq_elem,
                                                    htab_del_elem);

          elem = (p_hash_elem) xcalloc (1, sizeof (struct hash_elem_def));
          elem->insn = insn;
          elem->idx = insn_idx;
          elem->length = get_attr_length (insn);

          /* Insert INSN into BUCKET hash bucket.  */
          slot = htab_find_slot (bucket->seq_candidates, elem, INSERT);
          *slot = elem;

          insn_idx++;
        }
    }
}
Exemple #18
0
		virtual	void			set_assoc(void* addrin, u32 addrinlen, udx_address* addr)
		{
			udx_hash hash = compute_hash(addrin, addrinlen);
			udx_haddress* h = find_by_hash(hash);
			if (h == nullptr)
			{
				add(h);
			}
		}
Exemple #19
0
		virtual	void			del_assoc(void* addrin, u32 addrinlen)
		{
			udx_hash hash = compute_hash(addrin, addrinlen);
			udx_haddress* h = find_by_hash(hash);
			if (h != nullptr)
			{
				remove(h);
				destroy(h);
			}
		}
ProtectionDomainCacheEntry* ProtectionDomainCacheTable::get(oop protection_domain) {
  unsigned int hash = compute_hash(protection_domain);
  int index = hash_to_index(hash);

  ProtectionDomainCacheEntry* entry = find_entry(index, protection_domain);
  if (entry == NULL) {
    entry = add_entry(index, hash, protection_domain);
  }
  return entry;
}
Exemple #21
0
grt_bool_t hash_map_insert(grt_word_t key, grt_word_t val) {
  grt_word_t arg_buf[2];
  arg_buf[0] = key;
  arg_buf[1] = val;
  grt_bool_t result;
  hash_t hash = compute_hash(key);
  grt_on(hash.proc, insert_handler_id, insert_local, 
	 arg_buf, 2*sizeof(grt_word_t), &result, sizeof(grt_bool_t));
  return (grt_bool_t) result;
}
Exemple #22
0
void
NdbPool::add_db_hash(Uint32 id)
{
  Ndb* t_ndb = m_pool_reference[id].ndb_reference;
  const char* schema_name = t_ndb->getSchemaName();
  Uint32 hash_entry = compute_hash(schema_name);
  Uint8 next_db_entry = m_hash_entry[hash_entry];
  m_pool_reference[id].next_db_object = next_db_entry;
  m_pool_reference[id].prev_db_object = (Uint8)NULL_HASH;
  m_hash_entry[hash_entry] = (Uint8)id;
}
grt_bool_t hashtable_find(grt_word_t val) {
  unsigned bucket = compute_hash(val);
  grt_word_t *loc = (grt_word_t*) &table[bucket];
  node_t *p;
  stm_start();
  stm_open_for_read(table_proc, loc);
  stm_read(table_proc, loc, (grt_word_t*) &p);
  grt_bool_t result = find_node_stm(val, p) == 0 ? GRT_FALSE : GRT_TRUE;
  stm_commit();
  return result;
}
void Dictionary::add_klass(Symbol* class_name, ClassLoaderData* loader_data,
                           KlassHandle obj) {
  assert_locked_or_safepoint(SystemDictionary_lock);
  assert(obj() != NULL, "adding NULL obj");
  assert(obj()->name() == class_name, "sanity check on name");
  assert(loader_data != NULL, "Must be non-NULL");

  unsigned int hash = compute_hash(class_name, loader_data);
  int index = hash_to_index(hash);
  DictionaryEntry* entry = new_entry(hash, obj(), loader_data);
  add_entry(index, entry);
}
void*
compute_thread(void *argument) {
	cout << __func__ << endl;

	struct per_thread *arg = (struct per_thread*) argument;

	for (int i = arg->prm.start; i < (arg->prm.start + arg->prm.rng); i++) {
		ulong64 hash = compute_hash(arg->org_img_.at(i).c_str());
		arg->fpstore_.insert(make_pair(arg->org_img_.at(i), hash));
		no++;
	}
}
void update_hash_memory(uint32_t current_oid, unsigned char *payload,
        uint16_t payload_len) {
    /* get markers from rabin finger printing */
    uint16_t store_marks[MAX_MARKS];
    uint16_t num_chunks = rabinFingerprints(store_marks, payload,
            payload_len, powers, MIN_CHUNK_LEN);
    printlog(logfile, system_loglevel, LOG_DEBUG, "num_chunks: %d ", num_chunks);
    for(int i = 0; i < num_chunks; i++) {
        printlog(logfile, system_loglevel, LOG_DEBUG, "%d ", store_marks[i]);
    }
    printlog(logfile, system_loglevel, LOG_DEBUG, "\n");

    /* create chunks based on these markers and hash them */
    uint16_t chunk_length = 0, last_marker = 0;
    time_t current_time = time(NULL);
    uint64_t hash_value = 0;
    for(int i = 0; i < num_chunks; i++) {
        chunk_length = store_marks[i] - last_marker; 
        hash_value = compute_hash(payload, last_marker, chunk_length);
        update_hashes(current_oid, payload, chunk_length, last_marker,
                hash_value, current_time);
    }

    /* hashes of the tail */
    uint16_t chunked_upto = 0;
    if(num_chunks == 0) {
        chunked_upto = 0;
    } else {
        chunked_upto = store_marks[num_chunks - 1];
    }
    if(chunked_upto < payload_len - 1) {
        chunk_length = payload_len - chunked_upto;
        hash_value = compute_hash(payload, chunked_upto, chunk_length);
        update_hashes(current_time, payload, chunk_length,
                chunked_upto, hash_value, current_time);
    }

    /* store these hashes in the hash memory */
    object_memory[current_oid]->timestamp = current_time;
}
Exemple #27
0
static struct list *download_loop(struct list *files, int isfailed)
{
	int ret;
	struct file local;
	struct list *iter;

	iter = list_head(files);
	while (iter) {
		struct file *file;
		char *fullname;

		file = iter->data;
		iter = iter->next;

		if (file->is_deleted) {
			continue;
		}

		fullname = mk_full_filename(path_prefix, file->filename);
		if (fullname == NULL) {
			abort();
		}

		memset(&local, 0, sizeof(struct file));
		local.filename = file->filename;
		populate_file_struct(&local, fullname);

		if (cmdline_option_quick) {
			ret = compute_hash_lazy(&local, fullname);
		} else {
			ret = compute_hash(&local, fullname);
		}
		if (ret != 0) {
			free(fullname);
			continue;
		}

		if (hash_needs_work(file, local.hash)) {
			full_download(file);
		} else {
			/* mark the file as good to save time later */
			file->do_not_update = 1;
		}
		free(fullname);
	}

	if (isfailed) {
		list_free_list(files);
	}

	return end_full_download();
}
Exemple #28
0
static int crypt_all(int *pcount, struct db_salt *salt)
{
	const int count = *pcount;
	int index = 0;
#ifdef _OPENMP
#pragma omp parallel for
#endif
	for (index = 0; index < count; index++)
	{
		compute_hash(cur_salt, saved_key[index], (unsigned char*)crypt_out[index]);
	}
	return count;
}
Exemple #29
0
int pp_linkset_match_bw(pp_linkset *ls, wchar_t *str) 
{
  int hashval;
  pp_linkset_node *p;
  if (ls==NULL) return 0; 
  hashval = compute_hash(ls, str);
  p = ls->hash_table[hashval];
  while(p!=0) {
    if (post_process_match(str,p->str)) return 1;
    p=p->next;
  }
  return 0;
}
Exemple #30
0
static int init_smg (void)
{
   unsigned int i, len;
   SLsmg_Char_Type *old, *neew;

   Smg_Inited = 0;

#ifdef REQUIRES_NON_BCE_SUPPORT
   Bce_Color_Offset = _pSLtt_get_bce_color_offset ();
#endif
   
   Screen_Rows = *tt_Screen_Rows;
   if (Screen_Rows > SLTT_MAX_SCREEN_ROWS)
     Screen_Rows = SLTT_MAX_SCREEN_ROWS;

   Screen_Cols = *tt_Screen_Cols;

   This_Col = This_Row = Start_Col = Start_Row = 0;

   This_Alt_Char = 0;
   SLsmg_set_color (0);
   Cls_Flag = 1;
   
   init_acs (ACS_MODE_AUTO);

   len = Screen_Cols + 3;
   for (i = 0; i < Screen_Rows; i++)
     {
	if ((NULL == (old = (SLsmg_Char_Type *) SLmalloc (sizeof(SLsmg_Char_Type) * len)))
	    || ((NULL == (neew = (SLsmg_Char_Type *) SLmalloc (sizeof(SLsmg_Char_Type) * len)))))
	  {
	     SLfree ((char *) old);
	     return -1;
	  }
	blank_line (old, len, ' ');
	blank_line (neew, len, ' ');
	SL_Screen[i].old = old;
	SL_Screen[i].neew = neew;
	SL_Screen[i].flags = 0;
#ifndef IBMPC_SYSTEM
	Blank_Hash = compute_hash (old, Screen_Cols);
	SL_Screen[i].new_hash = SL_Screen[i].old_hash =  Blank_Hash;
#endif
     }
   
   _pSLtt_color_changed_hook = SLsmg_touch_screen;
   Screen_Trashed = 1;
   Smg_Inited = 1;
   return 0;
}