static void bitmap_file_unmap(struct bitmap *bitmap) { struct page **map, *sb_page; unsigned long *attr; int pages; unsigned long flags; spin_lock_irqsave(&bitmap->lock, flags); map = bitmap->filemap; bitmap->filemap = NULL; attr = bitmap->filemap_attr; bitmap->filemap_attr = NULL; pages = bitmap->file_pages; bitmap->file_pages = 0; sb_page = bitmap->sb_page; bitmap->sb_page = NULL; spin_unlock_irqrestore(&bitmap->lock, flags); while (pages--) if (map[pages]->index != 0) /* 0 is sb_page, release it below */ free_buffers(map[pages]); kfree(map); kfree(attr); if (sb_page) free_buffers(sb_page); }
IGL_INLINE void igl::viewer::OpenGL_state::free() { shader_mesh.free(); shader_overlay_lines.free(); shader_overlay_points.free(); free_buffers(); }
int main(int argc, char** argv) { char* mpi_inbuf; char* mpi_outbuf; char* farc_inbuf; char* farc_outbuf; MPI_Init(&argc, &argv); test_start("pack(2, [MPI_INT])"); init_buffers(20*sizeof(int), &mpi_inbuf, &farc_inbuf, &mpi_outbuf, &farc_outbuf); farc::DDT_Init(); farc::Datatype* t1 = new farc::PrimitiveDatatype(farc::PrimitiveDatatype::INT); int res = compare_ddt_info(MPI_INT, t1); farc::DDT_Commit(t1); farc::DDT_Pack(farc_inbuf, farc_outbuf, t1, 2); int position = 0; MPI_Pack(mpi_inbuf, 2, MPI_INT, mpi_outbuf, 20*sizeof(int), &position, MPI_COMM_WORLD); res += compare_buffers(20*sizeof(int), &mpi_inbuf, &farc_inbuf, &mpi_outbuf, &farc_outbuf); free_buffers(&mpi_inbuf, &farc_inbuf, &mpi_outbuf, &farc_outbuf); test_result(res); MPI_Finalize(); return 0; }
void pl_snd_shutdown() { int i; sound_ready = 0; sound_stop = 1; for (i = 0; i < AUDIO_CHANNELS; i++) { if (sound_stream[i].thread_handle != -1) { //sceKernelWaitThreadEnd(sound_stream[i].threadhandle,NULL); sceKernelDeleteThread(sound_stream[i].thread_handle); } sound_stream[i].thread_handle = -1; } for (i = 0; i < AUDIO_CHANNELS; i++) { if (sound_stream[i].sound_ch_handle != -1) { sceAudioOutReleasePort(sound_stream[i].sound_ch_handle); sound_stream[i].sound_ch_handle = -1; } } free_buffers(); }
void manual_query() { char query[1024]; unsigned int qlen; GWBUF** tmpbuf; free_buffers(); printf("Enter query: "); fgets(query,1024,stdin); qlen = strnlen(query, 1024); if((tmpbuf = malloc(sizeof(GWBUF*)))== NULL){ printf("Error: cannot allocate enough memory.\n"); skygw_log_write(LOGFILE_ERROR,"Error: cannot allocate enough memory.\n"); return; } instance.buffer = tmpbuf; instance.buffer_count = 1; instance.buffer[0] = gwbuf_alloc(qlen + 5); gwbuf_set_type(instance.buffer[0],GWBUF_TYPE_MYSQL); memcpy(instance.buffer[0]->sbuf->data + 5,query,qlen); instance.buffer[0]->sbuf->data[0] = (qlen); instance.buffer[0]->sbuf->data[1] = (qlen << 8); instance.buffer[0]->sbuf->data[2] = (qlen << 16); instance.buffer[0]->sbuf->data[3] = 0x00; instance.buffer[0]->sbuf->data[4] = 0x03; }
void BKE_movieclip_reload(MovieClip *clip) { /* clear cache */ free_buffers(clip); clip->tracking.stabilization.ok = false; /* update clip source */ detect_clip_source(clip); clip->lastsize[0] = clip->lastsize[1] = 0; movieclip_load_get_szie(clip); movieclip_calc_length(clip); /* same as for image update -- don't use notifiers because they are not 100% sure to succeeded * (node trees which are not currently visible wouldn't be refreshed) */ { Scene *scene; for (scene = G.main->scene.first; scene; scene = scene->id.next) { if (scene->nodetree) { nodeUpdateID(scene->nodetree, &clip->id); } } } }
/*** * Shuts down the audio systems and frees the buffers. */ void audio_shutdown() { int i; stop_audio = 1; for (i = 0; i < AUDIO_CHANNELS; i++) { if (audio_status[i].ThreadHandle != -1) { sceKernelDeleteThread(audio_status[i].ThreadHandle); } audio_status[i].ThreadHandle = -1; } for (i = 0; i < AUDIO_CHANNELS; i++) { if (audio_status[i].Handle != -1) { sceAudioOutReleasePort(audio_status[i].Handle); audio_status[i].Handle = -1; } } free_buffers(); sceKernelDeleteMutex(audio_mutex); }
int main(int argc, char** argv) { char* mpi_inbuf; char* mpi_outbuf; char* farc_inbuf; char* farc_outbuf; MPI_Init(&argc, &argv); test_start("pack(1, hvector[[int], count=2, blklen=2, stride=-5*sizeof(int)])"); init_buffers(20*sizeof(int), &mpi_inbuf, &farc_inbuf, &mpi_outbuf, &farc_outbuf); farc::DDT_Init(); farc::Datatype* t1 = new farc::PrimitiveDatatype(farc::PrimitiveDatatype::INT); farc::Datatype* t2 = new farc::HVectorDatatype(2, 2, -5*sizeof(int), t1); farc::DDT_Commit(t2); farc::DDT_Pack(farc_inbuf+10*sizeof(int), farc_outbuf, t2, 1); MPI_Datatype newtype; MPI_Type_hvector(2, 2, -5*sizeof(int), MPI_INT, &newtype); MPI_Type_commit(&newtype); int position = 0; MPI_Pack(mpi_inbuf+10*sizeof(int), 1, newtype, mpi_outbuf, 20*sizeof(int), &position, MPI_COMM_WORLD); int res = compare_ddt_info(newtype, t2); res = compare_buffers(20*sizeof(int), &mpi_inbuf, &farc_inbuf, &mpi_outbuf, &farc_outbuf); // inspect_buffers(20*sizeof(int), &mpi_inbuf, &farc_inbuf, &mpi_outbuf, &farc_outbuf); free_buffers(&mpi_inbuf, &farc_inbuf, &mpi_outbuf, &farc_outbuf); test_result(res); MPI_Finalize(); return 0; }
static struct vid_buffer *alloc_buffers(struct v4l2_pix_format *fmt, int *num_bufs) { struct v4l2_requestbuffers req; struct vid_buffer *vb = NULL; int offs[3], stride[3]; int i, j; if (get_plane_fmt(fmt, offs, stride)) return NULL; req.count = *num_bufs; req.type = V4L2_BUF_TYPE_VIDEO_OUTPUT; req.memory = V4L2_MEMORY_MMAP; xioctl(vid_fd, VIDIOC_REQBUFS, &req); if (req.count != *num_bufs) fprintf(stderr, "V4L2: requested %d buffers, got %d\n", *num_bufs, req.count); vb = malloc(req.count * sizeof(*vb)); if (!vb) return NULL; for (i = 0; i < req.count; i++) { struct v4l2_buffer *buf = &vb[i].buf; uint8_t *data; buf->index = i; buf->type = V4L2_BUF_TYPE_VIDEO_OUTPUT; buf->memory = V4L2_MEMORY_MMAP; xioctl(vid_fd, VIDIOC_QUERYBUF, buf); data = mmap(NULL, buf->length, PROT_READ|PROT_WRITE, MAP_SHARED, vid_fd, buf->m.offset); if (data == MAP_FAILED) { perror("mmap"); goto err; } memset(data, 0, buf->length); for (j = 0; j < 3; j++) vb[i].data[j] = data + offs[j]; } *num_bufs = req.count; return vb; err: if (vb) free_buffers(vb, req.count); return NULL; }
static int v4l2_alloc(struct frame_format *ff, unsigned max_mem, struct frame **fr, unsigned *nf) { struct vid_buffer *vb; struct frame *frames; int offs[3], stride[3]; int frame_size; int nframes; int i, j; if (get_plane_fmt(&sfmt.fmt.pix, offs, stride)) return -1; switch (sfmt.fmt.pix.pixelformat) { case V4L2_PIX_FMT_YUV420: frame_size = ff->width * ff->height * 3 / 2; break; case V4L2_PIX_FMT_NV12: frame_size = ff->width * ff->height * 3 / 2; break; case V4L2_PIX_FMT_YUYV: frame_size = ff->width * ff->height * 2; break; default: return -1; } nframes = MAX(max_mem / frame_size, MIN_FRAMES + 1); fprintf(stderr, "V4L2: memman allocating %d frames\n", nframes); vb = alloc_buffers(&sfmt.fmt.pix, &nframes); if (!vb) return -1; frames = calloc(nframes, sizeof(*frames)); if (!frames) goto err; for (i = 0; i < nframes; i++) { frames[i].ff = ff; for (j = 0; j < 3; j++) { frames[i].virt[j] = vb[i].data[j]; frames[i].linesize[j] = stride[j]; } } vid_buffers = vb; *fr = vid_frames = frames; *nf = nframes; return 0; err: free_buffers(vb, nframes); return -1; }
void org_close(void) { int d; org_stop(); free_buffers(); for(d=0;d<NUM_DRUMS;d++) if (drumtable[d].samples) free(drumtable[d].samples); }
HRESULT AllocLAVFrameBuffers(LAVFrame *pFrame, ptrdiff_t stride) { LAVPixFmtDesc desc = getPixelFormatDesc(pFrame->format); if (stride < pFrame->width) { // Ensure alignment of at least 32 on all planes stride = FFALIGN(pFrame->width, 64); } stride *= desc.codedbytes; int alignedHeight = FFALIGN(pFrame->height, 2); memset(pFrame->data, 0, sizeof(pFrame->data)); memset(pFrame->stereo, 0, sizeof(pFrame->stereo)); memset(pFrame->stride, 0, sizeof(pFrame->stride)); for (int plane = 0; plane < desc.planes; plane++) { ptrdiff_t planeStride = stride / desc.planeWidth[plane]; size_t size = planeStride * (alignedHeight / desc.planeHeight[plane]); pFrame->data[plane] = (BYTE *)_aligned_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE, 64); if (pFrame->data[plane] == nullptr) { free_buffers(pFrame); return E_OUTOFMEMORY; } pFrame->stride[plane] = planeStride; } if (pFrame->flags & LAV_FRAME_FLAG_MVC) { for (int plane = 0; plane < desc.planes; plane++) { size_t size = pFrame->stride[plane] * (alignedHeight / desc.planeHeight[plane]); pFrame->stereo[plane] = (BYTE *)_aligned_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE, 64); if (pFrame->stereo[plane] == nullptr) { free_buffers(pFrame); return E_OUTOFMEMORY; } } } pFrame->destruct = &free_buffers; pFrame->flags |= LAV_FRAME_FLAG_BUFFER_MODIFY; return S_OK; }
/* free all memory involved into manipulating with filesystem */ void reiserfs_free (reiserfs_filsys_t fs) { reiserfs_free_bitmap_blocks(fs); /* release super block and memory used by filesystem handler */ brelse (SB_BUFFER_WITH_SB (fs)); free_buffers (); free (fs->file_name); freemem (fs); }
static void cleanup(void) { int i = V4L2_BUF_TYPE_VIDEO_OUTPUT; ioctl(vid_fd, VIDIOC_STREAMOFF, &i); free_buffers(vid_buffers, num_buffers); vid_buffers = NULL; close(vid_fd); vid_fd = -1; pixconv = NULL; }
void RTcmix::close() { rtcmix_debug(NULL, "RTcmix::close entered"); run_status = RT_SHUTDOWN; AudioDevice *dev = audioDevice; audioDevice = NULL; delete dev; audio_config = NO; free_buffers(); #ifdef MULTI_THREAD InputFile::destroyConversionBuffers(); #endif rtcmix_debug(NULL, "RTcmix::close exited"); }
/* * Run performance tests for a number of different sizes and cached/uncached * permutations. */ static int perf_test(void) { const unsigned num_buf_sizes = sizeof(buf_sizes) / sizeof(buf_sizes[0]); unsigned i; int ret; ret = init_buffers(); if (ret != 0) return ret; #if TEST_VALUE_RANGE != 0 /* Setup buf_sizes array, if required */ for (i = 0; i < TEST_VALUE_RANGE; i++) buf_sizes[i] = i; #endif /* See function comment */ do_uncached_write(large_buf_write, 0, small_buf_read, 1, SMALL_BUFFER_SIZE); printf("\n** rte_memcpy() - memcpy perf. tests (C = compile-time constant) **\n" "======= ============== ============== ============== ==============\n" " Size Cache to cache Cache to mem Mem to cache Mem to mem\n" "(bytes) (ticks) (ticks) (ticks) (ticks)\n" "------- -------------- -------------- -------------- --------------"); /* Do tests where size is a variable */ for (i = 0; i < num_buf_sizes; i++) { ALL_PERF_TESTS_FOR_SIZE((size_t)buf_sizes[i]); } printf("\n------- -------------- -------------- -------------- --------------"); /* Do tests where size is a compile-time constant */ ALL_PERF_TESTS_FOR_SIZE(63U); ALL_PERF_TESTS_FOR_SIZE(64U); ALL_PERF_TESTS_FOR_SIZE(65U); ALL_PERF_TESTS_FOR_SIZE(255U); ALL_PERF_TESTS_FOR_SIZE(256U); ALL_PERF_TESTS_FOR_SIZE(257U); ALL_PERF_TESTS_FOR_SIZE(1023U); ALL_PERF_TESTS_FOR_SIZE(1024U); ALL_PERF_TESTS_FOR_SIZE(1025U); ALL_PERF_TESTS_FOR_SIZE(1518U); printf("\n======= ============== ============== ============== ==============\n\n"); free_buffers(); return 0; }
void BKE_movieclip_reload(MovieClip *clip) { /* clear cache */ free_buffers(clip); clip->tracking.stabilization.ok = FALSE; /* update clip source */ if (BLI_testextensie_array(clip->name, imb_ext_movie)) clip->source = MCLIP_SRC_MOVIE; else clip->source = MCLIP_SRC_SEQUENCE; movieclip_calc_length(clip); }
// Destructor for the class. brutefir::~brutefir() { free_buffers(); free_coeff(); // free objects delete m_convolver; delete m_dither; // free configuration structure if (bfconf != NULL) { free(bfconf); bfconf = NULL; } }
void RTcmix::free_globals() { free_buffers(); free_bus_config(); freefuncs(); delete [] rtQueue; rtQueue = NULL; delete rtHeap; rtHeap = NULL; #ifdef MULTI_THREAD delete taskManager; taskManager = NULL; InputFile::destroyConversionBuffers(); #endif }
static int pxa3xx_gcu_remove(struct platform_device *dev) { struct pxa3xx_gcu_priv *priv = platform_get_drvdata(dev); struct resource *r = priv->resource_mem; pxa3xx_gcu_wait_idle(priv); misc_deregister(&priv->misc_dev); dma_free_coherent(&dev->dev, SHARED_SIZE, priv->shared, priv->shared_phys); iounmap(priv->mmio_base); release_mem_region(r->start, resource_size(r)); clk_disable(priv->clk); free_buffers(dev, priv); kfree(priv); return 0; }
void RTcmix::free_globals() { rtcmix_debug(NULL, "RTcmix::free_globals entered"); free_buffers(); free_bus_config(); freefuncs(); delete [] rtQueue; rtQueue = NULL; delete rtHeap; rtHeap = NULL; delete [] inputFileTable; inputFileTable = NULL; delete [] AuxToAuxPlayList; AuxToAuxPlayList = NULL; delete [] ToAuxPlayList; ToAuxPlayList = NULL; delete [] ToOutPlayList; ToAuxPlayList = NULL; delete [] BusConfigs; BusConfigs = NULL; // Reset state of all global vars runToOffset = false; bufOffset = 0; rtsetparams_called = 0; audioLoopStarted = 0; audio_config = 1; elapsed = 0; run_status = RT_GOOD; rtrecord = false; rtfileit = 0; rtoutfile = 0; output_data_format = -1; output_header_type = -1; #ifdef MULTI_THREAD delete taskManager; taskManager = NULL; InputFile::destroyConversionBuffers(); #endif }
static bool init_buffers(void) { int i; // free the old buffers, as we're probably going to change their size here in a sec free_buffers(); /* figure some stuff out real quick about buffer lengths --- */ // convert the ms-per-beat stuff into samples song.samples_per_beat = MSToSamples(song.ms_per_beat); song.note_closing_samples = MSToSamples(song.ms_of_last_beat_of_note); // take the suggestion on cache ahead time (which is in ms) and figure out how many beats that is buffer_beats = (cache_ahead_time / song.ms_per_beat) + 1; if (buffer_beats < 3) buffer_beats = 3; // now figure out how many samples that is. buffer_samples = (buffer_beats * song.samples_per_beat); // now figure out how many bytes THAT is. outbuffer_size_bytes = buffer_samples * 2 * 2; // @ 16-bits, and stereo sound // initilize the per-channel output buffers for(i=0;i<16;i++) { note_channel[i].outbuffer = (signed short *)malloc(outbuffer_size_bytes); note_channel[i].number = i; //memset(note_channel[i].outbuffer, 0, outbuffer_size_bytes); } // initilize the final (mixed) output buffers for(i=0;i<2;i++) { final_buffer[i].samples = (signed short *)malloc(outbuffer_size_bytes); //memset(final_buffer[i].samples, 0, outbuffer_size_bytes); } return 0; }
static char *modulo_operation(char *op1, char *op2, t_op *operation) { char *op_cpy1; char *op_cpy2; char *res1; char *res2; char *res3; if (op2[0] == operation->operands[0]) { my_puterror("Division by zero\n"); return (NULL); } if (epure_sym(op1, op2, &op_cpy1, &op_cpy2, operation->operators[3]) == RETURN_FAILURE) return (NULL); res1 = inf_div(op_cpy1, op_cpy2, operation->operands, operation->operators[3]); res2 = inf_mul(op_cpy2, res1, operation->operands, operation->operators[3]); res3 = inf_sub(op_cpy1, res2, operation->operands, operation->operators[3]); free_buffers(&op_cpy1, &op_cpy2, &res1, &res2); return (res3); }
int main(int argc, char** argv) { char* mpi_inbuf; char* mpi_outbuf; char* farc_inbuf; char* farc_outbuf; MPI_Init(&argc, &argv); test_start("unpack(2, hindexed[{(1*MPI_INT, offset=4), (3*MPI_INT, offset=16), (2*MPI_INT, offset=32)}])"); init_buffers(20*sizeof(int), &mpi_inbuf, &farc_inbuf, &mpi_outbuf, &farc_outbuf); MPI_Datatype mpitype; int blocklen[3] = {1, 3, 2}; MPI_Aint disp[3] = {4, 16, 32}; MPI_Type_create_hindexed(3, blocklen, disp, MPI_INT, &mpitype); MPI_Type_commit(&mpitype); farc::DDT_Init(); farc::Datatype* t1 = new farc::PrimitiveDatatype(farc::PrimitiveDatatype::INT); farc::Datatype* t2 = new farc::HIndexedDatatype(3, blocklen, disp, t1); farc::DDT_Commit(t2); farc::DDT_Unpack(farc_inbuf, farc_outbuf, t2, 2); int position = 0; MPI_Unpack(mpi_inbuf, 20*sizeof(int), &position, mpi_outbuf, 2, mpitype, MPI_COMM_WORLD); int res = compare_buffers(20*sizeof(int), &mpi_inbuf, &farc_inbuf, &mpi_outbuf, &farc_outbuf); free_buffers(&mpi_inbuf, &farc_inbuf, &mpi_outbuf, &farc_outbuf); test_result(res); MPI_Finalize(); return 0; }
/*** * Initializes the audio buffers and a callback thread for each channel. */ int setup_audio() { int i, j, failed; stop_audio = 0; for (i = 0; i < AUDIO_CHANNELS; i++) { audio_status[i].Handle = -1; audio_status[i].ThreadHandle = -1; audio_status[i].LeftVolume = PSP_AUDIO_MAX_VOLUME; audio_status[i].RightVolume = PSP_AUDIO_MAX_VOLUME; audio_status[i].Callback = NULL; audio_status[i].Userdata = NULL; for (j = 0; j < 2; j++) { audio_buffer[i][j] = NULL; audio_buffer_samples[i][j] = 0; } } /* Initialize buffers */ for (i = 0; i < AUDIO_CHANNELS; i++) { for (j = 0; j < 2; j++) { if (!(audio_buffer[i][j] = (short*)malloc(AUDIO_SAMPLE_COUNT * sizeof(PspStereoSample)))) { printf("Couldn't initialize audio buffer for channel %i, bailing.", i); free_buffers(); sceKernelExitProcess(0); return 0; } audio_buffer_samples[i][j] = AUDIO_SAMPLE_COUNT; } } /* Initialize channels */ for (i = 0, failed = 0; i < AUDIO_CHANNELS; i++) { audio_status[i].Handle = sceAudioOutOpenPort(SCE_AUDIO_OUT_PORT_TYPE_VOICE, AUDIO_SAMPLE_COUNT, AUDIO_OUTPUT_RATE, SCE_AUDIO_OUT_MODE_STEREO); if (audio_status[i].Handle < 0) { failed = 1; break; } } if (failed) { for (i = 0; i < AUDIO_CHANNELS; i++) { if (audio_status[i].Handle != -1) { sceAudioOutReleasePort(audio_status[i].Handle); audio_status[i].Handle = -1; } } printf("Couldn't open audio port for the device, bailing."); free_buffers(); sceKernelExitProcess(0); return 0; } char label[16]; strcpy(label, "audiotX"); for (i = 0; i < AUDIO_CHANNELS; i++) { label[6] = '0' + i; audio_status[i].ThreadHandle = sceKernelCreateThread(label, (void*)&audio_channel_thread, 0x10000100, 0x10000, 0, 0, NULL); if (audio_status[i].ThreadHandle < 0) { audio_status[i].ThreadHandle = -1; failed = 1; break; } if (sceKernelStartThread(audio_status[i].ThreadHandle, sizeof(i), &i) != 0) { failed = 1; break; } } if (failed) { stop_audio = 1; for (i = 0; i < AUDIO_CHANNELS; i++) { if (audio_status[i].ThreadHandle != -1) { sceKernelDeleteThread(audio_status[i].ThreadHandle); } audio_status[i].ThreadHandle = -1; } printf("Couldn't initialize audio callback thread. Bailing."); sceKernelExitProcess(0); return 0; } // initialize the buffer our libretro audio callback will fill with data as it's available retro_audio_callback_buffer = (int16_t*)malloc(sizeof(int16_t) * AUDIO_SAMPLE_COUNT * 4); if (!retro_audio_callback_buffer) { printf("Couldn't initialize retro_audio_callback_buffer. Bailing."); sceKernelExitProcess(0); } curr_buffer_frames = 0; // setup our callbacks set_audio_channel_callback(0, audio_callback, 0); // initialize the audio buffer mutex audio_mutex = sceKernelCreateMutex("AudioMutex", 0, 1, 0); return AUDIO_SAMPLE_COUNT; }
void BKE_movieclip_free(MovieClip *clip) { free_buffers(clip); BKE_tracking_free(&clip->tracking); }
void BKE_movieclip_clear_cache(MovieClip *clip) { free_buffers(clip); }
int main(int argc, char *argv[]) { //Filter Out Bad number of arguments if (argc < 3){ printf("[!] Must Specify Arguments\n"); help(argv[0]); return ARGC_FAIL; } CCI_CONTEXT *ctx = malloc(sizeof(CCI_CONTEXT)); memset(ctx,0x0,sizeof(CCI_CONTEXT)); for(int i = 1; i < argc; i++){ if(strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0){ help(argv[0]); free_buffers(ctx); return 0; } else if(strcmp(argv[i], "-i") == 0 || strcmp(argv[i], "--info") == 0) ctx->flags[info] = True; else if(strcmp(argv[i], "-p") == 0 || strcmp(argv[i], "--partition_info") == 0) ctx->flags[part_info] = True; else if(strcmp(argv[i], "-r") == 0 || strcmp(argv[i], "--restore") == 0) ctx->flags[restore] = True; else if(strcmp(argv[i], "-t") == 0 || strcmp(argv[i], "--trim") == 0) ctx->flags[trim] = True; else if(strcmp(argv[i], "-u") == 0 || strcmp(argv[i], "--remove_update") == 0){ ctx->flags[trim] = True; ctx->flags[remove_update_partition] = True; } else if(strcmp(argv[i], "-x") == 0 && ctx->flags[extract] == False && i+1 < (argc - 1)){ ctx->flags[extract] = True; ctx->outfile.arg_len = strlen(argv[i+1]); ctx->outfile.argument = malloc(ctx->outfile.arg_len); if(ctx->outfile.argument == NULL){ puts("[!] MEM ERROR\n"); return Fail; } memcpy(ctx->outfile.argument,argv[i+1],ctx->outfile.arg_len+1); } else if(strncmp(argv[i], "--extract=",10) == 0 && ctx->flags[extract] == False){ ctx->flags[extract] = True; ctx->outfile.arg_len = strlen(argv[i]+10); ctx->outfile.argument = malloc(ctx->outfile.arg_len); if(ctx->outfile.argument == NULL){ puts("[!] MEM ERROR\n"); return Fail; } memcpy(ctx->outfile.argument,argv[i]+10,ctx->outfile.arg_len+1); } else if(i == argc-1){ FILE *cci = fopen(argv[i],"rb"); if(cci == NULL){ printf("[!] Failed to open '%s', last argument must be a CCI file.\n",argv[i]); return Fail; } ctx->cci_file.arg_len = strlen(argv[i]); ctx->cci_file.argument = malloc(ctx->cci_file.arg_len+1); if(ctx->cci_file.argument == NULL){ puts("[!] MEM ERROR\n"); return Fail; } memcpy(ctx->cci_file.argument,argv[i],ctx->cci_file.arg_len+1); fclose(cci); } } if(ctx->flags[restore] == True && ctx->flags[trim] == True){ printf("[!] You cannot trim and restore a CCI at the same time\n"); help(argv[0]); free_buffers(ctx); return 1; } int Action = 0; for(int i = 0; i < 6; i++){ if(ctx->flags[i] == True) Action++; } if(!Action){ printf("[!] Nothing To Do\n"); help(argv[0]); free_buffers(ctx); return 1; } if(NCSDProcess(ctx) != 0) goto fail_cleanup; printf("[*] Completed Successfully\n"); free_buffers(ctx); return 0; fail_cleanup: printf("[!] Failed\n"); free_buffers(ctx); return 1; }
static int __devinit pxa3xx_gcu_probe(struct platform_device *dev) { int i, ret, irq; struct resource *r; struct pxa3xx_gcu_priv *priv; priv = kzalloc(sizeof(struct pxa3xx_gcu_priv), GFP_KERNEL); if (!priv) return -ENOMEM; for (i = 0; i < 8; i++) { ret = add_buffer(dev, priv); if (ret) { dev_err(&dev->dev, "failed to allocate DMA memory\n"); goto err_free_priv; } } init_waitqueue_head(&priv->wait_idle); init_waitqueue_head(&priv->wait_free); spin_lock_init(&priv->spinlock); /* we allocate the misc device structure as part of our own allocation, * so we can get a pointer to our priv structure later on with * container_of(). This isn't really necessary as we have a fixed minor * number anyway, but this is to avoid statics. */ priv->misc_fops.owner = THIS_MODULE; priv->misc_fops.write = pxa3xx_gcu_misc_write; priv->misc_fops.unlocked_ioctl = pxa3xx_gcu_misc_ioctl; priv->misc_fops.mmap = pxa3xx_gcu_misc_mmap; priv->misc_dev.minor = MISCDEV_MINOR, priv->misc_dev.name = DRV_NAME, priv->misc_dev.fops = &priv->misc_fops, /* register misc device */ ret = misc_register(&priv->misc_dev); if (ret < 0) { dev_err(&dev->dev, "misc_register() for minor %d failed\n", MISCDEV_MINOR); goto err_free_priv; } /* handle IO resources */ r = platform_get_resource(dev, IORESOURCE_MEM, 0); if (r == NULL) { dev_err(&dev->dev, "no I/O memory resource defined\n"); ret = -ENODEV; goto err_misc_deregister; } if (!request_mem_region(r->start, resource_size(r), dev->name)) { dev_err(&dev->dev, "failed to request I/O memory\n"); ret = -EBUSY; goto err_misc_deregister; } priv->mmio_base = ioremap_nocache(r->start, resource_size(r)); if (!priv->mmio_base) { dev_err(&dev->dev, "failed to map I/O memory\n"); ret = -EBUSY; goto err_free_mem_region; } /* allocate dma memory */ priv->shared = dma_alloc_coherent(&dev->dev, SHARED_SIZE, &priv->shared_phys, GFP_KERNEL); if (!priv->shared) { dev_err(&dev->dev, "failed to allocate DMA memory\n"); ret = -ENOMEM; goto err_free_io; } /* enable the clock */ priv->clk = clk_get(&dev->dev, NULL); if (IS_ERR(priv->clk)) { dev_err(&dev->dev, "failed to get clock\n"); ret = -ENODEV; goto err_free_dma; } ret = clk_enable(priv->clk); if (ret < 0) { dev_err(&dev->dev, "failed to enable clock\n"); goto err_put_clk; } /* request the IRQ */ irq = platform_get_irq(dev, 0); if (irq < 0) { dev_err(&dev->dev, "no IRQ defined\n"); ret = -ENODEV; goto err_put_clk; } ret = request_irq(irq, pxa3xx_gcu_handle_irq, 0, DRV_NAME, priv); if (ret) { dev_err(&dev->dev, "request_irq failed\n"); ret = -EBUSY; goto err_put_clk; } platform_set_drvdata(dev, priv); priv->resource_mem = r; pxa3xx_gcu_reset(priv); pxa3xx_gcu_init_debug_timer(); dev_info(&dev->dev, "registered @0x%p, DMA 0x%p (%d bytes), IRQ %d\n", (void *) r->start, (void *) priv->shared_phys, SHARED_SIZE, irq); return 0; err_put_clk: clk_disable(priv->clk); clk_put(priv->clk); err_free_dma: dma_free_coherent(&dev->dev, SHARED_SIZE, priv->shared, priv->shared_phys); err_free_io: iounmap(priv->mmio_base); err_free_mem_region: release_mem_region(r->start, resource_size(r)); err_misc_deregister: misc_deregister(&priv->misc_dev); err_free_priv: platform_set_drvdata(dev, NULL); free_buffers(dev, priv); kfree(priv); return ret; }
static void test_communication(void) { int ret; WSADATA wsa_data; SOCKET sock; struct hostent *host; struct sockaddr_in addr; SECURITY_STATUS status; ULONG attrs; SCHANNEL_CRED cred; CredHandle cred_handle; CtxtHandle context; SecPkgCredentials_NamesA names; SecPkgContext_StreamSizes sizes; SecPkgContext_ConnectionInfo conn_info; CERT_CONTEXT *cert; SecBufferDesc buffers[2]; SecBuffer *buf; unsigned buf_size = 4000; unsigned char *data; unsigned data_size; if (!pAcquireCredentialsHandleA || !pFreeCredentialsHandle || !pInitializeSecurityContextA || !pDeleteSecurityContext || !pQueryContextAttributesA || !pDecryptMessage || !pEncryptMessage) { skip("Required secur32 functions not available\n"); return; } /* Create a socket and connect to www.winehq.org */ ret = WSAStartup(0x0202, &wsa_data); if (ret) { skip("Can't init winsock 2.2\n"); return; } host = gethostbyname("www.winehq.org"); if (!host) { skip("Can't resolve www.winehq.org\n"); return; } addr.sin_family = host->h_addrtype; addr.sin_addr = *(struct in_addr *)host->h_addr_list[0]; addr.sin_port = htons(443); sock = socket(host->h_addrtype, SOCK_STREAM, 0); if (sock == SOCKET_ERROR) { skip("Can't create socket\n"); return; } ret = connect(sock, (struct sockaddr *)&addr, sizeof(addr)); if (ret == SOCKET_ERROR) { skip("Can't connect to www.winehq.org\n"); return; } /* Create client credentials */ init_cred(&cred); cred.grbitEnabledProtocols = SP_PROT_TLS1_CLIENT; cred.dwFlags = SCH_CRED_NO_DEFAULT_CREDS|SCH_CRED_MANUAL_CRED_VALIDATION; status = pAcquireCredentialsHandleA(NULL, (SEC_CHAR *)UNISP_NAME_A, SECPKG_CRED_OUTBOUND, NULL, &cred, NULL, NULL, &cred_handle, NULL); ok(status == SEC_E_OK, "AcquireCredentialsHandleA failed: %08x\n", status); if (status != SEC_E_OK) return; /* Initialize the connection */ init_buffers(&buffers[0], 4, buf_size); init_buffers(&buffers[1], 4, buf_size); buffers[0].pBuffers[0].BufferType = SECBUFFER_TOKEN; status = pInitializeSecurityContextA(&cred_handle, NULL, (SEC_CHAR *)"localhost", ISC_REQ_CONFIDENTIALITY|ISC_REQ_STREAM, 0, 0, NULL, 0, &context, &buffers[0], &attrs, NULL); ok(status == SEC_I_CONTINUE_NEEDED, "Expected SEC_I_CONTINUE_NEEDED, got %08x\n", status); buffers[1].cBuffers = 1; buffers[1].pBuffers[0].BufferType = SECBUFFER_TOKEN; buffers[0].pBuffers[0].cbBuffer = 1; memset(buffers[1].pBuffers[0].pvBuffer, 0xfa, buf_size); status = pInitializeSecurityContextA(&cred_handle, &context, (SEC_CHAR *)"localhost", ISC_REQ_CONFIDENTIALITY|ISC_REQ_STREAM, 0, 0, &buffers[1], 0, NULL, &buffers[0], &attrs, NULL); todo_wine ok(status == SEC_E_INVALID_TOKEN, "Expected SEC_E_INVALID_TOKEN, got %08x\n", status); todo_wine ok(buffers[0].pBuffers[0].cbBuffer == 0, "Output buffer size was not set to 0.\n"); buffers[1].cBuffers = 1; buffers[1].pBuffers[0].BufferType = SECBUFFER_TOKEN; buffers[0].pBuffers[0].cbBuffer = 1; memset(buffers[1].pBuffers[0].pvBuffer, 0, buf_size); status = pInitializeSecurityContextA(&cred_handle, &context, (SEC_CHAR *)"localhost", ISC_REQ_CONFIDENTIALITY|ISC_REQ_STREAM, 0, 0, &buffers[1], 0, NULL, &buffers[0], &attrs, NULL); ok(status == SEC_E_INVALID_TOKEN, "Expected SEC_E_INVALID_TOKEN, got %08x\n", status); todo_wine ok(buffers[0].pBuffers[0].cbBuffer == 0, "Output buffer size was not set to 0.\n"); buffers[0].pBuffers[0].cbBuffer = 0; status = pInitializeSecurityContextA(&cred_handle, &context, (SEC_CHAR *)"localhost", ISC_REQ_CONFIDENTIALITY|ISC_REQ_STREAM, 0, 0, &buffers[1], 0, NULL, &buffers[0], &attrs, NULL); todo_wine ok(status == SEC_E_INSUFFICIENT_MEMORY || status == SEC_E_INVALID_TOKEN, "Expected SEC_E_INSUFFICIENT_MEMORY or SEC_E_INVALID_TOKEN, got %08x\n", status); buffers[0].pBuffers[0].cbBuffer = buf_size; status = pInitializeSecurityContextA(&cred_handle, NULL, (SEC_CHAR *)"localhost", ISC_REQ_CONFIDENTIALITY|ISC_REQ_STREAM, 0, 0, NULL, 0, &context, &buffers[0], &attrs, NULL); ok(status == SEC_I_CONTINUE_NEEDED, "Expected SEC_I_CONTINUE_NEEDED, got %08x\n", status); buf = &buffers[0].pBuffers[0]; send(sock, buf->pvBuffer, buf->cbBuffer, 0); buf->cbBuffer = buf_size; status = pInitializeSecurityContextA(&cred_handle, &context, (SEC_CHAR *)"localhost", ISC_REQ_CONFIDENTIALITY|ISC_REQ_STREAM, 0, 0, NULL, 0, NULL, &buffers[0], &attrs, NULL); ok(status == SEC_E_INCOMPLETE_MESSAGE, "Got unexpected status %#x.\n", status); ok(buffers[0].pBuffers[0].cbBuffer == buf_size, "Output buffer size changed.\n"); ok(buffers[0].pBuffers[0].BufferType == SECBUFFER_TOKEN, "Output buffer type changed.\n"); buffers[1].cBuffers = 4; buffers[1].pBuffers[0].cbBuffer = 0; status = pInitializeSecurityContextA(&cred_handle, &context, (SEC_CHAR *)"localhost", ISC_REQ_CONFIDENTIALITY|ISC_REQ_STREAM, 0, 0, &buffers[1], 0, NULL, &buffers[0], &attrs, NULL); ok(status == SEC_E_INCOMPLETE_MESSAGE, "Got unexpected status %#x.\n", status); ok(buffers[0].pBuffers[0].cbBuffer == buf_size, "Output buffer size changed.\n"); ok(buffers[0].pBuffers[0].BufferType == SECBUFFER_TOKEN, "Output buffer type changed.\n"); buf = &buffers[1].pBuffers[0]; buf->cbBuffer = buf_size; ret = receive_data(sock, buf); if (ret == -1) return; buffers[1].pBuffers[0].cbBuffer = 4; status = pInitializeSecurityContextA(&cred_handle, &context, (SEC_CHAR *)"localhost", ISC_REQ_CONFIDENTIALITY|ISC_REQ_STREAM, 0, 0, &buffers[1], 0, NULL, &buffers[0], &attrs, NULL); ok(status == SEC_E_INCOMPLETE_MESSAGE, "Got unexpected status %#x.\n", status); ok(buffers[0].pBuffers[0].cbBuffer == buf_size, "Output buffer size changed.\n"); ok(buffers[0].pBuffers[0].BufferType == SECBUFFER_TOKEN, "Output buffer type changed.\n"); buffers[1].pBuffers[0].cbBuffer = 5; status = pInitializeSecurityContextA(&cred_handle, &context, (SEC_CHAR *)"localhost", ISC_REQ_CONFIDENTIALITY|ISC_REQ_STREAM, 0, 0, &buffers[1], 0, NULL, &buffers[0], &attrs, NULL); ok(status == SEC_E_INCOMPLETE_MESSAGE, "Got unexpected status %#x.\n", status); ok(buffers[0].pBuffers[0].cbBuffer == buf_size, "Output buffer size changed.\n"); ok(buffers[0].pBuffers[0].BufferType == SECBUFFER_TOKEN, "Output buffer type changed.\n"); buffers[1].pBuffers[0].cbBuffer = ret; status = pInitializeSecurityContextA(&cred_handle, &context, (SEC_CHAR *)"localhost", ISC_REQ_CONFIDENTIALITY|ISC_REQ_STREAM, 0, 0, &buffers[1], 0, NULL, &buffers[0], &attrs, NULL); buffers[1].pBuffers[0].cbBuffer = buf_size; while (status == SEC_I_CONTINUE_NEEDED) { buf = &buffers[0].pBuffers[0]; send(sock, buf->pvBuffer, buf->cbBuffer, 0); buf->cbBuffer = buf_size; buf = &buffers[1].pBuffers[0]; ret = receive_data(sock, buf); if (ret == -1) return; buf->BufferType = SECBUFFER_TOKEN; status = pInitializeSecurityContextA(&cred_handle, &context, (SEC_CHAR *)"localhost", ISC_REQ_CONFIDENTIALITY|ISC_REQ_STREAM, 0, 0, &buffers[1], 0, NULL, &buffers[0], &attrs, NULL); buffers[1].pBuffers[0].cbBuffer = buf_size; } ok(status == SEC_E_OK || broken(status == SEC_E_INVALID_TOKEN) /* WinNT */, "InitializeSecurityContext failed: %08x\n", status); if(status != SEC_E_OK) { win_skip("Handshake failed\n"); return; } status = pQueryCredentialsAttributesA(&cred_handle, SECPKG_CRED_ATTR_NAMES, &names); ok(status == SEC_E_NO_CREDENTIALS || status == SEC_E_UNSUPPORTED_FUNCTION /* before Vista */, "expected SEC_E_NO_CREDENTIALS, got %08x\n", status); status = pQueryContextAttributesA(&context, SECPKG_ATTR_REMOTE_CERT_CONTEXT, (void*)&cert); ok(status == SEC_E_OK, "QueryContextAttributesW(SECPKG_ATTR_REMOTE_CERT_CONTEXT) failed: %08x\n", status); if(status == SEC_E_OK) { test_remote_cert(cert); CertFreeCertificateContext(cert); } status = pQueryContextAttributesA(&context, SECPKG_ATTR_CONNECTION_INFO, (void*)&conn_info); ok(status == SEC_E_OK, "QueryContextAttributesW(SECPKG_ATTR_CONNECTION_INFO) failed: %08x\n", status); if(status == SEC_E_OK) { ok(conn_info.dwCipherStrength >= 128, "conn_info.dwCipherStrength = %d\n", conn_info.dwCipherStrength); ok(conn_info.dwHashStrength >= 128, "conn_info.dwHashStrength = %d\n", conn_info.dwHashStrength); } status = pQueryContextAttributesA(&context, SECPKG_ATTR_STREAM_SIZES, &sizes); ok(status == SEC_E_OK, "QueryContextAttributesW(SECPKG_ATTR_STREAM_SIZES) failed: %08x\n", status); reset_buffers(&buffers[0]); /* Send a simple request so we get data for testing DecryptMessage */ buf = &buffers[0].pBuffers[0]; data = buf->pvBuffer; buf->BufferType = SECBUFFER_STREAM_HEADER; buf->cbBuffer = sizes.cbHeader; ++buf; buf->BufferType = SECBUFFER_DATA; buf->pvBuffer = data + sizes.cbHeader; buf->cbBuffer = sizeof(http_request) - 1; memcpy(buf->pvBuffer, http_request, sizeof(http_request) - 1); ++buf; buf->BufferType = SECBUFFER_STREAM_TRAILER; buf->pvBuffer = data + sizes.cbHeader + sizeof(http_request) -1; buf->cbBuffer = sizes.cbTrailer; status = pEncryptMessage(&context, 0, &buffers[0], 0); ok(status == SEC_E_OK, "EncryptMessage failed: %08x\n", status); if (status != SEC_E_OK) return; buf = &buffers[0].pBuffers[0]; send(sock, buf->pvBuffer, buffers[0].pBuffers[0].cbBuffer + buffers[0].pBuffers[1].cbBuffer + buffers[0].pBuffers[2].cbBuffer, 0); reset_buffers(&buffers[0]); buf->cbBuffer = buf_size; data_size = receive_data(sock, buf); /* Too few buffers */ --buffers[0].cBuffers; status = pDecryptMessage(&context, &buffers[0], 0, NULL); ok(status == SEC_E_INVALID_TOKEN, "Expected SEC_E_INVALID_TOKEN, got %08x\n", status); /* No data buffer */ ++buffers[0].cBuffers; status = pDecryptMessage(&context, &buffers[0], 0, NULL); ok(status == SEC_E_INVALID_TOKEN, "Expected SEC_E_INVALID_TOKEN, got %08x\n", status); /* Two data buffers */ buffers[0].pBuffers[0].BufferType = SECBUFFER_DATA; buffers[0].pBuffers[1].BufferType = SECBUFFER_DATA; status = pDecryptMessage(&context, &buffers[0], 0, NULL); ok(status == SEC_E_INVALID_TOKEN, "Expected SEC_E_INVALID_TOKEN, got %08x\n", status); /* Too few empty buffers */ buffers[0].pBuffers[1].BufferType = SECBUFFER_EXTRA; status = pDecryptMessage(&context, &buffers[0], 0, NULL); ok(status == SEC_E_INVALID_TOKEN, "Expected SEC_E_INVALID_TOKEN, got %08x\n", status); /* Incomplete data */ buffers[0].pBuffers[1].BufferType = SECBUFFER_EMPTY; buffers[0].pBuffers[0].cbBuffer = (data[3]<<8) | data[4]; status = pDecryptMessage(&context, &buffers[0], 0, NULL); ok(status == SEC_E_INCOMPLETE_MESSAGE, "Expected SEC_E_INCOMPLETE_MESSAGE, got %08x\n", status); ok(buffers[0].pBuffers[0].BufferType == SECBUFFER_MISSING, "Expected first buffer to be SECBUFFER_MISSING\n"); ok(buffers[0].pBuffers[0].cbBuffer == 5, "Expected first buffer to be a five bytes\n"); buffers[0].pBuffers[0].cbBuffer = data_size; buffers[0].pBuffers[0].BufferType = SECBUFFER_DATA; buffers[0].pBuffers[1].BufferType = SECBUFFER_EMPTY; status = pDecryptMessage(&context, &buffers[0], 0, NULL); ok(status == SEC_E_OK, "DecryptMessage failed: %08x\n", status); if (status == SEC_E_OK) { ok(buffers[0].pBuffers[0].BufferType == SECBUFFER_STREAM_HEADER, "Expected first buffer to be SECBUFFER_STREAM_HEADER\n"); ok(buffers[0].pBuffers[1].BufferType == SECBUFFER_DATA, "Expected second buffer to be SECBUFFER_DATA\n"); ok(buffers[0].pBuffers[2].BufferType == SECBUFFER_STREAM_TRAILER, "Expected third buffer to be SECBUFFER_STREAM_TRAILER\n"); data = buffers[0].pBuffers[1].pvBuffer; data[buffers[0].pBuffers[1].cbBuffer] = 0; } pDeleteSecurityContext(&context); pFreeCredentialsHandle(&cred_handle); free_buffers(&buffers[0]); free_buffers(&buffers[1]); closesocket(sock); }