static void _create_sos_pd_cb(int err, void *data) { process_create_data *proc = (process_create_data *) data; if (err) { _fail(err, proc); return; } dprintf(5, "SOS page directory allocated at %p\n", proc->pcb->sos_pd); dprintf(5, "\tCreating vspace...\n"); err = _create_vspace(proc->pcb); if (err) { _fail(err, proc); return; } dprintf(5, "\tCreating cspace...\n"); err = _create_cspace(proc->pcb); if (err) { _fail(err, proc); return; } dprintf(5, "\tCreating IPC buffer...\n"); err = _create_ipc_buffer(proc); if (err) { _fail(err, proc); return; } }
ATerm SSL_fdcopy(ATerm fdinA, ATerm fdoutA) { int fdin, fdout; int n; char buf[SSL_COPY_BUFSIZE]; if(ATgetType(fdinA) != AT_INT || ATgetType(fdinA) != AT_INT) _fail(fdinA); fdin = ATgetInt((ATermInt)fdinA); fdout = ATgetInt((ATermInt)fdoutA); while( (n = read(fdin, buf, SSL_COPY_BUFSIZE)) > 0 ) if(write(fdout, buf, n) != n) { ATfprintf(stderr, "SSL_fdcopy: write error\n"); _fail((ATerm) ATempty); } if(n < 0) { ATfprintf(stderr, "SSL_fdcopy: read error\n"); _fail((ATerm) ATempty); } return (ATerm) ATempty; }
static void _start_process(int err, seL4_Word pc, void *cookie) { process_create_data *data = (process_create_data *) cookie; if (err) { _fail(err, data); return; } seL4_UserContext context; dprintf(5, "\tAttaching stdout and stderr...\n"); err = _create_stderrout(data->pcb); if (err) { _fail(err, data); return; } dprintf(5, "\tSetting initial program counter...\n"); // Set initial seL4 thread context, starting the process memset(&context, 0, sizeof(context)); context.pc = pc; context.sp = SOS_PROCESS_STACK_TOP; seL4_TCB_WriteRegisters(data->pcb->tcb_cap, 1, 0, 2, &context); data->pcb->running = 1; // Call back _reply(SOS_PROCESS_SUCCESS, data->pcb->pid, data->cb, data->cookie); _num_procs++; free(data); return; }
SqlStorage::ResultType SqlStorage::insertMail( const QDateTime &dateTime, const QString &subject, const QString &readableText, const QByteArray &headers, const QByteArray &body, quint64 &emlId ) { QCryptographicHash hash( QCryptographicHash::Sha1 ); hash.addData( body ); QByteArray hashValue = hash.result(); _queryValidateMail.bindValue( ":eml_hash", hashValue ); if ( ! _queryValidateMail.exec() ) { _fail( "Query _queryValidateMail failed", _queryValidateMail ); return RESULT_ERROR; } else if ( _queryValidateMail.first() ) { return RESULT_DUPLICATE; } _queryInsertMail.bindValue( ":eml_hash", hashValue ); // Use ISODate, because it will specify that the time is in UTC. // Otherwise time is assumed to be local which would be bad _queryInsertMail.bindValue( ":eml_date", dateTime.toString(Qt::ISODate)); _queryInsertMail.bindValue( ":eml_subj", subject ); _queryInsertMail.bindValue( ":eml_body", readableText ); _queryInsertMail.bindValue( ":eml_msg", headers + body); if ( ! _queryInsertMail.exec() ) { _fail( "Query _queryInsertMail failed", _queryInsertMail ); return RESULT_ERROR; } if ( _queryInsertMail.first() ) { emlId = _queryInsertMail.value( 0 ).toULongLong(); return RESULT_OK; } else { return RESULT_ERROR; } }
static crypto_t _cipher_new(crypto_t c, gchar *key, const gchar *algoname, const gint cipher_mode, const guint cipher_flags) { gcry_error_t e; c->algo = gcry_cipher_map_name(algoname); if (c->algo ==0) { return (_fail(c, g_strdup_printf("algorithm `%s' was not available", algoname))); } c->cipher.flags = cipher_flags; c->cipher.mode = cipher_mode; c->cipher.should_pad = (cipher_mode != GCRY_CIPHER_MODE_STREAM && cipher_mode != GCRY_CIPHER_MODE_CFB && cipher_mode != GCRY_CIPHER_MODE_OFB) ? TRUE : FALSE; c->cipher.blklen = gcry_cipher_get_algo_blklen(c->algo); if (c->cipher.blklen ==0) return (_fail(c, g_strdup("gcry_cipher_get_algo_blklen failed"))); e = gcry_cipher_open(&c->cipher.h, c->algo, cipher_mode, cipher_flags); if (e != 0) { return (_fail(c, g_strdup_printf("gcry_cipher_open failed: %s", gpg_strerror(e)))); } return (_setkey(c, key)); }
int main() { pthread_t alloc_pth[N_ALLOC_TH], gcollect_pth; int i, err; cuoo_init(); _obj_type = cuoo_type_new_opaque_hcs(NULL, sizeof(cu_word_t)); err = GC_pthread_create(&gcollect_pth, NULL, _gcollect_proc, NULL); if (err) _fail(err, "GC_pthread_create"); for (i = 0; i < N_ALLOC_TH; ++i) { err = GC_pthread_create(&alloc_pth[i], NULL, _alloc_proc, &i + i); if (err) _fail(err, "GC_pthread_create"); } for (i = 0; i < N_ALLOC_TH; ++i) { err = GC_pthread_join(alloc_pth[i], NULL); if (err) _fail(err, "GC_pthread_join"); } err = GC_pthread_join(gcollect_pth, NULL); if (err) _fail(err, "GC_pthread_join"); return 2*!!cu_test_bug_count(); }
/* shim */ u3_noun _cqe_shim_fun(u3_noun zep, u3_noun tub) { u3_noun p_tub, q_tub; u3x_cell(tub, &p_tub, &q_tub); if ( c3n == u3du(q_tub) ) { return _fail(tub); } else { u3_noun p_zep, q_zep; u3_noun iq_tub = u3h(q_tub); u3x_cell(zep, &p_zep, &q_zep); if ( _(u3a_is_cat(p_zep)) && _(u3a_is_cat(q_zep)) && _(u3a_is_cat(iq_tub)) ) { if ( (iq_tub >= p_zep) && (iq_tub <= q_zep) ) { return _next(tub); } else return _fail(tub); } else { return u3m_bail(c3__fail); } } }
ATerm SSL_string_to_int(ATerm t) { const char *s = NULL; char *end = NULL; int k = 0; if(!ATisString(t)) { _fail(t); } s = AT_getString(t); errno = 0; k = strtol(s, &end, 10); if(end == s || errno) { _fail(x); } while(isspace(*end)) end++; if(*end) { _fail(x); } return((ATerm) ATmakeInt(k)); }
void SqlStorage::_prepareStatements() { _queryValidateMail = XSqlQuery(db); if ( ! _queryValidateMail.prepare( QLatin1String("SELECT eml_id FROM xtbatch.eml " " WHERE :eml_hash=eml_hash::bytea;")) ) _fail( "Failed to prepare query _queryValidateMail", _queryValidateMail ); _queryInsertMail = XSqlQuery(db); if ( ! _queryInsertMail.prepare( QLatin1String("INSERT INTO xtbatch.eml " "(eml_hash, eml_date, eml_subj, eml_body, eml_msg, eml_status) " "VALUES " "(:eml_hash, :eml_date, :eml_subj, :eml_body," " :eml_msg, 'I') " "returning eml_id;")) ) _fail( "Failed to prepare query _queryInsertMail", _queryInsertMail ); _queryInsertAddress = XSqlQuery(db); if ( ! _queryInsertAddress.prepare( QLatin1String("INSERT INTO xtbatch.emladdr " "(emladdr_eml_id, emladdr_type, emladdr_addr, emladdr_name) " "VALUES (:emladdr_eml_id, :emladdr_type, :emladdr_addr, " ":emladdr_name)") ) ) _fail( "Failed to prepare query _queryInsertAddress", _queryInsertAddress ); _queryMarkMailReady = QSqlQuery(db); if ( ! _queryMarkMailReady.prepare( QLatin1String("UPDATE xtbatch.eml SET eml_status = 'O' WHERE eml_id = ?") ) ) _fail( "Failed to prepare query _queryMarkMailReady", _queryMarkMailReady ); }
/* shim */ u2_noun // produce j2_mcx(Pt5, shim, fun)(u2_wire wir_r, u2_noun zep, // retain u2_noun tub) // retain { u2_noun p_tub, q_tub; u2_bi_cell(wir_r, tub, &p_tub, &q_tub); if ( u2_no == u2_dust(q_tub) ) { return _fail(wir_r, tub); } else { u2_noun p_zep, q_zep; u2_noun iq_tub = u2_h(q_tub); u2_bi_cell(wir_r, zep, &p_zep, &q_zep); if ( u2_fly_is_cat(p_zep) && u2_fly_is_cat(q_zep) && u2_fly_is_cat(iq_tub) ) { if ( (iq_tub >= p_zep) && (iq_tub <= q_zep) ) { return _next(wir_r, tub); } else return _fail(wir_r, tub); } else { return u2_bl_bail(wir_r, c3__fail); } } }
ATerm SSL_setenv(ATerm name, ATerm value, ATerm overwrite) { if(!t_is_string(name)) _fail(name); if(!t_is_string(value)) _fail(value); if(!ATisInt(overwrite)) _fail(overwrite); setenv(ATgetName(ATgetSymbol(name)), ATgetName(ATgetSymbol(value)), ATgetInt((ATermInt)overwrite)); return (ATerm)ATempty; }
ATerm SSL_rename(ATerm oldname, ATerm newname) { if(!t_is_string(oldname) || !t_is_string(newname)) _fail(oldname); if(rename(ATgetName(ATgetSymbol(oldname)),ATgetName(ATgetSymbol(newname))) != 0) _fail(oldname); return newname; }
/** * Note: mandatory in C89 and C99, not in BSD */ ATerm SSL_remove(ATerm pathname) { if(!t_is_string(pathname)) _fail(pathname); if(remove(ATgetName(ATgetSymbol(pathname))) != 0) _fail(pathname); return (ATerm) ATempty; }
ATerm SSL_link(ATerm existingpath, ATerm newpath) { if(!t_is_string(existingpath) || !t_is_string(newpath)) _fail(existingpath); if(link(ATgetName(ATgetSymbol(existingpath)), ATgetName(ATgetSymbol(newpath))) != 0) _fail(existingpath); return newpath; }
u3_noun _cqe_stew_fun(u3_noun hel, u3_noun tub) { u3_noun p_tub, q_tub; u3x_cell(tub, &p_tub, &q_tub); if ( c3n == u3du(q_tub) ) { return _fail(tub); } else { u3_noun iq_tub = u3h(q_tub); if ( !_(u3a_is_cat(iq_tub)) ) { return u3m_bail(c3__fail); } else while ( 1 ) { if ( c3n == u3du(hel) ) { return _fail(tub); } else { u3_noun n_hel, l_hel, r_hel; u3_noun pn_hel, qn_hel; c3_o bit_o; u3x_trel(hel, &n_hel, &l_hel, &r_hel); u3x_cell(n_hel, &pn_hel, &qn_hel); if ( (c3n == u3du(pn_hel)) ) { bit_o = __((iq_tub == pn_hel)); } else { u3_noun hpn_hel = u3h(pn_hel); u3_noun tpn_hel = u3t(pn_hel); if ( !_(u3a_is_cat(hpn_hel)) || !_(u3a_is_cat(tpn_hel)) ) { return _fail(tub); } else bit_o = __((iq_tub >= hpn_hel) && (iq_tub <= tpn_hel)); } if ( c3y == bit_o ) { return u3x_good (u3n_slam_on(u3k(qn_hel), u3k(tub))); } else { if ( c3y == _stew_wor(iq_tub, pn_hel) ) { hel = l_hel; } else hel = r_hel; } } } } }
u2_noun // produce j2_mcx(Pt5, stew, fun)(u2_wire wir_r, u2_noun hel, // retain u2_noun tub) // retain { u2_noun p_tub, q_tub; u2_bi_cell(wir_r, tub, &p_tub, &q_tub); if ( u2_no == u2_dust(q_tub) ) { return _fail(wir_r, tub); } else { u2_noun iq_tub = u2_h(q_tub); if ( !u2_fly_is_cat(iq_tub) ) { return u2_bl_bail(wir_r, c3__fail); } else while ( 1 ) { if ( u2_no == u2_dust(hel) ) { return _fail(wir_r, tub); } else { u2_noun n_hel, l_hel, r_hel; u2_noun pn_hel, qn_hel; c3_t bit_t; u2_bi_trel(wir_r, hel, &n_hel, &l_hel, &r_hel); u2_bi_cell(wir_r, n_hel, &pn_hel, &qn_hel); if ( (u2_no == u2_dust(pn_hel)) ) { bit_t = (iq_tub == pn_hel); } else { u2_noun hpn_hel = u2_h(pn_hel); u2_noun tpn_hel = u2_t(pn_hel); if ( !u2_fly_is_cat(hpn_hel) || !u2_fly_is_cat(tpn_hel) ) { return _fail(wir_r, tub); } else bit_t = (iq_tub >= hpn_hel) && (iq_tub <= tpn_hel); } if ( bit_t ) { return u2_bl_good (wir_r, u2_nk_mong(wir_r, qn_hel, u2_rx(wir_r, tub))); } else { if ( u2_yes == _stew_wor(wir_r, iq_tub, pn_hel) ) { hel = l_hel; } else hel = r_hel; } } } } }
/** * Note: mandatory in C89 and C99 */ ATerm SSL_getenv(ATerm name) { char *value; if(!t_is_string(name)) _fail(name); value = getenv(ATgetName(ATgetSymbol(name))); if(value == NULL) _fail(name); return (ATerm)ATmakeString(value); }
SYLPH_BEGIN_NAMESPACE LinuxBundleAppSelf::LinuxBundleAppSelf(int argc, char * argv[]) { // First, make binreloc work... BrInitError error; if (br_init(&error) == 0 && error != BR_INIT_ERROR_DISABLED) _fail("LibSylph", "Couldn't init binreloc!", __FILE__, __LINE__); _location = br_find_exe(""); if (_location == "") { _fail("LibSylph", "Couldn't init binreloc!", __FILE__, __LINE__); } }
/* Create a new process from CPIO */ int process_create(char *app_name, process_create_cb cb, void *cookie) { int err; dprintf(5, "abcde\n"); dprintf(5, "process_create: %.128s\n", app_name); process_create_data *data = malloc(sizeof(struct process_create_data)); if (data == NULL) { dprintf(6, "process_create: OOM\n"); _reply(SOS_PROCESS_OOM, -1, cb, cookie); return SOS_PROCESS_OOM; } dprintf(8, "bzero procreate data\n"); bzero(data, sizeof(struct process_create_data)); dprintf(8, "bzero procreate data done\n"); data->pcb = malloc(sizeof(struct sos_pcb)); if (data->pcb == NULL) { dprintf(5, "process_create: could not allocate for PCB\n"); _fail(SOS_PROCESS_OOM, data); return SOS_PROCESS_OOM; } else { dprintf(6, "process_create: PCB is at %p\n", data->pcb); } bzero(data->pcb, sizeof(struct sos_pcb)); data->pcb->stime = time_stamp(); dprintf(6, "\nCopying app name...\n"); strncpy(data->pcb->app_name, app_name, SOS_PATH_MAX); data->cb = cb; data->cookie = cookie; dprintf(3, "\nStarting \"%s\"...\n", app_name); dprintf(5, "\tSetting PID...\n"); err = _set_pid(data); if (err) { dprintf(6, "Could not get PID\n"); _fail(err, data); return err; } dprintf(5, "\tCreating SOS page directory...\n"); err = _create_sos_pd(data); if (err) { _fail(err, data); return err; } // The rest happens in CPS return SOS_PROCESS_SUCCESS; }
ATerm SSL_read_term_from_stream(ATerm stream_term) { FILE* stream = stream_from_term(stream_term); if(stream == NULL) _fail(stream_term); ATerm result = ATreadFromFile(stream); if(result == NULL) { ATfprintf(stderr, "not a valid term\n"); _fail(stream_term); } return result; }
static u2_noun // produce _next(u2_wire wir_r, u2_noun tub) // retain { u2_noun p_tub, q_tub; u2_noun zac; u2_bi_cell(wir_r, tub, &p_tub, &q_tub); if ( u2_no == u2_dust(q_tub) ) { return _fail(wir_r, tub); } else { u2_noun iq_tub = u2_h(q_tub); u2_noun tq_tub = u2_t(q_tub); zac = _slip(wir_r, iq_tub, p_tub); return u2_bc (wir_r, zac, u2_bq(wir_r, u2_nul, u2_rx(wir_r, iq_tub), u2_rx(wir_r, zac), u2_rx(wir_r, tq_tub))); } }
void _subtest(char *name, void *(*func)(void), const char *file, uint line) { uint subtestp; // Push tests status stack if (++current == SUBTEST_MAX_DEPTH) { bail("Too deep subtest nesting. You can change macro SUBTEST_MAX_DEPTH to change this value."); } plan(-1); func(); done_testing(-1); // Pop tests status stack subtestp = current--; assert(current >= 0); if (tests[subtestp].run == 0) { _fail(file, line, "No tests run for subtest \"%s\"", name); } else { __ok((tests[subtestp].run == tests[subtestp].pass), 0, file, line, name, NULL); } }
ATerm SSL_write_term_to_stream_taf(ATerm stream_term, ATerm term) { FILE* stream = stream_from_term(stream_term); if(stream == NULL) _fail(stream_term); ATwriteToSharedTextFile(term, stream); return stream_term; }
/** * ATerm IO on streams */ ATerm SSL_write_term_to_stream_baf(ATerm stream_term, ATerm term) { FILE* stream = stream_from_term(stream_term); if(stream == NULL) _fail(stream_term); ATwriteToBinaryFile(term, stream); return stream_term; }
ATerm SSL_is_int(ATerm t) { if(ATgetType(t) == AT_INT) return(t); else _fail(t); return(t); }
ATerm SSL_isPlaceholder(ATerm t) { int type = ATgetType(t); if(type == AT_PLACEHOLDER) { return t; } else { _fail(t); } }
static crypto_t _setkey(crypto_t c, gchar *key) { gcry_error_t e; gsize keylen; #ifdef _1 g_message("[%s] key=%s", __func__, key); #endif c->cipher.key = (gchar*) crypto_hex2bytes(key, &keylen); if (c->cipher.key == NULL || keylen ==0) { return (_fail(c, g_strdup("crypto_hex2bytes failed: invalid " "hexadecimal string length"))); } #ifdef _1 crypto_dump("c->cipher.key", (guchar*) c->cipher.key, keylen); #endif c->cipher.keylen = gcry_cipher_get_algo_keylen(c->algo); if (c->cipher.keylen ==0) { return (_fail(c, g_strdup_printf("gcry_cipher_get_algo_keylen failed " "c->cipher.keylen=%" G_GSIZE_FORMAT", " "keylen=%" G_GSIZE_FORMAT, c->cipher.keylen, keylen))); } #ifdef _1 if (keylen > c->cipher.keylen) { g_warning("key length exceeds %lu, ignoring the exceeding bytes",keylen); keylen = c->cipher.keylen; } #endif e = gcry_cipher_setkey(c->cipher.h, c->cipher.key, keylen); if (e != 0) { return (_fail(c, g_strdup_printf("gcry_cipher_setkey failed: %s", gpg_strerror(e)))); } c->rc = EXIT_SUCCESS; return (c); }
ATerm SSL_int(ATerm t) { if(ATgetType(t) == AT_INT) return(t); else if(ATgetType(t) == AT_REAL) return((ATerm) ATmakeInt((int)ATgetReal((ATermReal) t))); else _fail(t); return(t); }
static crypto_t _hash_new(crypto_t c, const gchar *algoname) { c->algo = gcry_md_map_name(algoname); if (c->algo ==0) { return (_fail(c, g_strdup_printf("algorithm `%s' was not available", algoname))); } return (c); }
ATerm SSL_modification_time(ATerm file) { struct stat buf; if(!t_is_string(file)) _fail(file); stat(ATgetName(ATgetSymbol(file)), &buf); return (ATerm)ATmakeInt(buf.st_mtime); }