libspe2  0.9a
Macros | Functions
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.

Macros

#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)
 

Macro Definition 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().

160 {
161  spe_program_handle_t *loader = emulated_loader_program();
162 
163  if (!loader)
164  return 0;
165 
166  return !_base_spe_verify_spe_elf_image(loader);
167 }

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
spectxSpecifies the SPE context
programhandle 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.

204 {
205  int rc = 0;
206  struct spe_ld_info ld_info;
207 
208  spe->base_private->loaded_program = program;
209 
210  if (spe->base_private->flags & SPE_ISOLATE) {
211  rc = spe_start_isolated_app(spe, program);
212 
213  } else if (spe->base_private->flags & SPE_ISOLATE_EMULATE) {
214  rc = spe_start_emulated_isolated_app(spe, program, &ld_info);
215 
216  } else {
217  rc = _base_spe_load_spe_elf(program,
218  spe->base_private->mem_mmap_base, &ld_info);
219  if (!rc)
221  }
222 
223  if (rc != 0) {
224  DEBUG_PRINTF ("Load SPE ELF failed..\n");
225  return -1;
226  }
227 
228  spe->base_private->entry = ld_info.entry;
229  spe->base_private->emulated_entry = ld_info.entry;
230 
231  return 0;
232 }

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().

39 {
40  int objfd, len;
41  char buf[20];
42  spe_program_handle_t *program;
43 
44  program = spectx->base_private->loaded_program;
45 
46  if (!program || !program->elf_image) {
47  DEBUG_PRINTF("%s called, but no program loaded\n", __func__);
48  return;
49  }
50 
51  objfd = openat(spectx->base_private->fd_spe_dir, "object-id", O_RDWR);
52  if (objfd < 0)
53  return;
54 
55  len = sprintf(buf, "%p", program->elf_image);
56  write(objfd, buf, len + 1);
57  close(objfd);
58 
60 }

Here is the call graph for this function: