def collect_extension_element(extension_el, pd, namespace, rp_elf, image, machine, bootinfo, pools): # New namespace for objects living in the extension. extn_namespace = namespace.add_namespace(extension_el.name) elf = None start = None name = None physpool = getattr(extension_el, 'physpool', None) pager = getattr(extension_el, 'pager', None) direct = getattr(extension_el, 'direct', None) # Push the overriding pools for the extension. image.push_attrs(physical=physpool, pager=pager, direct=direct) if hasattr(extension_el, "file"): elf = UnpreparedElfFile(filename=extension_el.file) if elf.elf_type != ET_EXEC: raise MergeError, "All the merged ELF files must be of EXEC type." segment_els = extension_el.find_children("segment") segs = collect_elf_segments(elf, image.EXTENSION, segment_els, extension_el.name, extn_namespace, image, machine, pools) segs_ms = [ bootinfo.record_segment_info(extension_el.name, seg, image, machine, pools) for seg in segs ] for seg_ms in segs_ms: pd.attach_memsection(seg_ms) # Record any patches being made to the program. patch_els = extension_el.find_children("patch") collect_patches(elf, patch_els, extension_el.file, image) start = elf.entry_point name = extension_el.file if hasattr(extension_el, "start"): start = extension_el.start name = extension_el.name # If no file is supplied, look for symbols in the root # program. if elf is None: elf = rp_elf elf = elf.prepare(elf.wordsize, elf.endianess) start = start_to_value(start, elf) bootinfo.add_elf_info(name=name, elf_type=image.EXTENSION, entry_point=start) image.pop_attrs()
def collect_pd_element(pd_el, ignore_name, namespace, image, machine, bootinfo, pools): """Collect the attributes of a PD element.""" # New namespace for objects living in the PD. pd_namespace = namespace.add_namespace(pd_el.name) pd = weaver.bootinfo.PD(pd_el.name, pd_namespace, image, machine, pools) virtpool = getattr(pd_el, 'virtpool', None) physpool = getattr(pd_el, 'physpool', None) direct = getattr(pd_el, 'direct', None) pd.set_platform_control(getattr(pd_el, "platform_control", False)) if hasattr(pd_el, 'pager'): pager = make_pager_attr(pd_el.pager) else: pager = None # Push the overriding attributes for the pd. image.push_attrs(virtual = virtpool, physical = physpool, pager = pager, direct = direct) pd.set_default_pools(image, bootinfo) # Collect the object environment env = collect_environment_element(pd_el.find_child('environment'), pd_namespace, machine, pools, image, bootinfo) if hasattr(pd_el, "file"): elf = PreparedElfFile(filename=pd_el.file) if elf.elf_type != ET_EXEC: raise MergeError, "All the merged ELF files must be of EXEC type." segment_els = pd_el.find_all_children("segment") segs = collect_elf_segments(elf, image.PROGRAM, segment_els, pd_el.name, pd_namespace, image, machine, pools) segs_ms = [bootinfo.record_segment_info(pd_el.name, seg, image, machine, pools) for seg in segs] for seg_ms in segs_ms: pd.attach_memsection(seg_ms) # Record any patches being made to the program. patch_els = pd_el.find_children("patch") collect_patches(elf, patch_els, image) # Collect threads in the PD. for thread_el in pd_el.find_children('thread'): if not ignore_name.match(thread_el.name): thread = collect_thread(elf, thread_el, ignore_name, pd_namespace, image, machine, pools, entry = "_thread_start") pd.add_thread(thread) # Record the thread and its stack in the environment. env.add_entry(key = thread.get_name(), cap_name = thread.get_name() + '/master') env.add_entry(key = thread.get_name() + "/STACK", cap_name = thread.get_name() + '/stack/master', attach = thread.get_stack().get_attrs().attach) # Collect memsections in the PD. for ms_el in pd_el.find_children('memsection'): if not ignore_name.match(ms_el.name): ms = collect_memsection_element(ms_el, ignore_name, pd_namespace, image, machine, pools) pd.attach_memsection(ms) image.add_group(0, [ms.get_ms()]) env.add_entry(key = ms.get_name(), cap_name = ms.get_name() + '/master', attach = ms.get_attrs().attach) # Collect any zones in the program. for zone_el in pd_el.find_children('zone'): (zone, non_zone_ms) = \ collect_zone_element(zone_el, ignore_name, pd_namespace, pools, image, bootinfo, machine) pd.attach_zone(zone) # Attach zones that aren't part of the zone to the program. for ms in non_zone_ms: pd.attach_memsection(ms) image.add_group(0, [ms.get_ms()]) env.add_entry(key = ms.get_name(), cap_name = ms.get_name() + '/master', attach = ms.get_attrs().attach) pd.add_environment(env) bootinfo.add_pd(pd) image.pop_attrs()
def collect_program_element(program_el, ignore_name, namespace, image, machine, bootinfo, pools): """Collect the attributes of a program element.""" # New namespace for objects living in the program's PD. prog_namespace = namespace.add_namespace(program_el.name) pd = weaver.bootinfo.PD(program_el.name, prog_namespace, image, machine, pools) elf = UnpreparedElfFile(filename=program_el.file) if elf.elf_type != ET_EXEC: raise MergeError, "All the merged ELF files must be of EXEC type." bootinfo.add_elf_info(name = program_el.file, elf_type = image.PROGRAM, entry_point = elf.entry_point) pd.elf = elf virtpool = getattr(program_el, 'virtpool', None) physpool = getattr(program_el, 'physpool', None) direct = getattr(program_el, 'direct', None) pd.set_platform_control(getattr(program_el, "platform_control", False)) if hasattr(program_el, 'pager'): pager = make_pager_attr(program_el.pager) else: pager = None # Push the overriding attributes for the program. image.push_attrs(virtual = virtpool, physical = physpool, pager = pager, direct = direct) pd.set_default_pools(image, bootinfo) # Collect the object environment env = collect_environment_element(program_el.find_child('environment'), prog_namespace, machine, pools, image, bootinfo) segment_els = program_el.find_all_children("segment") segs = collect_elf_segments(elf, image.PROGRAM, segment_els, program_el.name, prog_namespace, image, machine, pools) segs_ms = [bootinfo.record_segment_info(program_el.name, seg, image, machine, pools) for seg in segs] for seg_ms in segs_ms: pd.attach_memsection(seg_ms) # Record any patches being made to the program. patch_els = program_el.find_children("patch") collect_patches(elf, patch_els, program_el.file, image) # Collect the main thread. thread = collect_thread(elf, program_el, ignore_name, prog_namespace, image, machine, pools, entry = elf.entry_point, name = program_el.name, namespace_thread_name = "main") pd.add_thread(thread) pd.set_server_thread(thread) # Add the virtual device elements # Virtual devices always get added to the global namespace because they # should be globally unique server_spawn_nvdevs = 0 dev_ns = namespace.root.get_namespace("dev") if dev_ns is None: raise MergeError, "Device namespace does not exist!" for v_el in program_el.find_children('virt_device'): virt_dev = pd.add_virt_dev(v_el.name, program_el.name, pd, thread, server_spawn_nvdevs) create_alias_cap(virt_dev, dev_ns) server_spawn_nvdevs += 1 # Record the main thread and its stack in the environment. env.add_entry(key = "MAIN", cap_name = 'main/master') env.add_entry(key = "MAIN/STACK", cap_name = 'main/stack/master', attach = thread.get_stack().get_attrs().attach) # If marked, sure that the program is exported to every # environment so that it can be found by other programs. # if hasattr(program_el, 'server'): bootinfo.add_server( key = program_el.server, cap_name = prog_namespace.abs_name('main') + '/stack/master') # Collect remaining threads. elf = pd.elf = pd.elf.prepare(image.wordsize, image.endianess) for thread_el in program_el.find_children('thread'): if not ignore_name.match(thread_el.name): thread = collect_thread(elf, thread_el, ignore_name, prog_namespace, image, machine, pools, entry = "_thread_start") pd.add_thread(thread) # Record the thread and its stack in the environment. env.add_entry(key = thread.get_name(), cap_name = thread.get_name() + '/master') env.add_entry(key = thread.get_name() + "/STACK", cap_name = thread.get_name() + '/stack/master', attach = thread.get_stack().get_attrs().attach) # Collect any other memsections in the program. for ms_el in program_el.find_children('memsection'): if not ignore_name.match(ms_el.name): ms = collect_memsection_element(ms_el, ignore_name, prog_namespace, image, machine, pools) pd.attach_memsection(ms) image.add_group(0, [ms.get_ms()]) env.add_entry(key = ms.get_name(), cap_name = ms.get_name() + '/master', attach = ms.get_attrs().attach) # Collect any zones in the program. for zone_el in program_el.find_children('zone'): (zone, non_zone_ms) = \ collect_zone_element(zone_el, ignore_name, prog_namespace, pools, image, bootinfo, machine) pd.attach_zone(zone) # Attach memsections that aren't part of the zone to the program. for ms in non_zone_ms: pd.attach_memsection(ms) image.add_group(0, [ms.get_ms()]) env.add_entry(key = ms.get_name(), cap_name = ms.get_name() + '/master', attach = ms.get_attrs().attach) # Collect the heap. Is there no element, create a fake one for # the collection code to use. heap_el = program_el.find_child('heap') if heap_el is None: heap_el = ParsedElement('heap') heap_ms = collect_memsection_element(heap_el, ignore_name, prog_namespace, image, machine, pools) pd.attach_heap(heap_ms) image.add_group(0, [heap_ms.get_ms()]) # Fill env with default values. env.add_entry(key = "HEAP", cap_name = 'heap/master', attach = heap_ms.get_attrs().attach) env.add_entry(key = "HEAP_BASE", base = heap_ms) env.add_entry(key = "HEAP_SIZE", value = heap_ms.get_attrs().size) pd.add_environment(env) bootinfo.add_pd(pd) image.pop_attrs()
def collect_extension_element(extension_el, pd, namespace, rp_elf, image, machine, bootinfo, pools): # New namespace for objects living in the extension. extn_namespace = namespace.add_namespace(extension_el.name) elf = None start = None name = None physpool = getattr(extension_el, 'physpool', None) pager = getattr(extension_el, 'pager', None) direct = getattr(extension_el, 'direct', None) # Push the overriding pools for the extension. image.push_attrs(physical = physpool, pager = pager, direct = direct) if hasattr(extension_el, "file"): elf = UnpreparedElfFile(filename=extension_el.file) if elf.elf_type != ET_EXEC: raise MergeError, "All the merged ELF files must be of EXEC type." segment_els = extension_el.find_children("segment") segs = collect_elf_segments(elf, image.EXTENSION, segment_els, extension_el.name, extn_namespace, image, machine, pools) segs_ms = [bootinfo.record_segment_info(extension_el.name, seg, image, machine, pools) for seg in segs] for seg_ms in segs_ms: pd.attach_memsection(seg_ms) # Record any patches being made to the program. patch_els = extension_el.find_children("patch") collect_patches(elf, patch_els, extension_el.file, image) start = elf.entry_point name = extension_el.file if hasattr(extension_el, "start"): start = extension_el.start name = extension_el.name # If no file is supplied, look for symbols in the root # program. if elf is None: elf = rp_elf elf = elf.prepare(elf.wordsize, elf.endianess) start = start_to_value(start, elf) bootinfo.add_elf_info(name = name, elf_type = image.EXTENSION, entry_point = start) image.pop_attrs()