load.c File Reference

#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include "elf_loader.h"
#include "create.h"
#include "spebase.h"
Include dependency graph for load.c:

Go to the source code of this file.

Defines

#define SPE_EMULATED_LOADER_FILE   "/usr/lib/spe/emulated-loader.bin"

Functions

void _base_spe_program_load_complete (spe_context_ptr_t spectx)
int _base_spe_emulated_loader_present (void)
int _base_spe_program_load (spe_context_ptr_t spe, spe_program_handle_t *program)

Define Documentation

#define SPE_EMULATED_LOADER_FILE   "/usr/lib/spe/emulated-loader.bin"

Definition at line 31 of file load.c.


Function Documentation

int _base_spe_emulated_loader_present ( void   ) 

Check if the emulated loader is present in the filesystem

Returns:
Non-zero if the loader is available, otherwise zero.

Definition at line 159 of file load.c.

References _base_spe_verify_spe_elf_image().

Referenced by _base_spe_context_create().

00160 {
00161         spe_program_handle_t *loader = emulated_loader_program();
00162 
00163         if (!loader)
00164                 return 0;
00165 
00166         return !_base_spe_verify_spe_elf_image(loader);
00167 }

Here is the call graph for this function:

int _base_spe_program_load ( spe_context_ptr_t  spectx,
spe_program_handle_t program 
)

_base_spe_program_load loads an ELF image into a context

Parameters:
spectx Specifies the SPE context
program handle to the ELF image

Definition at line 203 of file load.c.

References _base_spe_load_spe_elf(), _base_spe_program_load_complete(), spe_context::base_private, DEBUG_PRINTF, spe_context_base_priv::emulated_entry, spe_ld_info::entry, spe_context_base_priv::entry, spe_context_base_priv::flags, spe_context_base_priv::loaded_program, spe_context_base_priv::mem_mmap_base, SPE_ISOLATE, and SPE_ISOLATE_EMULATE.

00204 {
00205         int rc = 0;
00206         struct spe_ld_info ld_info;
00207 
00208         spe->base_private->loaded_program = program;
00209 
00210         if (spe->base_private->flags & SPE_ISOLATE) {
00211                 rc = spe_start_isolated_app(spe, program);
00212 
00213         } else if (spe->base_private->flags & SPE_ISOLATE_EMULATE) {
00214                 rc = spe_start_emulated_isolated_app(spe, program, &ld_info);
00215 
00216         } else {
00217                 rc = _base_spe_load_spe_elf(program,
00218                                 spe->base_private->mem_mmap_base, &ld_info);
00219                 if (!rc)
00220                         _base_spe_program_load_complete(spe);
00221         }
00222 
00223         if (rc != 0) {
00224                 DEBUG_PRINTF ("Load SPE ELF failed..\n");
00225                 return -1;
00226         }
00227 
00228         spe->base_private->entry = ld_info.entry;
00229         spe->base_private->emulated_entry = ld_info.entry;
00230 
00231         return 0;
00232 }

Here is the call graph for this function:

void _base_spe_program_load_complete ( spe_context_ptr_t  spectx  ) 

Register the SPE program's start address with the oprofile and gdb, by writing to the object-id file.

Definition at line 38 of file load.c.

References __spe_context_update_event(), spe_context::base_private, DEBUG_PRINTF, spe_program_handle::elf_image, spe_context_base_priv::fd_spe_dir, and spe_context_base_priv::loaded_program.

Referenced by _base_spe_context_run(), and _base_spe_program_load().

00039 {
00040         int objfd, len;
00041         char buf[20];
00042         spe_program_handle_t *program;
00043 
00044         program = spectx->base_private->loaded_program;
00045 
00046         if (!program || !program->elf_image) {
00047                 DEBUG_PRINTF("%s called, but no program loaded\n", __func__);
00048                 return;
00049         }
00050 
00051         objfd = openat(spectx->base_private->fd_spe_dir, "object-id", O_RDWR);
00052         if (objfd < 0)
00053                 return;
00054 
00055         len = sprintf(buf, "%p", program->elf_image);
00056         write(objfd, buf, len + 1);
00057         close(objfd);
00058 
00059         __spe_context_update_event();
00060 }

Here is the call graph for this function:


Generated by  doxygen 1.6.2