Changeset 9b63fbf in rtems


Ignore:
Timestamp:
Jul 14, 2004, 9:05:15 PM (17 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, 4.8, 4.9, 5, master
Children:
ef6d69c3
Parents:
a0f29ca4
Message:

2004-07-14 Joel Sherrill <joel@…>

PR 650/rtems

  • score/src/coremsg.c: Check for mathemathical overflow when calculating amount of memory to allocate for message buffers.
Location:
cpukit
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • cpukit/ChangeLog

    ra0f29ca4 r9b63fbf  
     12004-07-14      Joel Sherrill <joel@OARcorp.com>
     2
     3        PR 650/rtems
     4        * score/src/coremsg.c: Check for mathemathical overflow when calculating
     5        amount of memory to allocate for message buffers.
     6
    172004-07-14      Joel Sherrill <joel@OARcorp.com>
    28
  • cpukit/score/src/coremsg.c

    ra0f29ca4 r9b63fbf  
    5252  CORE_message_queue_Control    *the_message_queue,
    5353  CORE_message_queue_Attributes *the_message_queue_attributes,
    54   uint32_t                       maximum_pending_messages,
    55   uint32_t                       maximum_message_size
     54  unsigned32                     maximum_pending_messages,
     55  unsigned32                     maximum_message_size
    5656)
    5757{
    58   uint32_t  message_buffering_required;
    59   uint32_t  allocated_message_size;
     58  unsigned32 message_buffering_required;
     59  unsigned32 allocated_message_size;
    6060
    6161  the_message_queue->maximum_pending_messages   = maximum_pending_messages;
     
    6363  the_message_queue->maximum_message_size       = maximum_message_size;
    6464  _CORE_message_queue_Set_notify( the_message_queue, NULL, NULL );
     65 
     66  /*
     67   *  Round size up to multiple of a pointer for chain init and
     68   *  check for overflow on adding overhead to each message.
     69   */
     70 
     71  allocated_message_size = maximum_message_size;
     72  if (allocated_message_size & (sizeof(unsigned32) - 1)) {
     73      allocated_message_size += sizeof(unsigned32);
     74      allocated_message_size &= ~(sizeof(unsigned32) - 1);
     75  }
     76   
     77  if (allocated_message_size < maximum_message_size)
     78    return FALSE;
    6579
    6680  /*
    67    * round size up to multiple of a ptr for chain init
     81   *  Calculate how much total memory is required for message buffering and
     82   *  check for overflow on the multiplication.
    6883   */
    69 
    70   allocated_message_size = maximum_message_size;
    71   if (allocated_message_size & (sizeof(uint32_t  ) - 1)) {
    72       allocated_message_size += sizeof(uint32_t  );
    73       allocated_message_size &= ~(sizeof(uint32_t  ) - 1);
    74   }
    75 
    7684  message_buffering_required = maximum_pending_messages *
    7785       (allocated_message_size + sizeof(CORE_message_queue_Buffer_control));
     86 
     87  if (message_buffering_required < allocated_message_size)
     88    return FALSE;
    7889
    79   the_message_queue->message_buffers = (CORE_message_queue_Buffer *)
     90  /*
     91   *  Attempt to allocate the message memory
     92   */
     93  the_message_queue->message_buffers = (CORE_message_queue_Buffer *)
    8094     _Workspace_Allocate( message_buffering_required );
    81 
     95 
    8296  if (the_message_queue->message_buffers == 0)
    8397    return FALSE;
    84 
     98 
     99  /*
     100   *  Initialize the pool of inactive messages, pending messages,
     101   *  and set of waiting threads.
     102   */
    85103  _Chain_Initialize (
    86104    &the_message_queue->Inactive_messages,
     
    89107    allocated_message_size + sizeof( CORE_message_queue_Buffer_control )
    90108  );
    91 
     109 
    92110  _Chain_Initialize_empty( &the_message_queue->Pending_messages );
    93 
     111 
    94112  _Thread_queue_Initialize(
    95113    &the_message_queue->Wait_queue,
Note: See TracChangeset for help on using the changeset viewer.