char * Digest_File(CCDigestAlg algorithm, const char *filename, char *buf) { int fd; __block CCDigestCtx ctx; dispatch_queue_t queue; dispatch_semaphore_t sema; dispatch_io_t io; __block int s_error = 0; /* dispatch_io_create_with_path requires an absolute path */ fd = open(filename, O_RDONLY); if (fd < 0) { return NULL; } (void)fcntl(fd, F_NOCACHE, 1); (void)osx_assumes_zero(CCDigestInit(algorithm, &ctx)); queue = dispatch_queue_create("com.apple.mtree.io", NULL); osx_assert(queue); sema = dispatch_semaphore_create(0); osx_assert(sema); io = dispatch_io_create(DISPATCH_IO_STREAM, fd, queue, ^(int error) { if (error != 0) { s_error = error; } (void)close(fd); (void)dispatch_semaphore_signal(sema); });
void osx_tlsche_stepforward( TiOsxTimeLineScheduler * sche, uint16 slicecount ) { uint8 i; TiOsxTaskHeap * heap = &(sche->taskheap); for (i=0; i<osx_taskheap_count(heap); i++) { osx_assert( heap->items[i] != NULL ); heap->items[i]->timeline -= slicecount; } }
char * Digest_End(CCDigestRef ctx, char *buf) { static const char hex[] = "0123456789abcdef"; uint8_t digest[32]; // SHA256 is the biggest size_t i, length; (void)osx_assumes_zero(CCDigestFinal(ctx, digest)); length = CCDigestOutputSize(ctx); osx_assert(length <= sizeof(digest)); for (i = 0; i < length; i++) { buf[i+i] = hex[digest[i] >> 4]; buf[i+i+1] = hex[digest[i] & 0x0f]; } buf[i+i] = '\0'; return buf; }
// Old compiler SPI static void _Block_byref_release(const void *arg) { struct Block_byref *byref = (struct Block_byref *)arg; int32_t refcount; // dereference the forwarding pointer since the compiler isn't doing this anymore (ever?) byref = byref->forwarding; // To support C++ destructors under GC we arrange for there to be a finalizer for this // by using an isa that directs the code to a finalizer that calls the byref_destroy method. if ((byref->flags & BLOCK_BYREF_NEEDS_FREE) == 0) { return; // stack or GC or global } refcount = byref->flags & BLOCK_REFCOUNT_MASK; osx_assert(refcount); if (latching_decr_int_should_deallocate(&byref->flags)) { if (byref->flags & BLOCK_BYREF_HAS_COPY_DISPOSE) { struct Block_byref_2 *byref2 = (struct Block_byref_2 *)(byref+1); (*byref2->byref_destroy)(byref); } _Block_deallocator((struct Block_layout *)byref); } }
TiOsxTaskPool * osx_taskpool_construct( char * mem, uint16 memsize ) { TiOsxTaskPool * tpl = (TiOsxTaskPool *)mem; TiOsxTaskPoolItem * item; int8 i; memset( mem, 0x00, memsize ); //tpl->capacity = (memsize - sizeof(TiOsxPool)) / sizeof(TiOsxTaskPoolItem); tpl->count = 0; //tpl->allocated = -1; tpl->emptylist = 0; osx_assert( CONFIG_OSX_TASKPOOL_CAPACITY > 0 ); item = _osx_taskpool_items( tpl ); for (i=0; i<CONFIG_OSX_TASKPOOL_CAPACITY; i++) { item[i].state = 0; item[i].taskid = i; item[i].taskfunction = NULL; item[i].taskdata = NULL; item[i].timeline = 0; item[i].deadline = 0; item[i].heapindex = i; //item[i].itemprev = -1; } // build the empty list for (i=0; i<CONFIG_OSX_TASKPOOL_CAPACITY-1; i++) { item[i].itemnext = i+1; } item[CONFIG_OSX_TASKPOOL_CAPACITY - 1].itemnext = -1; return tpl; }