int shm_cbuffer_create(shm_cbuffer_t **shm_cbuf, const char *name, const size_t obj_size, const size_t count) { assert( 0 < obj_size ); assert( 0 < count ); if(obj_size <= 0 || count <= 0) return -1; // create shared memory region // 16-byte alignment for objects // total size multiple of page sizes long ps = sysconf(_SC_PAGESIZE); size_t total_aligned_size = _align(sizeof(shm_cbuffer_t)) + _align(obj_size) * count; total_aligned_size = _align_on(total_aligned_size, ps); //printf("total_aligned_size :%d\n", total_aligned_size); int mem = shm_open(name, O_CREAT | /*O_EXCL*/O_TRUNC | O_RDWR, S_IRUSR|S_IWUSR); if(mem == -1) return -1; ftruncate(mem, total_aligned_size); // map shm to addr space *shm_cbuf = (shm_cbuffer_t*) mmap(0, total_aligned_size, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_LOCKED|MAP_POPULATE, mem, 0); if(*shm_cbuf == MAP_FAILED) { //failed because MAP_LOCKED? try without *shm_cbuf = (shm_cbuffer_t*) mmap(0, total_aligned_size, PROT_READ|PROT_WRITE, MAP_SHARED | MAP_POPULATE, mem, 0); if(*shm_cbuf == MAP_FAILED) { //failed again.... shm_unlink(name); return -1; } } // init header memset(*shm_cbuf, 0, sizeof(shm_cbuffer_t)); (**shm_cbuf).mem = (void*)_align(sizeof(shm_cbuffer_t)); (**shm_cbuf).size = _align(obj_size); (**shm_cbuf).count = count; init_lock (&(**shm_cbuf).lock); sem_init(&(**shm_cbuf).free, 1, count); sem_init(&(**shm_cbuf).used, 1, 0); (**shm_cbuf).fd = mem; (**shm_cbuf).fsize = total_aligned_size; strncpy((**shm_cbuf).name, name, CBUFFER_MAX_NAME-1); //printf("mem %d, size %d, count %d, name %s\n", _align(sizeof(shm_cbuffer_t)), (**shm_cbuf).size, (**shm_cbuf).count, (**shm_cbuf).name); return 0; }
static void *_add_target_v1(struct target *t, void *out, void *end) { void *out_sp = out; struct dm_target_spec_v1 sp; size_t sp_size = sizeof(struct dm_target_spec_v1); int len; out += sp_size; if (out >= end) return_NULL; sp.status = 0; sp.sector_start = t->start; sp.length = t->length; strncpy(sp.target_type, t->type, sizeof(sp.target_type)); len = strlen(t->params); if ((out + len + 1) >= end) return_NULL; strcpy((char *) out, t->params); out += len + 1; /* align next block */ out = _align(out, ALIGNMENT_V1); sp.next = out - out_sp; memcpy(out_sp, &sp, sp_size); return out; }
int32_t _expand( struct buffer * self, uint32_t length ) { int32_t offset = _offset( self ); uint32_t needlength = offset + self->length + length; if ( needlength <= self->capacity ) { return 0; } if ( self->capacity - self->length >= length ) { _align( self ); } else { void * newbuffer = NULL; uint32_t newcapacity = self->capacity; if ( newcapacity < MIN_BUFFER_LENGTH ) { newcapacity = MIN_BUFFER_LENGTH; } for ( ; newcapacity < needlength; ) { newcapacity <<= 1; } if ( self->orignbuffer != self->buffer ) { _align( self ); } newbuffer = (char *)realloc( self->orignbuffer, newcapacity ); if ( newbuffer == NULL ) { return -1; } self->capacity = newcapacity; self->orignbuffer = self->buffer = newbuffer; } return 0; }
static inline size_t _gl_image_size(GLenum format, GLenum type, GLsizei width, GLsizei height, GLsizei depth, GLboolean has_unpack_subimage) { unsigned bits_per_element; unsigned bits_per_pixel; _gl_format_size(format, type, bits_per_element, bits_per_pixel); GLint alignment = 4; GLint row_length = 0; GLint image_height = 0; GLint skip_rows = 0; GLint skip_pixels = 0; GLint skip_images = 0; _glGetIntegerv(GL_UNPACK_ALIGNMENT, &alignment); if (has_unpack_subimage) { _glGetIntegerv(GL_UNPACK_ROW_LENGTH, &row_length); _glGetIntegerv(GL_UNPACK_IMAGE_HEIGHT, &image_height); _glGetIntegerv(GL_UNPACK_SKIP_ROWS, &skip_rows); _glGetIntegerv(GL_UNPACK_SKIP_PIXELS, &skip_pixels); _glGetIntegerv(GL_UNPACK_SKIP_IMAGES, &skip_images); } if (row_length <= 0) { row_length = width; } size_t row_stride = (row_length*bits_per_pixel + 7)/8; if ((bits_per_element == 1*8 || bits_per_element == 2*8 || bits_per_element == 4*8 || bits_per_element == 8*8) && (GLint)bits_per_element < alignment*8) { row_stride = _align(row_stride, alignment); } if (image_height <= 0) { image_height = height; } /* XXX: GL_UNPACK_IMAGE_HEIGHT and GL_UNPACK_SKIP_IMAGES should probably * not be considered for pixel rectangles. */ size_t image_stride = image_height*row_stride; size_t size = depth*image_stride; size += (skip_pixels*bits_per_pixel + 7)/8; size += skip_rows*row_stride; size += skip_images*image_stride; return size; }
unsigned type_paramsize(type *t) { targ_size_t sz = 0; if (tyfunc(t->Tty)) { for (param_t *p = t->Tparamtypes; p; p = p->Pnext) { size_t n = type_size(p->Ptype); n = _align(REGSIZE,n); // align to REGSIZE boundary sz += n; } } return sz; }
static int do_cd_encrypt( HANDLE h_src, HANDLE h_dst, u64 iso_sz, xts_key *v_key, cd_callback callback, void *param ) { void *buff; u32 bytes, block; u32 w_len; int resl; u64 offset = 0; u64 remain = iso_sz; do { buff = VirtualAlloc(NULL, CD_BUFSZ, MEM_COMMIT+MEM_RESERVE, PAGE_READWRITE); if (buff == NULL) { resl = ST_NOMEM; break; } resl = ST_OK; do { block = d32(min(remain, CD_BUFSZ)); w_len = _align(block, CD_SECTOR_SIZE); if (ReadFile(h_src, buff, block, &bytes, NULL) == 0) { resl = ST_IO_ERROR; break; } xts_encrypt(buff, buff, w_len, offset, v_key); if (WriteFile(h_dst, buff, w_len, &bytes, NULL) == 0) { resl = ST_IO_ERROR; break; } remain -= block, offset += w_len; if (callback != NULL) { resl = callback(iso_sz, offset, param); } } while ( (remain != 0) && (resl == ST_OK) ); } while (0); if (buff != NULL) { VirtualFree(buff, 0, MEM_RELEASE); } return resl; }
void cp_parallelized_crypt( int is_encrypt, xts_key *key, fc_callback on_complete, void *param, const unsigned char *in, unsigned char *out, u32 len, u64 offset) { req_item *item; req_part *part; u32 part_sz; u32 part_of; if ( (len < F_OP_THRESOLD) || ((item = ExAllocateFromNPagedLookasideList(&pool_req_mem)) == NULL) ) { if (is_encrypt != 0) { xts_encrypt(in, out, len, offset, key); } else { xts_decrypt(in, out, len, offset, key); } on_complete(param); return; } item->is_encrypt = is_encrypt; item->length = len; item->in = in; item->out = out; item->offset = offset; item->on_complete = on_complete; item->param = param; item->key = key; part_sz = _align(len / dc_cpu_count, F_MIN_REQ); part_of = 0; part = &item->parts[0]; do { part_sz = min(part_sz, len); part->item = item; part->offset = part_of; part->length = part_sz; InterlockedPushEntrySList(&pool_head, &part->entry); part_of += part_sz; len -= part_sz; part++; } while (len != 0); KeSetEvent(&pool_signal_event, IO_NO_INCREMENT, FALSE); }
int dc_parallelized_crypt( int is_encrypt, xts_key *key, callback_ex on_complete, void *param1, void *param2, const unsigned char *in, unsigned char *out, u32 len, u64 offset) { req_item *item; req_part *part; u32 part_sz; u32 part_of; if ( (item = ExAllocateFromNPagedLookasideList(&pool_req_mem)) == NULL) { return 0; } item->is_encrypt = is_encrypt; item->length = len; item->in = in; item->out = out; item->offset = offset; item->on_complete = on_complete; item->param1 = param1; item->param2 = param2; item->key = key; part_sz = _align(len / dc_cpu_count, F_MIN_REQ); part_of = 0; part = &item->parts[0]; do { part_sz = min(part_sz, len); part->item = item; part->offset = part_of; part->length = part_sz; ExInterlockedPushEntrySList(&pool_head, &part->entry, &pool_lock); part_of += part_sz; len -= part_sz; part++; } while (len != 0); KeSetEvent(&pool_signal_event, IO_NO_INCREMENT, FALSE); return 1; }
static inline size_t _gl_image_size(GLenum format, GLenum type, GLsizei width, GLsizei height, GLsizei depth, GLboolean has_unpack_subimage) { unsigned num_channels = _gl_format_channels(format); unsigned bits_per_element; unsigned bits_per_pixel; switch (type) { case GL_BITMAP: bits_per_pixel = bits_per_element = 1; break; case GL_BYTE: case GL_UNSIGNED_BYTE: bits_per_element = 8; bits_per_pixel = bits_per_element * num_channels; break; case GL_SHORT: case GL_UNSIGNED_SHORT: case GL_HALF_FLOAT: bits_per_element = 16; bits_per_pixel = bits_per_element * num_channels; break; case GL_INT: case GL_UNSIGNED_INT: case GL_FLOAT: bits_per_element = 32; bits_per_pixel = bits_per_element * num_channels; break; case GL_UNSIGNED_BYTE_3_3_2: case GL_UNSIGNED_BYTE_2_3_3_REV: bits_per_pixel = bits_per_element = 8; break; case GL_UNSIGNED_SHORT_4_4_4_4: case GL_UNSIGNED_SHORT_4_4_4_4_REV: case GL_UNSIGNED_SHORT_5_5_5_1: case GL_UNSIGNED_SHORT_1_5_5_5_REV: case GL_UNSIGNED_SHORT_5_6_5: case GL_UNSIGNED_SHORT_5_6_5_REV: case GL_UNSIGNED_SHORT_8_8_MESA: case GL_UNSIGNED_SHORT_8_8_REV_MESA: bits_per_pixel = bits_per_element = 16; break; case GL_UNSIGNED_INT_8_8_8_8: case GL_UNSIGNED_INT_8_8_8_8_REV: case GL_UNSIGNED_INT_10_10_10_2: case GL_UNSIGNED_INT_2_10_10_10_REV: case GL_UNSIGNED_INT_24_8: case GL_UNSIGNED_INT_10F_11F_11F_REV: case GL_UNSIGNED_INT_5_9_9_9_REV: case GL_UNSIGNED_INT_S8_S8_8_8_NV: case GL_UNSIGNED_INT_8_8_S8_S8_REV_NV: bits_per_pixel = bits_per_element = 32; break; case GL_FLOAT_32_UNSIGNED_INT_24_8_REV: bits_per_pixel = bits_per_element = 64; break; default: os::log("apitrace: warning: %s: unexpected type GLenum 0x%04X\n", __FUNCTION__, type); bits_per_pixel = bits_per_element = 0; break; } GLint alignment = 4; GLint row_length = 0; GLint image_height = 0; GLint skip_rows = 0; GLint skip_pixels = 0; GLint skip_images = 0; _glGetIntegerv(GL_UNPACK_ALIGNMENT, &alignment); if (has_unpack_subimage) { _glGetIntegerv(GL_UNPACK_ROW_LENGTH, &row_length); _glGetIntegerv(GL_UNPACK_IMAGE_HEIGHT, &image_height); _glGetIntegerv(GL_UNPACK_SKIP_ROWS, &skip_rows); _glGetIntegerv(GL_UNPACK_SKIP_PIXELS, &skip_pixels); _glGetIntegerv(GL_UNPACK_SKIP_IMAGES, &skip_images); } if (row_length <= 0) { row_length = width; } size_t row_stride = (row_length*bits_per_pixel + 7)/8; if ((bits_per_element == 1*8 || bits_per_element == 2*8 || bits_per_element == 4*8 || bits_per_element == 8*8) && (GLint)bits_per_element < alignment*8) { row_stride = _align(row_stride, alignment); } if (image_height <= 0) { image_height = height; } /* XXX: GL_UNPACK_IMAGE_HEIGHT and GL_UNPACK_SKIP_IMAGES should probably * not be considered for pixel rectangles. */ size_t image_stride = image_height*row_stride; size_t size = depth*image_stride; size += (skip_pixels*bits_per_pixel + 7)/8; size += skip_rows*row_stride; size += skip_images*image_stride; return size; }
Error PCKPacker::flush(bool p_verbose) { if (!file) { ERR_FAIL_COND_V(!file, ERR_INVALID_PARAMETER); return ERR_INVALID_PARAMETER; }; // write the index file->store_32(files.size()); for (int i=0; i<files.size(); i++) { file->store_pascal_string(files[i].path); files[i].offset_offset = file->get_pos(); file->store_64(0); // offset file->store_64(files[i].size); // size // # empty md5 file->store_32(0); file->store_32(0); file->store_32(0); file->store_32(0); }; uint64_t ofs = file->get_pos(); ofs = _align(ofs, alignment); _pad(file, ofs - file->get_pos()); const uint32_t buf_max = 65536; uint8_t *buf = memnew_arr(uint8_t, buf_max); int count = 0; for (int i=0; i<files.size(); i++) { FileAccess* src = FileAccess::open(files[i].src_path, FileAccess::READ); uint64_t to_write = files[i].size; while (to_write > 0) { int read = src->get_buffer(buf, MIN(to_write, buf_max)); file->store_buffer(buf, read); to_write -= read; }; uint64_t pos = file->get_pos(); file->seek(files[i].offset_offset); // go back to store the file's offset file->store_64(ofs); file->seek(pos); ofs = _align(ofs + files[i].size, alignment); _pad(file, ofs - pos); src->close(); memdelete(src); count += 1; if (p_verbose) { if (count % 100 == 0) { printf("%i/%i (%.2f)\r", count, files.size(), float(count) / files.size() * 100); fflush(stdout); }; }; }; if (p_verbose) printf("\n"); file->close(); return OK; };
static int _dm_names_v1(struct dm_ioctl_v1 *dmi) { const char *dev_dir = dm_dir(); int r = 1, len; const char *name; struct dirent *dirent; DIR *d; struct dm_names *names, *old_names = NULL; void *end = (void *) dmi + dmi->data_size; struct stat buf; char path[PATH_MAX]; log_warn("WARNING: Device list may be incomplete with interface " "version 1."); log_warn("Please upgrade your kernel device-mapper driver."); if (!(d = opendir(dev_dir))) { log_sys_error("opendir", dev_dir); return 0; } names = (struct dm_names *) ((void *) dmi + dmi->data_start); names->dev = 0; /* Flags no data */ while ((dirent = readdir(d))) { name = dirent->d_name; if (name[0] == '.' || !strcmp(name, "control")) continue; if (old_names) old_names->next = (uint32_t) ((void *) names - (void *) old_names); snprintf(path, sizeof(path), "%s/%s", dev_dir, name); if (stat(path, &buf)) { log_sys_error("stat", path); continue; } if (!S_ISBLK(buf.st_mode)) continue; names->dev = (uint64_t) buf.st_rdev; names->next = 0; len = strlen(name); if (((void *) (names + 1) + len + 1) >= end) { log_error("Insufficient buffer space for device list"); r = 0; break; } strcpy(names->name, name); old_names = names; names = _align((void *) ++names + len + 1, ALIGNMENT); } if (closedir(d)) log_sys_error("closedir", dev_dir); return r; }
static NTSTATUS dc_trim_irp(dev_hook *hook, PIRP irp) { PIO_STACK_LOCATION irp_sp = IoGetCurrentIrpStackLocation(irp); PDEVICE_MANAGE_DATA_SET_ATTRIBUTES p_set = irp->AssociatedIrp.SystemBuffer; u32 length = irp_sp->Parameters.DeviceIoControl.InputBufferLength; u64 offset, rnglen; PDEVICE_DATA_SET_RANGE range; PDEVICE_MANAGE_DATA_SET_ATTRIBUTES n_set; u64 off1, off2; u64 len1, len2; u32 i; if ( (length < sizeof(DEVICE_MANAGE_DATA_SET_ATTRIBUTES)) || (p_set->Action != DeviceDsmAction_Trim) || (length < d64(p_set->DataSetRangesOffset) + d64(p_set->DataSetRangesLength)) ) { return dc_forward_irp(hook, irp); } if (dc_conf_flags & CONF_DISABLE_TRIM) { return dc_release_irp(hook, irp, STATUS_SUCCESS); } if ( (n_set = mm_pool_alloc(TRIM_BUFF_MAX(p_set))) == NULL ) { return dc_release_irp(hook, irp, STATUS_INSUFFICIENT_RESOURCES); } n_set->Size = sizeof(DEVICE_MANAGE_DATA_SET_ATTRIBUTES); n_set->Action = DeviceDsmAction_Trim; n_set->Flags = 0; n_set->ParameterBlockOffset = 0; n_set->ParameterBlockLength = 0; n_set->DataSetRangesOffset = _align(sizeof(DEVICE_MANAGE_DATA_SET_ATTRIBUTES), sizeof(DEVICE_DATA_SET_RANGE)); n_set->DataSetRangesLength = 0; if (p_set->Flags & DEVICE_DSM_FLAG_ENTIRE_DATA_SET_RANGE) { if (hook->flags & F_NO_REDIRECT) { TRIM_ADD_RANGE(n_set, hook->head_len, hook->dsk_size - hook->head_len); } else { TRIM_ADD_RANGE(n_set, hook->head_len, LEN_BEFORE_STORAGE(hook)); TRIM_ADD_RANGE(n_set, OFF_END_OF_STORAGE(hook), LEN_AFTER_STORAGE(hook)); } } else { for (i = 0, range = addof(p_set, p_set->DataSetRangesOffset); i < p_set->DataSetRangesLength / sizeof(DEVICE_DATA_SET_RANGE); i++, range++) { if ( (offset = range->StartingOffset) + (rnglen = range->LengthInBytes) > hook->use_size ) { continue; } if (hook->flags & F_NO_REDIRECT) { TRIM_ADD_RANGE(n_set, offset + hook->head_len, min(rnglen, hook->use_size - offset)); continue; } len1 = intersect(&off1, offset, rnglen, hook->head_len, LEN_BEFORE_STORAGE(hook)); len2 = intersect(&off2, offset, rnglen, OFF_END_OF_STORAGE(hook), LEN_AFTER_STORAGE(hook)); TRIM_ADD_RANGE(n_set, off1, len1); TRIM_ADD_RANGE(n_set, off2, len2); } } if (n_set->DataSetRangesLength != 0) { io_hook_ioctl(hook, IOCTL_STORAGE_MANAGE_DATA_SET_ATTRIBUTES, n_set, TRIM_BUFF_LENGTH(n_set), NULL, 0); } mm_pool_free(n_set); return dc_release_irp(hook, irp, STATUS_SUCCESS); }
static int pe2mod(wchar_t *in, wchar_t *out) { IMAGE_DOS_HEADER *d_head; IMAGE_NT_HEADERS *n_head; IMAGE_SECTION_HEADER *t_sect; boot_mod *b_mod = NULL; HMODULE image = NULL; u32 *reloc = NULL; int resl = 1; u32 r_num, offs; HANDLE h_out; u32 i, found; u32 code_off; u32 bytes, n; u8 *s_data; u32 s_size; do { if ( (image = LoadLibraryEx(in, NULL, DONT_RESOLVE_DLL_REFERENCES)) == NULL ) { break; } d_head = pv(dSZ(image) & ~(PAGE_SIZE - 1)); n_head = addof(d_head, d_head->e_lfanew); t_sect = IMAGE_FIRST_SECTION(n_head); found = 0; /* find '.text' section */ for (i = 0; i < n_head->FileHeader.NumberOfSections; i++, t_sect++) { if (_stricmp(t_sect->Name, ".text") == 0) { found = 1; break; } } if (found == 0) { wprintf(L"Invalid PE image %s, section '.text' is not found\n", in); break; } if ( (reloc = calloc(1, n_head->OptionalHeader.SizeOfImage)) == NULL ) { break; } if ( (b_mod = calloc(1, n_head->OptionalHeader.SizeOfImage)) == NULL ) { break; } if (r_num = pe_save_relocs(d_head, reloc)) { /* save needed relocs */ for (i = 0, n = 0; i < r_num; i++) { if (in_reg(reloc[i], t_sect->VirtualAddress, t_sect->Misc.VirtualSize) != 0) { b_mod->relocs[n++] = reloc[i]; } } b_mod->n_rels = n; code_off = _align(sizeof(boot_mod) + n * sizeof(u32), 16); } else { code_off = _align(sizeof(boot_mod), 16); } s_data = addof(d_head, t_sect->VirtualAddress); s_size = t_sect->SizeOfRawData; /* find minimum section RAW size */ for (i = t_sect->SizeOfRawData - 1; i != 0; i--, s_size--) { if (s_data[i] != 0) break; } b_mod->mod_sign = 'DCBM'; b_mod->raw_size = s_size + code_off; b_mod->virt_size = t_sect->Misc.VirtualSize + code_off; b_mod->entry_rva = n_head->OptionalHeader.AddressOfEntryPoint - t_sect->VirtualAddress + code_off; memcpy(addof(b_mod, code_off), s_data, s_size); /* rebase image and fix relocs */ for (i = 0; i < b_mod->n_rels; i++) { offs = b_mod->relocs[i] - t_sect->VirtualAddress + code_off; p32(addof(b_mod, offs))[0] -= n_head->OptionalHeader.ImageBase + t_sect->VirtualAddress - code_off; b_mod->relocs[i] = offs; } h_out = CreateFile( out, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL); if (h_out != INVALID_HANDLE_VALUE) { if (WriteFile(h_out, b_mod, b_mod->raw_size, &bytes, NULL) != 0) { wprintf(L"Boot module OK (Virtual size: %d, Raw size: %d, EP: %d)\n", b_mod->virt_size, b_mod->raw_size, b_mod->entry_rva); resl = 0; } CloseHandle(h_out); } else { wprintf(L"Can not write to %s", out); } } while (0); if (reloc != NULL) { free(reloc); } if (b_mod != NULL) { free(b_mod); } if (image != NULL) { FreeLibrary(image); } return resl; }
static inline size_t _gl_image_size(GLenum format, GLenum type, GLsizei width, GLsizei height, GLsizei depth, GLboolean has_unpack_subimage) { unsigned bits_per_pixel = _gl_format_size(format, type); GLint alignment = 4; GLint row_length = 0; GLint image_height = 0; GLint skip_rows = 0; GLint skip_pixels = 0; GLint skip_images = 0; _glGetIntegerv(GL_UNPACK_ALIGNMENT, &alignment); if (has_unpack_subimage) { _glGetIntegerv(GL_UNPACK_ROW_LENGTH, &row_length); _glGetIntegerv(GL_UNPACK_IMAGE_HEIGHT, &image_height); _glGetIntegerv(GL_UNPACK_SKIP_ROWS, &skip_rows); _glGetIntegerv(GL_UNPACK_SKIP_PIXELS, &skip_pixels); _glGetIntegerv(GL_UNPACK_SKIP_IMAGES, &skip_images); } if (row_length <= 0) { row_length = width; } size_t row_stride = (row_length*bits_per_pixel + 7)/8; /* * The OpenGL specification states that the unpack alignment should be * ignored if the number of bits per element is not 1, 2, 4, or 8 times the * number of bits in a GL ubyte, but the matter of fact is that the number * of bits per element is always one of those. */ if (_is_pot(alignment)) { row_stride = _align(row_stride, alignment); } if (image_height <= 0) { image_height = height; } size_t image_stride = image_height*row_stride; /* * We can't just do * * size = depth*image_stride * * here as that could result in reading beyond the end of the buffer when * selecting sub-rectangles via GL_UNPACK_SKIP_*. */ size_t size = (width*bits_per_pixel + 7)/8; if (height > 1) { size += (height - 1)*row_stride; } if (depth > 1) { size += (depth - 1)*image_stride; } /* XXX: GL_UNPACK_IMAGE_HEIGHT and GL_UNPACK_SKIP_IMAGES should probably * not be considered for pixel rectangles. */ size += (skip_pixels*bits_per_pixel + 7)/8; size += skip_rows*row_stride; size += skip_images*image_stride; return size; }
static struct dm_ioctl *_dm_ioctl_setup(struct devmapping *dm, int flags) { void *buffer; void *p; const size_t min_size = 16 * 1024; size_t len = sizeof(struct dm_ioctl); struct dm_ioctl *io; struct dm_target_spec *tgt; int i; char params[1024]; char key[80]; key[0] = '\0'; for (i = 0; i < (int) sizeof(dm->key); i++) { char tmp[8]; sprintf(tmp, "%02x", dm->key[i]); strcat(key, tmp); } char srcdev[128]; // XXX: Handle non crypt targets and non twofish (use param) if (dm->src_type == dmsrc_loopback) strcpy(srcdev, dm->type_data.loop.loop_dev); else if (dm->src_type == dmsrc_partition) strcpy(srcdev, dm->type_data.part.part_dev); sprintf(params, "twofish %s 0 %s 0", key, srcdev); LOG_VOL("Params = '%s'", params); if (len < min_size) len = min_size; if (!(buffer = malloc(len))) { LOGE("out of memory"); return NULL; } memset(buffer, 0, len); io = buffer; tgt = (struct dm_target_spec *) &buffer[sizeof(struct dm_ioctl)]; io->version[0] = 4; io->version[1] = 0; io->version[2] = 0; io->data_size = len; io->data_start = sizeof(struct dm_ioctl); io->flags = flags; io->dev = 0; io->target_count = 1; io->event_nr = 1; strncpy(io->name, dm->target, sizeof(io->name)); tgt->status = 0; tgt->sector_start = 0; tgt->length = (dm->size_mb * (1024 * 1024)) / 512; strncpy(tgt->target_type, "crypt", sizeof(tgt->target_type)); p = buffer + sizeof(struct dm_ioctl) + sizeof(struct dm_target_spec); strcpy((char *) p, params); p+= strlen(params) + 1; p = _align(p, 8); tgt->next = p - buffer; return io; }
void outdata(symbol *s) { #if HTOD return; #endif int seg; targ_size_t offset; int flags; const int codeseg = cseg; symbol_debug(s); #ifdef DEBUG debugy && dbg_printf("outdata('%s')\n",s->Sident); #endif //printf("outdata('%s', ty=x%x)\n",s->Sident,s->Stype->Tty); //symbol_print(s); // Data segment variables are always live on exit from a function s->Sflags |= SFLlivexit; dt_t *dtstart = s->Sdt; s->Sdt = NULL; // it will be free'd targ_size_t datasize = 0; tym_t ty = s->ty(); #if SCPP && TARGET_WINDOS if (eecontext.EEcompile) { s->Sfl = (s->ty() & mTYfar) ? FLfardata : FLextern; s->Sseg = UNKNOWN; goto Lret; // don't output any data } #endif if (ty & mTYexport && config.wflags & WFexpdef && s->Sclass != SCstatic) objmod->export_symbol(s,0); // export data definition for (dt_t *dt = dtstart; dt; dt = dt->DTnext) { //printf("\tdt = %p, dt = %d\n",dt,dt->dt); switch (dt->dt) { case DT_abytes: { // Put out the data for the string, and // reserve a spot for a pointer to that string datasize += size(dt->Dty); // reserve spot for pointer to string #if TARGET_SEGMENTED if (tybasic(dt->Dty) == TYcptr) { dt->DTseg = codeseg; dt->DTabytes += Offset(codeseg); goto L1; } else if (tybasic(dt->Dty) == TYfptr && dt->DTnbytes > config.threshold) { targ_size_t foffset; dt->DTseg = objmod->fardata(s->Sident,dt->DTnbytes,&foffset); dt->DTabytes += foffset; L1: objmod->write_bytes(SegData[dt->DTseg],dt->DTnbytes,dt->DTpbytes); break; } else #endif { dt->DTabytes += objmod->data_readonly(dt->DTpbytes,dt->DTnbytes,&dt->DTseg); } break; } case DT_ibytes: datasize += dt->DTn; break; case DT_nbytes: //printf("DT_nbytes %d\n", dt->DTnbytes); datasize += dt->DTnbytes; break; case DT_azeros: /* A block of zeros */ //printf("DT_azeros %d\n", dt->DTazeros); case_azeros: datasize += dt->DTazeros; if (dt == dtstart && !dt->DTnext && s->Sclass != SCcomdat && (s->Sseg == UNKNOWN || s->Sseg <= UDATA)) { /* first and only, so put in BSS segment */ switch (ty & mTYLINK) { #if TARGET_SEGMENTED case mTYfar: // if far data s->Sseg = objmod->fardata(s->Sident,datasize,&s->Soffset); s->Sfl = FLfardata; break; case mTYcs: s->Sseg = codeseg; Offset(codeseg) = _align(datasize,Offset(codeseg)); s->Soffset = Offset(codeseg); Offset(codeseg) += datasize; s->Sfl = FLcsdata; break; #endif case mTYthreadData: assert(config.objfmt == OBJ_MACH && I64); case mTYthread: { seg_data *pseg = objmod->tlsseg_bss(); s->Sseg = pseg->SDseg; objmod->data_start(s, datasize, pseg->SDseg); if (config.objfmt == OBJ_OMF) pseg->SDoffset += datasize; else objmod->lidata(pseg->SDseg, pseg->SDoffset, datasize); s->Sfl = FLtlsdata; break; } default: s->Sseg = UDATA; objmod->data_start(s,datasize,UDATA); objmod->lidata(s->Sseg,s->Soffset,datasize); s->Sfl = FLudata; // uninitialized data break; } assert(s->Sseg && s->Sseg != UNKNOWN); if (s->Sclass == SCglobal || (s->Sclass == SCstatic && config.objfmt != OBJ_OMF)) // if a pubdef to be done objmod->pubdefsize(s->Sseg,s,s->Soffset,datasize); // do the definition searchfixlist(s); if (config.fulltypes && !(s->Sclass == SCstatic && funcsym_p)) // not local static cv_outsym(s); #if SCPP out_extdef(s); #endif goto Lret; } break; case DT_common: assert(!dt->DTnext); outcommon(s,dt->DTazeros); goto Lret; case DT_xoff: { symbol *sb = dt->DTsym; if (tyfunc(sb->ty())) #if SCPP nwc_mustwrite(sb); #else ; #endif else if (sb->Sdt) // if initializer for symbol { if (!s->Sseg) s->Sseg = DATA; outdata(sb); // write out data for symbol } } case DT_coff: datasize += size(dt->Dty); break; default: #ifdef DEBUG dbg_printf("dt = %p, dt = %d\n",dt,dt->dt); #endif assert(0); } }
/** performs an iterative alignment of the measurement to the model. * The model needs to be added using addToModel before this call. * * @param measurement - the pointcloud that needs to be matched * @param max_iter - maximum number of iterations * @param min_mse - minimum average square distance between points after which to stop * @param min_mse_diff - minimum difference in average square distance between points after which to stop * @param overlap - percentage of overlap, range between [0..1]. A value of * 0.95 will discard 5% of the pairs with the worst matches */ void align( _Adapter measurement, size_t max_iter, double min_mse, double min_mse_diff, double overlap ) { minResult = _align( measurement, max_iter, min_mse, min_mse_diff, overlap ); measurement.applyTransform( minResult.C_global2globalnew ); }