static void print_params(compile_t* c, printbuf_t* buf, ast_t* params) { ast_t* param = ast_child(params); while(param != NULL) { AST_GET_CHILDREN(param, id, ptype); // Print the parameter. printbuf(buf, ", "); print_type_name(c, buf, ptype); // Smash trailing primes to underscores. const char* name = ast_name(id); size_t len = strlen(name) + 1; size_t buf_size = len; char* buffer = (char*)ponyint_pool_alloc_size(buf_size); memcpy(buffer, name, len); len--; while(buffer[--len] == '\'') buffer[len] = '_'; printbuf(buf, " %s", buffer); param = ast_sibling(param); ponyint_pool_free_size(buf_size, buffer); } }
static void print_typeexpr(printbuf_t* buffer, ast_t* type, const char* sep, bool square) { if(square) printbuf(buffer, "["); else printbuf(buffer, "("); ast_t* child = ast_child(type); while(child != NULL) { ast_t* next = ast_sibling(child); print_type(buffer, child); if(next != NULL) printbuf(buffer, "%s", sep); child = next; } if(square) printbuf(buffer, "]"); else printbuf(buffer, ")"); }
/* * lanplus_encrypt_aes_cbc_128 * * Encrypt with the AES CBC 128 algorithm * * param iv is the 16 byte initialization vector * param key is the 16 byte key used by the AES algorithm * param input is the data to be encrypted * param input_length is the number of bytes to be encrypted. This MUST * be a multiple of the block size, 16. * param output is the encrypted output * param bytes_written is the number of bytes written. This param is set * to 0 on failure, or if 0 bytes were input. */ void lanplus_encrypt_aes_cbc_128(const uint8_t * iv, const uint8_t * key, const uint8_t * input, uint32_t input_length, uint8_t * output, uint32_t * bytes_written) { EVP_CIPHER_CTX ctx; EVP_CIPHER_CTX_init(&ctx); EVP_EncryptInit_ex(&ctx, EVP_aes_128_cbc(), NULL, key, iv); EVP_CIPHER_CTX_set_padding(&ctx, 0); *bytes_written = 0; if (input_length == 0) return; if (verbose >= 5) { printbuf(iv, 16, "encrypting with this IV"); printbuf(key, 16, "encrypting with this key"); printbuf(input, input_length, "encrypting this data"); } /* * The default implementation adds a whole block of padding if the input * data is perfectly aligned. We would like to keep that from happening. * We have made a point to have our input perfectly padded. */ assert((input_length % IPMI_CRYPT_AES_CBC_128_BLOCK_SIZE) == 0); if(!EVP_EncryptUpdate(&ctx, output, (int *)bytes_written, input, input_length)) { /* Error */ *bytes_written = 0; return; } else { uint32_t tmplen; if(!EVP_EncryptFinal_ex(&ctx, output + *bytes_written, (int *)&tmplen)) { *bytes_written = 0; return; /* Error */ } else { /* Success */ *bytes_written += tmplen; EVP_CIPHER_CTX_cleanup(&ctx); } } }
static const char* make_mangled_name(reach_method_t* m) { // Generate the mangled name. // cap_name[_Arg1_Arg2]_args_result printbuf_t* buf = printbuf_new(); printbuf(buf, "%s_", m->name); for(size_t i = 0; i < m->param_count; i++) printbuf(buf, "%s", m->params[i].type->mangle); printbuf(buf, "%s", m->result->mangle); const char* name = stringtab(buf->m); printbuf_free(buf); return name; }
static void print_base_type(compile_t* c, printbuf_t* buf, ast_t* type) { if(ast_id(type) == TK_NOMINAL) { const char* name = genname_type(type); const char* c_name = c_type_name(c, name); if(c_name != NULL) printbuf(buf, c_name); else printbuf(buf, "%s*", name); } else { printbuf(buf, "void*"); } }
static size_t deflate_write(SDL_RWops *rw, const void *ptr, size_t size, size_t maxnum) { ZData *z = ZDATA(rw); size_t totalsize = size * maxnum; size_t available; size_t remaining = totalsize; size_t offset = 0; while(remaining) { available = z->buffer_size - (z->buffer_ptr - z->buffer); size_t copysize = remaining > available ? available : remaining; PRINT("avail = %lu; copysize = %lu\n", available, copysize); if(available) { remaining -= copysize; memcpy(z->buffer_ptr, (uint8_t*)ptr + offset, copysize); printbuf(z->buffer_ptr, copysize); offset += copysize; z->buffer_ptr += copysize; z->pos += copysize; } else { deflate_flush(z); } } return maxnum; }
int mymain(void) { char buf[512]; puts("sd init begin\n"); // uart_init(); SDHC_Init(); puts("sd init over\n"); SDHC_ReadBlocks(0x1, 1, (unsigned int)buf); printbuf(buf, 512); SDHC_ReadBlocks(0x1dc000, 1, (unsigned int)buf); printbuf(buf, 512); return 0; }
static void printwhere (void) { int i; char c; int cnt; printbuf (); for (i = 0; i < where - curline; i++) { c = curline[i]; if (c == '\t') { cnt = 8 - (i % TABSIZE); } else { cnt = 1; } while (cnt--) { (void) fputc ('^', stderr); } } (void) fputc ('\n', stderr); }
static void print_types(compile_t* c, FILE* fp, printbuf_t* buf) { size_t i = HASHMAP_BEGIN; reachable_type_t* t; while((t = reachable_types_next(c->reachable, &i)) != NULL) { // Print the docstring if we have one. ast_t* def = (ast_t*)ast_data(t->ast); ast_t* docstring = ast_childidx(def, 6); if(ast_id(docstring) == TK_STRING) fprintf(fp, "/*\n%s*/\n", ast_name(docstring)); if(!is_pointer(t->ast) && !is_maybe(t->ast) && !is_machine_word(t->ast)) { // Forward declare an opaque type. fprintf(fp, "typedef struct %s %s;\n\n", t->name, t->name); // Function signature for the allocator. printbuf(buf, "/* Allocate a %s without initialising it. */\n%s* %s_Alloc();\n\n", t->name, t->name, t->name ); } print_methods(c, t, buf); } }
const char* genname_fun(token_id cap, const char* name, ast_t* typeargs) { // cap_name[_Arg1_Arg2] printbuf_t* buf = printbuf_new(); printbuf(buf, "%s_%s", lexer_print(cap), name); types_append(buf, typeargs); return stringtab_buf(buf); }
void bufchar(char c) { if(c == '\n' || c == '\r') { if(m_buf != "") printbuf(); m_buf = ""; return; } m_buf += c; }
static const char* stringtab_two(const char* a, const char* b) { if(a == NULL) a = "_"; assert(b != NULL); printbuf_t* buf = printbuf_new(); printbuf(buf, "%s_%s", a, b); return stringtab_buf(buf); }
static const char* make_full_name(reach_type_t* t, reach_method_t* m) { // Generate the full mangled name. // pkg_Type[_Arg1_Arg2]_cap_name[_Arg1_Arg2]_args_result printbuf_t* buf = printbuf_new(); printbuf(buf, "%s_%s", t->name, m->mangled_name); const char* name = stringtab(buf->m); printbuf_free(buf); return name; }
int zset_rank(ldb_context_t* context, const ldb_slice_t* name, const ldb_slice_t* key, int reverse, uint64_t* rank){ int retval = 0; ldb_zset_iterator_t *iterator = NULL; if(reverse == 0){ iterator = ziterator(context, name, NULL, LDB_SCORE_MIN, LDB_SCORE_MAX, INT32_MAX, FORWARD); }else{ iterator = ziterator(context, name, NULL, LDB_SCORE_MAX, LDB_SCORE_MIN, INT32_MAX, BACKWARD); } ldb_slice_t *slice_key = NULL; uint64_t tmp = 0; while(1){ if(!ldb_zset_iterator_valid(iterator)){ retval = LDB_OK_NOT_EXIST; goto end; } int64_t score = 0; size_t raw_klen = 0; const char* raw_key = ldb_zset_iterator_key_raw(iterator, &raw_klen); if(decode_zscore_key(raw_key, raw_klen, NULL, &slice_key, &score)<0){ retval = LDB_OK_NOT_EXIST; goto end; } size_t raw_vlen =0; const char* raw_val = ldb_zset_iterator_val_raw(iterator, &raw_vlen); assert(raw_vlen >= LDB_VAL_META_SIZE); uint8_t type = leveldb_decode_fixed8(raw_val); if((type & LDB_VALUE_TYPE_VAL)&& !(type & LDB_VALUE_TYPE_LAT)){ printf("%s, score=%ld\n", __func__, score); printbuf(raw_key, raw_klen); if(compare_with_length(ldb_slice_data(key), ldb_slice_size(key), ldb_slice_data(slice_key), ldb_slice_size(slice_key))==0){ ldb_slice_destroy(slice_key); retval = LDB_OK; break; } ++tmp; } ldb_slice_destroy(slice_key); if(ldb_zset_iterator_next(iterator)){ retval = LDB_OK_NOT_EXIST; goto end; } } *rank = tmp; end: ldb_zset_iterator_destroy(iterator); return retval; }
static void print_method(compile_t* c, printbuf_t* buf, reach_type_t* t, reach_method_t* m) { if(!emit_fun(m->r_fun)) return; AST_GET_CHILDREN(m->r_fun, cap, id, typeparams, params, rtype, can_error, body, docstring); // Print the docstring if we have one. if(ast_id(docstring) == TK_STRING) { printbuf(buf, "/*\n" "%s" "*/\n", ast_name(docstring) ); } // Print the function signature. if((ast_id(cap) != TK_AT) || !is_none(rtype)) print_type_name(c, buf, rtype); else printbuf(buf, "void"); printbuf(buf, " %s", m->full_name); switch(ast_id(m->r_fun)) { case TK_NEW: case TK_BE: { ast_t* def = (ast_t*)ast_data(t->ast); if(ast_id(def) == TK_ACTOR) printbuf(buf, "__send"); break; } default: {} } printbuf(buf, "("); if(ast_id(cap) != TK_AT) { print_type_name(c, buf, t->ast); printbuf(buf, " self"); print_params(c, buf, params, true); } else { print_params(c, buf, params, false); } printbuf(buf, ");\n\n"); }
static void print_type_name(compile_t* c, printbuf_t* buf, ast_t* type) { if(is_pointer(type) || is_maybe(type)) { int depth = print_pointer_type(c, buf, type); for(int i = 0; i < depth; i++) printbuf(buf, "*"); } else { print_base_type(c, buf, type); } }
static void print_method(compile_t* c, printbuf_t* buf, reachable_type_t* t, const char* name, ast_t* typeargs) { const char* funname = genname_fun(t->name, name, typeargs); LLVMValueRef func = LLVMGetNamedFunction(c->module, funname); if(func == NULL) return; // Get a reified function. ast_t* fun = get_fun(t->ast, name, typeargs); if(fun == NULL) return; AST_GET_CHILDREN(fun, cap, id, typeparams, params, rtype, can_error, body, docstring); // Print the docstring if we have one. if(ast_id(docstring) == TK_STRING) { printbuf(buf, "/*\n" "%s" "*/\n", ast_name(docstring) ); } // Print the function signature. print_type_name(c, buf, rtype); printbuf(buf, " %s", funname); switch(ast_id(fun)) { case TK_NEW: case TK_BE: { ast_t* def = (ast_t*)ast_data(t->ast); if(ast_id(def) == TK_ACTOR) printbuf(buf, "__send"); break; } default: {} } printbuf(buf, "("); print_type_name(c, buf, t->ast); printbuf(buf, " self"); print_params(c, buf, params); printbuf(buf, ");\n\n"); ast_free_unattached(fun); }
static reach_type_t* add_tuple(reach_t* r, ast_t* type, pass_opt_t* opt) { if(contains_dontcare(type)) return NULL; reach_type_t* t = reach_type(r, type); if(t != NULL) return t; t = add_reach_type(r, type); t->underlying = TK_TUPLETYPE; t->type_id = r->next_type_id++; t->field_count = (uint32_t)ast_childcount(t->ast); t->fields = (reach_field_t*)calloc(t->field_count, sizeof(reach_field_t)); printbuf_t* mangle = printbuf_new(); printbuf(mangle, "%d", t->field_count); ast_t* child = ast_child(type); size_t index = 0; while(child != NULL) { t->fields[index].ast = ast_dup(child); t->fields[index].type = add_type(r, child, opt); printbuf(mangle, "%s", t->fields[index].type->mangle); index++; child = ast_sibling(child); } t->mangle = stringtab(mangle->m); printbuf_free(mangle); return t; }
void xfer(int from, int to) { uchar buf[4096]; int i, n, modified, ok, total, errs, dropped; if(fork() == 0) return; total = ok = errs = dropped = 0; for(;;){ n = read(from, buf, sizeof(buf)); if(n <= 0){ fprint(2, "%d -> %d EOF\n", from, to); exits(0); } modified = 0; if(errrate){ for(i = 0; i < n; i++){ if(lnrand(errrate) == 0){ buf[i] ^= 0xff; modified = 1; } } } if(droprate && lnrand(droprate) == 0){ fprint(2, "!!!!!!!!!!!!!!%d -> %d dropped %d (%d/%d)\n", from, to, ok, dropped, total); ok = 0; dropped++; total++; continue; } if(modified){ fprint(2, "!!!!!!!!!!!!!!%d -> %d %d (%d/%d)\n", from, to, ok, errs, total); ok = 0; errs++; } else ok++; total++; if(debug > 1){ fprint(2, "%d -> %d (%d)", from, to, n); printbuf(buf, n); } n = write(to, buf, n); if(n < 0){ fprint(2, "%d -> %d write err\n", from, to); exits(0); } } }
void send_sequence(char *seq, int len ) { int transfered; int r; printbuf(seq, len ); libusb_bulk_transfer(sr16_devh, 2, seq, len, &transfered, 3000 ); if ( r ) { perror("libusb_bulk_transfer"); } }
static void types_append(printbuf_t* buf, ast_t* elements) { // _Arg1_Arg2 if(elements == NULL) return; ast_t* elem = ast_child(elements); while(elem != NULL) { printbuf(buf, "_"); type_append(buf, elem, false); elem = ast_sibling(elem); } }
static size_t inflate_read(SDL_RWops *rw, void *ptr, size_t size, size_t maxnum) { ZData *z = ZDATA(rw); size_t totalsize = size * maxnum; int ret = Z_OK; if(!totalsize) { return 0; } z->stream->avail_out = totalsize; z->stream->next_out = ptr; PRINT("inflate_read()\n"); while(z->stream->avail_out && ret != Z_STREAM_END) { z->stream->avail_in = z->buffer_fillsize - (z->buffer_ptr - z->buffer); if(!z->stream->avail_in) { z->buffer_fillsize = SDL_RWread(z->wrapped, z->buffer, 1, z->buffer_size); z->buffer_ptr = z->buffer; z->stream->avail_in = z->buffer_fillsize - (z->buffer_ptr - z->buffer); } z->stream->next_in = z->buffer_ptr; PRINT(" -- begin read %i --- \n", z->stream->avail_in); printbuf(z->stream->next_in, z->stream->avail_in); PRINT(" -- end read --- \n"); switch(ret = inflate(z->stream, Z_NO_FLUSH)) { case Z_OK: case Z_STREAM_END: PRINT("read ok\n"); break; default: PRINT("inflate error: %i\n", ret); SDL_SetError("inflate error: %i", ret); ret = Z_STREAM_END; break; } z->buffer_ptr = z->stream->next_in; } z->pos += (totalsize - z->stream->avail_out); return (totalsize - z->stream->avail_out) / size; }
void *producer(void *param) { printf("start producer...\n"); while(1) { pthread_mutex_lock(&mutex); if (((in + 1) % BUFFER_SIZE != out)) { int d = genrnd(10); in = (in + 1) % BUFFER_SIZE; buffer[in] = d; printf("produce %d ", d); printbuf(); } pthread_mutex_unlock(&mutex); usleep(genrnd(10000)); } }
void *consumer(void *param) { printf("start consumer...\n"); while(1) { pthread_mutex_lock(&mutex); if (out != in) { out = (out + 1) % BUFFER_SIZE; int d = buffer[out]; buffer[out] = -1; printf("consume %d ", d); printbuf(); } pthread_mutex_unlock(&mutex); usleep(genrnd(10000)); } }
static void type_append(printbuf_t* buf, ast_t* type, bool first) { switch(ast_id(type)) { case TK_UNIONTYPE: { // u3_Arg1_Arg2_Arg3 printbuf(buf, "u%d", ast_childcount(type)); types_append(buf, type); return; } case TK_ISECTTYPE: { // i3_Arg1_Arg2_Arg3 printbuf(buf, "i%d", ast_childcount(type)); types_append(buf, type); return; } case TK_TUPLETYPE: { // t3_Arg1_Arg2_Arg3 printbuf(buf, "t%d", ast_childcount(type)); types_append(buf, type); return; } case TK_NOMINAL: { // pkg_Type[_Arg1_Arg2]_cap AST_GET_CHILDREN(type, package, name, typeargs, cap, eph); ast_t* def = (ast_t*)ast_data(type); ast_t* pkg = ast_nearest(def, TK_PACKAGE); const char* pkg_name = package_symbol(pkg); if(pkg_name != NULL) printbuf(buf, "%s_", pkg_name); printbuf(buf, "%s", ast_name(name)); types_append(buf, typeargs); if(!first) printbuf(buf, "_%s", ast_get_print(cap)); return; } default: {} } assert(0); }
static struct ipmi_rs * ipmi_pef_msg_exchange(struct ipmi_intf * intf, struct ipmi_rq * req, char * txt) { /* // common IPMItool rqst/resp handling */ struct ipmi_rs * rsp = intf->sendrecv(intf, req); if (!rsp) return(NULL); if (rsp->ccode) { lprintf(LOG_ERR, " **Error %x in '%s' command", rsp ? rsp->ccode : 0, txt); return(NULL); } if (verbose > 2) printbuf(rsp->data, rsp->data_len, txt); return(rsp); }
void CDEnet_end_send(struct tcb* tcp) { int sockfd = tcp->u_arg[0]; if (CDE_provenance_mode && CDE_network_content_mode && isProvCapturedSock(sockfd)) { vb(2); if (socket_data_handle(tcp, SOCK_SEND) < 0) { // TODO } } if (CDE_nw_mode && db_isCapturedSock(currdb, sockfd)) { vb(2); if (CDE_verbose_mode >= 3) { char buff[KEYLEN]; size_t buflength = tcp->u_arg[2]; if (umoven(tcp, tcp->u_arg[1], buflength, buff) < 0) { return; } buff[tcp->u_arg[2]] = '\0'; vbp(3, "action %d [%ld] checksum %u ", SOCK_SEND, tcp->u_arg[2], checksum(buff, buflength)); if (CDE_verbose_mode >= 3) printbuf(buff, buflength); } long pid = tcp->pid; char *pidkey, *sockid; db_get_pid_sock(currdb, pid, sockfd, &pidkey, &sockid); if (pidkey == NULL || sockid == NULL) { vbp(0, "error"); return; } ull_t sendid = db_getPkgCounterInc(currdb, pidkey, sockid, SOCK_SEND); char* prov_pid = getMappedPid(pidkey); // convert this pid to corresponding prov_pid ull_t u_rval; db_getSendRecvResult(netdb, SOCK_SEND, prov_pid, sockid, sendid, &u_rval, NULL); // get recorded result struct user_regs_struct regs; EXITIF(ptrace(PTRACE_GETREGS, pid, NULL, ®s)<0); SET_RETURN_CODE(®s, u_rval); if (u_rval < 0) { // set errno? TODO } EXITIF(ptrace(PTRACE_SETREGS, pid, NULL, ®s)<0); free(prov_pid); free(sockid); free(pidkey); } }
int main() { char c, input = 0; init_buffer(); while ('q' != input) { printf("enter action (p=put,g=get,y=print,q=quit): "); scanf("\n%c", &input); switch(input) { case 'p': printf(" enter character to put: "); scanf("\n%c", &input); put(input); break; case 'g': c = get(); if (!c) { printf(" can't get from empty buffer.\n"); } else { printf(" character removed is: %c\n",c); } break; case 'y': printbuf(); break; case 'q': break; default: printf(" unrecognized action\n"); break; } } return 0; }
int main() { /* Initialize values which can't use static initializers. */ asn_long2INTEGER(&otp_format, 2); /* Alphanumeric */ asn_long2INTEGER(&kvno, 5); OBJECT_IDENTIFIER_set_arcs(&alg_sha256.algorithm, sha256_arcs, sizeof(*sha256_arcs), sizeof(sha256_arcs) / sizeof(*sha256_arcs)); OBJECT_IDENTIFIER_set_arcs(&alg_sha1.algorithm, sha1_arcs, sizeof(*sha1_arcs), sizeof(sha1_arcs) / sizeof(*sha1_arcs)); printf("Minimal OTP-TOKEN-INFO:\n"); der_encode(&asn_DEF_OTP_TOKENINFO, &token_info_1, consume, NULL); printbuf(); printf("\nMaximal OTP-TOKEN-INFO:\n"); der_encode(&asn_DEF_OTP_TOKENINFO, &token_info_2, consume, NULL); printbuf(); printf("\nMinimal PA-OTP-CHALLENGE:\n"); der_encode(&asn_DEF_PA_OTP_CHALLENGE, &challenge_1, consume, NULL); printbuf(); printf("\nMaximal PA-OTP-CHALLENGE:\n"); der_encode(&asn_DEF_PA_OTP_CHALLENGE, &challenge_2, consume, NULL); printbuf(); printf("\nMinimal PA-OTP-REQUEST:\n"); der_encode(&asn_DEF_PA_OTP_REQUEST, &request_1, consume, NULL); printbuf(); printf("\nMaximal PA-OTP-REQUEST:\n"); der_encode(&asn_DEF_PA_OTP_REQUEST, &request_2, consume, NULL); printbuf(); printf("\nPA-OTP-ENC-REQUEST:\n"); der_encode(&asn_DEF_PA_OTP_ENC_REQUEST, &enc_request, consume, NULL); printbuf(); printf("\n"); return 0; }
// FIG 0/14 FEC sub-channel organization // ETSI EN 300 401 6.2.2 bool fig0_14(fig0_common_t& fig0, int indent) { uint8_t i = 1, SubChId, FEC_scheme; uint8_t* f = fig0.f; char desc[256]; bool complete = false; while (i < fig0.figlen) { // iterate over Sub-channel SubChId = f[i] >> 2; complete |= fig0_14_is_complete(SubChId); FEC_scheme = f[i] & 0x3; sprintf(desc, "SubChId=0x%X, FEC scheme=%d %s", SubChId, FEC_scheme, FEC_schemes_str[FEC_scheme]); printbuf(desc, indent+1, NULL, 0); i++; } return complete; }