Changeset 0d77c4f2 in rtems


Ignore:
Timestamp:
Jul 21, 2016, 12:35:00 AM (3 years ago)
Author:
Pavel Pisa <pisa@…>
Branches:
4.11
Children:
ae3578a2
Parents:
fd6cd36
git-author:
Pavel Pisa <pisa@…> (07/21/16 00:35:00)
git-committer:
Pavel Pisa <pisa@…> (10/02/16 08:40:33)
Message:

libdl/rtl-obj.c: synchronize cache after code relocation.

Memory content changes caused by relocation has to be
propagated to memory/cache level which is used/snooped
during instruction cache fill.

Closes #2438
Updates #2782

Location:
cpukit/libdl
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • cpukit/libdl/rtl-elf.c

    rfd6cd36 r0d77c4f2  
    945945    return false;
    946946
     947  rtems_rtl_obj_synchronize_cache (obj);
     948
    947949  rtems_rtl_symbol_obj_erase_local (obj);
    948950
  • cpukit/libdl/rtl-obj.c

    rfd6cd36 r0d77c4f2  
    557557  uint32_t mask = RTEMS_RTL_OBJ_SECT_REL | RTEMS_RTL_OBJ_SECT_RELA;
    558558  return rtems_rtl_obj_section_handler (mask, obj, fd, handler, data);
     559}
     560
     561/**
     562 * Cache synchronization after runtime object load (dlopen)
     563 */
     564typedef struct
     565{
     566  uint32_t mask;
     567  void     *start_va;
     568  void     *end_va;
     569} rtems_rtl_obj_sect_sync_ctx_t;
     570
     571static bool
     572rtems_rtl_obj_sect_sync_handler (rtems_chain_node* node, void* data)
     573{
     574  rtems_rtl_obj_sect_t*   sect = (rtems_rtl_obj_sect_t*) node;
     575  rtems_rtl_obj_sect_sync_ctx_t* sync_ctx = data;
     576  uintptr_t old_end;
     577  uintptr_t new_start;
     578
     579  if ( !(sect->flags & sync_ctx->mask) || !sect->size)
     580    return true;
     581
     582  if (sync_ctx->end_va == sync_ctx->start_va) {
     583    sync_ctx->start_va = sect->base;
     584  } else {
     585    old_end = (uintptr_t)sync_ctx->end_va & ~(CPU_CACHE_LINE_BYTES - 1);
     586    new_start = (uintptr_t)sect->base & ~(CPU_CACHE_LINE_BYTES - 1);
     587    if ( (sect->base <  sync_ctx->start_va) ||
     588         (new_start - old_end > CPU_CACHE_LINE_BYTES) ) {
     589      rtems_cache_instruction_sync_after_code_change(sync_ctx->start_va,
     590                             sync_ctx->end_va - sync_ctx->start_va + 1);
     591      sync_ctx->start_va = sect->base;
     592    }
     593  }
     594
     595  sync_ctx->end_va = sect->base + sect->size;
     596
     597  return true;
     598}
     599
     600void
     601rtems_rtl_obj_synchronize_cache (rtems_rtl_obj_t*    obj)
     602{
     603  rtems_rtl_obj_sect_sync_ctx_t sync_ctx;
     604
     605  if (rtems_cache_get_instruction_line_size() == 0)
     606    return;
     607
     608  sync_ctx.mask = RTEMS_RTL_OBJ_SECT_TEXT | RTEMS_RTL_OBJ_SECT_CONST |
     609                  RTEMS_RTL_OBJ_SECT_DATA | RTEMS_RTL_OBJ_SECT_BSS |
     610                  RTEMS_RTL_OBJ_SECT_EXEC;
     611
     612  sync_ctx.start_va = 0;
     613  sync_ctx.end_va = sync_ctx.start_va;
     614  rtems_rtl_chain_iterate (&obj->sections,
     615                           rtems_rtl_obj_sect_sync_handler,
     616                           &sync_ctx);
     617
     618  if (sync_ctx.end_va != sync_ctx.start_va) {
     619    rtems_cache_instruction_sync_after_code_change(sync_ctx.start_va,
     620                              sync_ctx.end_va - sync_ctx.start_va);
     621  }
    559622}
    560623
  • cpukit/libdl/rtl-obj.h

    rfd6cd36 r0d77c4f2  
    495495
    496496/**
     497 * Synchronize caches to make code visible to CPU(s)
     498 *
     499 * @param obj The object file's descriptor.
     500 */
     501void rtems_rtl_obj_synchronize_cache (rtems_rtl_obj_t*    obj);
     502
     503/**
    497504 * Relocate an object file's unresolved reference.
    498505 *
  • cpukit/libdl/rtl-rap.c

    rfd6cd36 r0d77c4f2  
    971971    return false;
    972972
     973  rtems_rtl_obj_synchronize_cache (obj);
     974
    973975  return true;
    974976}
Note: See TracChangeset for help on using the changeset viewer.