Changeset 22afb034 in rtems


Ignore:
Timestamp:
Feb 18, 2019, 12:46:22 AM (9 months ago)
Author:
Chris Johns <chrisj@…>
Branches:
master
Children:
be62def9
Parents:
bdec62c4
git-author:
Chris Johns <chrisj@…> (02/18/19 00:46:22)
git-committer:
Chris Johns <chrisj@…> (02/19/19 22:08:14)
Message:

libdl/alloc: Add a locking interface to the allocator.

  • Allow an allocator to lock the allocations. This is needed to lock the heap allocator so the text and trampoline table are as close together as possible to allow for the largest possible object file size.
  • Update the default heap allocator to lock the heap allocator.
  • Update ELF loading to lock the allocator.

Updates #3685

Location:
cpukit
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • cpukit/include/rtems/rtl/rtl-allocator.h

    rbdec62c4 r22afb034  
    5151  RTEMS_RTL_ALLOC_NEW,        /**< Allocate new memory. */
    5252  RTEMS_RTL_ALLOC_DEL,        /**< Delete allocated memory. */
     53  RTEMS_RTL_ALLOC_LOCK,       /**< Lock the allocator. */
     54  RTEMS_RTL_ALLOC_UNLOCK,     /**< Unlock the allocator. */
    5355  RTEMS_RTL_ALLOC_WR_ENABLE,  /**< Enable writes to the memory. */
    5456  RTEMS_RTL_ALLOC_WR_DISABLE, /**< Disable writes to the memory. */
     
    121123 */
    122124void rtems_rtl_alloc_del (rtems_rtl_alloc_tag tag, void* address);
     125
     126/**
     127 * The Runtime Loader allocator lock. An allocator that depends on a
     128 * separate allocation process, for example the heap, may need to be
     129 * locked during loading of an object file to make sure the locality
     130 * of the memory. This call be used to lock such an allocator.
     131 *  Allocator calls in this interface are protected by the RTL lock.
     132 */
     133void rtems_rtl_alloc_lock (void);
     134
     135/**
     136 * The Runtime Loader allocator unlock. An allocator that depends on a
     137 * separate allocation process, for example the heap, may need to be
     138 * locked during loading of an object file to make sure the locality
     139 * of the memory. This call can be used to unlock such an allocator.
     140 * Allocator calls in this interface are protected by the RTL lock.
     141 */
     142void rtems_rtl_alloc_unlock (void);
    123143
    124144/**
  • cpukit/libdl/rtl-alloc-heap.c

    rbdec62c4 r22afb034  
    1818#include "rtl-alloc-heap.h"
    1919
     20#include <rtems/score/apimutex.h>
     21
    2022void
    2123rtems_rtl_alloc_heap (rtems_rtl_alloc_cmd cmd,
     
    2426                      size_t              size)
    2527{
    26   if (cmd == RTEMS_RTL_ALLOC_NEW)
    27     *address = malloc (size);
    28   else if (cmd == RTEMS_RTL_ALLOC_DEL)
     28  switch (cmd)
    2929  {
    30     free (*address);
    31     *address = NULL;
     30    case RTEMS_RTL_ALLOC_NEW:
     31      *address = malloc (size);
     32      break;
     33    case RTEMS_RTL_ALLOC_DEL:
     34      free (*address);
     35      *address = NULL;
     36      break;
     37    case RTEMS_RTL_ALLOC_LOCK:
     38      _RTEMS_Lock_allocator();
     39      break;
     40    case RTEMS_RTL_ALLOC_UNLOCK:
     41      _RTEMS_Unlock_allocator();
     42      break;
     43    default:
     44      break;
    3245  }
    3346}
  • cpukit/libdl/rtl-allocator.c

    rbdec62c4 r22afb034  
    109109
    110110void
     111rtems_rtl_alloc_lock (void)
     112{
     113  rtems_rtl_data* rtl = rtems_rtl_lock ();
     114
     115  if (rtems_rtl_trace (RTEMS_RTL_TRACE_ALLOCATOR))
     116    printf ("rtl: alloc: lock\n");
     117
     118  if (rtl != NULL)
     119    rtl->allocator.allocator (RTEMS_RTL_ALLOC_LOCK,
     120                              RTEMS_RTL_ALLOC_OBJECT, /* should be ignored */
     121                              NULL,
     122                              0);
     123
     124  rtems_rtl_unlock ();
     125}
     126
     127
     128void
     129rtems_rtl_alloc_unlock (void)
     130{
     131  rtems_rtl_data* rtl = rtems_rtl_lock ();
     132
     133  if (rtems_rtl_trace (RTEMS_RTL_TRACE_ALLOCATOR))
     134    printf ("rtl: alloc: unlock\n");
     135
     136  if (rtl != NULL)
     137    rtl->allocator.allocator (RTEMS_RTL_ALLOC_UNLOCK,
     138                              RTEMS_RTL_ALLOC_OBJECT, /* should be ignored */
     139                              NULL,
     140                              0);
     141
     142  rtems_rtl_unlock ();
     143}
     144void
    111145rtems_rtl_alloc_wr_disable (rtems_rtl_alloc_tag tag, void* address)
    112146{
  • cpukit/libdl/rtl-elf.c

    rbdec62c4 r22afb034  
    14581458
    14591459  /*
     1460   * Lock the allocator so the section memory and the trampoline memory are as
     1461   * clock as possible.
     1462   */
     1463  rtems_rtl_alloc_lock ();
     1464
     1465  /*
    14601466   * Allocate the sections.
    14611467   */
     
    14821488    return false;
    14831489
     1490  /*
     1491   * Unlock the allocator.
     1492   */
     1493  rtems_rtl_alloc_unlock ();
     1494
    14841495  if (!rtems_rtl_obj_load_symbols (obj, fd, rtems_rtl_elf_symbols, &ehdr))
    14851496    return false;
Note: See TracChangeset for help on using the changeset viewer.