Beispiel #1
0
void dynamic_free(dfile *df,int key)
{
  int block,length,next_block;

  if (!convert_key(df,key,&block,&length))
     return;
  (void) store_int((char *)(df->keylist+key*2),-df->first_free_key);
  (void) store_int((char *)(df->keylist+key*2+1),0);
  df->first_free_key=key;

/* simply keep adding blocks onto the top of the free list */
  
   while(length>0)
   {
      if (block<=0)
         return;
      next_block = dynamic_get_next_block(df,block);
      dynamic_seek_block(df,block);
      store_int(stack,-df->first_free_block);
      if (write(df->data_fd,stack,4)!=4)
         handle_error("Failed to write next block");
      df->first_free_block=block;
      block = next_block;
      length -= (df->granularity-4);
   }
   if (!(sys_flags&SECURE_DYNAMIC))
      dynamic_key_sync(df);
}
Beispiel #2
0
void dynamic_key_sync(dfile *df)
{
  int fd,length;
  char *oldstack,*to;
  oldstack=stack;

  store_int((char *)df->keylist,df->first_free_block);
  store_int((char *)(df->keylist+1),df->first_free_key);

/* doing a straight open could mean losing the key data
   dont risk it by moving the file first
   this is grossly slow, so provide a means of escaping it */

  sprintf(oldstack,"files/%s/keys",df->fname);
  if (!(sys_flags&SECURE_DYNAMIC)) {
    stack=end_string(oldstack);
    to=stack;
    sprintf(to,"files/%s/keys.b",df->fname);
    rename(oldstack,to);
  }
  fd=open(oldstack,O_CREAT|O_WRONLY|O_TRUNC,S_IRUSR|S_IWUSR);
  if (fd<0) handle_error("Failed to open key file");
  length=(df->nkeys+1)*8;
  if (write(fd,df->keylist,length)!=length)
    handle_error("Failed to write key data");
  close(fd);    
  
  stack=oldstack;  
}
Beispiel #3
0
int dynamic_find_free_key(dfile *df)
{
  int *newlist,oldnkeys,i,key;
  
  if (!df->first_free_key) {
    oldnkeys=df->nkeys;
    df->nkeys+=100;
    newlist=(int *)MALLOC((df->nkeys+1)*8);
    if (df->keylist) {
      memcpy(newlist+2,df->keylist+2,(oldnkeys+1)*8);
      FREE(df->keylist);
    }
    df->keylist=newlist;
    df->first_free_key=oldnkeys+1;
    newlist+=df->first_free_key*2;
    for(i=-df->first_free_key-1;i>=-df->nkeys;i--) {
      newlist=(int *) ALFIX store_int((char *)newlist,i); 
      newlist=(int *) ALFIX store_int((char *)newlist,0);
    }
    newlist=(int *) ALFIX store_int((char *)newlist,0); 
    newlist=(int *) ALFIX store_int((char *)newlist,0);
  }
  key=df->first_free_key;
  (void) get_int(&(df->first_free_key),(char *)(df->keylist+key*2));
  df->first_free_key=-df->first_free_key;
  return key;
}
Beispiel #4
0
void sync_notes(int background)
{
    int n,fd;
    struct itimerval new;
    char *oldstack;
    oldstack=stack;

    if (background && fork()) return;

    if (sys_flags&VERBOSE || sys_flags&PANIC)
	log("sync","Dumping notes to disk");
    for(n=0;n<NOTE_HASH_SIZE;n++) sync_note_hash(n);
    if (sys_flags&VERBOSE || sys_flags&PANIC)    
	log("sync","Note dump completed");
    
#ifdef PC
    fd=open("files\\notes\\track",O_CREAT|O_WRONLY|O_TRUNC|O_BINARY);
#else
    fd=open("files/notes/track",O_CREAT|O_WRONLY|O_SYNC|O_TRUNC,S_IRUSR|S_IWUSR);
#endif
    if (fd<0) handle_error("Failed to open track file.");
    stack=store_int(stack,unique);
    stack=store_int(stack,news_start);
    stack=store_int(stack,news_count);
    if (write(fd,oldstack,12)<0)
	handle_error("Failed to write track file.");
    close(fd);
    
    stack=oldstack;
    
    if (background) exit(0);
}
Beispiel #5
0
int dynamic_save(dfile *df,char *data,int l,int key)
{
  int block,length,next_block,blength,free_block;


/* key==0 means this is a new entry */
  
  if (!key) {
    key=dynamic_find_free_key(df);
    block=dynamic_find_free_block(df);
  }
  else if (!convert_key(df,key,&block,&length)) return -1;

/*  printf("Dynamic Save key=%d\n",key); */

  (void) store_int((char *)(df->keylist+key*2),block);
  (void) store_int((char *)(df->keylist+key*2+1),l);  
  blength=df->granularity-4;
  while(l>0) {
    next_block=dynamic_get_next_block(df,block);
/*    printf("DS block %d / next block %d\n",block,next_block);  */

/* do we need more space ? */

    if (l>blength) {
      if (next_block<=0) next_block=dynamic_find_free_block(df);
    }
    else {

/* can we free up any blocks at the end ? */
    
      free_block=next_block;
      while(free_block>0) {
        next_block=dynamic_get_next_block(df,free_block);
        dynamic_seek_block(df,free_block);
        store_int(stack,-df->first_free_block);
        if (write(df->data_fd,stack,4)!=4)
          handle_error("Failed to write next block");
        df->first_free_block=free_block;
        free_block=next_block;
      }
      next_block=0;
    }
    store_int(stack,next_block);
    dynamic_seek_block(df,block);
    if (write(df->data_fd,stack,4)!=4)
      handle_error("Failed to write next block");
    if (write(df->data_fd,data,blength)!=blength)
      handle_error("Failed to write block data");
    block=next_block;
    l-=blength;
    data+=blength;
  }

  /* make sure the keylist is up to date */
  
  if (!(sys_flags&SECURE_DYNAMIC)) dynamic_key_sync(df);
  return key;
}
Beispiel #6
0
STORAGE_SET *containerDataStore(CONTAINER_DATA *data) {
  STORAGE_SET *set = new_storage_set();
  store_double(set, "capacity", data->capacity);
  store_string(set, "key",      data->key);
  store_int   (set, "pick_diff",data->pick_diff);
  store_int   (set, "closable", data->closable);
  store_int   (set, "closed",   data->closed);
  store_int   (set, "locked",   data->locked);
  return set;
}
void unload_gs(void){

	/*
	 * Change this code.
	 */
	store_string("Operation", "aString", gs->aString);
	store_int("Operation", "anInt", gs->anInt);
	store_double("Operation", "aDouble", gs->aDouble);
	store_matrix("Operation","aMatrix",&gs->aMatrix);

	store_int("Task","Priority",gs->task_prio);
}
Beispiel #8
0
STORAGE_SET   *resetStore       (RESET_DATA *reset) {
  STORAGE_SET *set = new_storage_set();
  store_int   (set, "type",     reset->type);
  store_int   (set, "times",    reset->times);
  store_int   (set, "chance",   reset->chance);
  store_int   (set, "max",      reset->max);
  store_int   (set, "room_max", reset->room_max);
  store_string(set, "arg",      bufferString(reset->arg));
  store_list  (set, "in",       gen_store_list(reset->in,   resetStore));
  store_list  (set, "on",       gen_store_list(reset->on,   resetStore));
  store_list  (set, "then",     gen_store_list(reset->then, resetStore));
  return set;
}
Beispiel #9
0
void sync_note_hash(int number)
{
    char *oldstack;
    note *scan,*check;
    int length,count=0,fd,t,tout;
    oldstack=stack;

    if (sys_flags&VERBOSE) {
	sprintf(stack,"Syncing note hash %d.",number);
	stack=end_string(stack);
	log("sync",oldstack);
	stack=oldstack;
    }

    t=time(0);

    for (scan=n_hash[number];scan;scan=check) {
      if (scan->flags&NEWS_ARTICLE) 
      	tout=NEWS_TIMEOUT;
      else
        tout=MAIL_TIMEOUT;
      if ((t-(scan->date))>tout) {
	remove_any_note(scan);
	check=n_hash[number];
      }
      else check=scan->hash_next;
    }

    stack=store_int(stack,0);

    for(scan=n_hash[number];scan;scan=scan->hash_next)
      count+=save_note(scan);

    store_int(oldstack,count);
    length=(int)stack-(int)oldstack;

#ifdef PC
    sprintf(stack,"files\\notes\\hash%d",number);
    fd=open(stack,O_CREAT|O_WRONLY|O_TRUNC|O_BINARY);
#else
    sprintf(stack,"files/notes/hash%d",number);
    fd=open(stack,O_CREAT|O_WRONLY|O_SYNC|O_TRUNC,S_IRUSR|S_IWUSR);
#endif
    if (fd<0) handle_error("Failed to open note file.");
    if (write(fd,oldstack,length)<0)
	handle_error("Failed to write note file.");
    close(fd);

    nhash_update[number]=0;
    stack=oldstack;
}
Beispiel #10
0
 void construct_mail_save(saved_player *sp)
 {
   int count=0,*scan;
   char *oldstack;
   stack=store_int(stack,sp->mail_sent);
   if (!(sp->mail_received)) stack=store_int(stack,0);
   else {
     oldstack=stack;
     stack=store_int(oldstack,0);
     for(scan=sp->mail_received;*scan;scan++,count++)
       stack=store_int(stack,*scan);
     store_int(oldstack,count);
   }
 }
