Esempio n. 1
0
void
rtems_rtl_alloc_indirect_new (rtems_rtl_alloc_tag_t tag,
                              rtems_rtl_ptr_t*      handle,
                              size_t                size)
{
  rtems_rtl_data_t* rtl = rtems_rtl_lock ();

  if (rtems_rtl_trace (RTEMS_RTL_TRACE_ALLOCATOR))
  {
    if (!rtems_rtl_ptr_null (handle))
      printf ("rtl: alloc: inew: %s handle=%p: not null\n",
              rtems_rtl_trace_tag_label (tag), handle);
    printf ("rtl: alloc: inew: %s handle=%p size=%zd\n",
            rtems_rtl_trace_tag_label (tag), handle, size);
  }

  if (rtl)
  {
    rtems_rtl_alloc_data_t* allocator = &rtl->allocator;
    handle->pointer = rtems_rtl_alloc_new (tag, size, false);
    if (!rtems_rtl_ptr_null (handle))
      rtems_chain_append_unprotected (&allocator->indirects[tag],
                                      &handle->node);
  }

  rtems_rtl_unlock ();
}
Esempio n. 2
0
rtems_rtl_allocator_t
rtems_rtl_alloc_hook (rtems_rtl_allocator_t handler)
{
  rtems_rtl_data_t* rtl = rtems_rtl_lock ();
  rtems_rtl_allocator_t previous = rtl->allocator.allocator;
  rtl->allocator.allocator = handler;
  rtems_rtl_unlock ();
  return previous;
}
Esempio n. 3
0
void
rtems_rtl_set_error (int error, const char* format, ...)
{
  rtems_rtl_data_t* rtl = rtems_rtl_lock ();
  va_list           ap;
  va_start (ap, format);
  rtl->last_errno = error;
  vsnprintf (rtl->last_error, sizeof (rtl->last_error), format, ap);
  rtems_rtl_unlock ();
  va_end (ap);
}
Esempio n. 4
0
bool
rtems_rtl_obj_find_file (rtems_rtl_obj_t* obj, const char* name)
{
  const char*       pname;
  rtems_rtl_data_t* rtl;

  /*
   * Parse the name. The object descriptor will have the archive name and/or
   * object name fields filled in. A find of the file will result in the file
   * name (fname) field pointing to the actual file if present on the file
   * system.
   */
  if (!rtems_rtl_obj_parse_name (obj, name))
    return false;

  /*
   * If the archive field (aname) is set we use that name else we use the
   * object field (oname). If selected name is absolute we just point the aname
   * field to the fname field to that name. If the field is relative we search
   * the paths set in the RTL for the file.
   */
  if (rtems_rtl_obj_aname_valid (obj))
    pname = rtems_rtl_obj_aname (obj);
  else
    pname = rtems_rtl_obj_oname (obj);

  rtl = rtems_rtl_lock ();

  if (!rtems_rtl_find_file (pname, rtl->paths, &obj->fname, &obj->fsize))
  {
    rtems_rtl_set_error (ENOENT, "file not found");
    rtems_rtl_unlock ();
    return false;
  }

  rtems_rtl_unlock ();

  return true;
}
Esempio n. 5
0
void
rtems_rtl_alloc_del (rtems_rtl_alloc_tag_t tag, void* address)
{
  rtems_rtl_data_t* rtl = rtems_rtl_lock ();

  if (rtems_rtl_trace (RTEMS_RTL_TRACE_ALLOCATOR))
    printf ("rtl: alloc: del: %s addr=%p\n",
            rtems_rtl_trace_tag_label (tag), address);

  if (rtl && address)
    rtl->allocator.allocator (false, tag, &address, 0);

  rtems_rtl_unlock ();
}
Esempio n. 6
0
int
rtems_rtl_get_error (char* message, size_t max_message)
{
  rtems_rtl_data_t* rtl = rtems_rtl_lock ();
  if (rtl != NULL)
  {
    int last_errno = rtl->last_errno;
    strncpy (message, rtl->last_error, sizeof (rtl->last_error));
    rtems_rtl_unlock ();
    return last_errno;
  }

  strncpy(message, "RTL init error", max_message);

  return EIO;
}
Esempio n. 7
0
void*
rtems_rtl_alloc_new (rtems_rtl_alloc_tag_t tag, size_t size, bool zero)
{
  rtems_rtl_data_t* rtl = rtems_rtl_lock ();
  void*             address = NULL;

  if (rtl)
    rtl->allocator.allocator (true, tag, &address, size);

  rtems_rtl_unlock ();

  if (rtems_rtl_trace (RTEMS_RTL_TRACE_ALLOCATOR))
    printf ("rtl: alloc: new: %s addr=%p size=%zu\n",
            rtems_rtl_trace_tag_label (tag), address, size);

  if (zero)
    memset (address, 0, size);

  return address;
}
Esempio n. 8
0
int
rtems_rtl_shell_command (int argc, char* argv[])
{
    const rtems_rtl_shell_cmd_t table[] =
    {
        {   "status", rtems_rtl_shell_status,
            "Display the status of the RTL"
        },
        {   "list", rtems_rtl_shell_list,
            "\tList the object files currently loaded"
        },
        {   "sym", rtems_rtl_shell_sym,
            "\tDisplay the symbols, sym [<name>], sym -o <obj> [<name>]"
        },
        {   "obj", rtems_rtl_shell_object,
            "\tDisplay the object details, obj <name>"
        }
    };

    int arg;
    int t;

    for (arg = 1; arg < argc; arg++)
    {
        if (argv[arg][0] != '-')
            break;

        switch (argv[arg][1])
        {
        case 'h':
            rtems_rtl_shell_usage (argv[0]);
            return 0;
        case 'l':
            printf ("%s: commands are:\n", argv[0]);
            for (t = 0;
                    t < (sizeof (table) / sizeof (const rtems_rtl_shell_cmd_t));
                    ++t)
                printf ("  %s\t%s\n", table[t].name, table[t].help);
            return 0;
        default:
            printf ("error: unknown option: %s\n", argv[arg]);
            return 1;
        }
    }

    if ((argc - arg) < 1)
        printf ("error: you need to provide a command, try %s -h\n", argv[0]);
    else
    {
        for (t = 0;
                t < (sizeof (table) / sizeof (const rtems_rtl_shell_cmd_t));
                ++t)
        {
            if (strncmp (argv[arg], table[t].name, strlen (argv[arg])) == 0)
            {
                rtems_rtl_data_t* rtl = rtems_rtl_data ();
                int               r;
                if (!rtl)
                {
                    printf ("error: cannot lock the linker\n");
                    return 1;
                }
                r = table[t].handler (rtl, argc - 1, argv + 1);
                rtems_rtl_unlock ();
                return r;
            }
        }
        printf ("error: command not found: %s (try -h)\n", argv[arg]);
    }

    return 1;
}