// Receive a value via IPC and return it. // If 'pg' is nonnull, then any page sent by the sender will be mapped at // that address. // If 'from_env_store' is nonnull, then store the IPC sender's envid in // *from_env_store. // If 'perm_store' is nonnull, then store the IPC sender's page permission // in *perm_store (this is nonzero iff a page was successfully // transferred to 'pg'). // If the system call fails, then store 0 in *fromenv and *perm (if // they're nonnull) and return the error. // Otherwise, return the value sent by the sender // // Hint: // Use 'thisenv' to discover the value and who sent it. // If 'pg' is null, pass sys_ipc_recv a value that it will understand // as meaning "no page". (Zero is not the right value, since that's // a perfectly valid place to map a page.) int32_t ipc_recv(envid_t *from_env_store, void *pg, int *perm_store) { // LAB 4: Your code here. //panic("ipc_recv not implemented"); /* lj */ int ret = 0; void *addr = NULL; #define SET_VALUE(var, value) \ do { \ if(var) { \ *var = value; \ }\ }while (0) \ addr = pg ? pg : (void *)-1; if((ret = sys_ipc_recv(addr)) < 0) { //SET_VALUE(from_env_store , 0); SET_VALUE(perm_store ,0); } else if(0 == ret) { //SET_VALUE(from_env_store , thisenv->env_ipc_from); SET_VALUE(perm_store , thisenv->env_ipc_perm); ret = thisenv->env_ipc_value; } SET_VALUE(from_env_store , thisenv->env_ipc_from); #undef SET_VALUE //cprintf("%x get from %x %d %d\n", thisenv->env_id, thisenv->env_ipc_from, thisenv->env_ipc_value, ret); return ret; }
void setSpeed(ESpeedWheel wheel, int value) { if(wheel == LEFT_WHEEL) { tLeftWheel->setPeriod(SET_VALUE(value)); } if(wheel == RIGHT_WHEEL) { tRightWheel->setPeriod(SET_VALUE(value)); } }
//--------------------------------------------------------- bool CGSPoints_Distances::On_Execute(void) { //----------------------------------------------------- CSG_Shapes *pPoints = Parameters("POINTS") ->asShapes(); CSG_Table *pTable = Parameters("TABLE") ->asTable(); //----------------------------------------------------- CSG_PRQuadTree QT(pPoints, 0); CSG_Simple_Statistics s; double x, y, z; for(int iPoint=0; iPoint<pPoints->Get_Count() && Set_Progress(iPoint, pPoints->Get_Count()); iPoint++) { TSG_Point p = pPoints->Get_Shape(iPoint)->Get_Point(0); if( QT.Select_Nearest_Points(p.x, p.y, 2) && QT.Get_Selected_Point(1, x, y, z) && (x != p.x || y != p.y) ) { s.Add_Value(SG_Get_Distance(x, y, p.x, p.y)); } } //----------------------------------------------------- if( s.Get_Count() > 0 ) { CSG_Table_Record *pRecord; pTable->Destroy(); pTable->Set_Name(CSG_String::Format(SG_T("%s [%s]"), _TL("Minimum Distance Analysis"), pPoints->Get_Name())); pTable->Add_Field(SG_T("NAME") , SG_DATATYPE_String); pTable->Add_Field(SG_T("VALUE") , SG_DATATYPE_Double); SET_VALUE(_TL("Mean Average") , s.Get_Mean()); SET_VALUE(_TL("Minimum") , s.Get_Minimum()); SET_VALUE(_TL("Maximum") , s.Get_Maximum()); SET_VALUE(_TL("Standard Deviation") , s.Get_StdDev()); SET_VALUE(_TL("Duplicates") , pPoints->Get_Count() - s.Get_Count()); DataObject_Update(pTable, SG_UI_DATAOBJECT_SHOW); return( true ); } Message_Dlg(_TL("not enough observations")); return( false ); }
setval_t set_remove(set_t *s, setkey_t k) { ptst_t *ptst; node_t *y, *z; qnode_t z_qn; setval_t ov = NULL; k = CALLER_TO_INTERNAL_KEY(k); ptst = critical_enter(); z = &s->root; while ( (y = (k <= z->k) ? z->l : z->r) != NULL ) z = y; if ( z->k == k ) { mcs_lock(&z->lock, &z_qn); if ( !IS_GARBAGE(z) ) { ov = GET_VALUE(z->v); SET_VALUE(z->v, NULL); } mcs_unlock(&z->lock, &z_qn); } if ( ov != NULL ) delete_finish(ptst, z); critical_exit(ptst); return ov; }
void useMemory(void *ptr, size_t size) { size_t nextData; void *tmp; nextData = ((t_metadata *)ptr)->_allocSize; ((t_metadata *)ptr)->_allocSize = (size + sizeof(t_metadata)); SET_VALUE(((t_metadata *)ptr)->_properties, _USED, 1); if (size + sizeof(t_metadata) == nextData) { if (((t_metadata *)ptr)->_nextFree != sbrk(0)) ((t_metadata *)ptr)->_nextFree->_prevFree = ((t_metadata *)ptr)->_prevFree; ((t_metadata *)ptr)->_prevFree->_nextFree = ((t_metadata *)ptr)->_nextFree; } else { tmp = ptr + size + sizeof(t_metadata); if (((t_metadata *)ptr)->_nextFree != sbrk(0)) ((t_metadata *)ptr)->_nextFree->_prevFree = tmp; create_link(&tmp, &ptr, size, nextData); } }
static void *javascript_add_ruby_fn(JSGlobalContextRef ctx, char *name, VALUE ruby_fn) { JSValueRef *_exception = NULL; JSObjectRef fn = NULL; if (!ruby_fns) { ruby_fns = g_hash_table_new(NULL, NULL); } JSObjectRef global = JSContextGetGlobalObject(ctx); fn = JS_fn(js_ruby_fn); if (!JSObjectSetPrivate(fn, (void*)ruby_fn)) { gpointer old_value = g_hash_table_lookup(ruby_fns, (gpointer)fn); if (old_value != NULL) RUBYFUNC_DEL((VALUE)old_value); RUBYFUNC_ADD(ruby_fn); g_hash_table_insert(ruby_fns, (gpointer)fn, (gpointer)ruby_fn); } SET_VALUE(global, name, fn); return NULL; }
void CPerigeeCopyOptions::SetApplyToAll(bool apply_to_all) { HKEY key = NULL; DWORD disposition = 0; RegCreateKeyEx(HKEY_CURRENT_USER, app_key, 0, NULL, 0, KEY_WRITE, NULL, &key, &disposition); SET_VALUE(key, apply_to_all); RegCloseKey(key); }
void PrefAgent::set_geometry (WXmTextField &field, WindowGeometry &wg) { static char buf[16]; snprintf (buf, sizeof(buf), "%dx%d", wg.width, wg.height); field.Value (buf); SET_VALUE (field, WindowGeometry, wg); }
void PrefAgent::set_integer (WXmTextField &field, int i) { static char buf[16]; snprintf (buf, sizeof(buf), "%d", i); field.Value (buf); SET_VALUE (field, Integer, i); }
mlib_status __mlib_VectorSet_S32( mlib_s32 *z, const mlib_s32 *c, mlib_s32 n) { mlib_s32 c0 = *c; __m128i val = _mm_set1_epi32(c0); SET_VALUE(mlib_s32); }
mlib_status __mlib_VectorSet_S16( mlib_s16 *z, const mlib_s16 *c, mlib_s32 n) { mlib_s16 c0 = *c; __m128i val = _mm_set1_epi16(c0); SET_VALUE(mlib_s16); }
int cmn_SetShiftedValue(volatile uint32_t* field, uint32_t value, uint32_t mask, uint32_t bitsToSetShift) { VALIDATE_BITS(value, mask); uint32_t currentValue; cmn_GetValue(field, ¤tValue, 0xffffffff); currentValue &= ~(mask << bitsToSetShift); // Clear all bits at specified location currentValue += (value << bitsToSetShift); // Set value at specified location SET_VALUE(*field, currentValue); return RP_OK; }
mlib_status __mlib_VectorSet_S8( mlib_s8 *z, const mlib_s8 *c, mlib_s32 n) { mlib_s8 c0 = *c; __m128i val = _mm_set1_epi8(c0); SET_VALUE(mlib_s8); }
static void *javascript_setup_ruby(JSGlobalContextRef ctx) { JSValueRef *_exception = NULL; JSObjectRef global = JSContextGetGlobalObject(ctx); SET_VALUE(global, "ruby_eval", JS_fn(evaluate_ruby)); return NULL; }
void PrefAgent::set_update (bool set) { XmStringLocalized mtfstring = CATGETS(Set_AgentLabel, set? 203 : 204, set ? "On" : "Off"); XtVaSetValues(f_update_toggle, XmNlabelString, (XmString)mtfstring, NULL); f_update_toggle.Set (set); SET_VALUE (f_update_toggle, Boolean, set); }
void jumpMemory(void *ptr, void *breakPoint, size_t space) { ((t_metadata *)ptr)->_nextFree = breakPoint; ((t_metadata *)ptr)->_nextElem = breakPoint; ((t_metadata *)breakPoint)->_allocSize = space; ((t_metadata *)breakPoint)->_prevFree = ptr; ((t_metadata *)breakPoint)->_nextFree = sbrk(0); ((t_metadata *)breakPoint)->_nextElem = sbrk(0); ((t_metadata *)breakPoint)->_properties = 0; SET_VALUE(((t_metadata *)breakPoint)->_properties, _JUMPED, 1); }
static grn_obj * construct_elements(gconstpointer data) { const int n_of_elements = 3; grn_obj *elements; const gchar *type_name; elements = g_new0(grn_obj, n_of_elements); type_name = gcut_data_get_string(data, "type_name"); #define SET_VALUE(index, name) \ if (g_str_equal(type_name, "Int32")) { \ GRN_INT32_INIT(&elements[index], 0); \ GRN_INT32_SET(context, &elements[index], \ gcut_data_get_int(data, name)); \ } if (g_str_equal(type_name, "Float")) { \ GRN_FLOAT_INIT(&elements[index], 0); \ GRN_FLOAT_SET(context, &elements[index], \ gcut_data_get_double(data, name)); \ } if (g_str_equal(type_name, "Bool")) { \ GRN_BOOL_INIT(&elements[index], 0); \ GRN_BOOL_SET(context, &elements[index], \ gcut_data_get_boolean(data, name)); \ } if (g_str_equal(type_name, "Text")) { \ GRN_TEXT_INIT(&elements[index], 0); \ GRN_TEXT_SETS(context, &elements[index], \ gcut_data_get_string(data, name)); \ } SET_VALUE(0, "first_element"); SET_VALUE(1, "second_element"); SET_VALUE(2, "third_element"); #undef SET_VALUE cut_take_memory(elements); return elements; }
void VideoTx(void) { static channel_t* bitsVtxAddr; static int firsttime = 1; int vtx_bits = 0; if (firsttime) { firsttime = 0; bitsVtxAddr = channels_find_by_name("bits_vtx"); } if (CommandData.vtx_sel[0] == vtx_osc) vtx_bits |= 0x1; if (CommandData.vtx_sel[1] == vtx_isc) vtx_bits |= 0x4; SET_VALUE(bitsVtxAddr, vtx_bits); }
void PrefAgent::set_lock (bool set) { if (set) { f_lock_toggle.WObject::Set(WArgList(XmNselectPixmap, window_system().locked_pixmap(f_lock_toggle.Parent()), XmNlabelPixmap, window_system().semilocked_pixmap(f_lock_toggle.Parent()), NULL)); } else { f_lock_toggle.WObject::Set(WArgList(XmNselectPixmap, window_system().semilocked_pixmap(f_lock_toggle.Parent()), XmNlabelPixmap, window_system().unlocked_pixmap(f_lock_toggle.Parent()), NULL)); } f_lock_toggle.Set (set); SET_VALUE (f_lock_toggle, Boolean, set); }
static KMF_RETURN gencert_nss(KMF_HANDLE_T kmfhandle, char *token, char *subject, char *altname, KMF_GENERALNAMECHOICES alttype, int altcrit, char *nickname, char *dir, char *prefix, KMF_KEY_ALG keyAlg, KMF_ALGORITHM_INDEX sigAlg, int keylen, char *trust, uint32_t ltime, KMF_BIGINT *serial, uint16_t kubits, int kucrit, KMF_CREDENTIAL *tokencred, EKU_LIST *ekulist, KMF_OID *curveoid) { KMF_RETURN kmfrv; KMF_KEY_HANDLE pubk, prik; KMF_X509_CERTIFICATE signedCert; KMF_X509_NAME certSubject; KMF_X509_NAME certIssuer; KMF_DATA x509DER; KMF_KEYSTORE_TYPE kstype = KMF_KEYSTORE_NSS; KMF_ATTRIBUTE attrlist[16]; int numattr = 0; if (token == NULL) token = DEFAULT_NSS_TOKEN; kmfrv = configure_nss(kmfhandle, dir, prefix); if (kmfrv != KMF_OK) return (kmfrv); (void) memset(&signedCert, 0, sizeof (signedCert)); (void) memset(&certSubject, 0, sizeof (certSubject)); (void) memset(&certIssuer, 0, sizeof (certIssuer)); (void) memset(&x509DER, 0, sizeof (x509DER)); /* If the subject name cannot be parsed, flag it now and exit */ if (kmf_dn_parser(subject, &certSubject) != KMF_OK) { cryptoerror(LOG_STDERR, gettext("Subject name cannot be parsed.\n")); return (PK_ERR_USAGE); } /* For a self-signed cert, the issuser and subject are the same */ if (kmf_dn_parser(subject, &certIssuer) != KMF_OK) { cryptoerror(LOG_STDERR, gettext("Subject name cannot be parsed.\n")); return (PK_ERR_USAGE); } kmfrv = genkeypair_nss(kmfhandle, token, nickname, dir, prefix, keyAlg, keylen, tokencred, curveoid, &prik, &pubk); if (kmfrv != KMF_OK) return (kmfrv); SET_VALUE(kmf_set_cert_pubkey(kmfhandle, &pubk, &signedCert), "keypair"); SET_VALUE(kmf_set_cert_version(&signedCert, 2), "version number"); SET_VALUE(kmf_set_cert_serial(&signedCert, serial), "serial number"); SET_VALUE(kmf_set_cert_validity(&signedCert, NULL, ltime), "validity time"); SET_VALUE(kmf_set_cert_sig_alg(&signedCert, sigAlg), "signature algorithm"); SET_VALUE(kmf_set_cert_subject(&signedCert, &certSubject), "subject name"); SET_VALUE(kmf_set_cert_issuer(&signedCert, &certIssuer), "issuer name"); if (altname != NULL) SET_VALUE(kmf_set_cert_subject_altname(&signedCert, altcrit, alttype, altname), "subjectAltName"); if (kubits) SET_VALUE(kmf_set_cert_ku(&signedCert, kucrit, kubits), "subjectAltName"); if (ekulist != NULL) { int i; for (i = 0; kmfrv == KMF_OK && i < ekulist->eku_count; i++) { SET_VALUE(kmf_add_cert_eku(&signedCert, &ekulist->ekulist[i], ekulist->critlist[i]), "Extended Key Usage"); } } /* * Construct attributes for the kmf_sign_cert operation. */ numattr = 0; kmf_set_attr_at_index(attrlist, numattr, KMF_KEYSTORE_TYPE_ATTR, &kstype, sizeof (kstype)); numattr++; kmf_set_attr_at_index(attrlist, numattr, KMF_KEY_HANDLE_ATTR, &prik, sizeof (KMF_KEY_HANDLE_ATTR)); numattr++; /* cert data that is to be signed */ kmf_set_attr_at_index(attrlist, numattr, KMF_X509_CERTIFICATE_ATTR, &signedCert, sizeof (KMF_X509_CERTIFICATE)); numattr++; /* output buffer for the signed cert */ kmf_set_attr_at_index(attrlist, numattr, KMF_CERT_DATA_ATTR, &x509DER, sizeof (KMF_DATA)); numattr++; kmf_set_attr_at_index(attrlist, numattr, KMF_ALGORITHM_INDEX_ATTR, &sigAlg, sizeof (sigAlg)); numattr++; if ((kmfrv = kmf_sign_cert(kmfhandle, numattr, attrlist)) != KMF_OK) { goto cleanup; } /* * Store the cert in the DB. */ numattr = 0; kmf_set_attr_at_index(attrlist, numattr, KMF_KEYSTORE_TYPE_ATTR, &kstype, sizeof (kstype)); numattr++; kmf_set_attr_at_index(attrlist, numattr, KMF_CERT_DATA_ATTR, &x509DER, sizeof (KMF_DATA)); numattr++; if (nickname != NULL) { kmf_set_attr_at_index(attrlist, numattr, KMF_CERT_LABEL_ATTR, nickname, strlen(nickname)); numattr++; } if (trust != NULL) { kmf_set_attr_at_index(attrlist, numattr, KMF_TRUSTFLAG_ATTR, trust, strlen(trust)); numattr++; } if (token != NULL) { kmf_set_attr_at_index(attrlist, numattr, KMF_TOKEN_LABEL_ATTR, token, strlen(token)); numattr++; } kmfrv = kmf_store_cert(kmfhandle, numattr, attrlist); cleanup: kmf_free_data(&x509DER); kmf_free_dn(&certSubject); kmf_free_dn(&certIssuer); return (kmfrv); }
static int gencert_pkcs11(KMF_HANDLE_T kmfhandle, char *token, char *subject, char *altname, KMF_GENERALNAMECHOICES alttype, int altcrit, char *certlabel, KMF_KEY_ALG keyAlg, KMF_ALGORITHM_INDEX sigAlg, int keylen, uint32_t ltime, KMF_BIGINT *serial, uint16_t kubits, int kucrit, KMF_CREDENTIAL *tokencred, EKU_LIST *ekulist, KMF_OID *curveoid) { KMF_RETURN kmfrv = KMF_OK; KMF_KEY_HANDLE pubk, prik; KMF_X509_CERTIFICATE signedCert; KMF_X509_NAME certSubject; KMF_X509_NAME certIssuer; KMF_DATA x509DER; KMF_KEYSTORE_TYPE kstype = KMF_KEYSTORE_PK11TOKEN; KMF_ATTRIBUTE attrlist[16]; int numattr = 0; KMF_KEY_ALG keytype; uint32_t keylength; (void) memset(&signedCert, 0, sizeof (signedCert)); (void) memset(&certSubject, 0, sizeof (certSubject)); (void) memset(&certIssuer, 0, sizeof (certIssuer)); (void) memset(&x509DER, 0, sizeof (x509DER)); /* If the subject name cannot be parsed, flag it now and exit */ if (kmf_dn_parser(subject, &certSubject) != KMF_OK) { cryptoerror(LOG_STDERR, gettext("Subject name cannot be parsed.\n")); return (PK_ERR_USAGE); } /* For a self-signed cert, the issuser and subject are the same */ if (kmf_dn_parser(subject, &certIssuer) != KMF_OK) { cryptoerror(LOG_STDERR, gettext("Subject name cannot be parsed.\n")); return (PK_ERR_USAGE); } keylength = keylen; /* bits */ keytype = keyAlg; /* Select a PKCS11 token */ kmfrv = select_token(kmfhandle, token, FALSE); if (kmfrv != KMF_OK) { return (kmfrv); } /* * Share the "genkeypair" routine for creating the keypair. */ kmfrv = genkeypair_pkcs11(kmfhandle, token, certlabel, keytype, keylength, tokencred, curveoid, &prik, &pubk); if (kmfrv != KMF_OK) return (kmfrv); SET_VALUE(kmf_set_cert_pubkey(kmfhandle, &pubk, &signedCert), "keypair"); SET_VALUE(kmf_set_cert_version(&signedCert, 2), "version number"); SET_VALUE(kmf_set_cert_serial(&signedCert, serial), "serial number"); SET_VALUE(kmf_set_cert_validity(&signedCert, NULL, ltime), "validity time"); SET_VALUE(kmf_set_cert_sig_alg(&signedCert, sigAlg), "signature algorithm"); SET_VALUE(kmf_set_cert_subject(&signedCert, &certSubject), "subject name"); SET_VALUE(kmf_set_cert_issuer(&signedCert, &certIssuer), "issuer name"); if (altname != NULL) SET_VALUE(kmf_set_cert_subject_altname(&signedCert, altcrit, alttype, altname), "subjectAltName"); if (kubits != 0) SET_VALUE(kmf_set_cert_ku(&signedCert, kucrit, kubits), "KeyUsage"); if (ekulist != NULL) { int i; for (i = 0; kmfrv == KMF_OK && i < ekulist->eku_count; i++) { SET_VALUE(kmf_add_cert_eku(&signedCert, &ekulist->ekulist[i], ekulist->critlist[i]), "Extended Key Usage"); } } /* * Construct attributes for the kmf_sign_cert operation. */ numattr = 0; kmf_set_attr_at_index(attrlist, numattr, KMF_KEYSTORE_TYPE_ATTR, &kstype, sizeof (kstype)); numattr++; kmf_set_attr_at_index(attrlist, numattr, KMF_KEY_HANDLE_ATTR, &prik, sizeof (KMF_KEY_HANDLE_ATTR)); numattr++; /* cert data that is to be signed */ kmf_set_attr_at_index(attrlist, numattr, KMF_X509_CERTIFICATE_ATTR, &signedCert, sizeof (KMF_X509_CERTIFICATE)); numattr++; /* output buffer for the signed cert */ kmf_set_attr_at_index(attrlist, numattr, KMF_CERT_DATA_ATTR, &x509DER, sizeof (KMF_DATA)); numattr++; kmf_set_attr_at_index(attrlist, numattr, KMF_ALGORITHM_INDEX_ATTR, &sigAlg, sizeof (sigAlg)); numattr++; if ((kmfrv = kmf_sign_cert(kmfhandle, numattr, attrlist)) != KMF_OK) { goto cleanup; } /* * Store the cert in the DB. */ numattr = 0; kmf_set_attr_at_index(attrlist, numattr, KMF_KEYSTORE_TYPE_ATTR, &kstype, sizeof (kstype)); numattr++; kmf_set_attr_at_index(attrlist, numattr, KMF_CERT_DATA_ATTR, &x509DER, sizeof (KMF_DATA)); numattr++; if (certlabel != NULL) { kmf_set_attr_at_index(attrlist, numattr, KMF_CERT_LABEL_ATTR, certlabel, strlen(certlabel)); numattr++; } kmfrv = kmf_store_cert(kmfhandle, numattr, attrlist); cleanup: kmf_free_data(&x509DER); kmf_free_dn(&certSubject); kmf_free_dn(&certIssuer); /* * If kmf_sign_cert or kmf_store_cert failed, then we need to clean up * the key pair from the token. */ if (kmfrv != KMF_OK) { /* delete the public key */ numattr = 0; kmf_set_attr_at_index(attrlist, numattr, KMF_KEYSTORE_TYPE_ATTR, &kstype, sizeof (kstype)); numattr++; kmf_set_attr_at_index(attrlist, numattr, KMF_KEY_HANDLE_ATTR, &pubk, sizeof (KMF_KEY_HANDLE)); numattr++; if (tokencred != NULL && tokencred->cred != NULL) { kmf_set_attr_at_index(attrlist, numattr, KMF_CREDENTIAL_ATTR, tokencred, sizeof (KMF_CREDENTIAL)); numattr++; } (void) kmf_delete_key_from_keystore(kmfhandle, numattr, attrlist); /* delete the private key */ numattr = 0; kmf_set_attr_at_index(attrlist, numattr, KMF_KEYSTORE_TYPE_ATTR, &kstype, sizeof (kstype)); numattr++; kmf_set_attr_at_index(attrlist, numattr, KMF_KEY_HANDLE_ATTR, &prik, sizeof (KMF_KEY_HANDLE)); numattr++; if (tokencred != NULL && tokencred->cred != NULL) { kmf_set_attr_at_index(attrlist, numattr, KMF_CREDENTIAL_ATTR, tokencred, sizeof (KMF_CREDENTIAL)); numattr++; } (void) kmf_delete_key_from_keystore(kmfhandle, numattr, attrlist); } return (kmfrv); }
setval_t set_update(set_t *s, setkey_t k, setval_t v, int overwrite) { ptst_t *ptst; qnode_t y_qn, z_qn; node_t *y, *z, *new_internal, *new_leaf; int fix_up = 0; setval_t ov = NULL; k = CALLER_TO_INTERNAL_KEY(k); ptst = critical_enter(); retry: z = &s->root; while ( (y = (k <= z->k) ? z->l : z->r) != NULL ) z = y; y = z->p; mcs_lock(&y->lock, &y_qn); if ( (((k <= y->k) ? y->l : y->r) != z) || IS_GARBAGE(y) ) { mcs_unlock(&y->lock, &y_qn); goto retry; } mcs_lock(&z->lock, &z_qn); assert(!IS_GARBAGE(z) && IS_LEAF(z)); if ( z->k == k ) { ov = GET_VALUE(z->v); if ( overwrite || (ov == NULL) ) SET_VALUE(z->v, v); } else { new_leaf = gc_alloc(ptst, gc_id); new_internal = gc_alloc(ptst, gc_id); new_leaf->k = k; new_leaf->v = MK_BLACK(v); new_leaf->l = NULL; new_leaf->r = NULL; new_leaf->p = new_internal; mcs_init(&new_leaf->lock); if ( z->k < k ) { new_internal->k = z->k; new_internal->l = z; new_internal->r = new_leaf; } else { new_internal->k = k; new_internal->l = new_leaf; new_internal->r = z; } new_internal->p = y; mcs_init(&new_internal->lock); if ( IS_UNBALANCED(z->v) ) { z->v = MK_BALANCED(z->v); new_internal->v = MK_BLACK(INTERNAL_VALUE); } else if ( IS_RED(y->v) ) { new_internal->v = MK_UNBALANCED(MK_RED(INTERNAL_VALUE)); fix_up = 1; } else { new_internal->v = MK_RED(INTERNAL_VALUE); } WMB(); z->p = new_internal; if ( y->l == z ) y->l = new_internal; else y->r = new_internal; } mcs_unlock(&y->lock, &y_qn); mcs_unlock(&z->lock, &z_qn); if ( fix_up ) fix_unbalance_up(ptst, new_internal); out: critical_exit(ptst); return ov; }
//----------------------------------------------------------------------------- // Test binary data transmission. // Format in: // <byte size>:<mode> // Format out: // <4 bytes binary checksum><#size bytes data> // If echo mode, also: // Format in: // <#size bytes data> // Format out: // OK/ER - according to CRC match on incomin data // Format in: // DONE // // To Do: // o Add mode/flag specifying 5-8 bit transfer. // Test that 0xff gets masked off accordingly when transfered. // (This should be an INFO result if failing) // o Clean up the DUPLEX_ECHO implementation. Currently it's an ugly hack // that doesn't match the arguments / behavior of the two other modes. void CeCosTestSerialFilter::CMD_TestBinary(CeCosSerial &pSer, char* args) { int size; cyg_mode_t mode; unsigned char *data_out, *data_in; int i; int crc; int loop_count = 0; INIT_VALUE(args); SET_VALUE(int, size); SET_VALUE(cyg_mode_t, mode); // Change behavior for DUPLEX mode. if (MODE_DUPLEX_ECHO == mode) { loop_count = size; size = 1024; // must be at least 4*block_size } // Generate data. data_out = (unsigned char*) malloc(size); if (!data_out) { fprintf(stderr, "Could not allocate %d byte buffer for data!\n", size); throw "data_out malloc failed"; } data_in = (unsigned char*) malloc(size); if (!data_in) { fprintf(stderr, "Could not allocate %d byte buffer for data!\n", size); throw "data_in malloc failed"; } int count = 0; for (i = 0; i < size; i++) { // Output 255 chars, not 256 so that we aren't a multiple/factor of the // likely buffer sizes in the system, this can mask problems as I've // found to my cost! unsigned char c = (unsigned char) (count++ % 255); // don't allow $s and @s in the data, nor 0x03 (GDB C-c), nor flow // control chars if ('$' == c || '@' == c || 0x03 == c || 0x11 == c || 0x13 == c) c = (unsigned char) '*'; data_out[i] = c; } // Do checksum. crc = DoCRC(data_out, size); // Send checksum to target. SendChecksum(pSer, crc); // Give the target 1/10th of a sec to digest it CeCosThreadUtils::Sleep(100); switch (mode) { case MODE_NO_ECHO: { // Simple transmit. Don't expect target to echo data back. TargetWrite(pSer, data_out, size); ReceiveDone(pSer, NULL, 0); } break; case MODE_EOP_ECHO: { int in_crc; TargetWrite(pSer, data_out, size); Trace("Finished write, waiting for target echo.\n"); // Expect target to echo the data TargetRead(pSer, data_in, size); // Check echoed data, and reply OK/ER accordingly. in_crc = DoCRC(data_in, size); SendStatus(pSer, (in_crc == crc)); // Dump seen/expected on console. if (in_crc != crc) { Trace("Data seen:\n"); PrintHex(data_in, size); Trace("<end>\n"); Trace("Data expected:\n"); PrintHex(data_out, size); Trace("<end>\n"); } ReceiveDone(pSer, data_in, size); } break; case MODE_DUPLEX_ECHO: { int block_size = 64; int fail, j; // This is a simple implementation (maybe too simple). // Host sends 4 packets with the same size (64 bytes atm). // Target echoes in this way: // packet1 -> packet1 // packet2 -> packet2, packet2 // packet3 -> packet3 // packet4 -> /dev/null // // The reads/writes are interleaved in a way that should ensure // the target out buffer to be full before the target starts to read // packet3. That is, the target should be both receiving (packet3) // and sending (packet2) at the same time. // This code needs restructuring. It's not very obvious what's // happening: The same block of data is output several times, // the target echoes the data back (one of the blocks is // echoed twice). Then the echoed data is compared agains the // outgoing data block. fail = 0; while (loop_count--) { int i; for (i = 0; i < block_size*4; i++) data_in[i] = 0; // out1: block_size -> block_size TargetWrite(pSer, data_out, block_size); // out2: block_size -> 2 x block_size TargetWrite(pSer, data_out, block_size); // in1: TargetRead(pSer, data_in, block_size); // out3: block_size -> block_size TargetWrite(pSer, data_out, block_size); // in2: TargetRead(pSer, &data_in[block_size], 2*block_size); // out4: block_size -> 0 TargetWrite(pSer, data_out, block_size); // in3: TargetRead(pSer, &data_in[block_size*3], block_size); if (0 == loop_count % 10) Trace("%d loops to go\n", loop_count); // Verify data. if (!fail) { for (j = 0; j < 4 && !fail; j++) { for (i = 0; i < block_size && !fail; i++) { if (data_out[i] != data_in[j*block_size + i]) { fail = 1; Trace("Failed at byte %d\n", j*block_size + i); Trace("Data seen:\n"); PrintHex(&data_in[j*block_size], block_size); Trace("<end>\n"); Trace("Data expected:\n"); PrintHex(data_out, block_size); Trace("<end>\n"); } } } } } // Check echoed data, and reply OK/ER accordingly. SendStatus(pSer, (!fail)); ReceiveDone(pSer, data_in, block_size*4); } break; default: Trace("Unknown mode. Ignoring.\n"); } // Free buffer. free(data_in); free(data_out); }
bool RarVM::ExecuteCode(VM_PreparedCommand *PreparedCode,int CodeSize) { int MaxOpCount=25000000; VM_PreparedCommand *Cmd=PreparedCode; while (1) { unsigned int *Op1=GetOperand(&Cmd->Op1); unsigned int *Op2=GetOperand(&Cmd->Op2); switch(Cmd->OpCode) { #ifndef NORARVM case VM_MOV: SET_VALUE(Cmd->ByteMode,Op1,GET_VALUE(Cmd->ByteMode,Op2)); break; #ifdef VM_OPTIMIZE case VM_MOVB: SET_VALUE(true,Op1,GET_VALUE(true,Op2)); break; case VM_MOVD: SET_VALUE(false,Op1,GET_VALUE(false,Op2)); break; #endif case VM_CMP: { unsigned int Value1=GET_VALUE(Cmd->ByteMode,Op1); unsigned int Result=UINT32(Value1-GET_VALUE(Cmd->ByteMode,Op2)); Flags=Result==0 ? VM_FZ:(Result>Value1)|(Result&VM_FS); } break; #ifdef VM_OPTIMIZE case VM_CMPB: { unsigned int Value1=GET_VALUE(true,Op1); unsigned int Result=UINT32(Value1-GET_VALUE(true,Op2)); Flags=Result==0 ? VM_FZ:(Result>Value1)|(Result&VM_FS); } break; case VM_CMPD: { unsigned int Value1=GET_VALUE(false,Op1); unsigned int Result=UINT32(Value1-GET_VALUE(false,Op2)); Flags=Result==0 ? VM_FZ:(Result>Value1)|(Result&VM_FS); } break; #endif case VM_ADD: { unsigned int Value1=GET_VALUE(Cmd->ByteMode,Op1); unsigned int Result=UINT32(Value1+GET_VALUE(Cmd->ByteMode,Op2)); Flags=Result==0 ? VM_FZ:(Result<Value1)|(Result&VM_FS); SET_VALUE(Cmd->ByteMode,Op1,Result); } break; #ifdef VM_OPTIMIZE case VM_ADDB: SET_VALUE(true,Op1,GET_VALUE(true,Op1)+GET_VALUE(true,Op2)); break; case VM_ADDD: SET_VALUE(false,Op1,GET_VALUE(false,Op1)+GET_VALUE(false,Op2)); break; #endif case VM_SUB: { unsigned int Value1=GET_VALUE(Cmd->ByteMode,Op1); unsigned int Result=UINT32(Value1-GET_VALUE(Cmd->ByteMode,Op2)); Flags=Result==0 ? VM_FZ:(Result>Value1)|(Result&VM_FS); SET_VALUE(Cmd->ByteMode,Op1,Result); } break; #ifdef VM_OPTIMIZE case VM_SUBB: SET_VALUE(true,Op1,GET_VALUE(true,Op1)-GET_VALUE(true,Op2)); break; case VM_SUBD: SET_VALUE(false,Op1,GET_VALUE(false,Op1)-GET_VALUE(false,Op2)); break; #endif case VM_JZ: if ((Flags & VM_FZ)!=0) { SET_IP(GET_VALUE(false,Op1)); continue; } break; case VM_JNZ: if ((Flags & VM_FZ)==0) { SET_IP(GET_VALUE(false,Op1)); continue; } break; case VM_INC: { unsigned int Result=UINT32(GET_VALUE(Cmd->ByteMode,Op1)+1); SET_VALUE(Cmd->ByteMode,Op1,Result); Flags=Result==0 ? VM_FZ:Result&VM_FS; } break; #ifdef VM_OPTIMIZE case VM_INCB: SET_VALUE(true,Op1,GET_VALUE(true,Op1)+1); break; case VM_INCD: SET_VALUE(false,Op1,GET_VALUE(false,Op1)+1); break; #endif case VM_DEC: { unsigned int Result=UINT32(GET_VALUE(Cmd->ByteMode,Op1)-1); SET_VALUE(Cmd->ByteMode,Op1,Result); Flags=Result==0 ? VM_FZ:Result&VM_FS; } break; #ifdef VM_OPTIMIZE case VM_DECB: SET_VALUE(true,Op1,GET_VALUE(true,Op1)-1); break; case VM_DECD: SET_VALUE(false,Op1,GET_VALUE(false,Op1)-1); break; #endif case VM_JMP: SET_IP(GET_VALUE(false,Op1)); continue; case VM_XOR: { unsigned int Result=UINT32(GET_VALUE(Cmd->ByteMode,Op1)^GET_VALUE(Cmd->ByteMode,Op2)); Flags=Result==0 ? VM_FZ:Result&VM_FS; SET_VALUE(Cmd->ByteMode,Op1,Result); } break; case VM_AND: { unsigned int Result=UINT32(GET_VALUE(Cmd->ByteMode,Op1)&GET_VALUE(Cmd->ByteMode,Op2)); Flags=Result==0 ? VM_FZ:Result&VM_FS; SET_VALUE(Cmd->ByteMode,Op1,Result); } break; case VM_OR: { unsigned int Result=UINT32(GET_VALUE(Cmd->ByteMode,Op1)|GET_VALUE(Cmd->ByteMode,Op2)); Flags=Result==0 ? VM_FZ:Result&VM_FS; SET_VALUE(Cmd->ByteMode,Op1,Result); } break; case VM_TEST: { unsigned int Result=UINT32(GET_VALUE(Cmd->ByteMode,Op1)&GET_VALUE(Cmd->ByteMode,Op2)); Flags=Result==0 ? VM_FZ:Result&VM_FS; } break; case VM_JS: if ((Flags & VM_FS)!=0) { SET_IP(GET_VALUE(false,Op1)); continue; } break; case VM_JNS: if ((Flags & VM_FS)==0) { SET_IP(GET_VALUE(false,Op1)); continue; } break; case VM_JB: if ((Flags & VM_FC)!=0) { SET_IP(GET_VALUE(false,Op1)); continue; } break; case VM_JBE: if ((Flags & (VM_FC|VM_FZ))!=0) { SET_IP(GET_VALUE(false,Op1)); continue; } break; case VM_JA: if ((Flags & (VM_FC|VM_FZ))==0) { SET_IP(GET_VALUE(false,Op1)); continue; } break; case VM_JAE: if ((Flags & VM_FC)==0) { SET_IP(GET_VALUE(false,Op1)); continue; } break; case VM_PUSH: R[7]-=4; SET_VALUE(false,(unsigned int *)&Mem[R[7]&VM_MEMMASK],GET_VALUE(false,Op1)); break; case VM_POP: SET_VALUE(false,Op1,GET_VALUE(false,(unsigned int *)&Mem[R[7] & VM_MEMMASK])); R[7]+=4; break; case VM_CALL: R[7]-=4; SET_VALUE(false,(unsigned int *)&Mem[R[7]&VM_MEMMASK],Cmd-PreparedCode+1); SET_IP(GET_VALUE(false,Op1)); continue; case VM_NOT: SET_VALUE(Cmd->ByteMode,Op1,~GET_VALUE(Cmd->ByteMode,Op1)); break; case VM_SHL: { unsigned int Value1=GET_VALUE(Cmd->ByteMode,Op1); unsigned int Value2=GET_VALUE(Cmd->ByteMode,Op2); unsigned int Result=UINT32(Value1<<Value2); Flags=(Result==0 ? VM_FZ:(Result&VM_FS))|((Value1<<(Value2-1))&0x80000000 ? VM_FC:0); SET_VALUE(Cmd->ByteMode,Op1,Result); } break; case VM_SHR: { unsigned int Value1=GET_VALUE(Cmd->ByteMode,Op1); unsigned int Value2=GET_VALUE(Cmd->ByteMode,Op2); unsigned int Result=UINT32(Value1>>Value2); Flags=(Result==0 ? VM_FZ:(Result&VM_FS))|((Value1>>(Value2-1))&VM_FC); SET_VALUE(Cmd->ByteMode,Op1,Result); } break; case VM_SAR: { unsigned int Value1=GET_VALUE(Cmd->ByteMode,Op1); unsigned int Value2=GET_VALUE(Cmd->ByteMode,Op2); unsigned int Result=UINT32(((int)Value1)>>Value2); Flags=(Result==0 ? VM_FZ:(Result&VM_FS))|((Value1>>(Value2-1))&VM_FC); SET_VALUE(Cmd->ByteMode,Op1,Result); } break; case VM_NEG: { unsigned int Result=UINT32(-GET_VALUE(Cmd->ByteMode,Op1)); Flags=Result==0 ? VM_FZ:VM_FC|(Result&VM_FS); SET_VALUE(Cmd->ByteMode,Op1,Result); } break; #ifdef VM_OPTIMIZE case VM_NEGB: SET_VALUE(true,Op1,-GET_VALUE(true,Op1)); break; case VM_NEGD: SET_VALUE(false,Op1,-GET_VALUE(false,Op1)); break; #endif case VM_PUSHA: { const int RegCount=sizeof(R)/sizeof(R[0]); for (int I=0,SP=R[7]-4;I<RegCount;I++,SP-=4) SET_VALUE(false,(unsigned int *)&Mem[SP & VM_MEMMASK],R[I]); R[7]-=RegCount*4; } break; case VM_POPA: { const int RegCount=sizeof(R)/sizeof(R[0]); for (unsigned int I=0,SP=R[7];I<RegCount;I++,SP+=4) R[7-I]=GET_VALUE(false,(unsigned int *)&Mem[SP & VM_MEMMASK]); } break; case VM_PUSHF: R[7]-=4; SET_VALUE(false,(unsigned int *)&Mem[R[7]&VM_MEMMASK],Flags); break; case VM_POPF: Flags=GET_VALUE(false,(unsigned int *)&Mem[R[7] & VM_MEMMASK]); R[7]+=4; break; case VM_MOVZX: SET_VALUE(false,Op1,GET_VALUE(true,Op2)); break; case VM_MOVSX: SET_VALUE(false,Op1,(signed char)GET_VALUE(true,Op2)); break; case VM_XCHG: { unsigned int Value1=GET_VALUE(Cmd->ByteMode,Op1); SET_VALUE(Cmd->ByteMode,Op1,GET_VALUE(Cmd->ByteMode,Op2)); SET_VALUE(Cmd->ByteMode,Op2,Value1); } break; case VM_MUL: { unsigned int Result=GET_VALUE(Cmd->ByteMode,Op1)*GET_VALUE(Cmd->ByteMode,Op2); SET_VALUE(Cmd->ByteMode,Op1,Result); } break; case VM_DIV: { unsigned int Divider=GET_VALUE(Cmd->ByteMode,Op2); if (Divider!=0) { unsigned int Result=GET_VALUE(Cmd->ByteMode,Op1)/Divider; SET_VALUE(Cmd->ByteMode,Op1,Result); } } break; case VM_ADC: { unsigned int Value1=GET_VALUE(Cmd->ByteMode,Op1); unsigned int FC=(Flags&VM_FC); unsigned int Result=UINT32(Value1+GET_VALUE(Cmd->ByteMode,Op2)+FC); Flags=Result==0 ? VM_FZ:(Result<Value1 || Result==Value1 && FC)|(Result&VM_FS); SET_VALUE(Cmd->ByteMode,Op1,Result); } break; case VM_SBB: { unsigned int Value1=GET_VALUE(Cmd->ByteMode,Op1); unsigned int FC=(Flags&VM_FC); unsigned int Result=UINT32(Value1-GET_VALUE(Cmd->ByteMode,Op2)-FC); Flags=Result==0 ? VM_FZ:(Result>Value1 || Result==Value1 && FC)|(Result&VM_FS); SET_VALUE(Cmd->ByteMode,Op1,Result); } break; #endif case VM_RET: if (R[7]>=VM_MEMSIZE) return(true); SET_IP(GET_VALUE(false,(unsigned int *)&Mem[R[7] & VM_MEMMASK])); R[7]+=4; continue; #ifdef VM_STANDARDFILTERS case VM_STANDARD: ExecuteStandardFilter((VM_StandardFilters)Cmd->Op1.Data); break; #endif case VM_PRINT: #ifdef DEBUG PrintState(Cmd-PreparedCode); #endif break; } Cmd++; --MaxOpCount; } }
/* actbus/steppers enable is handled separately in StoreActBus() */ void ControlPower(void) { static int firsttime = 1; static channel_t* latchingAddr[2]; static channel_t* switchGyAddr; static channel_t* switchMiscAddr; int latch0 = 0, latch1 = 0, gybox = 0, misc = 0; int i; if (firsttime) { firsttime = 0; latchingAddr[0] = channels_find_by_name("latch0"); latchingAddr[1] = channels_find_by_name("latch1"); switchGyAddr = channels_find_by_name("switch_gy"); switchMiscAddr = channels_find_by_name("switch_misc"); } if (CommandData.power.hub232_off) { if (CommandData.power.hub232_off > 0) CommandData.power.hub232_off--; misc |= 0x08; } if (CommandData.power.charge.set_count > 0) { CommandData.power.charge.set_count--; if (CommandData.power.charge.set_count < LATCH_PULSE_LEN) misc |= 0x0040; } if (CommandData.power.charge.rst_count > 0) { CommandData.power.charge.rst_count--; if (CommandData.power.charge.rst_count < LATCH_PULSE_LEN) misc |= 0x0080; } for (i = 0; i < 6; i++) { if (CommandData.power.gyro_off[i] || CommandData.power.gyro_off_auto[i]) { if (CommandData.power.gyro_off[i] > 0) CommandData.power.gyro_off[i]--; if (CommandData.power.gyro_off_auto[i] > 0) CommandData.power.gyro_off_auto[i]--; gybox |= 0x01 << i; } } if (CommandData.power.gybox_off) { if (CommandData.power.gybox_off > 0) CommandData.power.gybox_off--; gybox |= 0x80; } if (CommandData.power.sc_tx.set_count > 0) { CommandData.power.sc_tx.set_count--; if (CommandData.power.sc_tx.set_count < LATCH_PULSE_LEN) latch0 |= 0x0001; } if (CommandData.power.sc_tx.rst_count > 0) { CommandData.power.sc_tx.rst_count--; if (CommandData.power.sc_tx.rst_count < LATCH_PULSE_LEN) latch0 |= 0x0002; } if (CommandData.power.das.set_count > 0) { CommandData.power.das.set_count--; if (CommandData.power.das.set_count < LATCH_PULSE_LEN) latch0 |= 0x0004; } if (CommandData.power.das.rst_count > 0) { CommandData.power.das.rst_count--; if (CommandData.power.das.rst_count < LATCH_PULSE_LEN) latch0 |= 0x0008; } if (CommandData.power.xsc0.set_count > 0) { CommandData.power.xsc0.set_count--; if (CommandData.power.xsc0.set_count < LATCH_PULSE_LEN) latch0 |= 0x0010; } if (CommandData.power.xsc0.rst_count > 0) { CommandData.power.xsc0.rst_count--; if (CommandData.power.xsc0.rst_count < LATCH_PULSE_LEN) latch0 |= 0x0020; } if (CommandData.power.xsc1.set_count > 0) { CommandData.power.xsc1.set_count--; if (CommandData.power.xsc1.set_count < LATCH_PULSE_LEN) latch0 |= 0x0040; } if (CommandData.power.xsc1.rst_count > 0) { CommandData.power.xsc1.rst_count--; if (CommandData.power.xsc1.rst_count < LATCH_PULSE_LEN) latch0 |= 0x0080; } if (CommandData.power.rw.set_count > 0) { CommandData.power.rw.set_count--; if (CommandData.power.rw.set_count < LATCH_PULSE_LEN) latch0 |= 0x0400; } if (CommandData.power.rw.rst_count > 0) { CommandData.power.rw.rst_count--; if (CommandData.power.rw.rst_count < LATCH_PULSE_LEN) latch0 |= 0x0800; } if (CommandData.power.piv.set_count > 0) { CommandData.power.piv.set_count--; if (CommandData.power.piv.set_count < LATCH_PULSE_LEN) latch0 |= 0x1000; } if (CommandData.power.piv.rst_count > 0) { CommandData.power.piv.rst_count--; if (CommandData.power.piv.rst_count < LATCH_PULSE_LEN) latch0 |= 0x2000; } if (CommandData.power.elmot.set_count > 0) { CommandData.power.elmot.set_count--; if (CommandData.power.elmot.set_count < LATCH_PULSE_LEN) latch0 |= 0x4000; } if (CommandData.power.elmot.rst_count > 0) { CommandData.power.elmot.rst_count--; if (CommandData.power.elmot.rst_count < LATCH_PULSE_LEN) latch0 |= 0x8000; } if (CommandData.power.bi0.set_count > 0) { CommandData.power.bi0.set_count--; if (CommandData.power.bi0.set_count < LATCH_PULSE_LEN) latch1 |= 0x0001; } if (CommandData.power.bi0.rst_count > 0) { CommandData.power.bi0.rst_count--; if (CommandData.power.bi0.rst_count < LATCH_PULSE_LEN) latch1 |= 0x0002; } if (CommandData.power.rx_main.set_count > 0) { CommandData.power.rx_main.set_count--; if (CommandData.power.rx_main.set_count < LATCH_PULSE_LEN) latch1 |= 0x0004; } if (CommandData.power.rx_main.rst_count > 0) { CommandData.power.rx_main.rst_count--; if (CommandData.power.rx_main.rst_count < LATCH_PULSE_LEN) latch1 |= 0x0008; } if (CommandData.power.rx_hk.set_count > 0) { CommandData.power.rx_hk.set_count--; if (CommandData.power.rx_hk.set_count < LATCH_PULSE_LEN) latch1 |= 0x5050; } if (CommandData.power.rx_hk.rst_count > 0) { CommandData.power.rx_hk.rst_count--; if (CommandData.power.rx_hk.rst_count < LATCH_PULSE_LEN) latch1 |= 0xa0a0; } if (CommandData.power.rx_amps.set_count > 0) { CommandData.power.rx_amps.set_count--; if (CommandData.power.rx_amps.set_count < LATCH_PULSE_LEN) latch1 |= 0x0500; } if (CommandData.power.rx_amps.rst_count > 0) { CommandData.power.rx_amps.rst_count--; if (CommandData.power.rx_amps.rst_count < LATCH_PULSE_LEN) latch1 |= 0x0a00; } SET_VALUE(latchingAddr[0], latch0); SET_VALUE(latchingAddr[1], latch1); SET_VALUE(switchGyAddr, gybox); SET_VALUE(switchMiscAddr, misc); }
void CPerigeeCopyOptions::Save() { HKEY key = NULL; DWORD disposition = 0; RegCreateKeyEx(HKEY_CURRENT_USER, app_key, 0, NULL, 0, KEY_WRITE, NULL, &key, &disposition); SET_VALUE(key, overwrite); SET_VALUE(key, skip_error_files); SET_VALUE(key, overwrite_read_only); SET_VALUE(key, clear_read_only_after_copy); SET_VALUE(key, only_copy_archive); SET_VALUE(key, clear_archive_after_copy); SET_VALUE(key, prompt_for_confirmation_when_deleting); SET_VALUE(key, use_perigee_copy_by_default_when_dragging); SET_VALUE(key, skip_inventory); SET_VALUE(key, debug_prompt); SET_VALUE(key, recycle); SET_VALUE(key, wait_for_previous); RegCloseKey(key); }
static KMF_RETURN gencsr_file(KMF_HANDLE_T kmfhandle, KMF_KEY_ALG keyAlg, int keylen, KMF_ENCODE_FORMAT fmt, char *subject, char *altname, KMF_GENERALNAMECHOICES alttype, int altcrit, uint16_t kubits, int kucrit, char *outcsr, char *outkey, EKU_LIST *ekulist, KMF_ALGORITHM_INDEX sigAlg) { KMF_RETURN kmfrv; KMF_KEY_HANDLE pubk, prik; KMF_X509_NAME csrSubject; KMF_CSR_DATA csr; KMF_DATA signedCsr = {NULL, 0}; char *fullcsrpath = NULL; char *fullkeypath = NULL; (void) memset(&csr, 0, sizeof (csr)); (void) memset(&csrSubject, 0, sizeof (csrSubject)); if (EMPTYSTRING(outcsr) || EMPTYSTRING(outkey)) { cryptoerror(LOG_STDERR, gettext("No output file was specified for " "the csr or key\n")); return (KMF_ERR_BAD_PARAMETER); } fullcsrpath = strdup(outcsr); if (verify_file(fullcsrpath)) { cryptoerror(LOG_STDERR, gettext("Cannot write the indicated output " "certificate file (%s).\n"), fullcsrpath); free(fullcsrpath); return (PK_ERR_USAGE); } /* If the subject name cannot be parsed, flag it now and exit */ if ((kmfrv = kmf_dn_parser(subject, &csrSubject)) != KMF_OK) { return (kmfrv); } /* * Share the "genkeypair" routine for creating the keypair. */ kmfrv = genkeypair_file(kmfhandle, keyAlg, keylen, fmt, outkey, &prik, &pubk); if (kmfrv != KMF_OK) return (kmfrv); SET_VALUE(kmf_set_csr_pubkey(kmfhandle, &pubk, &csr), "SetCSRPubKey"); SET_VALUE(kmf_set_csr_version(&csr, 2), "SetCSRVersion"); SET_VALUE(kmf_set_csr_subject(&csr, &csrSubject), "kmf_set_csr_subject"); SET_VALUE(kmf_set_csr_sig_alg(&csr, sigAlg), "kmf_set_csr_sig_alg"); if (altname != NULL) { SET_VALUE(kmf_set_csr_subject_altname(&csr, altname, altcrit, alttype), "kmf_set_csr_subject_altname"); } if (kubits != NULL) { SET_VALUE(kmf_set_csr_ku(&csr, kucrit, kubits), "kmf_set_csr_ku"); } if (ekulist != NULL) { int i; for (i = 0; kmfrv == KMF_OK && i < ekulist->eku_count; i++) { SET_VALUE(kmf_add_csr_eku(&csr, &ekulist->ekulist[i], ekulist->critlist[i]), "Extended Key Usage"); } } if ((kmfrv = kmf_sign_csr(kmfhandle, &csr, &prik, &signedCsr)) == KMF_OK) { kmfrv = kmf_create_csr_file(&signedCsr, fmt, fullcsrpath); } cleanup: if (fullkeypath) free(fullkeypath); if (fullcsrpath) free(fullcsrpath); kmf_free_data(&signedCsr); kmf_free_kmf_key(kmfhandle, &prik); kmf_free_signed_csr(&csr); return (kmfrv); }
static KMF_RETURN gencsr_nss(KMF_HANDLE_T kmfhandle, char *token, char *subject, char *altname, KMF_GENERALNAMECHOICES alttype, int altcrit, char *nickname, char *dir, char *prefix, KMF_KEY_ALG keyAlg, int keylen, uint16_t kubits, int kucrit, KMF_ENCODE_FORMAT fmt, char *csrfile, KMF_CREDENTIAL *tokencred, EKU_LIST *ekulist, KMF_ALGORITHM_INDEX sigAlg, KMF_OID *curveoid) { KMF_RETURN kmfrv; KMF_KEY_HANDLE pubk, prik; KMF_X509_NAME csrSubject; KMF_CSR_DATA csr; KMF_DATA signedCsr = {NULL, 0}; KMF_KEYSTORE_TYPE kstype = KMF_KEYSTORE_NSS; int numattr = 0; KMF_ATTRIBUTE attrlist[16]; if (token == NULL) token = DEFAULT_NSS_TOKEN; kmfrv = configure_nss(kmfhandle, dir, prefix); if (kmfrv != KMF_OK) return (kmfrv); (void) memset(&csr, 0, sizeof (csr)); (void) memset(&csrSubject, 0, sizeof (csrSubject)); (void) memset(&pubk, 0, sizeof (pubk)); (void) memset(&prik, 0, sizeof (prik)); /* If the subject name cannot be parsed, flag it now and exit */ if ((kmfrv = kmf_dn_parser(subject, &csrSubject)) != KMF_OK) { return (kmfrv); } kmfrv = genkeypair_nss(kmfhandle, token, nickname, dir, prefix, keyAlg, keylen, tokencred, curveoid, &prik, &pubk); if (kmfrv != KMF_OK) return (kmfrv); SET_VALUE(kmf_set_csr_pubkey(kmfhandle, &pubk, &csr), "kmf_set_csr_pubkey"); SET_VALUE(kmf_set_csr_version(&csr, 2), "kmf_set_csr_version"); SET_VALUE(kmf_set_csr_subject(&csr, &csrSubject), "kmf_set_csr_subject"); SET_VALUE(kmf_set_csr_sig_alg(&csr, sigAlg), "kmf_set_csr_sig_alg"); if (altname != NULL) { SET_VALUE(kmf_set_csr_subject_altname(&csr, altname, altcrit, alttype), "kmf_set_csr_subject_altname"); } if (kubits != NULL) { SET_VALUE(kmf_set_csr_ku(&csr, kucrit, kubits), "kmf_set_csr_ku"); } if (ekulist != NULL) { int i; for (i = 0; kmfrv == KMF_OK && i < ekulist->eku_count; i++) { SET_VALUE(kmf_add_csr_eku(&csr, &ekulist->ekulist[i], ekulist->critlist[i]), "Extended Key Usage"); } } if ((kmfrv = kmf_sign_csr(kmfhandle, &csr, &prik, &signedCsr)) == KMF_OK) { kmfrv = kmf_create_csr_file(&signedCsr, fmt, csrfile); } cleanup: (void) kmf_free_data(&signedCsr); (void) kmf_free_kmf_key(kmfhandle, &prik); /* delete the key */ numattr = 0; kmf_set_attr_at_index(attrlist, numattr, KMF_KEYSTORE_TYPE_ATTR, &kstype, sizeof (kstype)); numattr++; kmf_set_attr_at_index(attrlist, numattr, KMF_PUBKEY_HANDLE_ATTR, &pubk, sizeof (KMF_KEY_HANDLE)); numattr++; if (tokencred != NULL && tokencred->credlen > 0) { kmf_set_attr_at_index(attrlist, numattr, KMF_CREDENTIAL_ATTR, tokencred, sizeof (KMF_CREDENTIAL)); numattr++; } if (token && strlen(token)) { kmf_set_attr_at_index(attrlist, numattr, KMF_TOKEN_LABEL_ATTR, token, strlen(token)); numattr++; } (void) kmf_delete_key_from_keystore(kmfhandle, numattr, attrlist); (void) kmf_free_signed_csr(&csr); return (kmfrv); }
void FCDEffectPassState::SetDefaultValue() { #define SET_VALUE(offset, valueType, actualValue) *((valueType*)(data + offset)) = actualValue; #define SET_ENUM(offset, nameSpace, actualValue) *((uint32*)(data + offset)) = nameSpace::actualValue; switch ((uint32) type) { case FUDaePassState::ALPHA_FUNC: SET_ENUM(0, FUDaePassStateFunction, ALWAYS); SET_VALUE(4, float, 0.0f); break; case FUDaePassState::BLEND_FUNC: SET_ENUM(0, FUDaePassStateBlendType, ONE); SET_ENUM(4, FUDaePassStateBlendType, ZERO); break; case FUDaePassState::BLEND_FUNC_SEPARATE: SET_ENUM(0, FUDaePassStateBlendType, ONE); SET_ENUM(4, FUDaePassStateBlendType, ZERO); SET_ENUM(8, FUDaePassStateBlendType, ONE); SET_ENUM(12, FUDaePassStateBlendType, ZERO); break; case FUDaePassState::BLEND_EQUATION: SET_ENUM(0, FUDaePassStateBlendEquation, ADD); break; case FUDaePassState::BLEND_EQUATION_SEPARATE: SET_ENUM(0, FUDaePassStateBlendEquation, ADD); SET_ENUM(4, FUDaePassStateBlendEquation, ADD); break; case FUDaePassState::COLOR_MATERIAL: SET_ENUM(0, FUDaePassStateFaceType, FRONT_AND_BACK); SET_ENUM(4, FUDaePassStateMaterialType, AMBIENT_AND_DIFFUSE); break; case FUDaePassState::CULL_FACE: SET_ENUM(0, FUDaePassStateFaceType, BACK); break; case FUDaePassState::DEPTH_FUNC: SET_ENUM(0, FUDaePassStateFunction, ALWAYS); break; case FUDaePassState::FOG_MODE: SET_ENUM(0, FUDaePassStateFogType, EXP); break; case FUDaePassState::FOG_COORD_SRC: SET_ENUM(0, FUDaePassStateFogCoordinateType, FOG_COORDINATE); break; case FUDaePassState::FRONT_FACE: SET_ENUM(0, FUDaePassStateFrontFaceType, COUNTER_CLOCKWISE); break; case FUDaePassState::LIGHT_MODEL_COLOR_CONTROL: SET_ENUM(0, FUDaePassStateLightModelColorControlType, SINGLE_COLOR); break; case FUDaePassState::LOGIC_OP: SET_ENUM(0, FUDaePassStateLogicOperation, COPY); break; case FUDaePassState::POLYGON_MODE: SET_ENUM(0, FUDaePassStateFaceType, FRONT_AND_BACK); SET_ENUM(4, FUDaePassStatePolygonMode, FILL); break; case FUDaePassState::SHADE_MODEL: SET_ENUM(0, FUDaePassStateShadeModel, SMOOTH); break; case FUDaePassState::STENCIL_FUNC: SET_ENUM(0, FUDaePassStateFunction, ALWAYS); SET_VALUE(4, uint8, 0); SET_VALUE(5, uint8, 0xFF); break; case FUDaePassState::STENCIL_OP: SET_ENUM(0, FUDaePassStateStencilOperation, KEEP); SET_ENUM(4, FUDaePassStateStencilOperation, KEEP); SET_ENUM(8, FUDaePassStateStencilOperation, KEEP); break; case FUDaePassState::STENCIL_FUNC_SEPARATE: SET_ENUM(0, FUDaePassStateFunction, ALWAYS); SET_ENUM(4, FUDaePassStateFunction, ALWAYS); SET_VALUE(8, uint8, 0); SET_VALUE(9, uint8, 0xFF); break; case FUDaePassState::STENCIL_OP_SEPARATE: SET_ENUM(0, FUDaePassStateFaceType, FRONT_AND_BACK); SET_ENUM(4, FUDaePassStateStencilOperation, KEEP); SET_ENUM(8, FUDaePassStateStencilOperation, KEEP); SET_ENUM(12, FUDaePassStateStencilOperation, KEEP); break; case FUDaePassState::STENCIL_MASK_SEPARATE: SET_ENUM(0, FUDaePassStateFaceType, FRONT_AND_BACK); SET_VALUE(4, uint8, 0xFF); break; case FUDaePassState::LIGHT_ENABLE: SET_VALUE(0, uint8, 0); SET_VALUE(1, bool, false); break; case FUDaePassState::LIGHT_AMBIENT: SET_VALUE(0, uint8, 0); SET_VALUE(1, FMVector4, FMVector4(0,0,0,1)); break; case FUDaePassState::LIGHT_DIFFUSE: case FUDaePassState::LIGHT_SPECULAR: case FUDaePassState::TEXTURE_ENV_COLOR: case FUDaePassState::CLIP_PLANE: SET_VALUE(0, uint8, 0); SET_VALUE(1, FMVector4, FMVector4::Zero); break; case FUDaePassState::LIGHT_POSITION: SET_VALUE(0, uint8, 0); SET_VALUE(1, FMVector4, FMVector4(0,0,1,0)); break; case FUDaePassState::LIGHT_CONSTANT_ATTENUATION: SET_VALUE(0, uint8, 0); SET_VALUE(1, float, 1.0f); break; case FUDaePassState::LIGHT_LINEAR_ATTENUATION: SET_VALUE(0, uint8, 0); SET_VALUE(1, float, 0.0f); break; case FUDaePassState::LIGHT_QUADRATIC_ATTENUATION: SET_VALUE(0, uint8, 0); SET_VALUE(1, float, 0.0f); break; case FUDaePassState::LIGHT_SPOT_CUTOFF: SET_VALUE(0, uint8, 0); SET_VALUE(1, float, 180.0f); break; case FUDaePassState::LIGHT_SPOT_DIRECTION: SET_VALUE(0, uint8, 0); SET_VALUE(1, FMVector3, FMVector3(0,0,-1)); break; case FUDaePassState::LIGHT_SPOT_EXPONENT: SET_VALUE(0, uint8, 0); SET_VALUE(1, float, 0.0f); break; case FUDaePassState::TEXTURE1D: case FUDaePassState::TEXTURE2D: case FUDaePassState::TEXTURE3D: case FUDaePassState::TEXTURECUBE: case FUDaePassState::TEXTURERECT: case FUDaePassState::TEXTUREDEPTH: SET_VALUE(0, uint8, 0); SET_VALUE(1, uint32, 0); break; case FUDaePassState::TEXTURE1D_ENABLE: case FUDaePassState::TEXTURE2D_ENABLE: case FUDaePassState::TEXTURE3D_ENABLE: case FUDaePassState::TEXTURECUBE_ENABLE: case FUDaePassState::TEXTURERECT_ENABLE: case FUDaePassState::TEXTUREDEPTH_ENABLE: case FUDaePassState::CLIP_PLANE_ENABLE: SET_VALUE(0, uint8, 0); SET_VALUE(1, bool, false); break; case FUDaePassState::TEXTURE_ENV_MODE: memset(data, 0, dataSize); break; case FUDaePassState::BLEND_COLOR: case FUDaePassState::CLEAR_COLOR: case FUDaePassState::FOG_COLOR: case FUDaePassState::SCISSOR: SET_VALUE(0, FMVector4, FMVector4::Zero); break; case FUDaePassState::LIGHT_MODEL_AMBIENT: case FUDaePassState::MATERIAL_AMBIENT: SET_VALUE(0, FMVector4, FMVector4(0.2f,0.2f,0.2f,1.0f)); break; case FUDaePassState::MATERIAL_DIFFUSE: SET_VALUE(0, FMVector4, FMVector4(0.8f,0.8f,0.8f,1.0f)); break; case FUDaePassState::MATERIAL_EMISSION: case FUDaePassState::MATERIAL_SPECULAR: SET_VALUE(0, FMVector4, FMVector4(0,0,0,1)); break; case FUDaePassState::POINT_DISTANCE_ATTENUATION: SET_VALUE(0, FMVector3, FMVector3(1,0,0)); break; case FUDaePassState::DEPTH_BOUNDS: case FUDaePassState::DEPTH_RANGE: SET_VALUE(0, FMVector2, FMVector2(0,1)); break; case FUDaePassState::POLYGON_OFFSET: SET_VALUE(0, FMVector2, FMVector2(0,0)); break; case FUDaePassState::DEPTH_MASK: SET_VALUE(0, bool, true); break; case FUDaePassState::CLEAR_STENCIL: SET_VALUE(0, uint32, 0); break; case FUDaePassState::STENCIL_MASK: SET_VALUE(0, uint32, 0xFFFFFFFF); break; case FUDaePassState::CLEAR_DEPTH: case FUDaePassState::FOG_DENSITY: case FUDaePassState::FOG_END: case FUDaePassState::LINE_WIDTH: case FUDaePassState::POINT_FADE_THRESHOLD_SIZE: case FUDaePassState::POINT_SIZE: case FUDaePassState::POINT_SIZE_MAX: SET_VALUE(0, float, 1.0f); break; case FUDaePassState::FOG_START: case FUDaePassState::MATERIAL_SHININESS: case FUDaePassState::POINT_SIZE_MIN: SET_VALUE(0, float, 0.0f); break; case FUDaePassState::COLOR_MASK: SET_VALUE(0, bool, true); SET_VALUE(1, bool, true); SET_VALUE(2, bool, true); SET_VALUE(3, bool, true); break; case FUDaePassState::LINE_STIPPLE: SET_VALUE(0, uint16, 1); SET_VALUE(2, uint16, 0xFF); break; case FUDaePassState::MODEL_VIEW_MATRIX: case FUDaePassState::PROJECTION_MATRIX: SET_VALUE(0, FMMatrix44, FMMatrix44::Identity); break; case FUDaePassState::LIGHTING_ENABLE: case FUDaePassState::ALPHA_TEST_ENABLE: case FUDaePassState::AUTO_NORMAL_ENABLE: case FUDaePassState::BLEND_ENABLE: case FUDaePassState::COLOR_LOGIC_OP_ENABLE: case FUDaePassState::CULL_FACE_ENABLE: case FUDaePassState::DEPTH_BOUNDS_ENABLE: case FUDaePassState::DEPTH_CLAMP_ENABLE: case FUDaePassState::DEPTH_TEST_ENABLE: case FUDaePassState::DITHER_ENABLE: case FUDaePassState::FOG_ENABLE: case FUDaePassState::LIGHT_MODEL_LOCAL_VIEWER_ENABLE: case FUDaePassState::LIGHT_MODEL_TWO_SIDE_ENABLE: case FUDaePassState::LINE_SMOOTH_ENABLE: case FUDaePassState::LINE_STIPPLE_ENABLE: case FUDaePassState::LOGIC_OP_ENABLE: case FUDaePassState::MULTISAMPLE_ENABLE: case FUDaePassState::NORMALIZE_ENABLE: case FUDaePassState::POINT_SMOOTH_ENABLE: case FUDaePassState::POLYGON_OFFSET_FILL_ENABLE: case FUDaePassState::POLYGON_OFFSET_LINE_ENABLE: case FUDaePassState::POLYGON_OFFSET_POINT_ENABLE: case FUDaePassState::POLYGON_SMOOTH_ENABLE: case FUDaePassState::POLYGON_STIPPLE_ENABLE: case FUDaePassState::RESCALE_NORMAL_ENABLE: case FUDaePassState::SAMPLE_ALPHA_TO_COVERAGE_ENABLE: case FUDaePassState::SAMPLE_ALPHA_TO_ONE_ENABLE: case FUDaePassState::SAMPLE_COVERAGE_ENABLE: case FUDaePassState::SCISSOR_TEST_ENABLE: case FUDaePassState::STENCIL_TEST_ENABLE: SET_VALUE(0, bool, false); break; case FUDaePassState::COLOR_MATERIAL_ENABLE: SET_VALUE(0, bool, true); break; case FUDaePassState::COUNT: case FUDaePassState::INVALID: default: FUFail(break); } #undef SET_ENUM #undef SET_VALUE }
static KMF_RETURN gencsr_pkcs11(KMF_HANDLE_T kmfhandle, char *token, char *subject, char *altname, KMF_GENERALNAMECHOICES alttype, int altcrit, char *certlabel, KMF_KEY_ALG keyAlg, int keylen, uint16_t kubits, int kucrit, KMF_ENCODE_FORMAT fmt, char *csrfile, KMF_CREDENTIAL *tokencred, EKU_LIST *ekulist, KMF_ALGORITHM_INDEX sigAlg, KMF_OID *curveoid) { KMF_RETURN kmfrv = KMF_OK; KMF_KEY_HANDLE pubk, prik; KMF_X509_NAME csrSubject; KMF_CSR_DATA csr; KMF_DATA signedCsr = {NULL, 0}; KMF_KEYSTORE_TYPE kstype = KMF_KEYSTORE_PK11TOKEN; int numattr = 0; KMF_ATTRIBUTE attrlist[16]; (void) memset(&csr, 0, sizeof (csr)); (void) memset(&csrSubject, 0, sizeof (csrSubject)); /* If the subject name cannot be parsed, flag it now and exit */ if ((kmfrv = kmf_dn_parser(subject, &csrSubject)) != KMF_OK) return (kmfrv); /* Select a PKCS11 token */ kmfrv = select_token(kmfhandle, token, FALSE); if (kmfrv != KMF_OK) return (kmfrv); /* * Share the "genkeypair" routine for creating the keypair. */ kmfrv = genkeypair_pkcs11(kmfhandle, token, certlabel, keyAlg, keylen, tokencred, curveoid, &prik, &pubk); if (kmfrv != KMF_OK) return (kmfrv); SET_VALUE(kmf_set_csr_pubkey(kmfhandle, &pubk, &csr), "keypair"); SET_VALUE(kmf_set_csr_version(&csr, 2), "version number"); SET_VALUE(kmf_set_csr_subject(&csr, &csrSubject), "subject name"); SET_VALUE(kmf_set_csr_sig_alg(&csr, sigAlg), "SignatureAlgorithm"); if (altname != NULL) { SET_VALUE(kmf_set_csr_subject_altname(&csr, altname, altcrit, alttype), "SetCSRSubjectAltName"); } if (kubits != 0) { SET_VALUE(kmf_set_csr_ku(&csr, kucrit, kubits), "SetCSRKeyUsage"); } if (ekulist != NULL) { int i; for (i = 0; kmfrv == KMF_OK && i < ekulist->eku_count; i++) { SET_VALUE(kmf_add_csr_eku(&csr, &ekulist->ekulist[i], ekulist->critlist[i]), "Extended Key Usage"); } } if ((kmfrv = kmf_sign_csr(kmfhandle, &csr, &prik, &signedCsr)) == KMF_OK) { kmfrv = kmf_create_csr_file(&signedCsr, fmt, csrfile); } cleanup: (void) kmf_free_data(&signedCsr); (void) kmf_free_signed_csr(&csr); /* delete the public key */ numattr = 0; kmf_set_attr_at_index(attrlist, numattr, KMF_KEYSTORE_TYPE_ATTR, &kstype, sizeof (kstype)); numattr++; kmf_set_attr_at_index(attrlist, numattr, KMF_PUBKEY_HANDLE_ATTR, &pubk, sizeof (KMF_KEY_HANDLE)); numattr++; if (tokencred != NULL && tokencred->cred != NULL) { kmf_set_attr_at_index(attrlist, numattr, KMF_CREDENTIAL_ATTR, tokencred, sizeof (KMF_CREDENTIAL)); numattr++; } (void) kmf_delete_key_from_keystore(kmfhandle, numattr, attrlist); /* * If there is an error, then we need to remove the private key * from the token. */ if (kmfrv != KMF_OK) { numattr = 0; kmf_set_attr_at_index(attrlist, numattr, KMF_KEYSTORE_TYPE_ATTR, &kstype, sizeof (kstype)); numattr++; kmf_set_attr_at_index(attrlist, numattr, KMF_KEY_HANDLE_ATTR, &prik, sizeof (KMF_KEY_HANDLE)); numattr++; if (tokencred != NULL && tokencred->cred != NULL) { kmf_set_attr_at_index(attrlist, numattr, KMF_CREDENTIAL_ATTR, tokencred, sizeof (KMF_CREDENTIAL)); numattr++; } (void) kmf_delete_key_from_keystore(kmfhandle, numattr, attrlist); } (void) kmf_free_kmf_key(kmfhandle, &prik); return (kmfrv); }