Beispiel #11
0
/* Store a count value in an integer field of a structure.  If count is
 * SIZE_MAX and the target is a signed field, store -1. */
static asn1_error_code
store_count(size_t count, const struct counted_info *counted, void *val)
{
    void *countptr = (char *)val + counted->lenoff;

    if (counted->lensigned) {
        if (count == SIZE_MAX)
            return store_int(-1, counted->lensize, countptr);
        else if ((intmax_t)count < 0)
            return ASN1_OVERFLOW;
        else
            return store_int(count, counted->lensize, countptr);
    } else
        return store_uint(count, counted->lensize, countptr);
}
Beispiel #12
0
/**
 * @brief       select/deselect a nandflash target
 * @author      Yang Yiming
 * @date        2012-12-25
 * @param       [in]nTarget target nandflash
 * @param       [in]bSelect AK_TRUE to select, AK_FALSE to deselect
 * @return      T_BOOL
 */
T_BOOL nfc_select(T_U8 nTarget, T_BOOL bSelect)
{
    //only when additional #ce is needed, this block is essential
    if (s_nPhyPos[nTarget] < INVALID_GPIO)
    {
        gpio_set_pin_dir(s_nPhyPos[nTarget], GPIO_DIR_OUTPUT);
        gpio_set_pin_level(s_nPhyPos[nTarget], bSelect ? GPIO_LEVEL_LOW : GPIO_LEVEL_HIGH);
    }

    if (bSelect)
    {
        g_clk_map |= CLK_NFC_EN;
        store_int(INT_EN_L2);
        sys_module_enable(eVME_NANDFLASH_CLK, AK_TRUE);
        sys_share_pin_lock(ePIN_AS_NANDFLASH);
        s_nActChip = nTarget;
    }
    else
    {
        s_nActChip = 0xFF;
        sys_module_enable(eVME_NANDFLASH_CLK, AK_FALSE);
        sys_share_pin_unlock(ePIN_AS_NANDFLASH);
        restore_int();
        g_clk_map &= ~CLK_NFC_EN;
    }
    
    return AK_TRUE;
}
Beispiel #13
0
void unload_gs(void){

	store_matrix("Operation","B",&gs->B);
	store_matrix("Operation","A",&gs->A);

	store_int("Task","Priority",gs->task_prio);
}
Beispiel #14
0
//
// store an integer in the set
PyObject *PyStorageSet_storeInt   (PyObject *self, PyObject *args) { 
  char *key = NULL;
  int   val = 0;
  PYSTORE_PARSE(args, key, val, "si");
  store_int(((PyStorageSet *)self)->set, key, val);
  return Py_BuildValue("i", 1);
}
Beispiel #15
0
/**
 * run_query - execute a query
 *
 * This method sends the query string to the server and waits for a
 * response. If the result is a result set, it returns true, if it is
 * an error, it processes the error packet and prints the error via
 * Serial.print(). If it is an Ok packet, it parses the packet and
 * returns false.
 *
 * query_len[in]   Number of bytes in the query string
 *
 * Returns boolean - true = result set available,
 *                   false = no result set returned.
*/
boolean Connector::run_query(int query_len)
{
  store_int(&buffer[0], query_len+1, 3);
  // TODO: Abort if query larger than sizeof(buffer);
  buffer[3] = byte(0x00);
  buffer[4] = byte(0x03);  // command packet

  // Send the query
  for (int c = 0; c < query_len+5; c++)
    client.write(buffer[c]);

  // Read a response packet and check it for Ok or Error.
  read_packet();
  ok_packet *p = (ok_packet *)malloc(sizeof(ok_packet));
  int res = parse_ok_packet(p);
  free(p);
  if (res == ERROR_PACKET) {
    parse_error_packet();
    return false;
  } else if (!res) {
    return false;
  }
  // Not an Ok packet, so we now have the result set to process.
#if defined WITH_SELECT
  columns_read = false;
#endif
  return true;
}
Beispiel #16
0
void unload_gs(void){

	store_double("Operation", "OutputGain", gs->OutputGain);
	store_double("Operation", "Ch0Gain", gs->Ch0Gain);
	store_double("Operation", "Ch1Gain", gs->Ch1Gain);
	store_double("Operation", "Ch2Gain", gs->Ch2Gain);

	store_int("Task","Priority",gs->task_prio);
}
void unload_gs(void){	//block specific

	store_string("Operation", "Wave", gs->wave);

	store_double("Operation", "DC", gs->wave_dc);
	store_double("Operation", "Amplitude", gs->wave_amp);
	store_double("Operation", "Frequency", gs->wave_freq);
	store_double("Operation", "DutyCycle", gs->wave_duty);

	store_int("Task","Priority",gs->task_prio);
}
void unload_gs(void){

	/*
	 * Insert code here
	 *
	 * Example:
	store_string("Operation", "Wave", gs->wave);
	store_double("Operation", "DC", gs->wave_dc);
	store_matrix("Operation","Am",&gs->Am);
	 */

	store_int("Task","Priority",gs->task_prio);
}
Beispiel #19
0
static      nialptr
to_int(nialptr x)
{
  nialptr     z,
              xi;
  nialint     i,
              t = tally(x);
  int         v = valence(x);

  /* create the result container */
  z = new_create_array(inttype, v, 0, shpptr(x, v));
  for (i = 0; i < t; i++) {
    xi = fetch_array(x, i);
    if (kind(xi) == inttype) {
      copy1(z, i, xi, 0);
    }
    else   /* type must be boolean */
      store_int(z, i, boolval(xi));
  }
  return (z);
}
Beispiel #20
0
int save_note(note *d)
{
    if (d->flags&NOT_READY) return 0;

    stack=store_int(stack,d->id);
    stack=store_int(stack,d->flags);
    stack=store_int(stack,d->date);
    stack=store_int(stack,d->read_count);
    stack=store_int(stack,d->next_sent);
    stack=store_string(stack,d->header);
    stack=store_int(stack,d->text.length);
    memcpy(stack,d->text.where,d->text.length);
    stack+=d->text.length;
    stack=store_string(stack,d->name);
    return 1;
}
Beispiel #21
0
/**
 * @brief Set the sd interface.
 *
 * Select the sd interface(INTERFACE_MMC1 or INTERFACE_SD2)and select the relevant registers,L2 ,pin.
 * @author Huang Xin
 * @date 2010-07-14
 * @param cif[in] The selected interface,INTERFACE_MMC1 or INTERFACE_SD2.
 * @return T_VOID
 */
