void msm6242_device::rtc_clock_updated(int year, int month, int day, int day_of_week, int hour, int minute, int second) { m_last_update_time = current_time(); }
static struct inode *f2fs_new_inode(struct inode *dir, umode_t mode) { struct f2fs_sb_info *sbi = F2FS_I_SB(dir); nid_t ino; struct inode *inode; bool nid_free = false; int err; inode = new_inode(dir->i_sb); if (!inode) return ERR_PTR(-ENOMEM); f2fs_lock_op(sbi); if (!alloc_nid(sbi, &ino)) { f2fs_unlock_op(sbi); err = -ENOSPC; goto fail; } f2fs_unlock_op(sbi); inode_init_owner(inode, dir, mode); inode->i_ino = ino; inode->i_blocks = 0; inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode); inode->i_generation = sbi->s_next_generation++; err = insert_inode_locked(inode); if (err) { err = -EINVAL; nid_free = true; goto fail; } /* If the directory encrypted, then we should encrypt the inode. */ if (f2fs_encrypted_inode(dir) && f2fs_may_encrypt(inode)) f2fs_set_encrypted_inode(inode); set_inode_flag(inode, FI_NEW_INODE); if (test_opt(sbi, INLINE_XATTR)) set_inode_flag(inode, FI_INLINE_XATTR); if (test_opt(sbi, INLINE_DATA) && f2fs_may_inline_data(inode)) set_inode_flag(inode, FI_INLINE_DATA); if (f2fs_may_inline_dentry(inode)) set_inode_flag(inode, FI_INLINE_DENTRY); f2fs_init_extent_tree(inode, NULL); stat_inc_inline_xattr(inode); stat_inc_inline_inode(inode); stat_inc_inline_dir(inode); trace_f2fs_new_inode(inode, 0); return inode; fail: trace_f2fs_new_inode(inode, err); make_bad_inode(inode); if (nid_free) set_inode_flag(inode, FI_FREE_NID); iput(inode); return ERR_PTR(err); }
static int f2fs_cross_rename(struct inode *old_dir, struct dentry *old_dentry, struct inode *new_dir, struct dentry *new_dentry) { struct f2fs_sb_info *sbi = F2FS_I_SB(old_dir); struct inode *old_inode = d_inode(old_dentry); struct inode *new_inode = d_inode(new_dentry); struct page *old_dir_page, *new_dir_page; struct page *old_page, *new_page; struct f2fs_dir_entry *old_dir_entry = NULL, *new_dir_entry = NULL; struct f2fs_dir_entry *old_entry, *new_entry; int old_nlink = 0, new_nlink = 0; int err = -ENOENT; if ((f2fs_encrypted_inode(old_dir) || f2fs_encrypted_inode(new_dir)) && (old_dir != new_dir) && (!fscrypt_has_permitted_context(new_dir, old_inode) || !fscrypt_has_permitted_context(old_dir, new_inode))) return -EPERM; old_entry = f2fs_find_entry(old_dir, &old_dentry->d_name, &old_page); if (!old_entry) { if (IS_ERR(old_page)) err = PTR_ERR(old_page); goto out; } new_entry = f2fs_find_entry(new_dir, &new_dentry->d_name, &new_page); if (!new_entry) { if (IS_ERR(new_page)) err = PTR_ERR(new_page); goto out_old; } /* prepare for updating ".." directory entry info later */ if (old_dir != new_dir) { if (S_ISDIR(old_inode->i_mode)) { old_dir_entry = f2fs_parent_dir(old_inode, &old_dir_page); if (!old_dir_entry) { if (IS_ERR(old_dir_page)) err = PTR_ERR(old_dir_page); goto out_new; } } if (S_ISDIR(new_inode->i_mode)) { new_dir_entry = f2fs_parent_dir(new_inode, &new_dir_page); if (!new_dir_entry) { if (IS_ERR(new_dir_page)) err = PTR_ERR(new_dir_page); goto out_old_dir; } } } /* * If cross rename between file and directory those are not * in the same directory, we will inc nlink of file's parent * later, so we should check upper boundary of its nlink. */ if ((!old_dir_entry || !new_dir_entry) && old_dir_entry != new_dir_entry) { old_nlink = old_dir_entry ? -1 : 1; new_nlink = -old_nlink; err = -EMLINK; if ((old_nlink > 0 && old_inode->i_nlink >= F2FS_LINK_MAX) || (new_nlink > 0 && new_inode->i_nlink >= F2FS_LINK_MAX)) goto out_new_dir; } f2fs_balance_fs(sbi, true); f2fs_lock_op(sbi); err = update_dent_inode(old_inode, new_inode, &new_dentry->d_name); if (err) goto out_unlock; if (file_enc_name(new_inode)) file_set_enc_name(old_inode); err = update_dent_inode(new_inode, old_inode, &old_dentry->d_name); if (err) goto out_undo; if (file_enc_name(old_inode)) file_set_enc_name(new_inode); /* update ".." directory entry info of old dentry */ if (old_dir_entry) f2fs_set_link(old_inode, old_dir_entry, old_dir_page, new_dir); /* update ".." directory entry info of new dentry */ if (new_dir_entry) f2fs_set_link(new_inode, new_dir_entry, new_dir_page, old_dir); /* update directory entry info of old dir inode */ f2fs_set_link(old_dir, old_entry, old_page, new_inode); down_write(&F2FS_I(old_inode)->i_sem); file_lost_pino(old_inode); up_write(&F2FS_I(old_inode)->i_sem); old_dir->i_ctime = current_time(old_dir); if (old_nlink) { down_write(&F2FS_I(old_dir)->i_sem); f2fs_i_links_write(old_dir, old_nlink > 0); up_write(&F2FS_I(old_dir)->i_sem); } f2fs_mark_inode_dirty_sync(old_dir); /* update directory entry info of new dir inode */ f2fs_set_link(new_dir, new_entry, new_page, old_inode); down_write(&F2FS_I(new_inode)->i_sem); file_lost_pino(new_inode); up_write(&F2FS_I(new_inode)->i_sem); new_dir->i_ctime = current_time(new_dir); if (new_nlink) { down_write(&F2FS_I(new_dir)->i_sem); f2fs_i_links_write(new_dir, new_nlink > 0); up_write(&F2FS_I(new_dir)->i_sem); } f2fs_mark_inode_dirty_sync(new_dir); f2fs_unlock_op(sbi); if (IS_DIRSYNC(old_dir) || IS_DIRSYNC(new_dir)) f2fs_sync_fs(sbi->sb, 1); return 0; out_undo: /* * Still we may fail to recover name info of f2fs_inode here * Drop it, once its name is set as encrypted */ update_dent_inode(old_inode, old_inode, &old_dentry->d_name); out_unlock: f2fs_unlock_op(sbi); out_new_dir: if (new_dir_entry) { f2fs_dentry_kunmap(new_inode, new_dir_page); f2fs_put_page(new_dir_page, 0); } out_old_dir: if (old_dir_entry) { f2fs_dentry_kunmap(old_inode, old_dir_page); f2fs_put_page(old_dir_page, 0); } out_new: f2fs_dentry_kunmap(new_dir, new_page); f2fs_put_page(new_page, 0); out_old: f2fs_dentry_kunmap(old_dir, old_page); f2fs_put_page(old_page, 0); out: return err; }
stopwatch_object(const char *& name) : name_(name), depth_(depth), timestamp_(current_time()) {}
double elapsed() { return current_time() - begin; }
/* * Parse the value from an LDAPv3 "Simple Paged Results" control. They look * like this: * * realSearchControlValue ::= SEQUENCE { * size INTEGER (0..maxInt), * -- requested page size from client * -- result set size estimate from server * cookie OCTET STRING * -- index for the pagedresults array in the connection * } * * Return an LDAP error code (LDAP_SUCCESS if all goes well). */ int pagedresults_parse_control_value( Slapi_PBlock *pb, struct berval *psbvp, ber_int_t *pagesize, int *index, Slapi_Backend *be ) { int rc = LDAP_SUCCESS; struct berval cookie = {0}; Connection *conn = pb->pb_conn; Operation *op = pb->pb_op; BerElement *ber = NULL; PagedResults *prp = NULL; time_t ctime = current_time(); int i; int maxreqs = config_get_maxsimplepaged_per_conn(); slapi_log_err(SLAPI_LOG_TRACE, "pagedresults_parse_control_value", "=>\n"); if ( NULL == conn || NULL == op || NULL == pagesize || NULL == index ) { slapi_log_err(SLAPI_LOG_ERR, "pagedresults_parse_control_value", "<= Error %d\n", LDAP_OPERATIONS_ERROR); return LDAP_OPERATIONS_ERROR; } *index = -1; if ( psbvp->bv_len == 0 || psbvp->bv_val == NULL ) { slapi_log_err(SLAPI_LOG_ERR, "pagedresults_parse_control_value", "<= no control value\n"); return LDAP_PROTOCOL_ERROR; } ber = ber_init( psbvp ); if ( ber == NULL ) { slapi_log_err(SLAPI_LOG_ERR, "pagedresults_parse_control_value", "<= no control value\n"); return LDAP_PROTOCOL_ERROR; } if ( ber_scanf( ber, "{io}", pagesize, &cookie ) == LBER_ERROR ) { slapi_log_err(SLAPI_LOG_ERR, "pagedresults_parse_control_value", "<= corrupted control value\n"); return LDAP_PROTOCOL_ERROR; } if (!maxreqs) { slapi_log_err(SLAPI_LOG_ERR, "pagedresults_parse_control_value", "Simple paged results requests per conn exceeded the limit: %d\n", maxreqs); return LDAP_UNWILLING_TO_PERFORM; } PR_EnterMonitor(conn->c_mutex); /* the ber encoding is no longer needed */ ber_free(ber, 1); if ( cookie.bv_len <= 0 ) { /* first time? */ int maxlen = conn->c_pagedresults.prl_maxlen; if (conn->c_pagedresults.prl_count == maxlen) { if (0 == maxlen) { /* first time */ conn->c_pagedresults.prl_maxlen = 1; conn->c_pagedresults.prl_list = (PagedResults *)slapi_ch_calloc(1, sizeof(PagedResults)); } else { /* new max length */ conn->c_pagedresults.prl_maxlen *= 2; conn->c_pagedresults.prl_list = (PagedResults *)slapi_ch_realloc( (char *)conn->c_pagedresults.prl_list, sizeof(PagedResults) * conn->c_pagedresults.prl_maxlen); /* initialze newly allocated area */ memset(conn->c_pagedresults.prl_list + maxlen, '\0', sizeof(PagedResults) * maxlen); } *index = maxlen; /* the first position in the new area */ prp = conn->c_pagedresults.prl_list + *index; prp->pr_current_be = be; } else { prp = conn->c_pagedresults.prl_list; for (i = 0; i < conn->c_pagedresults.prl_maxlen; i++, prp++) { if (!prp->pr_current_be) { /* unused slot; take it */ _pr_cleanup_one_slot(prp); prp->pr_current_be = be; *index = i; break; } else if (((prp->pr_timelimit > 0) && (ctime > prp->pr_timelimit)) || /* timelimit exceeded */ (prp->pr_flags & CONN_FLAG_PAGEDRESULTS_ABANDONED) /* abandoned */) { _pr_cleanup_one_slot(prp); conn->c_pagedresults.prl_count--; prp->pr_current_be = be; *index = i; break; } } } if ((maxreqs > 0) && (*index >= maxreqs)) { rc = LDAP_UNWILLING_TO_PERFORM; slapi_log_err(SLAPI_LOG_TRACE, "pagedresults_parse_control_value", "Simple paged results requests per conn exeeded the limit: %d\n", maxreqs); goto bail; } if ((*index > -1) && (*index < conn->c_pagedresults.prl_maxlen) && !conn->c_pagedresults.prl_list[*index].pr_mutex) { conn->c_pagedresults.prl_list[*index].pr_mutex = PR_NewLock(); } conn->c_pagedresults.prl_count++; } else { /* Repeated paged results request. * PagedResults is already allocated. */ char *ptr = slapi_ch_malloc(cookie.bv_len + 1); memcpy(ptr, cookie.bv_val, cookie.bv_len); *(ptr+cookie.bv_len) = '\0'; *index = strtol(ptr, NULL, 10); slapi_ch_free_string(&ptr); if ((conn->c_pagedresults.prl_maxlen <= *index) || (*index < 0)){ rc = LDAP_PROTOCOL_ERROR; slapi_log_err(SLAPI_LOG_ERR, "pagedresults_parse_control_value", "Invalid cookie: %d\n", *index); *index = -1; /* index is invalid. reinitializing it. */ goto bail; } prp = conn->c_pagedresults.prl_list + *index; if (!(prp->pr_search_result_set)) { /* freed and reused for the next backend. */ conn->c_pagedresults.prl_count++; } } /* reset sizelimit */ op->o_pagedresults_sizelimit = -1; if ((*index > -1) && (*index < conn->c_pagedresults.prl_maxlen)) { if (conn->c_pagedresults.prl_list[*index].pr_flags & CONN_FLAG_PAGEDRESULTS_ABANDONED) { /* repeated case? */ prp = conn->c_pagedresults.prl_list + *index; _pr_cleanup_one_slot(prp); rc = LDAP_CANCELLED; } else { /* Need to keep the latest msgid to prepare for the abandon. */ conn->c_pagedresults.prl_list[*index].pr_msgid = op->o_msgid; } } else { rc = LDAP_PROTOCOL_ERROR; slapi_log_err(SLAPI_LOG_ERR, "pagedresults_parse_control_value", "Invalid cookie: %d\n", *index); } bail: slapi_ch_free((void **)&cookie.bv_val); /* cleaning up the rest of the timedout or abandoned if any */ prp = conn->c_pagedresults.prl_list; for (i = 0; i < conn->c_pagedresults.prl_maxlen; i++, prp++) { if (prp->pr_current_be && (((prp->pr_timelimit > 0) && (ctime > prp->pr_timelimit)) || /* timelimit exceeded */ (prp->pr_flags & CONN_FLAG_PAGEDRESULTS_ABANDONED)) /* abandoned */) { _pr_cleanup_one_slot(prp); conn->c_pagedresults.prl_count--; if (i == *index) { /* registered slot is expired and cleaned up. return cancelled. */ *index = -1; rc = LDAP_CANCELLED; } } } PR_ExitMonitor(conn->c_mutex); slapi_log_err(SLAPI_LOG_TRACE, "pagedresults_parse_control_value", "<= idx %d\n", *index); return rc; }
satcheckt::resultt ranking_synthesis_satt::check_for_counterexample( const exprt &templ, c_valuest &c_values, fine_timet &conversion_time, fine_timet &solver_time) { satcheckt::resultt result; satcheckt solver; bv_pointerst converter(ns, solver); solver.set_message_handler(get_message_handler()); solver.set_verbosity(verbosity); converter.set_message_handler(get_message_handler()); converter.set_verbosity(verbosity); show_coefficients(c_values); fine_timet before = current_time(); converter.set_to_true(templ); for(c_valuest::const_iterator it=c_values.begin(); it!=c_values.end(); it++) { equal_exprt eq; if(it->first.get("identifier")=="termination::constant$C") { mp_integer cval; if(to_integer(largest_constant, cval)) throw "number conversion failed"; mp_integer b=cval * it->second; eq=equal_exprt(it->first, from_integer(b, it->first.type())); } else eq=equal_exprt(it->first, from_integer(it->second, it->first.type())); converter.set_to_true(eq); } conversion_time+=current_time()-before; before = current_time(); result=solver.prop_solve(); solver_time+=current_time()-before; solver_calls++; std::string output; if(result==satcheckt::P_SATISFIABLE) show_counterexample(converter); else if(result==satcheckt::P_UNSATISFIABLE) output += " ... YES!\n"; else output += "ERROR\n"; debug(output); return result; }
double chrono_ellapsed(struct chrono_t *chrono) { return chrono->status == CHRONO_STOPPED ? chrono->ellapsed : chrono->ellapsed + (current_time() - chrono->start); }
void bench_eccKeyAgree(void) { ecc_key genKey, genKey2; double start, total, each, milliEach; int i, ret; byte shared[1024]; byte sig[1024]; byte digest[32]; word32 x = 0; ecc_init(&genKey); ecc_init(&genKey2); ret = InitRng(&rng); if (ret < 0) { printf("InitRNG failed\n"); return; } ret = ecc_make_key(&rng, 32, &genKey); if (ret != 0) { printf("ecc_make_key failed\n"); return; } ret = ecc_make_key(&rng, 32, &genKey2); if (ret != 0) { printf("ecc_make_key failed\n"); return; } /* 256 bit */ start = current_time(1); for(i = 0; i < agreeTimes; i++) { x = sizeof(shared); ret = ecc_shared_secret(&genKey, &genKey2, shared, &x); if (ret != 0) { printf("ecc_shared_secret failed\n"); return; } } total = current_time(0) - start; each = total / agreeTimes; /* per second */ milliEach = each * 1000; /* millisconds */ printf("EC-DHE key agreement %6.3f milliseconds, avg over %d" " iterations\n", milliEach, agreeTimes); /* make dummy digest */ for (i = 0; i < (int)sizeof(digest); i++) digest[i] = (byte)i; start = current_time(1); for(i = 0; i < agreeTimes; i++) { x = sizeof(sig); ret = ecc_sign_hash(digest, sizeof(digest), sig, &x, &rng, &genKey); if (ret != 0) { printf("ecc_sign_hash failed\n"); return; } } total = current_time(0) - start; each = total / agreeTimes; /* per second */ milliEach = each * 1000; /* millisconds */ printf("EC-DSA sign time %6.3f milliseconds, avg over %d" " iterations\n", milliEach, agreeTimes); start = current_time(1); for(i = 0; i < agreeTimes; i++) { int verify = 0; ret = ecc_verify_hash(sig, x, digest, sizeof(digest), &verify, &genKey); if (ret != 0) { printf("ecc_verify_hash failed\n"); return; } } total = current_time(0) - start; each = total / agreeTimes; /* per second */ milliEach = each * 1000; /* millisconds */ printf("EC-DSA verify time %6.3f milliseconds, avg over %d" " iterations\n", milliEach, agreeTimes); ecc_free(&genKey2); ecc_free(&genKey); }
static void event_loop(Display *dpy, Window win) { while (1) { while (XPending(dpy) > 0) { XEvent event; XNextEvent(dpy, &event); switch (event.type) { case Expose: /* we'll redraw below */ break; case ConfigureNotify: reshape(event.xconfigure.width, event.xconfigure.height); break; case KeyPress: { char buffer[10]; int code; code = XLookupKeysym(&event.xkey, 0); if (code == XK_Left) { view_roty += 5.0; } else if (code == XK_Right) { view_roty -= 5.0; } else if (code == XK_Up) { view_rotx += 5.0; } else if (code == XK_Down) { view_rotx -= 5.0; } else { (void) XLookupString(&event.xkey, buffer, sizeof(buffer), NULL, NULL); if (buffer[0] == 27) { /* escape */ return; } } } } } /* next frame */ angle += 2.0; draw(); glXSwapBuffers(dpy, win); /* calc framerate */ { static int t0 = -1; static int frames = 0; int t = current_time(); if (t0 < 0) t0 = t; frames++; if (t - t0 >= 5.0) { GLfloat seconds = t - t0; GLfloat fps = frames / seconds; printf("%d frames in %3.1f seconds = %6.3f FPS\n", frames, seconds, fps); t0 = t; frames = 0; } } } }
void chrono_reset(struct chrono_t *chrono) { chrono->ellapsed = 0.0; chrono->start = current_time(); }
/* * Runs sender operations for Naor-Pinkas semi-honest OT */ int ot_np_send(struct state *st, void *msgs, int maxlength, int num_ots, int N, ot_msg_reader ot_msg_reader, ot_item_reader ot_item_reader) { mpz_t r, gr, pk, pk0; mpz_t *Cs = NULL, *Crs = NULL, *pk0s = NULL; char buf[field_size], *msg = NULL; int err = 0; double start, end; #ifdef AES_HW fprintf(stderr, "OT-NP: Using AESNI\n"); #endif #ifdef SHA fprintf(stderr, "OT-NP: Using SHA-1\n"); #endif start = current_time(); mpz_inits(r, gr, pk, pk0, NULL); msg = (char *) ot_malloc(sizeof(char) * maxlength); if (msg == NULL) ERROR; Cs = (mpz_t *) ot_malloc(sizeof(mpz_t) * (N - 1)); if (Cs == NULL) ERROR; Crs = (mpz_t *) ot_malloc(sizeof(mpz_t) * (N - 1)); if (Crs == NULL) ERROR; pk0s = (mpz_t *) ot_malloc(sizeof(mpz_t) * num_ots); if (pk0s == NULL) ERROR; for (int i = 0; i < num_ots; ++i) { mpz_init(pk0s[i]); } #ifdef AES_HW AES_KEY key; AES_set_encrypt_key((unsigned char *) "abcd", 128, &key); #endif // choose r \in_R Zq random_element(r, &st->p); // compute g^r mpz_powm(gr, st->p.g, r, st->p.p); // choose C_i's \in_R Zq for (int i = 0; i < N - 1; ++i) { mpz_inits(Cs[i], Crs[i], NULL); random_element(Cs[i], &st->p); } end = current_time(); fprintf(stderr, "Initialization: %f\n", end - start); // send g^r to receiver start = current_time(); mpz_to_array(buf, gr, sizeof buf); if (sendall(st->sockfd, buf, sizeof buf) == -1) ERROR; end = current_time(); fprintf(stderr, "Send g^r to receiver: %f\n", end - start); // send Cs to receiver start = current_time(); for (int i = 0; i < N - 1; ++i) { mpz_to_array(buf, Cs[i], sizeof buf); if (sendall(st->sockfd, buf, sizeof buf) == -1) ERROR; } end = current_time(); fprintf(stderr, "Send Cs to receiver: %f\n", end - start); start = current_time(); for (int i = 0; i < N - 1; ++i) { // compute C_i^r mpz_powm(Crs[i], Cs[i], r, st->p.p); } end = current_time(); fprintf(stderr, "Compute C_i^r: %f\n", end - start); start = current_time(); for (int j = 0; j < num_ots; ++j) { // get pk0 from receiver if (recvall(st->sockfd, buf, sizeof buf) == -1) ERROR; array_to_mpz(pk0s[j], buf, sizeof buf); } end = current_time(); fprintf(stderr, "Get pk0 from receiver: %f\n", end - start); for (int j = 0; j < num_ots; ++j) { void *ot = ot_msg_reader(msgs, j); for (int i = 0; i < N; ++i) { char *item; ssize_t itemlength; if (i == 0) { // compute pk0^r mpz_powm(pk0, pk0s[j], r, st->p.p); mpz_to_array(buf, pk0, sizeof buf); (void) mpz_invert(pk0, pk0, st->p.p); } else { mpz_mul(pk, pk0, Crs[i - 1]); mpz_mod(pk, pk, st->p.p); mpz_to_array(buf, pk, sizeof buf); } #ifdef AES_HW if (AES_encrypt_message((unsigned char *) buf, sizeof buf, (unsigned char *) msg, maxlength, &key)) ERROR; #endif #ifdef SHA (void) memset(msg, '\0', maxlength); sha1_hash(msg, maxlength, i, (unsigned char *) buf, sizeof buf); #endif ot_item_reader(ot, i, &item, &itemlength); assert(itemlength <= maxlength); xorarray((unsigned char *) msg, maxlength, (unsigned char *) item, itemlength); if (sendall(st->sockfd, msg, maxlength) == -1) ERROR; } } cleanup: mpz_clears(r, gr, pk, pk0, NULL); if (pk0s) { for (int i = 0; i < num_ots; ++i) { mpz_clear(pk0s[i]); } ot_free(pk0s); } if (Crs) { for (int i = 0; i < N - 1; ++i) mpz_clear(Crs[i]); ot_free(Crs); } if (Cs) { for (int i = 0; i < N - 1; ++i) mpz_clear(Cs[i]); ot_free(Cs); } if (msg) ot_free(msg); return err; }
int ot_np_recv(struct state *st, void *choices, int nchoices, int maxlength, int N, void *out, ot_choice_reader ot_choice_reader, ot_msg_writer ot_msg_writer) { mpz_t gr, pk0, pks; mpz_t *Cs = NULL, *ks = NULL; char buf[field_size], *from = NULL, *msg = NULL; int err = 0; double start, end; #ifdef AES_HW fprintf(stderr, "OT-NP: Using AESNI\n"); #endif #ifdef SHA fprintf(stderr, "OT-NP: Using SHA-1\n"); #endif mpz_inits(gr, pk0, pks, NULL); msg = (char *) ot_malloc(sizeof(char) * maxlength); if (msg == NULL) ERROR; from = (char *) ot_malloc(sizeof(char) * maxlength); if (from == NULL) ERROR; Cs = (mpz_t *) ot_malloc(sizeof(mpz_t) * (N - 1)); if (Cs == NULL) ERROR; for (int i = 0; i < N - 1; ++i) { mpz_init(Cs[i]); } ks = (mpz_t *) ot_malloc(sizeof(mpz_t) * nchoices); if (ks == NULL) ERROR; for (int j = 0; j < nchoices; ++j) { mpz_init(ks[j]); } #ifdef AES_HW AES_KEY key; AES_set_encrypt_key((unsigned char *) "abcd", 128, &key); #endif // get g^r from sender start = current_time(); if (recvall(st->sockfd, buf, sizeof buf) == -1) ERROR; array_to_mpz(gr, buf, sizeof buf); end = current_time(); fprintf(stderr, "Get g^r from sender: %f\n", end - start); // get Cs from sender start = current_time(); for (int i = 0; i < N - 1; ++i) { if (recvall(st->sockfd, buf, sizeof buf) == -1) ERROR; array_to_mpz(Cs[i], buf, sizeof buf); } end = current_time(); fprintf(stderr, "Get Cs from sender: %f\n", end - start); start = current_time(); for (int j = 0; j < nchoices; ++j) { long choice; choice = ot_choice_reader(choices, j); // choose random k mpz_urandomb(ks[j], st->p.rnd, sizeof buf * 8); mpz_mod(ks[j], ks[j], st->p.q); // compute pks = g^k mpz_powm(pks, st->p.g, ks[j], st->p.p); // compute pk0 = C_1 / g^k regardless of whether our choice is 0 or 1 to // avoid a potential side-channel attack (void) mpz_invert(pk0, pks, st->p.p); mpz_mul(pk0, pk0, Cs[0]); mpz_mod(pk0, pk0, st->p.p); mpz_set(pk0, choice == 0 ? pks : pk0); mpz_to_array(buf, pk0, sizeof buf); // send pk0 to sender if (sendall(st->sockfd, buf, sizeof buf) == -1) ERROR; } end = current_time(); fprintf(stderr, "Send pk0s to sender: %f\n", end - start); for (int j = 0; j < nchoices; ++j) { long choice; choice = ot_choice_reader(choices, j); // compute decryption key (g^r)^k mpz_powm(ks[j], gr, ks[j], st->p.p); for (int i = 0; i < N; ++i) { mpz_to_array(buf, ks[j], sizeof buf); // get H xor M0 from sender if (recvall(st->sockfd, msg, maxlength) == -1) ERROR; #ifdef AES_HW if (AES_encrypt_message((unsigned char *) buf, sizeof buf, (unsigned char *) from, maxlength, &key)) ERROR; #endif #ifdef SHA (void) memset(from, '\0', maxlength); sha1_hash(from, maxlength, i, (unsigned char *) buf, sizeof buf); #endif xorarray((unsigned char *) msg, maxlength, (unsigned char *) from, maxlength); if (i == choice) { ot_msg_writer(out, j, msg, maxlength); } } } cleanup: mpz_clears(gr, pk0, pks, NULL); if (ks) { for (int j = 0; j < nchoices; ++j) { mpz_clear(ks[j]); } ot_free(ks); } if (Cs) { for (int i = 0; i < N - 1; ++i) mpz_clear(Cs[i]); ot_free(Cs); } if (msg) ot_free(msg); if (from) ot_free(from); return err; }
static int cmd_minip(int argc, const cmd_args *argv) { if (argc == 1) { minip_usage: printf("minip commands\n"); printf("mi [a]rp dump arp table\n"); printf("mi [s]tatus print ip status\n"); printf("mi [t]est [dest] [port] [cnt] send <cnt> test packets to the dest:port\n"); } else { switch(argv[1].str[0]) { case 'a': arp_cache_dump(); break; case 's': { uint32_t ipaddr = minip_get_ipaddr(); printf("hostname: %s\n", minip_get_hostname()); printf("ip: %u.%u.%u.%u\n", IPV4_SPLIT(ipaddr)); } break; case 't': { uint32_t count = 1; uint32_t host = 0x0100000A; // 10.0.0.1 uint32_t port = 1025; udp_socket_t *handle; switch (argc) { case 5: count = argv[4].u; case 4: port = argv[3].u; case 3: host = str_ip_to_int(argv[2].str, strlen(argv[2].str)); break; } if (udp_open(host, port, port, &handle) != NO_ERROR) { printf("udp_open to %u.%u.%u.%u:%u failed\n", IPV4_SPLIT(host), port); return -1; } #define BUFSIZE 1470 uint8_t *buf; buf = malloc(BUFSIZE); if (!buf) { udp_close(handle); return -1; } memset(buf, 0x00, BUFSIZE); printf("sending %u packet(s) to %u.%u.%u.%u:%u\n", count, IPV4_SPLIT(host), port); lk_time_t t = current_time(); uint32_t failures = 0; for (uint32_t i = 0; i < count; i++) { if (udp_send(buf, BUFSIZE, handle) != 0) { failures++; } buf[128]++; } t = current_time() - t; printf("%d pkts failed\n", failures); uint64_t total_count = (uint64_t)count * BUFSIZE; printf("wrote %llu bytes in %u msecs (%llu bytes/sec)\n", total_count, (uint32_t)t, total_count * 1000 / t); free(buf); udp_close(handle); #undef BUFSIZE } break; default: goto minip_usage; } } return 0; }
static int ext4_ioctl_setproject(struct file *filp, __u32 projid) { struct inode *inode = file_inode(filp); struct super_block *sb = inode->i_sb; struct ext4_inode_info *ei = EXT4_I(inode); int err, rc; handle_t *handle; kprojid_t kprojid; struct ext4_iloc iloc; struct ext4_inode *raw_inode; struct dquot *transfer_to[MAXQUOTAS] = { }; if (!ext4_has_feature_project(sb)) { if (projid != EXT4_DEF_PROJID) return -EOPNOTSUPP; else return 0; } if (EXT4_INODE_SIZE(sb) <= EXT4_GOOD_OLD_INODE_SIZE) return -EOPNOTSUPP; kprojid = make_kprojid(&init_user_ns, (projid_t)projid); if (projid_eq(kprojid, EXT4_I(inode)->i_projid)) return 0; err = -EPERM; /* Is it quota file? Do not allow user to mess with it */ if (ext4_is_quota_file(inode)) return err; err = ext4_get_inode_loc(inode, &iloc); if (err) return err; raw_inode = ext4_raw_inode(&iloc); if (!EXT4_FITS_IN_INODE(raw_inode, ei, i_projid)) { err = ext4_expand_extra_isize(inode, EXT4_SB(sb)->s_want_extra_isize, &iloc); if (err) return err; } else { brelse(iloc.bh); } err = dquot_initialize(inode); if (err) return err; handle = ext4_journal_start(inode, EXT4_HT_QUOTA, EXT4_QUOTA_INIT_BLOCKS(sb) + EXT4_QUOTA_DEL_BLOCKS(sb) + 3); if (IS_ERR(handle)) return PTR_ERR(handle); err = ext4_reserve_inode_write(handle, inode, &iloc); if (err) goto out_stop; transfer_to[PRJQUOTA] = dqget(sb, make_kqid_projid(kprojid)); if (!IS_ERR(transfer_to[PRJQUOTA])) { /* __dquot_transfer() calls back ext4_get_inode_usage() which * counts xattr inode references. */ down_read(&EXT4_I(inode)->xattr_sem); err = __dquot_transfer(inode, transfer_to); up_read(&EXT4_I(inode)->xattr_sem); dqput(transfer_to[PRJQUOTA]); if (err) goto out_dirty; } EXT4_I(inode)->i_projid = kprojid; inode->i_ctime = current_time(inode); out_dirty: rc = ext4_mark_iloc_dirty(handle, inode, &iloc); if (!err) err = rc; out_stop: ext4_journal_stop(handle); return err; }
void bench_rsa(void) { int i; int ret; byte tmp[3072]; size_t bytes; word32 idx = 0; byte message[] = "Everyone gets Friday off."; byte enc[512]; /* for up to 4096 bit */ const int len = (int)strlen((char*)message); double start, total, each, milliEach; RsaKey rsaKey; int rsaKeySz = 2048; /* used in printf */ #ifdef USE_CERT_BUFFERS_1024 XMEMCPY(tmp, rsa_key_der_1024, sizeof_rsa_key_der_1024); bytes = sizeof_rsa_key_der_1024; rsaKeySz = 1024; #elif defined(USE_CERT_BUFFERS_2048) XMEMCPY(tmp, rsa_key_der_2048, sizeof_rsa_key_der_2048); bytes = sizeof_rsa_key_der_2048; #else FILE* file = fopen(certRSAname, "rb"); if (!file) { printf("can't find %s, Please run from CyaSSL home dir\n", certRSAname); return; } bytes = fread(tmp, 1, sizeof(tmp), file); fclose(file); #endif /* USE_CERT_BUFFERS */ #ifdef HAVE_CAVIUM if (RsaInitCavium(&rsaKey, CAVIUM_DEV_ID) != 0) printf("RSA init cavium failed\n"); #endif ret = InitRng(&rng); if (ret < 0) { printf("InitRNG failed\n"); return; } ret = InitRsaKey(&rsaKey, 0); if (ret < 0) { printf("InitRsaKey failed\n"); return; } ret = RsaPrivateKeyDecode(tmp, &idx, &rsaKey, (word32)bytes); start = current_time(1); for (i = 0; i < ntimes; i++) ret = RsaPublicEncrypt(message,len,enc,sizeof(enc), &rsaKey, &rng); total = current_time(0) - start; each = total / ntimes; /* per second */ milliEach = each * 1000; /* milliseconds */ printf("RSA %d encryption took %6.3f milliseconds, avg over %d" " iterations\n", rsaKeySz, milliEach, ntimes); if (ret < 0) { printf("Rsa Public Encrypt failed\n"); return; } start = current_time(1); for (i = 0; i < ntimes; i++) { byte out[512]; /* for up to 4096 bit */ RsaPrivateDecrypt(enc, (word32)ret, out, sizeof(out), &rsaKey); } total = current_time(0) - start; each = total / ntimes; /* per second */ milliEach = each * 1000; /* milliseconds */ printf("RSA %d decryption took %6.3f milliseconds, avg over %d" " iterations\n", rsaKeySz, milliEach, ntimes); FreeRsaKey(&rsaKey); #ifdef HAVE_CAVIUM RsaFreeCavium(&rsaKey); #endif }
long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) { struct inode *inode = file_inode(filp); struct super_block *sb = inode->i_sb; struct ext4_inode_info *ei = EXT4_I(inode); unsigned int flags; ext4_debug("cmd = %u, arg = %lu\n", cmd, arg); switch (cmd) { case FS_IOC_GETFSMAP: return ext4_ioc_getfsmap(sb, (void __user *)arg); case EXT4_IOC_GETFLAGS: flags = ei->i_flags & EXT4_FL_USER_VISIBLE; return put_user(flags, (int __user *) arg); case EXT4_IOC_SETFLAGS: { int err; if (!inode_owner_or_capable(inode)) return -EACCES; if (get_user(flags, (int __user *) arg)) return -EFAULT; if (flags & ~EXT4_FL_USER_VISIBLE) return -EOPNOTSUPP; /* * chattr(1) grabs flags via GETFLAGS, modifies the result and * passes that to SETFLAGS. So we cannot easily make SETFLAGS * more restrictive than just silently masking off visible but * not settable flags as we always did. */ flags &= EXT4_FL_USER_MODIFIABLE; if (ext4_mask_flags(inode->i_mode, flags) != flags) return -EOPNOTSUPP; err = mnt_want_write_file(filp); if (err) return err; inode_lock(inode); err = ext4_ioctl_setflags(inode, flags); inode_unlock(inode); mnt_drop_write_file(filp); return err; } case EXT4_IOC_GETVERSION: case EXT4_IOC_GETVERSION_OLD: return put_user(inode->i_generation, (int __user *) arg); case EXT4_IOC_SETVERSION: case EXT4_IOC_SETVERSION_OLD: { handle_t *handle; struct ext4_iloc iloc; __u32 generation; int err; if (!inode_owner_or_capable(inode)) return -EPERM; if (ext4_has_metadata_csum(inode->i_sb)) { ext4_warning(sb, "Setting inode version is not " "supported with metadata_csum enabled."); return -ENOTTY; } err = mnt_want_write_file(filp); if (err) return err; if (get_user(generation, (int __user *) arg)) { err = -EFAULT; goto setversion_out; } inode_lock(inode); handle = ext4_journal_start(inode, EXT4_HT_INODE, 1); if (IS_ERR(handle)) { err = PTR_ERR(handle); goto unlock_out; } err = ext4_reserve_inode_write(handle, inode, &iloc); if (err == 0) { inode->i_ctime = current_time(inode); inode->i_generation = generation; err = ext4_mark_iloc_dirty(handle, inode, &iloc); } ext4_journal_stop(handle); unlock_out: inode_unlock(inode); setversion_out: mnt_drop_write_file(filp); return err; } case EXT4_IOC_GROUP_EXTEND: { ext4_fsblk_t n_blocks_count; int err, err2=0; err = ext4_resize_begin(sb); if (err) return err; if (get_user(n_blocks_count, (__u32 __user *)arg)) { err = -EFAULT; goto group_extend_out; } if (ext4_has_feature_bigalloc(sb)) { ext4_msg(sb, KERN_ERR, "Online resizing not supported with bigalloc"); err = -EOPNOTSUPP; goto group_extend_out; } err = mnt_want_write_file(filp); if (err) goto group_extend_out; err = ext4_group_extend(sb, EXT4_SB(sb)->s_es, n_blocks_count); if (EXT4_SB(sb)->s_journal) { jbd2_journal_lock_updates(EXT4_SB(sb)->s_journal); err2 = jbd2_journal_flush(EXT4_SB(sb)->s_journal); jbd2_journal_unlock_updates(EXT4_SB(sb)->s_journal); } if (err == 0) err = err2; mnt_drop_write_file(filp); group_extend_out: ext4_resize_end(sb); return err; } case EXT4_IOC_MOVE_EXT: { struct move_extent me; struct fd donor; int err; if (!(filp->f_mode & FMODE_READ) || !(filp->f_mode & FMODE_WRITE)) return -EBADF; if (copy_from_user(&me, (struct move_extent __user *)arg, sizeof(me))) return -EFAULT; me.moved_len = 0; donor = fdget(me.donor_fd); if (!donor.file) return -EBADF; if (!(donor.file->f_mode & FMODE_WRITE)) { err = -EBADF; goto mext_out; } if (ext4_has_feature_bigalloc(sb)) { ext4_msg(sb, KERN_ERR, "Online defrag not supported with bigalloc"); err = -EOPNOTSUPP; goto mext_out; } else if (IS_DAX(inode)) { ext4_msg(sb, KERN_ERR, "Online defrag not supported with DAX"); err = -EOPNOTSUPP; goto mext_out; } err = mnt_want_write_file(filp); if (err) goto mext_out; err = ext4_move_extents(filp, donor.file, me.orig_start, me.donor_start, me.len, &me.moved_len); mnt_drop_write_file(filp); if (copy_to_user((struct move_extent __user *)arg, &me, sizeof(me))) err = -EFAULT; mext_out: fdput(donor); return err; } case EXT4_IOC_GROUP_ADD: { struct ext4_new_group_data input; if (copy_from_user(&input, (struct ext4_new_group_input __user *)arg, sizeof(input))) return -EFAULT; return ext4_ioctl_group_add(filp, &input); } case EXT4_IOC_MIGRATE: { int err; if (!inode_owner_or_capable(inode)) return -EACCES; err = mnt_want_write_file(filp); if (err) return err; /* * inode_mutex prevent write and truncate on the file. * Read still goes through. We take i_data_sem in * ext4_ext_swap_inode_data before we switch the * inode format to prevent read. */ inode_lock((inode)); err = ext4_ext_migrate(inode); inode_unlock((inode)); mnt_drop_write_file(filp); return err; } case EXT4_IOC_ALLOC_DA_BLKS: { int err; if (!inode_owner_or_capable(inode)) return -EACCES; err = mnt_want_write_file(filp); if (err) return err; err = ext4_alloc_da_blocks(inode); mnt_drop_write_file(filp); return err; } case EXT4_IOC_SWAP_BOOT: { int err; if (!(filp->f_mode & FMODE_WRITE)) return -EBADF; err = mnt_want_write_file(filp); if (err) return err; err = swap_inode_boot_loader(sb, inode); mnt_drop_write_file(filp); return err; } case EXT4_IOC_RESIZE_FS: { ext4_fsblk_t n_blocks_count; int err = 0, err2 = 0; ext4_group_t o_group = EXT4_SB(sb)->s_groups_count; if (copy_from_user(&n_blocks_count, (__u64 __user *)arg, sizeof(__u64))) { return -EFAULT; } err = ext4_resize_begin(sb); if (err) return err; err = mnt_want_write_file(filp); if (err) goto resizefs_out; err = ext4_resize_fs(sb, n_blocks_count); if (EXT4_SB(sb)->s_journal) { jbd2_journal_lock_updates(EXT4_SB(sb)->s_journal); err2 = jbd2_journal_flush(EXT4_SB(sb)->s_journal); jbd2_journal_unlock_updates(EXT4_SB(sb)->s_journal); } if (err == 0) err = err2; mnt_drop_write_file(filp); if (!err && (o_group > EXT4_SB(sb)->s_groups_count) && ext4_has_group_desc_csum(sb) && test_opt(sb, INIT_INODE_TABLE)) err = ext4_register_li_request(sb, o_group); resizefs_out: ext4_resize_end(sb); return err; } case FITRIM: { struct request_queue *q = bdev_get_queue(sb->s_bdev); struct fstrim_range range; int ret = 0; if (!capable(CAP_SYS_ADMIN)) return -EPERM; if (!blk_queue_discard(q)) return -EOPNOTSUPP; if (copy_from_user(&range, (struct fstrim_range __user *)arg, sizeof(range))) return -EFAULT; range.minlen = max((unsigned int)range.minlen, q->limits.discard_granularity); ret = ext4_trim_fs(sb, &range); if (ret < 0) return ret; if (copy_to_user((struct fstrim_range __user *)arg, &range, sizeof(range))) return -EFAULT; return 0; } case EXT4_IOC_PRECACHE_EXTENTS: return ext4_ext_precache(inode); case EXT4_IOC_SET_ENCRYPTION_POLICY: if (!ext4_has_feature_encrypt(sb)) return -EOPNOTSUPP; return fscrypt_ioctl_set_policy(filp, (const void __user *)arg); case EXT4_IOC_GET_ENCRYPTION_PWSALT: { #ifdef CONFIG_FS_ENCRYPTION int err, err2; struct ext4_sb_info *sbi = EXT4_SB(sb); handle_t *handle; if (!ext4_has_feature_encrypt(sb)) return -EOPNOTSUPP; if (uuid_is_zero(sbi->s_es->s_encrypt_pw_salt)) { err = mnt_want_write_file(filp); if (err) return err; handle = ext4_journal_start_sb(sb, EXT4_HT_MISC, 1); if (IS_ERR(handle)) { err = PTR_ERR(handle); goto pwsalt_err_exit; } err = ext4_journal_get_write_access(handle, sbi->s_sbh); if (err) goto pwsalt_err_journal; generate_random_uuid(sbi->s_es->s_encrypt_pw_salt); err = ext4_handle_dirty_metadata(handle, NULL, sbi->s_sbh); pwsalt_err_journal: err2 = ext4_journal_stop(handle); if (err2 && !err) err = err2; pwsalt_err_exit: mnt_drop_write_file(filp); if (err) return err; } if (copy_to_user((void __user *) arg, sbi->s_es->s_encrypt_pw_salt, 16)) return -EFAULT; return 0; #else return -EOPNOTSUPP; #endif } case EXT4_IOC_GET_ENCRYPTION_POLICY: return fscrypt_ioctl_get_policy(filp, (void __user *)arg); case EXT4_IOC_FSGETXATTR: { struct fsxattr fa; memset(&fa, 0, sizeof(struct fsxattr)); fa.fsx_xflags = ext4_iflags_to_xflags(ei->i_flags & EXT4_FL_USER_VISIBLE); if (ext4_has_feature_project(inode->i_sb)) { fa.fsx_projid = (__u32)from_kprojid(&init_user_ns, EXT4_I(inode)->i_projid); } if (copy_to_user((struct fsxattr __user *)arg, &fa, sizeof(fa))) return -EFAULT; return 0; } case EXT4_IOC_FSSETXATTR: { struct fsxattr fa; int err; if (copy_from_user(&fa, (struct fsxattr __user *)arg, sizeof(fa))) return -EFAULT; /* Make sure caller has proper permission */ if (!inode_owner_or_capable(inode)) return -EACCES; if (fa.fsx_xflags & ~EXT4_SUPPORTED_FS_XFLAGS) return -EOPNOTSUPP; flags = ext4_xflags_to_iflags(fa.fsx_xflags); if (ext4_mask_flags(inode->i_mode, flags) != flags) return -EOPNOTSUPP; err = mnt_want_write_file(filp); if (err) return err; inode_lock(inode); err = ext4_ioctl_check_project(inode, &fa); if (err) goto out; flags = (ei->i_flags & ~EXT4_FL_XFLAG_VISIBLE) | (flags & EXT4_FL_XFLAG_VISIBLE); err = ext4_ioctl_setflags(inode, flags); if (err) goto out; err = ext4_ioctl_setproject(filp, fa.fsx_projid); out: inode_unlock(inode); mnt_drop_write_file(filp); return err; } case EXT4_IOC_SHUTDOWN: return ext4_shutdown(sb, arg); default: return -ENOTTY; } }
void bench_dh(void) { int i, ret; byte tmp[1024]; size_t bytes; word32 idx = 0, pubSz, privSz = 0, pubSz2, privSz2, agreeSz; byte pub[256]; /* for 2048 bit */ byte priv[256]; /* for 2048 bit */ byte pub2[256]; /* for 2048 bit */ byte priv2[256]; /* for 2048 bit */ byte agree[256]; /* for 2048 bit */ double start, total, each, milliEach; DhKey dhKey; int dhKeySz = 2048; /* used in printf */ #ifdef USE_CERT_BUFFERS_1024 XMEMCPY(tmp, dh_key_der_1024, sizeof_dh_key_der_1024); bytes = sizeof_dh_key_der_1024; dhKeySz = 1024; #elif defined(USE_CERT_BUFFERS_2048) XMEMCPY(tmp, dh_key_der_2048, sizeof_dh_key_der_2048); bytes = sizeof_dh_key_der_2048; #else FILE* file = fopen(certDHname, "rb"); if (!file) { printf("can't find %s, Please run from CyaSSL home dir\n", certDHname); return; } ret = InitRng(&rng); if (ret < 0) { printf("InitRNG failed\n"); return; } bytes = fread(tmp, 1, sizeof(tmp), file); #endif /* USE_CERT_BUFFERS */ InitDhKey(&dhKey); bytes = DhKeyDecode(tmp, &idx, &dhKey, (word32)bytes); if (bytes != 0) { printf("dhekydecode failed, can't benchmark\n"); #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) fclose(file); #endif return; } start = current_time(1); for (i = 0; i < ntimes; i++) DhGenerateKeyPair(&dhKey, &rng, priv, &privSz, pub, &pubSz); total = current_time(0) - start; each = total / ntimes; /* per second */ milliEach = each * 1000; /* milliseconds */ printf("DH %d key generation %6.3f milliseconds, avg over %d" " iterations\n", dhKeySz, milliEach, ntimes); DhGenerateKeyPair(&dhKey, &rng, priv2, &privSz2, pub2, &pubSz2); start = current_time(1); for (i = 0; i < ntimes; i++) DhAgree(&dhKey, agree, &agreeSz, priv, privSz, pub2, pubSz2); total = current_time(0) - start; each = total / ntimes; /* per second */ milliEach = each * 1000; /* milliseconds */ printf("DH %d key agreement %6.3f milliseconds, avg over %d" " iterations\n", dhKeySz, milliEach, ntimes); #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) fclose(file); #endif FreeDhKey(&dhKey); }
static void ShowMenuScreen(void) { MenuScreenConfiguration * configuration = Screen.configuration; MenuScreenChoice * choices = configuration->choices; int options = configuration->options; const ScreenColor normalColor = SCGray; const ScreenColor highlightColor = SCWhite; const ScreenColor disabledColor = SCDarkGray; const int topTextLine = 10; const int animationLine = (topTextLine + 2); const int extraTextLine = (animationLine + 2); const int keyboardTextLine = 1; const int startKeyboardRowsLine = 3; const int numKeyboardRows = 3; const int numListRows = 5; const int startListLine = 1; const int startChoicesLine = (SCREEN_HEIGHT - (Screen.numChoices * 2)); const char keyboardRows[numKeyboardRows][32] = { "1 2 3 4 5 6 7 8 9 0 - + = _ . < ", " A B C D E F G H I J K L M N O ", " P Q R S T U V W X Y Z space " }; const char listBorder[32] = "--------------------"; const int spacePos = (strchr(keyboardRows[2], 's') - keyboardRows[2]); const char animationChars[] = "-*"; const gsi_time animationTickTime = 500; BOOL done = FALSE; int choiceIndex; BOOL keyboard; BOOL touching; BOOL list; BOOL animated; int x, y; int touchingLine; int touchingPos; int choiceLine; int keyboardLine; BOOL wasTouching = FALSE; int wasTouchingChoice = -1; ScreenColor color; int i; int range; char touchingChar; char wasTouchingChar = 0; int keyboardPos; int numListItems; int listScroll = 0; BOOL wasTouchingUp = FALSE; BOOL wasTouchingDown = FALSE; int listItem; const char * choiceSelection; int animationCount = 0; gsi_time lastAnimationTime = current_time(); gsi_time now; char animationText[] = "-"; // is it animated? animated = (options & SCREEN_OPTION_ANIMATED)?TRUE:FALSE; // is there a keyboard? keyboard = (options & SCREEN_OPTION_KEYBOARD)?TRUE:FALSE; // is there a list? list = (options & SCREEN_OPTION_LIST)?TRUE:FALSE; // we can't have a list and a keyboard if(keyboard && list) OS_Panic("Can't have a keyboard and a list on a menu screen\n"); // call the init func if(configuration->initFunc) { configuration->initFunc(); if(NextMenuScreenConfiguration) return; } // if there is a keyboard, get the initial position if(keyboard) keyboardPos = (int)strlen(Screen.keyboardText); // loop until we're done while(!done) { // wait for a screen update to complete SVC_WaitVBlankIntr(); // call the think func if(configuration->thinkFunc) { configuration->thinkFunc(); if(NextMenuScreenConfiguration) return; } // count the number of list items if(list) { for(numListItems = 0 ; numListItems < MAX_LIST_STRINGS ; numListItems++) { if(Screen.list[numListItems][0] == '\0') break; } } // check for a touch touching = GetTouch(&x, &y); if(touching) { // figure out which line we're touching touchingLine = (y / (TOUCH_Y_RANGE / SCREEN_HEIGHT)); // figure out which position we're touching touchingPos = (x / (TOUCH_X_RANGE / SCREEN_WIDTH)); } else if (wasTouching) { // check for touching a choice if(wasTouchingChoice != -1) { choiceSelection = choices[wasTouchingChoice].text; wasTouchingChoice = -1; // call the chose func if(configuration->choseFunc) { configuration->choseFunc(choiceSelection); if(NextMenuScreenConfiguration) return; } } // check for touching up on the list else if(wasTouchingUp) { if(listScroll > 0) listScroll--; } // check for touching down on the list else if(wasTouchingDown) { if(listScroll < (numListItems - numListRows)) listScroll++; } // check for touching a keyboard char else if(wasTouchingChar != 0) { // check for backspace if(wasTouchingChar == '<') { if(keyboardPos > 0) { keyboardPos--; Screen.keyboardText[keyboardPos] = '\0'; } } else { if(keyboardPos < MAX_KEYBOARD_TEXT_LEN) { Screen.keyboardText[keyboardPos] = wasTouchingChar; keyboardPos++; Screen.keyboardText[keyboardPos] = '\0'; } } } } wasTouching = touching; // clear both screens ClearScreens(); // show the title on the top screen SetTopScreenLineCentered(topTextLine, SCYellow, configuration->topScreenText); // show animation if(animated) { now = current_time(); if((now - lastAnimationTime) >= animationTickTime) { animationCount++; animationCount %= strlen(animationChars); lastAnimationTime += animationTickTime; } animationText[0] = animationChars[animationCount]; SetTopScreenLineCentered(animationLine, SCYellow, animationText); } // show extra text for(i = 0 ; i < MAX_EXTRA_TEXT_STRINGS ; i++) { if(options & SCREEN_OPTION_EXTRAS_CENTERED) SetTopScreenLineCentered(extraTextLine + i, SCWhite, Screen.extraText[i]); else SetTopScreenLine(extraTextLine + i, SCWhite, Screen.extraText[i]); } // show the list if(list) { // clear touching vars wasTouchingUp = FALSE; wasTouchingDown = FALSE; // show "up" if needed if(listScroll > 0) { if(touching && (touchingLine == startListLine)) { wasTouchingUp = TRUE; color = highlightColor; } else { color = normalColor; } SetBottomScreenLineCentered(startListLine, color, "up"); } // show the top line SetBottomScreenLineCentered(startListLine + 1, normalColor, listBorder); // show the list items for(i = 0 ; i < numListRows ; i++) { listItem = (listScroll + i); if(listItem >= numListItems) break; // is this item being touched? if(touching && (touchingLine == (startListLine + 2 + i))) Screen.listSelection = listItem; // set the color if(Screen.listSelection == listItem) color = highlightColor; else color = normalColor; // show the item SetBottomScreenLineCentered(startListLine + 2 + i, color, Screen.list[listScroll + i]); } // show the bottom line SetBottomScreenLineCentered(startListLine + numListRows + 2, normalColor, listBorder); // show "down" if needed if(listScroll < (numListItems - numListRows)) { if(touching && (touchingLine == (startListLine + numListRows + 3))) { wasTouchingDown = TRUE; color = highlightColor; } else { color = normalColor; } SetBottomScreenLineCentered(startListLine + numListRows + 3, color, "down"); } } // show a keyboard if(keyboard) { // show the text SetBottomScreenLine(keyboardTextLine, SCGreen, Screen.keyboardText); // clear touching var wasTouchingChar = 0; // loop through the keyboard rows for(i = 0 ; i < numKeyboardRows ; i++) { // get the line to show this row on keyboardLine = (startKeyboardRowsLine + i); // check if we're touching this row if(touching && (touchingLine == keyboardLine)) { // get the char we're touching touchingChar = keyboardRows[i][touchingPos]; // handle touching 'space' specially if(islower(touchingChar)) { wasTouchingChar = ' '; touchingPos = spacePos; range = 5; } else { if(touchingChar != ' ') wasTouchingChar = touchingChar; range = 1; } // show the keyboard row with the selection highlighted SetBottomScreenLineHighlight( keyboardLine, normalColor, keyboardRows[i], touchingPos, range, highlightColor); } else { // show the keyboard row SetBottomScreenLine(keyboardLine, normalColor, keyboardRows[i]); } } } // show the choices wasTouchingChoice = -1; for(choiceIndex = 0 ; choiceIndex < Screen.numChoices ; choiceIndex++) { // this is the line to show this choice on choiceLine = (startChoicesLine + (choiceIndex * 2)); // check if we're touching this choice if((choices[choiceIndex].options & CHOICE_OPTION_DISABLED) || ((choices[choiceIndex].options & CHOICE_OPTION_NEEDS_LIST_SELECTION) && (Screen.listSelection == -1))) { color = disabledColor; } else if(touching && (touchingLine == choiceLine)) { color = highlightColor; wasTouchingChoice = choiceIndex; } else { color = normalColor; } // show the line SetBottomScreenLineCentered(choiceLine, color, choices[choiceIndex].text); } } }
int ext4_inline_data_truncate(struct inode *inode, int *has_inline) { handle_t *handle; int inline_size, value_len, needed_blocks, no_expand, err = 0; size_t i_size; void *value = NULL; struct ext4_xattr_ibody_find is = { .s = { .not_found = -ENODATA, }, }; struct ext4_xattr_info i = { .name_index = EXT4_XATTR_INDEX_SYSTEM, .name = EXT4_XATTR_SYSTEM_DATA, }; needed_blocks = ext4_writepage_trans_blocks(inode); handle = ext4_journal_start(inode, EXT4_HT_INODE, needed_blocks); if (IS_ERR(handle)) return PTR_ERR(handle); ext4_write_lock_xattr(inode, &no_expand); if (!ext4_has_inline_data(inode)) { *has_inline = 0; ext4_journal_stop(handle); return 0; } if ((err = ext4_orphan_add(handle, inode)) != 0) goto out; if ((err = ext4_get_inode_loc(inode, &is.iloc)) != 0) goto out; down_write(&EXT4_I(inode)->i_data_sem); i_size = inode->i_size; inline_size = ext4_get_inline_size(inode); EXT4_I(inode)->i_disksize = i_size; if (i_size < inline_size) { /* Clear the content in the xattr space. */ if (inline_size > EXT4_MIN_INLINE_DATA_SIZE) { if ((err = ext4_xattr_ibody_find(inode, &i, &is)) != 0) goto out_error; BUG_ON(is.s.not_found); value_len = le32_to_cpu(is.s.here->e_value_size); value = kmalloc(value_len, GFP_NOFS); if (!value) { err = -ENOMEM; goto out_error; } err = ext4_xattr_ibody_get(inode, i.name_index, i.name, value, value_len); if (err <= 0) goto out_error; i.value = value; i.value_len = i_size > EXT4_MIN_INLINE_DATA_SIZE ? i_size - EXT4_MIN_INLINE_DATA_SIZE : 0; err = ext4_xattr_ibody_inline_set(handle, inode, &i, &is); if (err) goto out_error; } /* Clear the content within i_blocks. */ if (i_size < EXT4_MIN_INLINE_DATA_SIZE) { void *p = (void *) ext4_raw_inode(&is.iloc)->i_block; memset(p + i_size, 0, EXT4_MIN_INLINE_DATA_SIZE - i_size); } EXT4_I(inode)->i_inline_size = i_size < EXT4_MIN_INLINE_DATA_SIZE ? EXT4_MIN_INLINE_DATA_SIZE : i_size; } out_error: up_write(&EXT4_I(inode)->i_data_sem); out: brelse(is.iloc.bh); ext4_write_unlock_xattr(inode, &no_expand); kfree(value); if (inode->i_nlink) ext4_orphan_del(handle, inode); if (err == 0) { inode->i_mtime = inode->i_ctime = current_time(inode); err = ext4_mark_inode_dirty(handle, inode); if (IS_SYNC(inode)) ext4_handle_sync(handle); } ext4_journal_stop(handle); return err; }
void clock_tests(void) { uint32_t c; lk_time_t t; lk_bigtime_t t2; thread_sleep(100); c = arch_cycle_count(); t = current_time(); c = arch_cycle_count() - c; printf("%u cycles per current_time()\n", c); thread_sleep(100); c = arch_cycle_count(); t2 = current_time_hires(); c = arch_cycle_count() - c; printf("%u cycles per current_time_hires()\n", c); printf("making sure time never goes backwards\n"); { printf("testing current_time()\n"); lk_time_t start = current_time(); lk_time_t last = start; for (;;) { t = current_time(); //printf("%lu %lu\n", last, t); if (TIME_LT(t, last)) { printf("WARNING: time ran backwards: %lu < %lu\n", last, t); } last = t; if (last - start > 5000) break; } } { printf("testing current_time_hires()\n"); lk_bigtime_t start = current_time_hires(); lk_bigtime_t last = start; for (;;) { t2 = current_time_hires(); //printf("%llu %llu\n", last, t2); if (t2 < last) { printf("WARNING: time ran backwards: %llu < %llu\n", last, t2); } last = t2; if (last - start > 5000000) break; } } printf("making sure current_time() and current_time_hires() are always the same base\n"); { lk_time_t start = current_time(); for (;;) { t = current_time(); t2 = current_time_hires(); if (t > ((t2 + 500) / 1000)) { printf("WARNING: current_time() ahead of current_time_hires() %lu %llu\n", t, t2); } if (t - start > 5000) break; } } printf("counting to 5, in one second intervals\n"); for (int i = 0; i < 5; i++) { thread_sleep(1000); printf("%d\n", i + 1); } printf("measuring cpu clock against current_time_hires()\n"); for (int i = 0; i < 5; i++) { uint cycles = arch_cycle_count(); lk_bigtime_t start = current_time_hires(); while ((current_time_hires() - start) < 1000000) ; cycles = arch_cycle_count() - cycles; printf("%u cycles per second\n", cycles); } }
safety_checkert::resultt bmc_all_propertiest::operator()() { status() << "Passing problem to " << solver.decision_procedure_text() << eom; solver.set_message_handler(get_message_handler()); // stop the time absolute_timet sat_start=current_time(); bmc.do_conversion(); // Collect _all_ goals in `goal_map'. // This maps property IDs to 'goalt' forall_goto_functions(f_it, goto_functions) forall_goto_program_instructions(i_it, f_it->second.body) if(i_it->is_assert()) goal_map[i_it->source_location.get_property_id()]=goalt(*i_it); // get the conditions for these goals from formula // collect all 'instances' of the properties for(symex_target_equationt::SSA_stepst::iterator it=bmc.equation.SSA_steps.begin(); it!=bmc.equation.SSA_steps.end(); it++) { if(it->is_assert()) { irep_idt property_id; if(it->source.pc->is_assert()) property_id=it->source.pc->source_location.get_property_id(); else if(it->source.pc->is_goto()) { // this is likely an unwinding assertion property_id=id2string( it->source.pc->source_location.get_function())+".unwind."+ std::to_string(it->source.pc->loop_number); goal_map[property_id].description=it->comment; } else continue; goal_map[property_id].instances.push_back(it); } } do_before_solving(); cover_goalst cover_goals(solver); cover_goals.set_message_handler(get_message_handler()); cover_goals.register_observer(*this); for(const auto &g : goal_map) { // Our goal is to falsify a property, i.e., we will // add the negation of the property as goal. literalt p=!solver.convert(g.second.as_expr()); cover_goals.add(p); } status() << "Running " << solver.decision_procedure_text() << eom; bool error=false; decision_proceduret::resultt result=cover_goals(); if(result==decision_proceduret::resultt::D_ERROR) { error=true; for(auto &g : goal_map) if(g.second.status==goalt::statust::UNKNOWN) g.second.status=goalt::statust::ERROR; } else { for(auto &g : goal_map) if(g.second.status==goalt::statust::UNKNOWN) g.second.status=goalt::statust::SUCCESS; } // output runtime { absolute_timet sat_stop=current_time(); status() << "Runtime decision procedure: " << (sat_stop-sat_start) << "s" << eom; } // report report(cover_goals); if(error) return safety_checkert::resultt::ERROR; bool safe=(cover_goals.number_covered()==0); if(safe) bmc.report_success(); // legacy, might go away else bmc.report_failure(); // legacy, might go away return safe?safety_checkert::resultt::SAFE:safety_checkert::resultt::UNSAFE; }
_lc_auto_save_runtime(double & store) : runtime(store) { this->begin_step = this->begin = current_time(); }
void advance_time( const boost::posix_time::time_duration& delay ) { current_time( current_time() + delay ); }
double step() { double now = current_time(); double ret = begin_step - now; begin_step = now; return ret; }
/** * Swap the information from the given @inode and the inode * EXT4_BOOT_LOADER_INO. It will basically swap i_data and all other * important fields of the inodes. * * @sb: the super block of the filesystem * @inode: the inode to swap with EXT4_BOOT_LOADER_INO * */ static long swap_inode_boot_loader(struct super_block *sb, struct inode *inode) { handle_t *handle; int err; struct inode *inode_bl; struct ext4_inode_info *ei_bl; qsize_t size, size_bl, diff; blkcnt_t blocks; unsigned short bytes; inode_bl = ext4_iget(sb, EXT4_BOOT_LOADER_INO, EXT4_IGET_SPECIAL); if (IS_ERR(inode_bl)) return PTR_ERR(inode_bl); ei_bl = EXT4_I(inode_bl); /* Protect orig inodes against a truncate and make sure, * that only 1 swap_inode_boot_loader is running. */ lock_two_nondirectories(inode, inode_bl); if (inode->i_nlink != 1 || !S_ISREG(inode->i_mode) || IS_SWAPFILE(inode) || IS_ENCRYPTED(inode) || (EXT4_I(inode)->i_flags & EXT4_JOURNAL_DATA_FL) || ext4_has_inline_data(inode)) { err = -EINVAL; goto journal_err_out; } if (IS_RDONLY(inode) || IS_APPEND(inode) || IS_IMMUTABLE(inode) || !inode_owner_or_capable(inode) || !capable(CAP_SYS_ADMIN)) { err = -EPERM; goto journal_err_out; } down_write(&EXT4_I(inode)->i_mmap_sem); err = filemap_write_and_wait(inode->i_mapping); if (err) goto err_out; err = filemap_write_and_wait(inode_bl->i_mapping); if (err) goto err_out; /* Wait for all existing dio workers */ inode_dio_wait(inode); inode_dio_wait(inode_bl); truncate_inode_pages(&inode->i_data, 0); truncate_inode_pages(&inode_bl->i_data, 0); handle = ext4_journal_start(inode_bl, EXT4_HT_MOVE_EXTENTS, 2); if (IS_ERR(handle)) { err = -EINVAL; goto err_out; } /* Protect extent tree against block allocations via delalloc */ ext4_double_down_write_data_sem(inode, inode_bl); if (inode_bl->i_nlink == 0) { /* this inode has never been used as a BOOT_LOADER */ set_nlink(inode_bl, 1); i_uid_write(inode_bl, 0); i_gid_write(inode_bl, 0); inode_bl->i_flags = 0; ei_bl->i_flags = 0; inode_set_iversion(inode_bl, 1); i_size_write(inode_bl, 0); inode_bl->i_mode = S_IFREG; if (ext4_has_feature_extents(sb)) { ext4_set_inode_flag(inode_bl, EXT4_INODE_EXTENTS); ext4_ext_tree_init(handle, inode_bl); } else memset(ei_bl->i_data, 0, sizeof(ei_bl->i_data)); } err = dquot_initialize(inode); if (err) goto err_out1; size = (qsize_t)(inode->i_blocks) * (1 << 9) + inode->i_bytes; size_bl = (qsize_t)(inode_bl->i_blocks) * (1 << 9) + inode_bl->i_bytes; diff = size - size_bl; swap_inode_data(inode, inode_bl); inode->i_ctime = inode_bl->i_ctime = current_time(inode); inode->i_generation = prandom_u32(); inode_bl->i_generation = prandom_u32(); reset_inode_seed(inode); reset_inode_seed(inode_bl); ext4_discard_preallocations(inode); err = ext4_mark_inode_dirty(handle, inode); if (err < 0) { /* No need to update quota information. */ ext4_warning(inode->i_sb, "couldn't mark inode #%lu dirty (err %d)", inode->i_ino, err); /* Revert all changes: */ swap_inode_data(inode, inode_bl); ext4_mark_inode_dirty(handle, inode); goto err_out1; } blocks = inode_bl->i_blocks; bytes = inode_bl->i_bytes; inode_bl->i_blocks = inode->i_blocks; inode_bl->i_bytes = inode->i_bytes; err = ext4_mark_inode_dirty(handle, inode_bl); if (err < 0) { /* No need to update quota information. */ ext4_warning(inode_bl->i_sb, "couldn't mark inode #%lu dirty (err %d)", inode_bl->i_ino, err); goto revert; } /* Bootloader inode should not be counted into quota information. */ if (diff > 0) dquot_free_space(inode, diff); else err = dquot_alloc_space(inode, -1 * diff); if (err < 0) { revert: /* Revert all changes: */ inode_bl->i_blocks = blocks; inode_bl->i_bytes = bytes; swap_inode_data(inode, inode_bl); ext4_mark_inode_dirty(handle, inode); ext4_mark_inode_dirty(handle, inode_bl); } err_out1: ext4_journal_stop(handle); ext4_double_up_write_data_sem(inode, inode_bl); err_out: up_write(&EXT4_I(inode)->i_mmap_sem); journal_err_out: unlock_two_nondirectories(inode, inode_bl); iput(inode_bl); return err; }
static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry, struct inode *new_dir, struct dentry *new_dentry, unsigned int flags) { struct f2fs_sb_info *sbi = F2FS_I_SB(old_dir); struct inode *old_inode = d_inode(old_dentry); struct inode *new_inode = d_inode(new_dentry); struct inode *whiteout = NULL; struct page *old_dir_page; struct page *old_page, *new_page = NULL; struct f2fs_dir_entry *old_dir_entry = NULL; struct f2fs_dir_entry *old_entry; struct f2fs_dir_entry *new_entry; bool is_old_inline = f2fs_has_inline_dentry(old_dir); int err = -ENOENT; if ((old_dir != new_dir) && f2fs_encrypted_inode(new_dir) && !fscrypt_has_permitted_context(new_dir, old_inode)) { err = -EPERM; goto out; } old_entry = f2fs_find_entry(old_dir, &old_dentry->d_name, &old_page); if (!old_entry) { if (IS_ERR(old_page)) err = PTR_ERR(old_page); goto out; } if (S_ISDIR(old_inode->i_mode)) { old_dir_entry = f2fs_parent_dir(old_inode, &old_dir_page); if (!old_dir_entry) { if (IS_ERR(old_dir_page)) err = PTR_ERR(old_dir_page); goto out_old; } } if (flags & RENAME_WHITEOUT) { err = f2fs_create_whiteout(old_dir, &whiteout); if (err) goto out_dir; } if (new_inode) { err = -ENOTEMPTY; if (old_dir_entry && !f2fs_empty_dir(new_inode)) goto out_whiteout; err = -ENOENT; new_entry = f2fs_find_entry(new_dir, &new_dentry->d_name, &new_page); if (!new_entry) { if (IS_ERR(new_page)) err = PTR_ERR(new_page); goto out_whiteout; } f2fs_balance_fs(sbi, true); f2fs_lock_op(sbi); err = acquire_orphan_inode(sbi); if (err) goto put_out_dir; err = update_dent_inode(old_inode, new_inode, &new_dentry->d_name); if (err) { release_orphan_inode(sbi); goto put_out_dir; } f2fs_set_link(new_dir, new_entry, new_page, old_inode); new_inode->i_ctime = current_time(new_inode); down_write(&F2FS_I(new_inode)->i_sem); if (old_dir_entry) f2fs_i_links_write(new_inode, false); f2fs_i_links_write(new_inode, false); up_write(&F2FS_I(new_inode)->i_sem); if (!new_inode->i_nlink) add_orphan_inode(new_inode); else release_orphan_inode(sbi); } else { f2fs_balance_fs(sbi, true); f2fs_lock_op(sbi); err = f2fs_add_link(new_dentry, old_inode); if (err) { f2fs_unlock_op(sbi); goto out_whiteout; } if (old_dir_entry) f2fs_i_links_write(new_dir, true); /* * old entry and new entry can locate in the same inline * dentry in inode, when attaching new entry in inline dentry, * it could force inline dentry conversion, after that, * old_entry and old_page will point to wrong address, in * order to avoid this, let's do the check and update here. */ if (is_old_inline && !f2fs_has_inline_dentry(old_dir)) { f2fs_put_page(old_page, 0); old_page = NULL; old_entry = f2fs_find_entry(old_dir, &old_dentry->d_name, &old_page); if (!old_entry) { err = -ENOENT; if (IS_ERR(old_page)) err = PTR_ERR(old_page); f2fs_unlock_op(sbi); goto out_whiteout; } } } down_write(&F2FS_I(old_inode)->i_sem); file_lost_pino(old_inode); if (new_inode && file_enc_name(new_inode)) file_set_enc_name(old_inode); up_write(&F2FS_I(old_inode)->i_sem); old_inode->i_ctime = current_time(old_inode); f2fs_mark_inode_dirty_sync(old_inode); f2fs_delete_entry(old_entry, old_page, old_dir, NULL); if (whiteout) { whiteout->i_state |= I_LINKABLE; set_inode_flag(whiteout, FI_INC_LINK); err = f2fs_add_link(old_dentry, whiteout); if (err) goto put_out_dir; whiteout->i_state &= ~I_LINKABLE; iput(whiteout); } if (old_dir_entry) { if (old_dir != new_dir && !whiteout) { f2fs_set_link(old_inode, old_dir_entry, old_dir_page, new_dir); } else { f2fs_dentry_kunmap(old_inode, old_dir_page); f2fs_put_page(old_dir_page, 0); } f2fs_i_links_write(old_dir, false); } f2fs_unlock_op(sbi); if (IS_DIRSYNC(old_dir) || IS_DIRSYNC(new_dir)) f2fs_sync_fs(sbi->sb, 1); return 0; put_out_dir: f2fs_unlock_op(sbi); if (new_page) { f2fs_dentry_kunmap(new_dir, new_page); f2fs_put_page(new_page, 0); } out_whiteout: if (whiteout) iput(whiteout); out_dir: if (old_dir_entry) { f2fs_dentry_kunmap(old_inode, old_dir_page); f2fs_put_page(old_dir_page, 0); } out_old: f2fs_dentry_kunmap(old_dir, old_page); f2fs_put_page(old_page, 0); out: return err; }
static int ext4_ioctl_setflags(struct inode *inode, unsigned int flags) { struct ext4_inode_info *ei = EXT4_I(inode); handle_t *handle = NULL; int err = -EPERM, migrate = 0; struct ext4_iloc iloc; unsigned int oldflags, mask, i; unsigned int jflag; /* Is it quota file? Do not allow user to mess with it */ if (ext4_is_quota_file(inode)) goto flags_out; oldflags = ei->i_flags; /* The JOURNAL_DATA flag is modifiable only by root */ jflag = flags & EXT4_JOURNAL_DATA_FL; /* * The IMMUTABLE and APPEND_ONLY flags can only be changed by * the relevant capability. * * This test looks nicer. Thanks to Pauline Middelink */ if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) { if (!capable(CAP_LINUX_IMMUTABLE)) goto flags_out; } /* * The JOURNAL_DATA flag can only be changed by * the relevant capability. */ if ((jflag ^ oldflags) & (EXT4_JOURNAL_DATA_FL)) { if (!capable(CAP_SYS_RESOURCE)) goto flags_out; } if ((flags ^ oldflags) & EXT4_EXTENTS_FL) migrate = 1; if (flags & EXT4_EOFBLOCKS_FL) { /* we don't support adding EOFBLOCKS flag */ if (!(oldflags & EXT4_EOFBLOCKS_FL)) { err = -EOPNOTSUPP; goto flags_out; } } else if (oldflags & EXT4_EOFBLOCKS_FL) { err = ext4_truncate(inode); if (err) goto flags_out; } handle = ext4_journal_start(inode, EXT4_HT_INODE, 1); if (IS_ERR(handle)) { err = PTR_ERR(handle); goto flags_out; } if (IS_SYNC(inode)) ext4_handle_sync(handle); err = ext4_reserve_inode_write(handle, inode, &iloc); if (err) goto flags_err; for (i = 0, mask = 1; i < 32; i++, mask <<= 1) { if (!(mask & EXT4_FL_USER_MODIFIABLE)) continue; /* These flags get special treatment later */ if (mask == EXT4_JOURNAL_DATA_FL || mask == EXT4_EXTENTS_FL) continue; if (mask & flags) ext4_set_inode_flag(inode, i); else ext4_clear_inode_flag(inode, i); } ext4_set_inode_flags(inode); inode->i_ctime = current_time(inode); err = ext4_mark_iloc_dirty(handle, inode, &iloc); flags_err: ext4_journal_stop(handle); if (err) goto flags_out; if ((jflag ^ oldflags) & (EXT4_JOURNAL_DATA_FL)) { /* * Changes to the journaling mode can cause unsafe changes to * S_DAX if we are using the DAX mount option. */ if (test_opt(inode->i_sb, DAX)) { err = -EBUSY; goto flags_out; } err = ext4_change_inode_journal_flag(inode, jflag); if (err) goto flags_out; } if (migrate) { if (flags & EXT4_EXTENTS_FL) err = ext4_ext_migrate(inode); else err = ext4_ind_migrate(inode); } flags_out: return err; }
THREAD_RETURN CYASSL_THREAD client_test(void* args) { SOCKET_T sockfd = 0; CYASSL_METHOD* method = 0; CYASSL_CTX* ctx = 0; CYASSL* ssl = 0; CYASSL* sslResume = 0; CYASSL_SESSION* session = 0; char resumeMsg[] = "resuming cyassl!"; int resumeSz = sizeof(resumeMsg); char msg[32] = "hello cyassl!"; /* GET may make bigger */ char reply[80]; int input; int msgSz = (int)strlen(msg); int port = yasslPort; char* host = (char*)yasslIP; char* domain = (char*)"www.yassl.com"; int ch; int version = CLIENT_INVALID_VERSION; int usePsk = 0; int sendGET = 0; int benchmark = 0; int doDTLS = 0; int matchName = 0; int doPeerCheck = 1; int nonBlocking = 0; int resumeSession = 0; int trackMemory = 0; char* cipherList = NULL; char* verifyCert = (char*)caCert; char* ourCert = (char*)cliCert; char* ourKey = (char*)cliKey; int argc = ((func_args*)args)->argc; char** argv = ((func_args*)args)->argv; ((func_args*)args)->return_code = -1; /* error state */ #ifdef NO_RSA verifyCert = (char*)eccCert; ourCert = (char*)cliEccCert; ourKey = (char*)cliEccKey; #endif (void)resumeSz; (void)session; (void)sslResume; (void)trackMemory; while ((ch = mygetopt(argc, argv, "?gdusmNrth:p:v:l:A:c:k:b:z")) != -1) { switch (ch) { case '?' : Usage(); exit(EXIT_SUCCESS); case 'g' : sendGET = 1; break; case 'd' : doPeerCheck = 0; break; case 'u' : doDTLS = 1; break; case 's' : usePsk = 1; break; case 't' : #ifdef USE_CYASSL_MEMORY trackMemory = 1; #endif break; case 'm' : matchName = 1; break; case 'h' : host = myoptarg; domain = myoptarg; break; case 'p' : port = atoi(myoptarg); #if !defined(NO_MAIN_DRIVER) || defined(USE_WINDOWS_API) if (port == 0) err_sys("port number cannot be 0"); #endif break; case 'v' : version = atoi(myoptarg); if (version < 0 || version > 3) { Usage(); exit(MY_EX_USAGE); } break; case 'l' : cipherList = myoptarg; break; case 'A' : verifyCert = myoptarg; break; case 'c' : ourCert = myoptarg; break; case 'k' : ourKey = myoptarg; break; case 'b' : benchmark = atoi(myoptarg); if (benchmark < 0 || benchmark > 1000000) { Usage(); exit(MY_EX_USAGE); } break; case 'N' : nonBlocking = 1; break; case 'r' : resumeSession = 1; break; case 'z' : #ifndef CYASSL_LEANPSK CyaSSL_GetObjectSize(); #endif break; default: Usage(); exit(MY_EX_USAGE); } } myoptind = 0; /* reset for test cases */ /* sort out DTLS versus TLS versions */ if (version == CLIENT_INVALID_VERSION) { if (doDTLS) version = CLIENT_DTLS_DEFAULT_VERSION; else version = CLIENT_DEFAULT_VERSION; } else { if (doDTLS) { if (version == 3) version = -2; else version = -1; } } #ifdef USE_CYASSL_MEMORY if (trackMemory) InitMemoryTracker(); #endif switch (version) { #ifndef NO_OLD_TLS case 0: method = CyaSSLv3_client_method(); break; case 1: method = CyaTLSv1_client_method(); break; case 2: method = CyaTLSv1_1_client_method(); break; #endif case 3: method = CyaTLSv1_2_client_method(); break; #ifdef CYASSL_DTLS case -1: method = CyaDTLSv1_client_method(); break; case -2: method = CyaDTLSv1_2_client_method(); break; #endif default: err_sys("Bad SSL version"); } if (method == NULL) err_sys("unable to get method"); ctx = CyaSSL_CTX_new(method); if (ctx == NULL) err_sys("unable to get ctx"); if (cipherList) if (CyaSSL_CTX_set_cipher_list(ctx, cipherList) != SSL_SUCCESS) err_sys("client can't set cipher list 1"); #ifdef CYASSL_LEANPSK usePsk = 1; #endif #if defined(NO_RSA) && !defined(HAVE_ECC) usePsk = 1; #endif if (usePsk) { #ifndef NO_PSK CyaSSL_CTX_set_psk_client_callback(ctx, my_psk_client_cb); if (cipherList == NULL) { const char *defaultCipherList; #ifdef HAVE_NULL_CIPHER defaultCipherList = "PSK-NULL-SHA256"; #else defaultCipherList = "PSK-AES128-CBC-SHA256"; #endif if (CyaSSL_CTX_set_cipher_list(ctx,defaultCipherList) !=SSL_SUCCESS) err_sys("client can't set cipher list 2"); } #endif } #ifdef OPENSSL_EXTRA CyaSSL_CTX_set_default_passwd_cb(ctx, PasswordCallBack); #endif #if defined(CYASSL_SNIFFER) && !defined(HAVE_NTRU) && !defined(HAVE_ECC) if (cipherList == NULL) { /* don't use EDH, can't sniff tmp keys */ if (CyaSSL_CTX_set_cipher_list(ctx, "AES256-SHA256") != SSL_SUCCESS) { err_sys("client can't set cipher list 3"); } } #endif #ifdef USER_CA_CB CyaSSL_CTX_SetCACb(ctx, CaCb); #endif #ifdef VERIFY_CALLBACK CyaSSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, myVerify); #endif #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) if (!usePsk){ if (CyaSSL_CTX_use_certificate_file(ctx, ourCert, SSL_FILETYPE_PEM) != SSL_SUCCESS) err_sys("can't load client cert file, check file and run from" " CyaSSL home dir"); if (CyaSSL_CTX_use_PrivateKey_file(ctx, ourKey, SSL_FILETYPE_PEM) != SSL_SUCCESS) err_sys("can't load client private key file, check file and run " "from CyaSSL home dir"); if (CyaSSL_CTX_load_verify_locations(ctx, verifyCert, 0) != SSL_SUCCESS) err_sys("can't load ca file, Please run from CyaSSL home dir"); } #endif #if !defined(NO_CERTS) if (!usePsk && doPeerCheck == 0) CyaSSL_CTX_set_verify(ctx, SSL_VERIFY_NONE, 0); #endif #ifdef HAVE_CAVIUM CyaSSL_CTX_UseCavium(ctx, CAVIUM_DEV_ID); #endif if (benchmark) { /* time passed in number of connects give average */ int times = benchmark; int i = 0; double start = current_time(), avg; for (i = 0; i < times; i++) { tcp_connect(&sockfd, host, port, doDTLS); ssl = CyaSSL_new(ctx); CyaSSL_set_fd(ssl, sockfd); if (CyaSSL_connect(ssl) != SSL_SUCCESS) err_sys("SSL_connect failed"); CyaSSL_shutdown(ssl); CyaSSL_free(ssl); CloseSocket(sockfd); } avg = current_time() - start; avg /= times; avg *= 1000; /* milliseconds */ printf("CyaSSL_connect avg took: %8.3f milliseconds\n", avg); CyaSSL_CTX_free(ctx); ((func_args*)args)->return_code = 0; exit(EXIT_SUCCESS); } ssl = CyaSSL_new(ctx); if (ssl == NULL) err_sys("unable to get SSL object"); if (doDTLS) { SOCKADDR_IN_T addr; build_addr(&addr, host, port); CyaSSL_dtls_set_peer(ssl, &addr, sizeof(addr)); tcp_socket(&sockfd, 1); } else { tcp_connect(&sockfd, host, port, 0); } CyaSSL_set_fd(ssl, sockfd); #ifdef HAVE_CRL if (CyaSSL_EnableCRL(ssl, CYASSL_CRL_CHECKALL) != SSL_SUCCESS) err_sys("can't enable crl check"); if (CyaSSL_LoadCRL(ssl, crlPemDir, SSL_FILETYPE_PEM, 0) != SSL_SUCCESS) err_sys("can't load crl, check crlfile and date validity"); if (CyaSSL_SetCRL_Cb(ssl, CRL_CallBack) != SSL_SUCCESS) err_sys("can't set crl callback"); #endif if (matchName && doPeerCheck) CyaSSL_check_domain_name(ssl, domain); #ifndef CYASSL_CALLBACKS if (nonBlocking) { CyaSSL_set_using_nonblock(ssl, 1); tcp_set_nonblocking(&sockfd); NonBlockingSSL_Connect(ssl); } else if (CyaSSL_connect(ssl) != SSL_SUCCESS) { /* see note at top of README */ int err = CyaSSL_get_error(ssl, 0); char buffer[80]; printf("err = %d, %s\n", err, CyaSSL_ERR_error_string(err, buffer)); err_sys("SSL_connect failed"); /* if you're getting an error here */ } #else timeout.tv_sec = 2; timeout.tv_usec = 0; NonBlockingSSL_Connect(ssl); /* will keep retrying on timeout */ #endif showPeer(ssl); if (sendGET) { printf("SSL connect ok, sending GET...\n"); msgSz = 28; strncpy(msg, "GET /index.html HTTP/1.0\r\n\r\n", msgSz); msg[msgSz] = '\0'; } if (CyaSSL_write(ssl, msg, msgSz) != msgSz) err_sys("SSL_write failed"); input = CyaSSL_read(ssl, reply, sizeof(reply)-1); if (input > 0) { reply[input] = 0; printf("Server response: %s\n", reply); if (sendGET) { /* get html */ while (1) { input = CyaSSL_read(ssl, reply, sizeof(reply)-1); if (input > 0) { reply[input] = 0; printf("%s\n", reply); } else break; } } } else if (input < 0) { int readErr = CyaSSL_get_error(ssl, 0); if (readErr != SSL_ERROR_WANT_READ) err_sys("CyaSSL_read failed"); } #ifndef NO_SESSION_CACHE if (resumeSession) { if (doDTLS) { strncpy(msg, "break", 6); msgSz = (int)strlen(msg); /* try to send session close */ CyaSSL_write(ssl, msg, msgSz); } session = CyaSSL_get_session(ssl); sslResume = CyaSSL_new(ctx); } #endif if (doDTLS == 0) /* don't send alert after "break" command */ CyaSSL_shutdown(ssl); /* echoserver will interpret as new conn */ CyaSSL_free(ssl); CloseSocket(sockfd); #ifndef NO_SESSION_CACHE if (resumeSession) { if (doDTLS) { SOCKADDR_IN_T addr; #ifdef USE_WINDOWS_API Sleep(500); #else sleep(1); #endif build_addr(&addr, host, port); CyaSSL_dtls_set_peer(sslResume, &addr, sizeof(addr)); tcp_socket(&sockfd, 1); } else { tcp_connect(&sockfd, host, port, 0); } CyaSSL_set_fd(sslResume, sockfd); CyaSSL_set_session(sslResume, session); showPeer(sslResume); #ifndef CYASSL_CALLBACKS if (nonBlocking) { CyaSSL_set_using_nonblock(sslResume, 1); tcp_set_nonblocking(&sockfd); NonBlockingSSL_Connect(sslResume); } else if (CyaSSL_connect(sslResume) != SSL_SUCCESS) err_sys("SSL resume failed"); #else timeout.tv_sec = 2; timeout.tv_usec = 0; NonBlockingSSL_Connect(ssl); /* will keep retrying on timeout */ #endif if (CyaSSL_session_reused(sslResume)) printf("reused session id\n"); else printf("didn't reuse session id!!!\n"); if (CyaSSL_write(sslResume, resumeMsg, resumeSz) != resumeSz) err_sys("SSL_write failed"); if (nonBlocking) { /* give server a chance to bounce a message back to client */ #ifdef USE_WINDOWS_API Sleep(500); #else sleep(1); #endif } input = CyaSSL_read(sslResume, reply, sizeof(reply)-1); if (input > 0) { reply[input] = 0; printf("Server resume response: %s\n", reply); } /* try to send session break */ CyaSSL_write(sslResume, msg, msgSz); CyaSSL_shutdown(sslResume); CyaSSL_free(sslResume); CloseSocket(sockfd); } #endif /* NO_SESSION_CACHE */ CyaSSL_CTX_free(ctx); ((func_args*)args)->return_code = 0; #ifdef USE_CYASSL_MEMORY if (trackMemory) ShowMemoryTracker(); #endif /* USE_CYASSL_MEMORY */ return 0; }
int ClientBenchmarkThroughput(WOLFSSL_CTX* ctx, char* host, word16 port, int doDTLS, int throughput) { double start, conn_time = 0, tx_time = 0, rx_time = 0; SOCKET_T sockfd; WOLFSSL* ssl; int ret; start = current_time(); ssl = wolfSSL_new(ctx); if (ssl == NULL) err_sys("unable to get SSL object"); tcp_connect(&sockfd, host, port, doDTLS, ssl); wolfSSL_set_fd(ssl, sockfd); if (wolfSSL_connect(ssl) == SSL_SUCCESS) { /* Perform throughput test */ char *tx_buffer, *rx_buffer; /* Record connection time */ conn_time = current_time() - start; /* Allocate TX/RX buffers */ tx_buffer = (char*)malloc(TEST_BUFFER_SIZE); rx_buffer = (char*)malloc(TEST_BUFFER_SIZE); if(tx_buffer && rx_buffer) { WC_RNG rng; /* Startup the RNG */ ret = wc_InitRng(&rng); if(ret == 0) { int xfer_bytes; /* Generate random data to send */ ret = wc_RNG_GenerateBlock(&rng, (byte*)tx_buffer, TEST_BUFFER_SIZE); wc_FreeRng(&rng); if(ret != 0) { err_sys("wc_RNG_GenerateBlock failed"); } /* Perform TX and RX of bytes */ xfer_bytes = 0; while(throughput > xfer_bytes) { int len, rx_pos, select_ret; /* Determine packet size */ len = min(TEST_BUFFER_SIZE, throughput - xfer_bytes); /* Perform TX */ start = current_time(); if (wolfSSL_write(ssl, tx_buffer, len) != len) { int writeErr = wolfSSL_get_error(ssl, 0); printf("wolfSSL_write error %d!\n", writeErr); err_sys("wolfSSL_write failed"); } tx_time += current_time() - start; /* Perform RX */ select_ret = tcp_select(sockfd, 1); /* Timeout=1 second */ if (select_ret == TEST_RECV_READY) { start = current_time(); rx_pos = 0; while(rx_pos < len) { ret = wolfSSL_read(ssl, &rx_buffer[rx_pos], len - rx_pos); if(ret <= 0) { int readErr = wolfSSL_get_error(ssl, 0); if (readErr != SSL_ERROR_WANT_READ) { printf("wolfSSL_read error %d!\n", readErr); err_sys("wolfSSL_read failed"); } } else { rx_pos += ret; } } rx_time += current_time() - start; } /* Compare TX and RX buffers */ if(XMEMCMP(tx_buffer, rx_buffer, len) != 0) { err_sys("Compare TX and RX buffers failed"); } /* Update overall position */ xfer_bytes += len; } } else { err_sys("wc_InitRng failed"); } } else { err_sys("Client buffer malloc failed"); } if(tx_buffer) free(tx_buffer); if(rx_buffer) free(rx_buffer); } else { err_sys("wolfSSL_connect failed"); } wolfSSL_shutdown(ssl); wolfSSL_free(ssl); CloseSocket(sockfd); printf("wolfSSL Client Benchmark %d bytes\n" "\tConnect %8.3f ms\n" "\tTX %8.3f ms (%8.3f MBps)\n" "\tRX %8.3f ms (%8.3f MBps)\n", throughput, conn_time * 1000, tx_time * 1000, throughput / tx_time / 1024 / 1024, rx_time * 1000, throughput / rx_time / 1024 / 1024 ); return EXIT_SUCCESS; }