예제 #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 ();
}
예제 #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;
}
예제 #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);
}
예제 #4
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 ();
}
예제 #5
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;
}
예제 #6
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;
}
예제 #7
0
void
rtems_rtl_alloc_indirect_del (rtems_rtl_alloc_tag_t tag,
                              rtems_rtl_ptr_t*      handle)
{
  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: idel: %s handle=%p: is null\n",
              rtems_rtl_trace_tag_label (tag), handle);
    printf ("rtl: alloc: idel: %s handle=%p\n",
            rtems_rtl_trace_tag_label (tag), handle);
  }

  if (rtl && !rtems_rtl_ptr_null (handle))
  {
    rtems_chain_extract_unprotected (&handle->node);
    rtems_rtl_alloc_del (tag, &handle->pointer);
  }
}
예제 #8
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;
}