T_VOID set_interface(T_eCARD_INTERFACE cif, T_U8 bus_mode)
{
    if(INTERFACE_NOT_SD != cif)
    {
    #if (DRV_SUPPORT_SPI_BOOT == 0)  
        g_clk_map |= CLK_MCI_EN;
    #endif    
        store_int(INT_EN_L2);

        //select pin share
    #if (CHIP_SEL_10C > 0)
        if(INTERFACE_SD2 == cif)
        {
            if(USE_ONE_BUS == bus_mode){
                s_PinSelect = ePIN_AS_MCI2_1LINE;
            }
            else{
                s_PinSelect = ePIN_AS_MCI2_4LINE;
            }
        }
        else
        {
            s_PinSelect = ePIN_AS_MCI1;
        }
    #else
        if(INTERFACE_SD2 == cif)
        {
            s_PinSelect = ePIN_AS_MCI2;
        }
        else
        {
            if (USE_EIGHT_BUS == bus_mode){
                s_PinSelect = ePIN_AS_MCI1_8LINE;
            }
            else{
                s_PinSelect = ePIN_AS_MCI1;
            }
        }
    #endif
    
        if(INTERFACE_SD2 == cif)
        {
            s_SdReg_Base    = MCI2_MODULE_BASE_ADDR;
            s_L2Select      = ADDR_MCI2;
            sys_module_enable(eVME_MCI2_CLK, AK_TRUE);
        }
        else
        {
            s_SdReg_Base    = MCI1_MODULE_BASE_ADDR;
            s_L2Select      = ADDR_MCI1;
            sys_module_enable(eVME_MCI1_CLK, AK_TRUE);
        }
        
        sys_share_pin_lock(s_PinSelect);
    }
    else
    {
        sys_module_enable(eVME_MCI1_CLK, AK_FALSE);
        sys_module_enable(eVME_MCI2_CLK, AK_FALSE);
        sys_share_pin_unlock(s_PinSelect);
        restore_int();
        #if (DRV_SUPPORT_SPI_BOOT == 0)  
        g_clk_map &= ~CLK_MCI_EN;
        #endif
    }
}
Beispiel #22
0
/* Given the enclosing tag t, decode from asn1/len the contents of the ASN.1
 * type specified by a, placing the result into val (caller-allocated). */
