void multiboot_init (void) { u8 *target = (u8 *) BASE_MODULE_NAME; unsigned module; /* Copy the module parameters. */ memory_copy (multiboot_module_info, (multiboot_module_info_type *) multiboot_info.module_base, multiboot_info.number_of_modules * sizeof (multiboot_module_info_type)); /* First of all, make sure module names and parameters are stored in a safe place. Otherwise, we may overwrite them later on in the boot process. */ for (module = 0; module < multiboot_info.number_of_modules; module++) { string_copy (target, multiboot_module_info[module].name); multiboot_module_info[module].name = target; target += string_length (target) + 1; } /* Now, save the memory map. */ memory_copy ((u8 *) BASE_MEMORY_MAP, (void *) multiboot_info.memory_map_address, multiboot_info.memory_map_length); /* Now, lets parse the kernel command line. */ // arguments_parse ((u8 *) multiboot_info.command_line, arguments_kernel, 0); }
static void send(struct ipv4_socket *sender, struct ipv4_socket *target, void *buffer, unsigned int count) { struct {struct ctrl_conheader header; char buffer[FUDGE_BSIZE];} packet; memory_copy(&packet.header.sender, sender, sizeof (struct ipv4_socket)); memory_copy(&packet.header.target, target, sizeof (struct ipv4_socket)); packet.header.count = memory_write(packet.buffer, FUDGE_BSIZE, buffer, count, 0); file_writeall(FILE_L1, &packet, sizeof (struct ctrl_conheader) + packet.header.count); }
void *ethernet_writehead(void *buffer, unsigned int type, unsigned char *sha, unsigned char *tha) { struct ethernet_header *header = buffer; header->type[0] = type >> 8; header->type[1] = type; memory_copy(header->sha, sha, ETHERNET_ADDRSIZE); memory_copy(header->tha, tha, ETHERNET_ADDRSIZE); return header + 1; }
/* Advance the text cursor, scrolling the video buffer if necessary */ int handle_scrolling(int nCursorOffset) { // If the cursor is within the screen, return it unmodified if (nCursorOffset < MAX_ROWS * MAX_COLS * 2) { return nCursorOffset; } // Shuffle the rows back one int i = 0; for (i = 1; i < MAX_ROWS ; i++) { memory_copy(get_screen_offset(0, i) + VIDEO_ADDRESS, get_screen_offset(0, i-1) + VIDEO_ADDRESS, MAX_COLS * 2); } // Blank the last line by setting all bytes to 0 char* pLastLine = (char*) get_screen_offset(0, MAX_ROWS - 1) + VIDEO_ADDRESS; for (i = 0; i < MAX_COLS * 2; i++) { pLastLine[i] = 0; } // Move the offset back one row, for it to be the last row nCursorOffset -= (2 * MAX_COLS); // Return the updated cursor position return nCursorOffset; }
/* Retrieves the class identifier * The identifier is a GUID and is 16 bytes of size * Returns 1 if successful or -1 on error */ int libolecf_property_set_get_class_identifier( libolecf_property_set_t *property_set, uint8_t *class_identifier, size_t size, libcerror_error_t **error ) { libolecf_internal_property_set_t *internal_property_set = NULL; static char *function = "libolecf_property_set_get_number_of_sections"; if( property_set == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid property set.", function ); return( -1 ); } internal_property_set = (libolecf_internal_property_set_t *) property_set; if( class_identifier == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid class identifier.", function ); return( -1 ); } if( size < 16 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL, "%s: class identifier too small.", function ); return( -1 ); } if( memory_copy( class_identifier, internal_property_set->class_identifier, 16 ) == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_COPY_FAILED, "%s: unable to copy class identifier.", function ); return( -1 ); } return( 1 ); }
/* This function is typically used to read pieces of file systems that may * span a sector, but will not span many sectors. Therefore, it may not need * to be optimized. */ void read_disk_bytes( uint8_t drive, void *buffer, uint64_t offset, uint32_t count) { static char sector_buffer[512]; char *iter_buffer = (char*)buffer; uint64_t iter_sector = offset >> SECTOR_SIZE_LOG2; uint32_t iter_offset = offset & (SECTOR_SIZE - 1); uint32_t iter_count = count; while (iter_count > 0) { read_disk_sectors(drive, sector_buffer, iter_sector, 1); const uint32_t read_amount = io_min_uint32(iter_count, SECTOR_SIZE - iter_offset); memory_copy( iter_buffer, sector_buffer + iter_offset, read_amount); iter_buffer += read_amount; iter_sector++; iter_offset = 0; iter_count -= read_amount; } }
void Kernel::copy_fields( Kernel & k_dst , unsigned i_dst , Kernel & k_src , unsigned i_src ) { static const char method[] = "phdmesh::Kernel::copy_fields" ; const std::vector<FieldBase*> & field_set = k_dst.mesh().mesh_meta_data().get_fields(); unsigned char * const s = reinterpret_cast<unsigned char*>(k_src.m_entities); unsigned char * const d = reinterpret_cast<unsigned char*>(k_dst.m_entities); DataMap * j = k_src.m_field_map ; DataMap * i = k_dst.m_field_map ; DataMap * const e = i + field_set.size(); for ( ; i != e ; ++i , ++j ) { if ( i->m_size ) { if ( j->m_size ) { if ( i->m_size == j->m_size ) { memory_copy( d + i->m_base + i->m_size * i_dst , s + j->m_base + j->m_size * i_src , i->m_size ); } else { std::ostringstream msg ; msg << method ; msg << " FAILED WITH INCOMPATIBLE FIELD SIZES" ; throw std::runtime_error( msg.str() ); } } else { memory_zero( d + i->m_base + i->m_size * i_dst , i->m_size ); } } } }
u8 * set_add(Set *S, u8 tag, u8 *begin, u8 *end, void *data) { hale_assert_input((end - begin) < 0xFF); memi key_count = end - begin; u8 *ptr = hale_memory_push(u8, &S->memory, // count + tag + u8[] + \0\0 (1 + 1 + key_count + 2) + sizeof(void*)); u8 *base = ptr; // Write key length. *ptr++ = (u8)(key_count); // Write the tag. *ptr++ = (u8)(tag); // Write key. memory_copy(ptr, begin, key_count); ptr += key_count; // Write zero terminator (compatible with ch8 and ch16). *ptr++ = 0; *ptr++ = 0; *(void**)ptr++ = data; S->count++; return base + 2; }
static unsigned int spawn(struct task *task, void *stack) { struct task *next = kernel_picktask(); if (!next) return 0; kernel_copydescriptors(task, next); if (kernel_setupbinary(next, ARCH_TASKSTACKADDRESS)) { memory_copy(gettaskdirectory(next->id), getkerneldirectory(), sizeof (struct mmu_directory)); kernel_usetask(next); ring_reset(&next->mailbox.ring); return next->id; } else { kernel_freetask(next); return 0; } }
/* Sets the identifier * Returns 1 if successful or -1 on error */ int libvslvm_logical_volume_values_set_identifier( libvslvm_logical_volume_values_t *logical_volume_values, const char *identifier, size_t identifier_size, libcerror_error_t **error ) { static char *function = "libvslvm_logical_volume_values_set_identifier"; if( logical_volume_values == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid logical volume values.", function ); return( -1 ); } if( identifier == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid identifier.", function ); return( -1 ); } if( identifier_size != 39 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS, "%s: identifier size value out of bounds.", function ); return( -1 ); } if( memory_copy( logical_volume_values->identifier, identifier, 39 ) == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_COPY_FAILED, "%s: unable to copy identifier.", function ); return( -1 ); } logical_volume_values->identifier[ 38 ] = 0; return( 1 ); }
/* Retrieves the security descriptor data size * Returns 1 if successful or -1 on error */ int libfsntfs_security_descriptor_values_get_data( libfsntfs_security_descriptor_values_t *security_descriptor_values, uint8_t *data, size_t data_size, libcerror_error_t **error ) { static char *function = "libfsntfs_security_descriptor_values_get_data"; if( security_descriptor_values == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid security descriptor values.", function ); return( -1 ); } if( data == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid data.", function ); return( -1 ); } if( data_size < security_descriptor_values->data_size ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS, "%s: invalid data size value out of bounds.", function ); return( -1 ); } if( memory_copy( data, security_descriptor_values->data, security_descriptor_values->data_size ) == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_SET_FAILED, "%s: unable to copy security descriptor data.", function ); return( -1 ); } return( 1 ); }
/* Retrieves the identifier * The identifier is a GUID and is 16 bytes of size * Returns 1 if successful or -1 on error */ int libbde_volume_master_key_get_identifier( libbde_volume_master_key_t *volume_master_key, uint8_t *identifier, size_t size, libcerror_error_t **error ) { static char *function = "libbde_volume_master_key_get_identifier"; if( volume_master_key == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid volume master key.", function ); return( -1 ); } if( identifier == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid identifier.", function ); return( -1 ); } if( size < 16 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL, "%s: identifier too small.", function ); return( -1 ); } if( memory_copy( identifier, volume_master_key->identifier, 16 ) == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_COPY_FAILED, "%s: unable to set identifier.", function ); return( -1 ); } return( 1 ); }
void tty_handle_scroll() { if (tty_y < VGA_HEIGHT) return; int last_row_offset = (VGA_HEIGHT - 1) * VGA_WIDTH; memory_copy((uint8_t*)VGA_MEMORY, (uint8_t*)VGA_MEMORY + VGA_WIDTH * 2, last_row_offset * 2); for (int i = 0; i < VGA_WIDTH; ++i) VGA_MEMORY[last_row_offset + i] = make_vgaentry(' ', tty_color); --tty_y; }
static void schedule(struct cpu_general *general, struct cpu_interrupt *interrupt, struct core *core) { if (core->task) { memory_copy(®isters[core->task->id], general, sizeof (struct cpu_general)); core->task->thread.ip = interrupt->eip.value; core->task->thread.sp = interrupt->esp.value; } kernel_schedule(core); if (core->task) { memory_copy(general, ®isters[core->task->id], sizeof (struct cpu_general)); interrupt->cs.value = gdt_getselector(&gdt->pointer, ARCH_UCODE); interrupt->ss.value = gdt_getselector(&gdt->pointer, ARCH_UDATA); interrupt->eip.value = core->task->thread.ip; interrupt->esp.value = core->task->thread.sp; mmu_setdirectory(gettaskdirectory(core->task->id)); } else { interrupt->cs.value = gdt_getselector(&gdt->pointer, ARCH_KCODE); interrupt->ss.value = gdt_getselector(&gdt->pointer, ARCH_KDATA); interrupt->eip.value = (unsigned int)cpu_halt; interrupt->esp.value = core->sp; mmu_setdirectory(getkerneldirectory()); } }
static unsigned int consoleinterface_writeodata(struct system_node *self, struct system_node *current, struct service_state *state, void *buffer, unsigned int count, unsigned int offset) { unsigned int total = videointerface.settings.w * videointerface.settings.h; unsigned int i; if (videointerface.settings.w != 80) return count; for (i = 0; i < count; i++) { char c = ((char *)buffer)[i]; if (c == '\b') cursor.offset--; if (c == '\t') cursor.offset = (cursor.offset + 8) & ~(8 - 1); if (c == '\r') cursor.offset -= (cursor.offset % videointerface.settings.w); if (c == '\n') cursor.offset += videointerface.settings.w - (cursor.offset % videointerface.settings.w); if (c >= ' ') { taddress[cursor.offset].character = c; taddress[cursor.offset].color = cursor.color; cursor.offset++; } if (cursor.offset >= total) { memory_copy(taddress, taddress + videointerface.settings.w, videointerface.settings.w * (videointerface.settings.h - 1) * sizeof (struct vga_character)); clear(videointerface.settings.w * (videointerface.settings.h - 1)); cursor.offset -= videointerface.settings.w; } } outcrt1(VGA_CRTINDEX_CRT0E, cursor.offset >> 8); outcrt1(VGA_CRTINDEX_CRT0F, cursor.offset); return count; }
static void setuptask() { struct task *task = kernel_picktask(); kernel_setupinit(task); kernel_copydescriptors(task, task); kernel_setupbinary(task, ARCH_TASKSTACKADDRESS); memory_copy(gettaskdirectory(task->id), getkerneldirectory(), sizeof (struct mmu_directory)); kernel_usetask(task); }
static bool realtek_start_transmit (u8 *data, unsigned int length, realtek_device_type *device) { long io_address = device->port_base; int entry; // netif_stop_queue(dev); /* Calculate the next Tx descriptor entry. */ entry = device->current_tx % NUMBER_OF_TX_DESCRIPTORS; // tp->tx_info[entry].skb = skb; // tp->tx_info[entry].mapping = 0; memory_copy (device->tx_buffer[entry], data, length); system_port_out_u32 (io_address + TxAddress0 + entry * 4, (u32) (device->tx_buffers_dma + (device->tx_buffer[entry] - device->tx_buffers))); /* Note: the chip doesn't have auto-pad! */ system_port_out_u32 (io_address + TxStatus0 + entry * 4, device->tx_flag | (length >= NETWORK_ETHERNET_MINIMUM_LENGTH ? length : NETWORK_ETHERNET_MINIMUM_LENGTH)); /* Typical path */ if (++device->current_tx - device->dirty_tx < NUMBER_OF_TX_DESCRIPTORS) { // netif_start_queue(dev); } else { device->tx_full = TRUE; } // dev->trans_start = jiffies; if (realtek_debug > 4) { log_print_formatted (&log_structure, LOG_URGENCY_DEBUG, "Queued Tx packet at %p size %d to slot %d.\n", data, length, entry); } return TRUE; }
unsigned int arp_writeheader(unsigned short htype, unsigned char hlength, unsigned short ptype, unsigned char plength, unsigned short operation, unsigned char *sha, unsigned char *shp, unsigned char *tha, unsigned char *thp, void *buffer) { struct arp_header *header = buffer; unsigned char *data = (unsigned char *)(header + 1); header->htype[0] = htype >> 8; header->htype[1] = htype; header->ptype[0] = ptype >> 8; header->ptype[1] = ptype; header->hlength = hlength; header->plength = plength; header->operation[0] = operation >> 8; header->operation[1] = operation; memory_copy(data, sha, hlength); memory_copy(data + hlength, shp, plength); memory_copy(data + hlength + plength, tha, hlength); memory_copy(data + hlength + plength + hlength, thp, plength); return sizeof (struct arp_header) + hlength + plength + hlength + plength; }
void *arp_writehead(void *buffer, unsigned int htype, unsigned char hlength, unsigned int ptype, unsigned char plength, unsigned int operation, unsigned char *sha, unsigned char *spa, unsigned char *tha, unsigned char *tpa) { struct arp_header *header = ethernet_writehead(buffer, ethernetprotocol.type, sha, tha); unsigned char *data = (unsigned char *)(header + 1); header->htype[0] = htype >> 8; header->htype[1] = htype; header->ptype[0] = ptype >> 8; header->ptype[1] = ptype; header->hlength = hlength; header->plength = plength; header->operation[0] = operation >> 8; header->operation[1] = operation; memory_copy(data, sha, header->hlength); memory_copy(data + header->hlength, spa, header->plength); memory_copy(data + header->hlength + header->plength, tha, header->hlength); memory_copy(data + header->hlength + header->plength + header->hlength, tpa, header->plength); return data + header->hlength + header->plength + header->hlength + header->plength; }
/* * Copy binary's section into a given mem_area. * @mma -- memory area to hold the section * @inode -- inode containing the binary * @off -- offset of the section in the file * @len -- length of the section * Note1: section has to be created beforehand. * Note2: it is assumed that all the file's pages are loaded in * inode's buffers. */ void aout_copy_section(struct mem_area *mma, struct inode *inode, off_t off, size_t len) { struct page *page; struct klist0_node *tmp; struct page *destpg; void *to = NULL; u32 pgnum, pgoff; size_t left, tocopy; /* where we start */ pgnum = (off & NOPAGE_MASK) >> PAGE_SHIFT; pgoff = off & PAGE_MASK; tmp = mma->m_plist.next; left = len; while (left > 0) { page = inode->i_map.i_pages[pgnum]; if (!((u32)to & PAGE_MASK)) { destpg = klist0_entry(tmp, struct page, area_list); to = page_to_addr(destpg); } if (pgoff) tocopy = MIN(left, (size_t)PAGE_SIZE - pgoff); else tocopy = MIN(left, (size_t)(PAGE_SIZE - ((u32)to & PAGE_MASK))); /*DPRINT("### copy: %x[%x] to %x[%x], %d bytes\n", page_to_addr(page) + pgoff, page->virt, to, destpg->virt, tocopy);*/ memory_copy(to, page_to_addr(page) + pgoff, tocopy); /* switch to next source page */ if (pgoff + tocopy == PAGE_SIZE) pgnum++; else pgoff = tocopy; left -= tocopy; to += tocopy; if (!((u32)to & PAGE_MASK)) tmp = tmp->next; else pgoff = 0; }
/* create a reply */ void context_create_reply(context_t *cont, word val, exception_t *excep) { context_lock(cont); if (NULL != excep) { memory_copy(&cont->last_exception, excep, sizeof(exception_t)); } memory_set(&cont->cmd, 0, sizeof(kplugs_command_t)); cont->cmd.val1 = val; cont->cmd.type = KPLUGS_REPLY; cont->has_answer = 1; context_unlock(cont); }
void gdt_setup_call_gate(uint8_t number, uint16_t selector, function_type address, uint8_t dpl, uint8_t params) { gate_descriptor_type gate_descriptor; gate_descriptor.offset_lo = (uint32_t) address & 0xFFFF; gate_descriptor.offset_hi = (((uint32_t) address) >> 16) & 0xFFFF; gate_descriptor.segment_selector = selector; gate_descriptor.params = params; gate_descriptor.zero = 0; gate_descriptor.dpl = dpl; gate_descriptor.present = 1; gate_descriptor.type = DESCRIPTOR_TYPE_CALL_GATE; memory_copy(&gdt[number], (void *) &gate_descriptor, 8); }
/* create a function */ int function_create(bytecode_t *code, word len, function_t **func) { int err = 0; /* the function must be executable because of the wrapper inside it */ *func = memory_alloc_exec(sizeof(function_t) + ((word)&wrapper_end - (word)&wrapper_start)); if (NULL == *func) { ERROR(-ERROR_MEM); } memory_set(*func, 0, sizeof(function_t)); atomic_set(&(*func)->ref_count, 1); err = function_check(code, len, *func); if (err < 0) { goto clean; } /* set the function wrapper's callback */ (*func)->code = code; memory_copy((*func)->func_code, &wrapper_start, ((word)&wrapper_end - (word)&wrapper_start)); if ((*func)->code[0].func.function_type == FUNC_VARIABLE_ARGUMENT) { *(word *)GET_FUNCTION_CALLBACK(*func) = (word)variable_argument_function_callback; } else { *(word *)GET_FUNCTION_CALLBACK(*func) = (word)standard_function_callback; } err = 0; if (code[0].func.name) { (*func)->name = (char *)((*func)->raw) + (*func)->string_table[code[0].func.name - 1]; err = function_check_name(*func); } clean: if (err < 0 && *func) { if ((*func)->string_table) { memory_free((*func)->string_table); } memory_free_exec(*func); *func = NULL; } return err; }
/* copy the reply back to the user */ int context_get_reply(context_t *cont, char *buf, word length) { word copy; context_lock(cont); /* return an answer if there is one */ if (cont->has_answer) { copy = (length > sizeof(kplugs_command_t)) ? sizeof(kplugs_command_t) : length; memory_copy(buf, &cont->cmd, copy); cont->has_answer = 0; } else { copy = 0; } context_unlock(cont); return (int)copy; }
void gdt_setup_tss_descriptor(uint16_t selector, void *address, int dpl, int limit) { descriptor_type tmpdesc; tmpdesc.limit_hi = 0; tmpdesc.limit_lo = limit; tmpdesc.granularity = 0; tmpdesc.base_lo = (uint32_t) address & 0xFFFF; tmpdesc.base_hi = ((uint32_t) address >> 16) & 0xFF; tmpdesc.base_hi2 = ((uint32_t) address >> 24) & 0xFF; tmpdesc.type = DESCRIPTOR_TYPE_TSS; tmpdesc.descriptor_type = 0; tmpdesc.dpl = dpl; tmpdesc.segment_present = 1; tmpdesc.zero = 0; tmpdesc.operation_size = 0; memory_copy(&gdt[selector], (void *) &tmpdesc, 8); }
void INIT_CODE multiboot_init (void) { char *target = (char *) BASE_MODULE_NAME; unsigned module; memory_copy(multiboot_module_info, (multiboot_module_info_type *) multiboot_info.module_base, multiboot_info.number_of_modules * sizeof (multiboot_module_info_type)); // First of all, make sure module names and parameters are stored in a safe place. Otherwise, we may overwrite them later on // in the boot process. for (module = 0; module < multiboot_info.number_of_modules; module++) { string_copy(target, multiboot_module_info[module].name); multiboot_module_info[module].name = target; target += string_length (target) + 1; } // Now, lets parse the kernel command line. */ arguments_parse ((char *) multiboot_info.command_line, arguments_kernel, 0); }
/* Basic printing function. */ static int print_simple (const char *string) { int index; /* Handle the NULL string. */ if (string == NULL) { print_simple ("(null)"); return 0; } for (index = 0; string[index] != '\0'; index++) { put_character (x_position, y_position, string[index], text_attribute); x_position++; if (x_position == DEBUG_SCREEN_WIDTH) { x_position = 0; y_position++; /* If we're passing the last line on screen, scroll everything upwards one line. */ if (y_position >= DEBUG_SCREEN_HEIGHT) { y_position = DEBUG_SCREEN_HEIGHT - 1; memory_copy ((void *) screen, (void *) &screen[DEBUG_SCREEN_WIDTH], (DEBUG_SCREEN_WIDTH * (DEBUG_SCREEN_HEIGHT - 1)) * 2); memory_set_uint16 ((void *) &screen[DEBUG_SCREEN_WIDTH * (DEBUG_SCREEN_HEIGHT - 1)], (background_attribute << 8) | ' ', DEBUG_SCREEN_WIDTH); } } } return index; }
// NOTE: This is a possible bottle neck in case the new scope paths // will appear too often. hale_internal CachedScope * _scope_make(HALE_STACK, ScopeArena *A, ScopePath *path) { auto cached_scope = hale_memory_push(CachedScope, &A->cached_scopes, 1); *cached_scope = {}; memory_copy(&cached_scope->nodes, &path->nodes, 1); cached_scope->properties = hale_memory_end(ScopeProperties*, &A->cached_scope_properties); StackMemory matches(stack); ScopeSelectorMatch *match = hale_memory_push(ScopeSelectorMatch, &matches, 1); ScopeProperties **properties; auto selector_it = hale_memory_begin(ScopeSelector, &A->selectors); auto selector_end = hale_memory_end(ScopeSelector, &A->selectors); while (selector_it != selector_end) { if (_scope_path_match(path, selector_it, match)) { properties = hale_memory_push(ScopeProperties*, &A->cached_scope_properties, 1); *properties = selector_it->properties; match = hale_memory_push(ScopeSelectorMatch, &matches, 1); } selector_it = selector_it->next(); } cached_scope->properties_count = hale_memory_end(ScopeProperties*, &A->cached_scope_properties) - cached_scope->properties; // TODO: We have all matched selectors in match, now we need to sort them. // - Do we really need to sort them? // - See the TODO above, because we'll have to sort selectors array by scores array. return cached_scope; }
/* Clones an extent * Returns 1 if successful or -1 on error */ int libfsext_extent_clone( libfsext_extent_t **destination_extent, libfsext_extent_t *source_extent, libcerror_error_t **error ) { static char *function = "libfsext_extent_clone"; if( destination_extent == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid extent.", function ); return( -1 ); } if( *destination_extent != NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, "%s: invalid destination extent value already set.", function ); return( -1 ); } if( source_extent == NULL ) { *destination_extent = source_extent; return( 1 ); } *destination_extent = memory_allocate_structure( libfsext_extent_t ); if( *destination_extent == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_INSUFFICIENT, "%s: unable to create destination extent.", function ); goto on_error; } if( memory_copy( *destination_extent, source_extent, sizeof( libfsext_extent_t ) ) == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_COPY_FAILED, "%s: unable to copy source to destination extent.", function ); goto on_error; } return( 1 ); on_error: if( *destination_extent != NULL ) { memory_free( *destination_extent ); *destination_extent = NULL; } return( -1 ); }
/* Clones the local descriptor value * Returns 1 if successful or -1 on error */ int libpff_local_descriptor_value_clone( libpff_local_descriptor_value_t **destination_local_descriptor_value, libpff_local_descriptor_value_t *source_local_descriptor_value, libcerror_error_t **error ) { static char *function = "libpff_local_descriptor_value_clone"; if( destination_local_descriptor_value == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid destination local descriptor value.", function ); return( -1 ); } if( *destination_local_descriptor_value != NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, "%s: invalid destination local descriptor value already set.", function ); return( -1 ); } if( source_local_descriptor_value == NULL ) { *destination_local_descriptor_value = NULL; return( 1 ); } *destination_local_descriptor_value = memory_allocate_structure( libpff_local_descriptor_value_t ); if( *destination_local_descriptor_value == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_INSUFFICIENT, "%s: unable to create destination local descriptor value.", function ); goto on_error; } if( memory_copy( *destination_local_descriptor_value, source_local_descriptor_value, sizeof( libpff_local_descriptor_value_t ) ) == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_COPY_FAILED, "%s: unable to copy local descriptor value.", function ); goto on_error; } return( 1 ); on_error: if( *destination_local_descriptor_value != NULL ) { memory_free( *destination_local_descriptor_value ); *destination_local_descriptor_value = NULL; } return( -1 ); }