Changeset e309f77 in rtems


Ignore:
Timestamp:
02/14/19 03:00:05 (5 years ago)
Author:
Chris Johns <chrisj@…>
Branches:
5, master
Children:
3ecb207
Parents:
e214ff4b
git-author:
Chris Johns <chrisj@…> (02/14/19 03:00:05)
git-committer:
Chris Johns <chrisj@…> (02/14/19 22:55:16)
Message:

libdl: Allocator does not unlock and lock memory on loading.

Close #3692

Location:
cpukit
Files:
5 edited

Legend:

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

    re214ff4b re309f77  
    4646
    4747/**
     48 * Define the allocation command the loader requires.
     49 */
     50enum rtems_rtl_alloc_cmd {
     51  RTEMS_RTL_ALLOC_NEW,        /**< Allocate new memory. */
     52  RTEMS_RTL_ALLOC_DEL,        /**< Delete allocated memory. */
     53  RTEMS_RTL_ALLOC_WR_ENABLE,  /**< Enable writes to the memory. */
     54  RTEMS_RTL_ALLOC_WR_DISABLE, /**< Disable writes to the memory. */
     55};
     56
     57/**
     58 * The allocator command type.
     59 */
     60typedef enum rtems_rtl_alloc_cmd rtems_rtl_alloc_cmd;
     61
     62/**
    4863 * The number of tags.
    4964 */
     
    5469 * overridded for customised allocation schemes or memory maps.
    5570 *
    56  * @param allocation If true the request is to allocate memory else free.
     71 * @param allocation The request command.
    5772 * @param tag The type of allocation request.
    5873 * @param address Pointer to the memory address. If an allocation the value is
     
    6479 *             not used if deleting or freeing a previous allocation.
    6580 */
    66 typedef void (*rtems_rtl_allocator)(bool                allocate,
     81typedef void (*rtems_rtl_allocator)(rtems_rtl_alloc_cmd cmd,
    6782                                    rtems_rtl_alloc_tag tag,
    6883                                    void**              address,
     
    108123
    109124/**
     125 * The Runtime Loader allocator enable write on a bloc of allocated memory.
     126 *
     127 * @param tag The type of allocation request. Must match the address.
     128 * @param address The memory address to write enable. A NULL is ignored.
     129 */
     130void rtems_rtl_alloc_wr_enable (rtems_rtl_alloc_tag tag, void* address);
     131
     132/**
     133 * The Runtime Loader allocator disable write on a bloc of allocated memory.
     134 *
     135 * @param tag The type of allocation request. Must match the address.
     136 * @param address The memory address to write disable. A NULL is ignored.
     137 */
     138void rtems_rtl_alloc_wr_disable (rtems_rtl_alloc_tag tag, void* address);
     139
     140/**
    110141 * Hook the Runtime Loader allocatior. A handler can call the previous handler
    111142 * in the chain to use it for specific tags. The default handler uses the
     
    137168void rtems_rtl_alloc_indirect_del (rtems_rtl_alloc_tag tag,
    138169                                   rtems_rtl_ptr*      handle);
     170
     171/**
     172 * Return the default tag for text sections.
     173 *
     174 * @return The text tag.
     175 */
     176rtems_rtl_alloc_tag rtems_rtl_alloc_text_tag (void);
     177
     178/**
     179 * Return the default tag for const sections.
     180 *
     181 * @return The const tag.
     182 */
     183rtems_rtl_alloc_tag rtems_rtl_alloc_const_tag (void);
     184
     185/**
     186 * Return the default tag for exception sections.
     187 *
     188 * @return The eh tag.
     189 */
     190rtems_rtl_alloc_tag rtems_rtl_alloc_eh_tag (void);
     191
     192/**
     193 * Return the default tag for data sections.
     194 *
     195 * @return The data tag.
     196 */
     197rtems_rtl_alloc_tag rtems_rtl_alloc_data_tag (void);
     198
     199/**
     200 * Return the default tag for bss sections.
     201 *
     202 * @return The bss tag.
     203 */
     204rtems_rtl_alloc_tag rtems_rtl_alloc_bss_tag (void);
    139205
    140206/**
  • cpukit/libdl/rtl-alloc-heap.c

    re214ff4b re309f77  
    1919
    2020void
    21 rtems_rtl_alloc_heap (bool                allocate,
     21rtems_rtl_alloc_heap (rtems_rtl_alloc_cmd cmd,
    2222                      rtems_rtl_alloc_tag tag,
    2323                      void**              address,
    2424                      size_t              size)
    2525{
    26   if (allocate)
     26  if (cmd == RTEMS_RTL_ALLOC_NEW)
    2727    *address = malloc (size);
    28   else
     28  else if (cmd == RTEMS_RTL_ALLOC_DEL)
    2929  {
    3030    free (*address);
  • cpukit/libdl/rtl-alloc-heap.h

    re214ff4b re309f77  
    2626 * Allocator handler for the standard libc heap.
    2727 *
    28  * @param allocation If true the request is to allocate memory else free.
     28 * @param cmd The allocation command.
    2929 * @param tag The type of allocation request.
    3030 * @param address Pointer to the memory address. If an allocation the value is
     
    3636 *             not used if deleting or freeing a previous allocation.
    3737 */
    38 void rtems_rtl_alloc_heap(bool                allocate,
     38void rtems_rtl_alloc_heap(rtems_rtl_alloc_cmd cmd,
    3939                          rtems_rtl_alloc_tag tag,
    4040                          void**              address,
  • cpukit/libdl/rtl-allocator.c

    re214ff4b re309f77  
    5858   * allocator.
    5959   */
    60   if (rtl)
    61     rtl->allocator.allocator (true, tag, &address, size);
     60  if (rtl != NULL)
     61    rtl->allocator.allocator (RTEMS_RTL_ALLOC_NEW, tag, &address, size);
    6262
    6363  rtems_rtl_unlock ();
     
    7070   * Only zero the memory if asked to and the allocation was successful.
    7171   */
    72   if (address && zero)
     72  if (address != NULL && zero)
    7373    memset (address, 0, size);
    7474
     
    8585            rtems_rtl_trace_tag_label (tag), address);
    8686
    87   if (rtl && address)
    88     rtl->allocator.allocator (false, tag, &address, 0);
     87  if (rtl != NULL && address != NULL)
     88    rtl->allocator.allocator (RTEMS_RTL_ALLOC_DEL, tag, &address, 0);
     89
     90  rtems_rtl_unlock ();
     91}
     92
     93void
     94rtems_rtl_alloc_wr_enable (rtems_rtl_alloc_tag tag, void* address)
     95{
     96  rtems_rtl_data* rtl = rtems_rtl_lock ();
     97
     98  if (rtems_rtl_trace (RTEMS_RTL_TRACE_ALLOCATOR))
     99    printf ("rtl: alloc: wr-enable: addr=%p\n", address);
     100
     101  if (rtl != NULL && address != NULL)
     102    rtl->allocator.allocator (RTEMS_RTL_ALLOC_WR_ENABLE,
     103                              tag,
     104                              address,
     105                              0);
     106
     107  rtems_rtl_unlock ();
     108}
     109
     110void
     111rtems_rtl_alloc_wr_disable (rtems_rtl_alloc_tag tag, void* address)
     112{
     113  rtems_rtl_data* rtl = rtems_rtl_lock ();
     114
     115  if (rtems_rtl_trace (RTEMS_RTL_TRACE_ALLOCATOR))
     116    printf ("rtl: alloc: wr-enable: addr=%p\n", address);
     117
     118  if (rtl != NULL && address != NULL)
     119    rtl->allocator.allocator (RTEMS_RTL_ALLOC_WR_DISABLE,
     120                              tag,
     121                              address,
     122                              0);
    89123
    90124  rtems_rtl_unlock ();
     
    149183    rtems_rtl_alloc_del (tag, &handle->pointer);
    150184  }
     185}
     186
     187rtems_rtl_alloc_tag
     188rtems_rtl_alloc_text_tag (void)
     189{
     190  return RTEMS_RTL_ALLOC_READ_EXEC;
     191}
     192
     193rtems_rtl_alloc_tag
     194rtems_rtl_alloc_const_tag (void)
     195{
     196  return RTEMS_RTL_ALLOC_READ;
     197}
     198
     199rtems_rtl_alloc_tag
     200rtems_rtl_alloc_eh_tag (void)
     201{
     202  return RTEMS_RTL_ALLOC_READ;
     203}
     204
     205rtems_rtl_alloc_tag
     206rtems_rtl_alloc_data_tag (void)
     207{
     208  return RTEMS_RTL_ALLOC_READ_WRITE;
     209}
     210
     211rtems_rtl_alloc_tag
     212rtems_rtl_alloc_bss_tag (void)
     213{
     214  return RTEMS_RTL_ALLOC_READ_WRITE;
    151215}
    152216
     
    162226  if (text_size)
    163227  {
    164     *text_base = rtems_rtl_alloc_new (RTEMS_RTL_ALLOC_READ_EXEC,
     228    *text_base = rtems_rtl_alloc_new (rtems_rtl_alloc_text_tag (),
    165229                                      text_size, false);
    166230    if (!*text_base)
     
    172236  if (const_size)
    173237  {
    174     *const_base = rtems_rtl_alloc_new (RTEMS_RTL_ALLOC_READ,
     238    *const_base = rtems_rtl_alloc_new (rtems_rtl_alloc_const_tag (),
    175239                                       const_size, false);
    176240    if (!*const_base)
     
    184248  if (eh_size)
    185249  {
    186     *eh_base = rtems_rtl_alloc_new (RTEMS_RTL_ALLOC_READ,
     250    *eh_base = rtems_rtl_alloc_new (rtems_rtl_alloc_eh_tag (),
    187251                                    eh_size, false);
    188252    if (!*eh_base)
     
    196260  if (data_size)
    197261  {
    198     *data_base = rtems_rtl_alloc_new (RTEMS_RTL_ALLOC_READ_WRITE,
     262    *data_base = rtems_rtl_alloc_new (rtems_rtl_alloc_data_tag (),
    199263                                      data_size, false);
    200264    if (!*data_base)
     
    208272  if (bss_size)
    209273  {
    210     *bss_base = rtems_rtl_alloc_new (RTEMS_RTL_ALLOC_READ_WRITE,
     274    *bss_base = rtems_rtl_alloc_new (rtems_rtl_alloc_bss_tag (),
    211275                                     bss_size, false);
    212276    if (!*bss_base)
  • cpukit/libdl/rtl-obj.c

    re214ff4b re309f77  
    10011001static bool
    10021002rtems_rtl_obj_sections_loader (uint32_t                   mask,
     1003                               rtems_rtl_alloc_tag        tag,
    10031004                               rtems_rtl_obj*             obj,
    10041005                               int                        fd,
     
    10141015  if (rtems_rtl_trace (RTEMS_RTL_TRACE_LOAD_SECT))
    10151016    printf ("rtl: loading section: mask:%08" PRIx32 " base:%p\n", mask, base);
     1017
     1018  rtems_rtl_alloc_wr_enable (tag, base);
    10161019
    10171020  while (!rtems_chain_is_tail (sections, node))
     
    10401043          {
    10411044            sect->base = 0;
     1045            rtems_rtl_alloc_wr_disable (tag, base);
    10421046            return false;
    10431047          }
     
    10681072  }
    10691073
     1074  rtems_rtl_alloc_wr_disable (tag, base);
     1075
    10701076  return true;
    10711077}
     
    11691175   */
    11701176  if (!rtems_rtl_obj_sections_loader (RTEMS_RTL_OBJ_SECT_TEXT,
     1177                                      rtems_rtl_alloc_text_tag (),
    11711178                                      obj, fd, obj->text_base, handler, data) ||
    11721179      !rtems_rtl_obj_sections_loader (RTEMS_RTL_OBJ_SECT_CONST,
     1180                                      rtems_rtl_alloc_const_tag (),
    11731181                                      obj, fd, obj->const_base, handler, data) ||
    11741182      !rtems_rtl_obj_sections_loader (RTEMS_RTL_OBJ_SECT_EH,
     1183                                      rtems_rtl_alloc_eh_tag (),
    11751184                                      obj, fd, obj->eh_base, handler, data) ||
    11761185      !rtems_rtl_obj_sections_loader (RTEMS_RTL_OBJ_SECT_DATA,
     1186                                      rtems_rtl_alloc_data_tag (),
    11771187                                      obj, fd, obj->data_base, handler, data) ||
    11781188      !rtems_rtl_obj_sections_loader (RTEMS_RTL_OBJ_SECT_BSS,
     1189                                      rtems_rtl_alloc_bss_tag (),
    11791190                                      obj, fd, obj->bss_base, handler, data))
    11801191  {
Note: See TracChangeset for help on using the changeset viewer.