static asn1_error_code
decode_atype(const taginfo *t, const unsigned char *asn1,
             size_t len, const struct atype_info *a, void *val)
{
    asn1_error_code ret;

    switch (a->type) {
    case atype_fn: {
        const struct fn_info *fn = a->tinfo;
        assert(fn->dec != NULL);
        return fn->dec(t, asn1, len, val);
    }
    case atype_sequence:
        return decode_sequence(asn1, len, a->tinfo, val);
    case atype_ptr: {
        const struct ptr_info *ptrinfo = a->tinfo;
        void *ptr = LOADPTR(val, ptrinfo);
        assert(ptrinfo->basetype != NULL);
        if (ptr != NULL) {
            /* Container was already allocated by a previous sequence field. */
            return decode_atype(t, asn1, len, ptrinfo->basetype, ptr);
        } else {
            ret = decode_atype_to_ptr(t, asn1, len, ptrinfo->basetype, &ptr);
            if (ret)
                return ret;
            STOREPTR(ptr, ptrinfo, val);
            break;
        }
    }
    case atype_offset: {
        const struct offset_info *off = a->tinfo;
        assert(off->basetype != NULL);
        return decode_atype(t, asn1, len, off->basetype,
                            (char *)val + off->dataoff);
    }
    case atype_optional: {
        const struct optional_info *opt = a->tinfo;
        return decode_atype(t, asn1, len, opt->basetype, val);
    }
    case atype_counted: {
        const struct counted_info *counted = a->tinfo;
        void *dataptr = (char *)val + counted->dataoff;
        size_t count;
        assert(counted->basetype != NULL);
        ret = decode_cntype(t, asn1, len, counted->basetype, dataptr, &count);
        if (ret)
            return ret;
        return store_count(count, counted, val);
    }
    case atype_tagged_thing: {
        const struct tagged_info *tag = a->tinfo;
        taginfo inner_tag;
        const taginfo *tp = t;
        const unsigned char *rem;
        size_t rlen;
        if (!tag->implicit) {
            ret = get_tag(asn1, len, &inner_tag, &asn1, &len, &rem, &rlen);
            if (ret)
                return ret;
            /* Note: we don't check rlen (it should be 0). */
            tp = &inner_tag;
            if (!check_atype_tag(tag->basetype, tp))
                return ASN1_BAD_ID;
        }
        return decode_atype(tp, asn1, len, tag->basetype, val);
    }
    case atype_bool: {
        intmax_t intval;
        ret = k5_asn1_decode_bool(asn1, len, &intval);
        if (ret)
            return ret;
        return store_int(intval, a->size, val);
    }
    case atype_int: {
        intmax_t intval;
        ret = k5_asn1_decode_int(asn1, len, &intval);
        if (ret)
            return ret;
        return store_int(intval, a->size, val);
    }
    case atype_uint: {
        uintmax_t intval;
        ret = k5_asn1_decode_uint(asn1, len, &intval);
        if (ret)
            return ret;
        return store_uint(intval, a->size, val);
    }
    case atype_int_immediate: {
        const struct immediate_info *imm = a->tinfo;
        intmax_t intval;
        ret = k5_asn1_decode_int(asn1, len, &intval);
        if (ret)
            return ret;
        if (intval != imm->val && imm->err != 0)
            return imm->err;
        break;
    }
    default:
        /* Null-terminated sequence types are handled in decode_atype_to_ptr,
         * since they create variable-sized objects. */
        assert(a->type != atype_nullterm_sequence_of);
        assert(a->type != atype_nonempty_nullterm_sequence_of);
        assert(a->type > atype_min);
        assert(a->type < atype_max);
        abort();
    }
    return 0;
}
// Store COMBAT_AUX_DATA in STORAGE_SET
// Normally named CombatAuxDataStore(*COMBAT_AUX_DATA)
STORAGE_SET *storeCombatAuxData(COMBAT_AUX_DATA *data) {
  STORAGE_SET *storage = new_storage_set();
  store_int(storage, "busy", data->busy);
  return storage;
}
Beispiel #24
0
__CILKRTS_BEGIN_EXTERN_C

/**
 * @brief Returns the global state object.  If called for the first time,
 * initializes the user-settable values in the global state, but does not
 * initialize the rest of the structure.
 */
global_state_t* cilkg_get_user_settable_values()
{
    // Environment variable value.  More than big enough for a 64-bit signed
    // integer.
    char envstr[24];

    // Abbreviating &global_state_singleton as g is not only shorter, it also
    // facilitates grepping for the string "g->", which appears ubiquitously
    // in the runtime code.
    global_state_t* g = &global_state_singleton;

    // TBD: We need synchronization around this loop to prevent
    // multiple threads from initializing this data.
    if (! cilkg_user_settable_values_initialized)
    {
        size_t len;

        // Preserve stealing disabled since it may have been set by the
        // debugger
        int stealing_disabled = g->stealing_disabled;

        // All fields will be zero until set.  In particular
        std::memset(g, 0, sizeof(global_state_t));

        // Fetch the number of cores.  There must be at last 1, since we're
        // executing on *something*, aren't we!?
        int hardware_cpu_count = __cilkrts_hardware_cpu_count();
        CILK_ASSERT(hardware_cpu_count > 0);

        bool under_ptool = __cilkrts_running_under_sequential_ptool();
        if (under_ptool)
            hardware_cpu_count = 1;

        g->stealing_disabled        = stealing_disabled;
        g->under_ptool              = under_ptool;
        g->force_reduce             = 0;   // Default Off
        g->P                        = hardware_cpu_count;   // Defaults to hardware CPU count
        g->max_user_workers         = 0;   // 0 unless set by user
        g->fiber_pool_size          = 7;   // Arbitrary default
        
        g->global_fiber_pool_size   = 3 * 3* g->P;  // Arbitrary default
        // 3*P was the default size of the worker array (including
        // space for extra user workers).  This parameter was chosen
        // to match previous versions of the runtime.

        if (4 == sizeof(void *))
            g->max_stacks           = 1200; // Only 1GB on 32-bit machines
        else
            g->max_stacks           = 2400; // 2GB on 64-bit machines

        // If we have 2400 1MB stacks, that is 2 gb.  If we reach this
        // limit on a single-socket machine, we may have other
        // problems.  Is 2400 too small for large multicore machines?

        // TBD(jsukha, 11/27/2012): I set this limit on stacks to be a
        // value independent of P.  When running on a Xeon Phi with
        // small values of P, I recall seeing a few microbenchmarks
        // (e.g., fib) where a limit of 10*P seemed to be
        // unnecessarily slowing things down.
        // 
        // That being said, the code has changed sufficiently that
        // this observation may no longer be true.
        //
        // Note: in general, the worst-case number of stacks required
        // for a Cilk computation with spawn depth "d" on P workers is
        // O(Pd).  Code with unbalanced recursion may run into issues
        // with this stack usage.

        g->max_steal_failures       = 128; // TBD: depend on max_workers?
        g->stack_size               = 0;   // 0 unless set by the user

        // Assume no record or replay log for now
        g->record_replay_file_name  = NULL;
        g->record_or_replay         = RECORD_REPLAY_NONE;  // set by user

        if (always_force_reduce())
            g->force_reduce = true;
        else if (cilkos_getenv(envstr, sizeof(envstr), "CILK_FORCE_REDUCE"))
            store_bool(&g->force_reduce, envstr);

        if (under_ptool)
            g->P = 1;  // Ignore environment variable if under cilkscreen
        else if (cilkos_getenv(envstr, sizeof(envstr), "CILK_NWORKERS"))
            // Set P to environment variable, but limit to no less than 1
            // and no more than 16 times the number of hardware threads.
            store_int(&g->P, envstr, 1, 16 * hardware_cpu_count);

        if (cilkos_getenv(envstr, sizeof(envstr), "CILK_MAX_USER_WORKERS"))
            // Set max_user_workers to environment variable, but limit to no
            // less than 1 and no more 16 times the number of hardware
            // threads.  If not specified, defaults (somewhat arbitrarily) to
            // the larger of 3 and twice the number of hardware threads.
            store_int(&g->max_user_workers, envstr, 1, 16*hardware_cpu_count);

        if (cilkos_getenv(envstr, sizeof(envstr), "CILK_STEAL_FAILURES"))
            // Set the number of times a worker should fail to steal before
            // it looks to see whether it should suspend itself.
            store_int<unsigned>(&g->max_steal_failures, envstr, 1, INT_MAX);

        // Compute the total number of workers to allocate.  Subtract one from
        // nworkers and user workers so that the first user worker isn't
        // factored in twice.
        //
        // total_workers must be computed now to support __cilkrts_get_total_workers
        g->total_workers = g->P + calc_max_user_workers(g) - 1;

#ifdef CILK_RECORD_REPLAY
        // RecordReplay: See if we've been asked to replay a log
        len = cilkos_getenv(envstr, 0, "CILK_REPLAY_LOG");
        if (len > 0)
        {
            len += 1;    // Allow for trailing NUL
            g->record_or_replay = REPLAY_LOG;
            g->record_replay_file_name = (char *)__cilkrts_malloc(len);
            cilkos_getenv(g->record_replay_file_name, len, "CILK_REPLAY_LOG");
        }

        // RecordReplay: See if we've been asked to record a log
        len = cilkos_getenv(envstr, 0, "CILK_RECORD_LOG");
        if (len > 0)
        {
            if (RECORD_REPLAY_NONE != g->record_or_replay)
                cilkos_warning("CILK_RECORD_LOG ignored since CILK_REPLAY_LOG is defined.\n");
            else
            {
                len += 1;    // Allow for trailing NUL
                g->record_or_replay = RECORD_LOG;
                g->record_replay_file_name = (char *)__cilkrts_malloc(len);
                cilkos_getenv(g->record_replay_file_name, len, "CILK_RECORD_LOG");
            }
        }
#endif
        
        cilkg_user_settable_values_initialized = true;
    }

    return g;
}
Beispiel #25
0
int __scanf_core_int (ReadWriteInfo *rw, const char *fmt, va_list ap, unsigned int flags)
{
  int size, c, t, m, width, category;
  const char *p;
  char *s;
  void *dest=NULL;
  uint64_t i=0;
  int neg=0, matches=0;
  int (*read)(ReadWriteInfo *rw);

  c = -1;
  read = rw->m_fnptr;

  for (p=fmt; *p; )
  {
    if (isspace((int)*p))
     {
      while (isspace((int)*p))
      p++;

        do 
         {
           c = read(rw);
         } while (isspace(c));
        
        continue;
     }

    if (*p != '%' || p[1]=='%')
     {
      if (*p == '%') p++;
      if (c==-1)
         c = read(rw);
    
    /*  if (c < 0)
        goto input_fail;
      if (*p++ != c)
        goto match_fail;
    */
      if (*p++ != c)
       {
         if (c < 0)
           goto input_fail;
         goto match_fail;
        }
      c = -1;
      continue;
     }

    p++;

    if (*p == '*')
     {
      dest = NULL;
      p++;
     } 
    else 
      dest = va_arg(ap, void *);

    if (!*p)
      goto fmt_fail;
    
    for (width =0; isdigit((int)*p); p++)
     {
       width = 10*width + *p - '0';
     }

    size = SIZE_def;
    category = 0;

    for (;;)
     {
       t = *p++;
       t |= 32;

       switch (t)
        {
          case 'h':
            if (*p == 'h')
             {
               p++; size = SIZE_hh; 
             }
             else 
               size = SIZE_h;
             continue;
          case 'l':
            if (*p == 'l') 
            {
              p++; size = SIZE_ll;
            }
            else
             size = SIZE_l;
            continue;
          case 'j':
            size = SIZE_ll;
            continue;
          case 'z':
          case 't':
            size = SIZE_l;
            continue;
          case 'd': case 'i': case 'o': case 'u': case 'x': case 'p':
            category = 1;
          case 'c': case 's': case '{':
            goto loop_end;
          case 'e': case 'f': case 'g':
            //if (flags & FLAG_INTONLY)
             goto fmt_fail;
          case 'n':
            goto loop_end;
          default:
            goto fmt_fail;
        }
     }
loop_end:

    if (c==-1 && t != 'n') 
     {
       c = read(rw);
       if (c < 0) 
        goto input_fail;
     }

    s = dest;

    switch (t)
     {
      case 'n':
       {
        int ttt = rw->m_size;
        if (c!=-1)
         ttt--;
        store_int(dest, size, 0, ttt);
        continue;   /* do not increment match count, etc! */
       }
      case 'c':
        width = width ? width : 1;
        while (c >= 0 && width) {
        if (dest) *s++ = c;
         c = read (rw);
         width--;
        }
        //c = -1;
        goto char_finish;
      default:
        while (isspace(c)) /* ignore spaces */
          c = read(rw);
        if (c < 0) 
          goto input_fail;
     }

    if (category==1)  // d, i, o, u, x, p
    {
      neg = 2;
      if (c == '-')
       neg=1;
      else 
       if (c == '+')
        neg=0;

      if (neg!=2)
       c = read(rw);  /* read beyond + or - */
      else
       neg=0;
    }

    i = m = 0;

    if (t=='p')
        t = 'x';

    if (t=='i' || t=='x')
     {
      if (c != '0')
       {
        if (t == 'i')
          t = 'd';
        goto int_start;
       }
      c = read(rw);
      if ((c|0x20) != 'x')
       {
        if (t == 'i')
         {
          t = 'o';
          /* lone 0 is valid octal */
          if ((unsigned)(c-'0') >= 8)
           goto match_fail;
         }
         goto int_start;
       }
       c = read(rw);
       t = 'x';
     }
int_start:
    switch (t)
     {
      case 'd':
      case 'u':
        width = width ? width : INT_MAX;
        for (m=0; isdigit(c) && width; m=1)
         {
          i = 10*i + c-'0';
          c = read(rw);
          width--;
         }
        goto int_finish;
      case 'o':
        for (m=0; (unsigned)(c)-'0' < 8; m=1)
         {
          i = (i<<3) + c-'0';
          c = read(rw);
         }
        goto int_finish;
      case 'p':
      case 'x':
        for (m=0; ; m=1)
         {
          if (isdigit(c))
            i = (i<<4) + c-'0';
          else
          if ((unsigned)(c|0x20)-'a' < 6)
            i = (i<<4) + (c|0x20)-'a'+10;
          else
            break;
          c = read(rw);
         }
int_finish:
        if (!m)
         goto match_fail;
        store_int(dest, size, neg, i);
        break;
      case 's':
       width = width ? width : INT_MAX ;
       s = dest;
       while(c >= 0 && width)
        {
         if (isspace(c))
          break;
         if (dest) *s++ = c;
          c = read(rw);
          width--;
        }
       if (dest) *s++ = 0;
        break;
     }

char_finish:
     if (dest) 
         matches++;
    }

  goto match_success;

fmt_fail:
input_fail:
  if (!matches) 
   matches--;
match_fail:
match_success:
  return matches;
}
Beispiel #26
0
STORAGE_SET *persistentDataStore(PERSISTENT_DATA *data) {
  STORAGE_SET *set = new_storage_set();
  store_bool(set, "persistent", data->persistent);
  store_int(set,  "activity",   data->activity);
  return set;
}
Beispiel #27
0
void unload_gs(void){

	store_int("Operation","SamplingPeriod",gs->sampling_period);

	store_int("Task","Priority",gs->task_prio);
}
Beispiel #28
0
void unload_gs(void){

	store_double("Operation", "Setpoint", gs->setpoint);

	store_int("Task","Priority",gs->task_prio);
}
/*
  send_authentication_packet

  This method builds a response packet used to respond to the server's
  challenge packet (called the handshake packet). It includes the user
  name and password scrambled using the SHA1 seed from the handshake
  packet. It also sets the character set (default is 8 which you can
  change to meet your needs).

  Note: you can also set the default database in this packet. See
        the code before for a comment on where this happens.

  The authentication packet is defined as follows.

  Bytes                        Name
  -----                        ----
  4                            client_flags
  4                            max_packet_size
  1                            charset_number
  23                           (filler) always 0x00...
  n (Null-Terminated String)   user
  n (Length Coded Binary)      scramble_buff (1 + x bytes)
  n (Null-Terminated String)   databasename (optional

  user[in]        User name
  password[in]    password
*/
void MySQL_Packet::send_authentication_packet(char *user, char *password)
{
  if (buffer != NULL)
    free(buffer);

  buffer = (byte *)malloc(256);

  int size_send = 4;

  // client flags
  buffer[size_send] = byte(0x85);
  buffer[size_send+1] = byte(0xa6);
  buffer[size_send+2] = byte(0x03);
  buffer[size_send+3] = byte(0x00);
  size_send += 4;

  // max_allowed_packet
  buffer[size_send] = 0;
  buffer[size_send+1] = 0;
  buffer[size_send+2] = 0;
  buffer[size_send+3] = 1;
  size_send += 4;

  // charset - default is 8
  buffer[size_send] = byte(0x08);
  size_send += 1;
  for(int i = 0; i < 24; i++)
    buffer[size_send+i] = 0x00;
  size_send += 23;

  // user name
  memcpy((char *)&buffer[size_send], user, strlen(user));
  size_send += strlen(user) + 1;
  buffer[size_send-1] = 0x00;

  // password - see scramble password
  byte *scramble = (uint8_t *)malloc(20);
  if (scramble_password(password, scramble)) {
    buffer[size_send] = 0x14;
    size_send += 1;
    for (int i = 0; i < 20; i++)
      buffer[i+size_send] = scramble[i];
    size_send += 20;
    buffer[size_send] = 0x00;
  }
  free(scramble);

  // terminate password response
  buffer[size_send] = 0x00;
  size_send += 1;

  // database
  buffer[size_send+1] = 0x00;
  size_send += 1;

  // Write packet size
  int p_size = size_send - 4;
  store_int(&buffer[0], p_size, 3);
  buffer[3] = byte(0x01);

  // Write the packet
  for (int i = 0; i < size_send; i++)
    client->write(buffer[i]);
}
Beispiel #30
0
STORAGE_SET *furnitureDataStore(FURNITURE_DATA *data) {
  STORAGE_SET *set = new_storage_set();
  store_int(set, "capacity", data->capacity);
  store_int(set, "type",     data->type);
  return set;
}