[PATCH 2/8] score: Fix allocation size calculation

2020-09-24 Thread Sebastian Huber
The previous multiplication error check is broken on 64-bit machines.  Use the
recommended check from SEI CERT C Coding Standard, "INT30-C. Ensure that
unsigned integer operations do not wrap".

Make sure the message size computation does not overflow.

Update #4007.
---
 cpukit/score/src/coremsg.c | 74 --
 1 file changed, 23 insertions(+), 51 deletions(-)

diff --git a/cpukit/score/src/coremsg.c b/cpukit/score/src/coremsg.c
index af8dbd6583..137d9973f4 100644
--- a/cpukit/score/src/coremsg.c
+++ b/cpukit/score/src/coremsg.c
@@ -19,28 +19,12 @@
 #endif
 
 #include 
+#include 
 #include 
 
-/*
- *  size_t_mult32_with_overflow
- *
- *  This method multiplies two size_t 32-bit numbers and checks
- *  for overflow.  It returns false if an overflow occurred and
- *  the result is bad.
- */
-static inline bool size_t_mult32_with_overflow(
-  size_t  a,
-  size_t  b,
-  size_t *c
-)
-{
-  long long x = (long long)a*b;
-
-  if ( x > SIZE_MAX )
-return false;
-  *c = (size_t) x;
-  return true;
-}
+#define MESSAGE_SIZE_LIMIT \
+  ( SIZE_MAX - sizeof( uintptr_t ) - 1 \
+- sizeof( CORE_message_queue_Buffer_control ) )
 
 bool _CORE_message_queue_Initialize(
   CORE_message_queue_Control *the_message_queue,
@@ -49,48 +33,36 @@ bool _CORE_message_queue_Initialize(
   size_t  maximum_message_size
 )
 {
-  size_t message_buffering_required = 0;
-  size_t aligned_message_size;
+  size_t buffer_size;
 
   the_message_queue->maximum_pending_messages   = maximum_pending_messages;
   the_message_queue->number_of_pending_messages = 0;
   the_message_queue->maximum_message_size   = maximum_message_size;
   _CORE_message_queue_Set_notify( the_message_queue, NULL );
 
-  /*
-   * Align up the maximum message size to be an integral multiple of the
-   * pointer size.
-   */
-  aligned_message_size = RTEMS_ALIGN_UP(
-maximum_message_size,
-sizeof( uintptr_t )
-  );
-
-  /*
-   * Check for an integer overflow.  It can occur while aligning up the maximum
-   * message size.
-   */
-  if (aligned_message_size < maximum_message_size)
+  /* Make sure the message size computation does not overflow */
+  if ( maximum_message_size > MESSAGE_SIZE_LIMIT ) {
 return false;
+  }
 
-  /*
-   *  Calculate how much total memory is required for message buffering and
-   *  check for overflow on the multiplication.
-   */
-  if ( !size_t_mult32_with_overflow(
-(size_t) maximum_pending_messages,
-aligned_message_size + sizeof(CORE_message_queue_Buffer_control),
-&message_buffering_required ) ) 
+  buffer_size = RTEMS_ALIGN_UP( maximum_message_size, sizeof( uintptr_t ) );
+  _Assert( buffer_size >= maximum_message_size );
+
+  buffer_size += sizeof( CORE_message_queue_Buffer_control );
+  _Assert( buffer_size >= sizeof( CORE_message_queue_Buffer_control ) );
+
+  /* Make sure the memory allocation size computation does not overflow */
+  if ( maximum_pending_messages > SIZE_MAX / buffer_size ) {
 return false;
+  }
 
-  /*
-   *  Attempt to allocate the message memory
-   */
-  the_message_queue->message_buffers = (CORE_message_queue_Buffer *)
- _Workspace_Allocate( message_buffering_required );
+  the_message_queue->message_buffers = _Workspace_Allocate(
+(size_t) maximum_pending_messages * buffer_size
+  );
 
-  if (the_message_queue->message_buffers == 0)
+  if ( the_message_queue->message_buffers == NULL ) {
 return false;
+  }
 
   /*
*  Initialize the pool of inactive messages, pending messages,
@@ -100,7 +72,7 @@ bool _CORE_message_queue_Initialize(
 &the_message_queue->Inactive_messages,
 the_message_queue->message_buffers,
 (size_t) maximum_pending_messages,
-aligned_message_size + sizeof( CORE_message_queue_Buffer_control )
+buffer_size
   );
 
   _Chain_Initialize_empty( &the_message_queue->Pending_messages );
-- 
2.26.2

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH 8/8] rtems: Add rtems_message_queue_construct()

2020-09-24 Thread Sebastian Huber
In contrast to message queues created by rtems_message_queue_create(), the
message queues constructed by this directive use a user-provided message buffer
storage area.

Add RTEMS_MESSAGE_QUEUE_BUFFER() to define a message buffer type for message
buffer storage areas.

Update #4007.
---
 cpukit/Makefile.am   |   2 +
 cpukit/include/rtems/rtems/message.h | 124 +++
 cpukit/include/rtems/rtems/messageimpl.h |  17 ++
 cpukit/include/rtems/score/coremsg.h |  10 ++
 cpukit/include/rtems/score/coremsgimpl.h |  67 +++-
 cpukit/posix/src/mqueueopen.c|   4 +-
 cpukit/rtems/src/msgqconstruct.c | 189 +++
 cpukit/rtems/src/msgqcreate.c| 178 +
 cpukit/score/src/coremsg.c   |  17 +-
 cpukit/score/src/coremsgclose.c  |   7 +-
 cpukit/score/src/coremsgwkspace.c|  53 +++
 spec/build/cpukit/librtemscpu.yml|   2 +
 testsuites/sptests/sp13/init.c   |  21 ++-
 testsuites/sptests/sp13/system.h |   2 +-
 14 files changed, 532 insertions(+), 161 deletions(-)
 create mode 100644 cpukit/rtems/src/msgqconstruct.c
 create mode 100644 cpukit/score/src/coremsgwkspace.c

diff --git a/cpukit/Makefile.am b/cpukit/Makefile.am
index e2bed4b844..2c35354e66 100644
--- a/cpukit/Makefile.am
+++ b/cpukit/Makefile.am
@@ -706,6 +706,7 @@ librtemscpu_a_SOURCES += rtems/src/intrcatch.c
 librtemscpu_a_SOURCES += rtems/src/modes.c
 librtemscpu_a_SOURCES += rtems/src/msg.c
 librtemscpu_a_SOURCES += rtems/src/msgqbroadcast.c
+librtemscpu_a_SOURCES += rtems/src/msgqconstruct.c
 librtemscpu_a_SOURCES += rtems/src/msgqcreate.c
 librtemscpu_a_SOURCES += rtems/src/msgqdelete.c
 librtemscpu_a_SOURCES += rtems/src/msgqflush.c
@@ -839,6 +840,7 @@ librtemscpu_a_SOURCES += score/src/coremsgflushwait.c
 librtemscpu_a_SOURCES += score/src/coremsginsert.c
 librtemscpu_a_SOURCES += score/src/coremsgseize.c
 librtemscpu_a_SOURCES += score/src/coremsgsubmit.c
+librtemscpu_a_SOURCES += score/src/coremsgwkspace.c
 librtemscpu_a_SOURCES += score/src/coremutexseize.c
 librtemscpu_a_SOURCES += score/src/percpu.c
 librtemscpu_a_SOURCES += score/src/percpuasm.c
diff --git a/cpukit/include/rtems/rtems/message.h 
b/cpukit/include/rtems/rtems/message.h
index 675cd98acc..a576132d95 100644
--- a/cpukit/include/rtems/rtems/message.h
+++ b/cpukit/include/rtems/rtems/message.h
@@ -21,6 +21,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #ifdef __cplusplus
 extern "C" {
@@ -65,6 +66,129 @@ rtems_status_code rtems_message_queue_create(
   rtems_id*id
 );
 
+/**
+ * @brief Defines a structure which can be used as a message queue buffer for
+ *   messages of the specified maximum size.
+ *
+ * Use this macro to define the message buffers for
+ * rtems_message_queue_construct().
+ *
+ * @param _maximum_message_size is the maximum message size in bytes.
+ */
+#define RTEMS_MESSAGE_QUEUE_BUFFER( _maximum_message_size ) \
+  struct { \
+CORE_message_queue_Buffer _buffer; \
+char _message[ _maximum_message_size ]; \
+  }
+
+/**
+ * @brief This structure defines the configuration of a message queue
+ *   constructed by rtems_message_queue_construct().
+ */
+typedef struct {
+  /**
+   * @brief This member defines the name of the message queue.
+   */
+  rtems_name name;
+
+  /**
+   * @brief This member defines the maximum number of pending messages
+   *   supported by the message queue.
+   */
+  uint32_t maximum_pending_messages;
+
+  /**
+   * @brief This member defines the maximum message size supported by the
+   *   message queue.
+   */
+  size_t maximum_message_size;
+
+  /**
+   * @brief This member shall point to the message buffer storage area begin.
+   *
+   * The message buffer storage area for the message queue shall be an array of
+   * the type defined by RTEMS_MESSAGE_QUEUE_BUFFER() with a maximum message
+   * size equal to the maximum message size of this configuration.
+   */
+  void *storage_area;
+
+  /**
+   * @brief This member defines size of the message buffer storage area in
+   *   bytes.
+   */
+  size_t storage_size;
+
+  /**
+   * @brief This member defines the optional handler to free the message buffer
+   *   storage area.
+   *
+   * It is called when the message queue is deleted.  It is called from task
+   * context under protection of the object allocator lock.  It is allowed to
+   * call free() in this handler.  If handler is NULL, then no action will be
+   * performed.
+   */
+  void ( *storage_free )( void * );
+
+  /**
+   * @brief This member defines the attributes of the message queue.
+   */
+  rtems_attribute attributes;
+} rtems_message_queue_config;
+
+/**
+ * @brief Constructs a message queue according to the specified configuration.
+ *
+ * In contrast to message queues created by rtems_message_queue_create(), the
+ * message queues constructed by this directive use a user-provided message
+ * buffer storage area.
+ *
+ * This directive is intended for 

[PATCH 0/8] Add rtems_message_queue_construct()

2020-09-24 Thread Sebastian Huber
In contrast to message queues created by rtems_message_queue_create(), the
message queues constructed by this directive use a user-provided message buffer
storage area.

Add RTEMS_MESSAGE_QUEUE_BUFFER() to define a message buffer type for message
buffer storage areas.

Sebastian Huber (8):
  score: Use RTEMS_ALIGN_UP()
  score: Fix allocation size calculation
  score: Gather message queue control initialization
  score: Improve _CORE_message_queue_Initialize()
  score: Simplify CORE_message_queue_Buffer
  score: Add 
  rtems: Remove Message_queue_Control::attribute_set
  rtems: Add rtems_message_queue_construct()

 cpukit/Makefile.am |   2 +
 cpukit/headers.am  |   1 +
 cpukit/include/rtems/confdefs/wkspace.h|   2 +-
 cpukit/include/rtems/rtems/message.h   | 124 ++
 cpukit/include/rtems/rtems/messagedata.h   |   6 +-
 cpukit/include/rtems/rtems/messageimpl.h   |  17 ++
 cpukit/include/rtems/rtems/msgmp.h |   7 +-
 cpukit/include/rtems/score/coremsg.h   |  52 ++
 cpukit/include/rtems/score/coremsgbuffer.h |  96 +++
 cpukit/include/rtems/score/coremsgimpl.h   | 108 +---
 cpukit/include/rtems/score/status.h|   4 +
 cpukit/libmisc/monitor/mon-queue.c |  16 +-
 cpukit/posix/src/mqueueopen.c  |  19 ++-
 cpukit/rtems/src/msgmp.c   |  20 +--
 cpukit/rtems/src/msgqconstruct.c   | 189 +
 cpukit/rtems/src/msgqcreate.c  | 175 +--
 cpukit/rtems/src/msgqdelete.c  |   2 +-
 cpukit/score/src/coremsg.c | 128 ++
 cpukit/score/src/coremsgclose.c|   7 +-
 cpukit/score/src/coremsginsert.c   |  20 +--
 cpukit/score/src/coremsgseize.c|  10 +-
 cpukit/score/src/coremsgsubmit.c   |   4 +-
 cpukit/score/src/coremsgwkspace.c  |  53 ++
 spec/build/cpukit/librtemscpu.yml  |   3 +
 testsuites/sptests/sp13/init.c |  21 ++-
 testsuites/sptests/sp13/system.h   |   2 +-
 testsuites/sptests/sp77/init.c |   2 +-
 testsuites/sptests/spmsgq_err01/init.c |  10 +-
 28 files changed, 761 insertions(+), 339 deletions(-)
 create mode 100644 cpukit/include/rtems/score/coremsgbuffer.h
 create mode 100644 cpukit/rtems/src/msgqconstruct.c
 create mode 100644 cpukit/score/src/coremsgwkspace.c

-- 
2.26.2

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH 1/8] score: Use RTEMS_ALIGN_UP()

2020-09-24 Thread Sebastian Huber
Update #4007.
---
 cpukit/score/src/coremsg.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/cpukit/score/src/coremsg.c b/cpukit/score/src/coremsg.c
index fc6f9eba03..af8dbd6583 100644
--- a/cpukit/score/src/coremsg.c
+++ b/cpukit/score/src/coremsg.c
@@ -51,7 +51,6 @@ bool _CORE_message_queue_Initialize(
 {
   size_t message_buffering_required = 0;
   size_t aligned_message_size;
-  size_t align_mask;
 
   the_message_queue->maximum_pending_messages   = maximum_pending_messages;
   the_message_queue->number_of_pending_messages = 0;
@@ -62,8 +61,10 @@ bool _CORE_message_queue_Initialize(
* Align up the maximum message size to be an integral multiple of the
* pointer size.
*/
-  align_mask = sizeof(uintptr_t) - 1;
-  aligned_message_size = ( maximum_message_size + align_mask ) & ~align_mask;
+  aligned_message_size = RTEMS_ALIGN_UP(
+maximum_message_size,
+sizeof( uintptr_t )
+  );
 
   /*
* Check for an integer overflow.  It can occur while aligning up the maximum
-- 
2.26.2

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH 3/8] score: Gather message queue control initialization

2020-09-24 Thread Sebastian Huber
Initialize the structure in a single code block after the error checks and
calculations.

Update #4007.
---
 cpukit/score/src/coremsg.c | 27 +++
 1 file changed, 11 insertions(+), 16 deletions(-)

diff --git a/cpukit/score/src/coremsg.c b/cpukit/score/src/coremsg.c
index 137d9973f4..57882f6426 100644
--- a/cpukit/score/src/coremsg.c
+++ b/cpukit/score/src/coremsg.c
@@ -35,11 +35,6 @@ bool _CORE_message_queue_Initialize(
 {
   size_t buffer_size;
 
-  the_message_queue->maximum_pending_messages   = maximum_pending_messages;
-  the_message_queue->number_of_pending_messages = 0;
-  the_message_queue->maximum_message_size   = maximum_message_size;
-  _CORE_message_queue_Set_notify( the_message_queue, NULL );
-
   /* Make sure the message size computation does not overflow */
   if ( maximum_message_size > MESSAGE_SIZE_LIMIT ) {
 return false;
@@ -64,19 +59,12 @@ bool _CORE_message_queue_Initialize(
 return false;
   }
 
-  /*
-   *  Initialize the pool of inactive messages, pending messages,
-   *  and set of waiting threads.
-   */
-  _Chain_Initialize (
-&the_message_queue->Inactive_messages,
-the_message_queue->message_buffers,
-(size_t) maximum_pending_messages,
-buffer_size
-  );
+  the_message_queue->maximum_pending_messages   = maximum_pending_messages;
+  the_message_queue->number_of_pending_messages = 0;
+  the_message_queue->maximum_message_size   = maximum_message_size;
 
+  _CORE_message_queue_Set_notify( the_message_queue, NULL );
   _Chain_Initialize_empty( &the_message_queue->Pending_messages );
-
   _Thread_queue_Object_initialize( &the_message_queue->Wait_queue );
 
   if ( discipline == CORE_MESSAGE_QUEUE_DISCIPLINES_PRIORITY ) {
@@ -85,5 +73,12 @@ bool _CORE_message_queue_Initialize(
 the_message_queue->operations = &_Thread_queue_Operations_FIFO;
   }
 
+  _Chain_Initialize (
+&the_message_queue->Inactive_messages,
+the_message_queue->message_buffers,
+(size_t) maximum_pending_messages,
+buffer_size
+  );
+
   return true;
 }
-- 
2.26.2

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH 7/8] rtems: Remove Message_queue_Control::attribute_set

2020-09-24 Thread Sebastian Huber
Add Message_queue_Control::is_global if RTEMS_MULTIPROCESSING is defined.  This
reduces the Message_queue_Control size in standard RTEMS configurations.

Update #4007.
---
 cpukit/include/rtems/rtems/messagedata.h |  6 --
 cpukit/libmisc/monitor/mon-queue.c   | 16 +++-
 cpukit/rtems/src/msgqcreate.c| 12 ++--
 cpukit/rtems/src/msgqdelete.c|  2 +-
 4 files changed, 26 insertions(+), 10 deletions(-)

diff --git a/cpukit/include/rtems/rtems/messagedata.h 
b/cpukit/include/rtems/rtems/messagedata.h
index fa1f681473..8c72fba078 100644
--- a/cpukit/include/rtems/rtems/messagedata.h
+++ b/cpukit/include/rtems/rtems/messagedata.h
@@ -40,8 +40,10 @@ typedef struct {
   Objects_Control Object;
   /** This field is the instance of the SuperCore Message Queue. */
   CORE_message_queue_Control  message_queue;
-  /** This field is the attribute set as defined by the API. */
-  rtems_attribute attribute_set;
+#if defined(RTEMS_MULTIPROCESSING)
+  /** This field is true if the message queue is offered globally */
+  boolis_global;
+#endif
 }   Message_queue_Control;
 
 /**
diff --git a/cpukit/libmisc/monitor/mon-queue.c 
b/cpukit/libmisc/monitor/mon-queue.c
index 9430797c6c..aadfcd3989 100644
--- a/cpukit/libmisc/monitor/mon-queue.c
+++ b/cpukit/libmisc/monitor/mon-queue.c
@@ -16,7 +16,21 @@ rtems_monitor_queue_canonical(
 {
 const Message_queue_Control *rtems_queue = (const Message_queue_Control *) 
queue_void;
 
-canonical_queue->attributes = rtems_queue->attribute_set;
+canonical_queue->attributes = 0;
+
+if (
+  rtems_queue->message_queue.operations
+== &_Thread_queue_Operations_priority
+) {
+  canonical_queue->attributes |= RTEMS_PRIORITY;
+}
+
+#if defined(RTEMS_MULTIPROCESSING)
+if ( rtems_queue->is_global ) {
+  canonical_queue->attributes |= RTEMS_GLOBAL;
+}
+#endif
+
 canonical_queue->maximum_message_size = 
rtems_queue->message_queue.maximum_message_size;
 canonical_queue->maximum_pending_messages = 
rtems_queue->message_queue.maximum_pending_messages;
 canonical_queue->number_of_pending_messages = 
rtems_queue->message_queue.number_of_pending_messages;
diff --git a/cpukit/rtems/src/msgqcreate.c b/cpukit/rtems/src/msgqcreate.c
index 79b198199e..20787f00a6 100644
--- a/cpukit/rtems/src/msgqcreate.c
+++ b/cpukit/rtems/src/msgqcreate.c
@@ -53,11 +53,11 @@ rtems_status_code rtems_message_queue_create(
 return RTEMS_INVALID_ADDRESS;
 
 #if defined(RTEMS_MULTIPROCESSING)
-  if ( !_System_state_Is_multiprocessing ) {
-attribute_set = _Attributes_Clear( attribute_set, RTEMS_GLOBAL );
+  if ( _System_state_Is_multiprocessing ) {
+is_global = _Attributes_Is_global( attribute_set );
+  } else {
+is_global = false;
   }
-
-  is_global = _Attributes_Is_global( attribute_set );
 #endif
 
   if ( count == 0 )
@@ -99,9 +99,9 @@ rtems_status_code rtems_message_queue_create(
 _Objects_Allocator_unlock();
 return RTEMS_TOO_MANY;
   }
-#endif
 
-  the_message_queue->attribute_set = attribute_set;
+  the_message_queue->is_global = is_global;
+#endif
 
   if (_Attributes_Is_priority( attribute_set ) )
 discipline = CORE_MESSAGE_QUEUE_DISCIPLINES_PRIORITY;
diff --git a/cpukit/rtems/src/msgqdelete.c b/cpukit/rtems/src/msgqdelete.c
index 791f96e676..e1d57addc9 100644
--- a/cpukit/rtems/src/msgqdelete.c
+++ b/cpukit/rtems/src/msgqdelete.c
@@ -60,7 +60,7 @@ rtems_status_code rtems_message_queue_delete(
   );
 
 #if defined(RTEMS_MULTIPROCESSING)
-  if ( _Attributes_Is_global( the_message_queue->attribute_set ) ) {
+  if ( the_message_queue->is_global ) {
 _Objects_MP_Close(
   &_Message_queue_Information,
   the_message_queue->Object.id
-- 
2.26.2

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH 6/8] score: Add

2020-09-24 Thread Sebastian Huber
Move the CORE_message_queue_Buffer definition to a separate header file to be
able to use it independent of the remaining Message Queue Handler API.

Change license to BSD-2-Clause according to file history.

Update #3053.
Update #4007.
---
 cpukit/headers.am  |  1 +
 cpukit/include/rtems/score/coremsg.h   | 39 +
 cpukit/include/rtems/score/coremsgbuffer.h | 96 ++
 spec/build/cpukit/librtemscpu.yml  |  1 +
 4 files changed, 99 insertions(+), 38 deletions(-)
 create mode 100644 cpukit/include/rtems/score/coremsgbuffer.h

diff --git a/cpukit/headers.am b/cpukit/headers.am
index 77df5ecb4c..23a84ca243 100644
--- a/cpukit/headers.am
+++ b/cpukit/headers.am
@@ -335,6 +335,7 @@ include_rtems_score_HEADERS += include/rtems/score/copyrt.h
 include_rtems_score_HEADERS += include/rtems/score/corebarrier.h
 include_rtems_score_HEADERS += include/rtems/score/corebarrierimpl.h
 include_rtems_score_HEADERS += include/rtems/score/coremsg.h
+include_rtems_score_HEADERS += include/rtems/score/coremsgbuffer.h
 include_rtems_score_HEADERS += include/rtems/score/coremsgimpl.h
 include_rtems_score_HEADERS += include/rtems/score/coremutex.h
 include_rtems_score_HEADERS += include/rtems/score/coremuteximpl.h
diff --git a/cpukit/include/rtems/score/coremsg.h 
b/cpukit/include/rtems/score/coremsg.h
index 2131fa0765..220c9839a5 100644
--- a/cpukit/include/rtems/score/coremsg.h
+++ b/cpukit/include/rtems/score/coremsg.h
@@ -21,7 +21,7 @@
 #ifndef _RTEMS_SCORE_COREMSG_H
 #define _RTEMS_SCORE_COREMSG_H
 
-#include 
+#include 
 #include 
 #include 
 #include 
@@ -43,13 +43,6 @@ extern "C" {
  * @{
  */
 
-/**
- *  This macro is defined when an API is enabled that requires that the
- *  Message Queue Handler include support for priority based enqueuing
- *  of messages.
- */
-#define RTEMS_SCORE_COREMSG_ENABLE_MESSAGE_PRIORITY
-
 #if defined(RTEMS_POSIX_API)
   /**
*  This macro is defined when an API is enabled that requires that the
@@ -67,36 +60,6 @@ extern "C" {
 
 typedef struct CORE_message_queue_Control CORE_message_queue_Control;
 
-/**
- * @brief The structure is used to organize message buffers of a message queue.
- */
-typedef struct {
-  /**
-   * @brief This member is used to enqueue the buffer in the pending or free
-   *   buffer queue of a message queue.
-   */
-  Chain_Node Node;
-
-  /** @brief This member defines the size of this message. */
-  size_t size;
-
-#if defined(RTEMS_SCORE_COREMSG_ENABLE_MESSAGE_PRIORITY)
-  /** @brief This member defines the priority of this message. */
-  int priority;
-#endif
-
-  /**
-   * @brief This member contains the actual message.
-   *
-   * This is a zero-length array since the maximum message size is defined by
-   * the user.  Use a size_t array to make sure that the member offset is at
-   * the structure end.  This enables a more efficient memcpy() on 64-bit
-   * targets and makes it easier to inspect the message buffers with a
-   * debugger.
-   */
-  size_t buffer[ RTEMS_ZERO_LENGTH_ARRAY ];
-} CORE_message_queue_Buffer;
-
 /**
  *  @brief The possible blocking disciplines for a message queue.
  *
diff --git a/cpukit/include/rtems/score/coremsgbuffer.h 
b/cpukit/include/rtems/score/coremsgbuffer.h
new file mode 100644
index 00..1960facb34
--- /dev/null
+++ b/cpukit/include/rtems/score/coremsgbuffer.h
@@ -0,0 +1,96 @@
+/* SPDX-License-Identifier: BSD-2-Clause */
+
+/**
+ * @file
+ *
+ * @ingroup RTEMSScoreMessageQueue
+ *
+ * @brief This header file defines the buffer data structure used by the
+ *   Message Queue Handler.
+ */
+
+/*
+ * Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)
+ * Copyright (C) 1989, 2009 On-Line Applications Research Corporation (OAR)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY 

[PATCH 5/8] score: Simplify CORE_message_queue_Buffer

2020-09-24 Thread Sebastian Huber
Merge CORE_message_queue_Buffer structure into
CORE_message_queue_Buffer_control.

Use a zero-length array for the actual message buffer.  This reduces the
structure size on all targets.

Update #4007.
---
 cpukit/include/rtems/confdefs/wkspace.h  |  2 +-
 cpukit/include/rtems/rtems/msgmp.h   |  7 ++--
 cpukit/include/rtems/score/coremsg.h | 53 +++-
 cpukit/include/rtems/score/coremsgimpl.h | 16 +++
 cpukit/rtems/src/msgmp.c | 20 -
 cpukit/score/src/coremsg.c   | 13 --
 cpukit/score/src/coremsginsert.c | 20 -
 cpukit/score/src/coremsgseize.c  | 10 ++---
 cpukit/score/src/coremsgsubmit.c |  4 +-
 testsuites/sptests/spmsgq_err01/init.c   |  3 +-
 10 files changed, 72 insertions(+), 76 deletions(-)

diff --git a/cpukit/include/rtems/confdefs/wkspace.h 
b/cpukit/include/rtems/confdefs/wkspace.h
index 3b464899dc..89d7c21b2a 100644
--- a/cpukit/include/rtems/confdefs/wkspace.h
+++ b/cpukit/include/rtems/confdefs/wkspace.h
@@ -71,7 +71,7 @@
 #define CONFIGURE_MESSAGE_BUFFERS_FOR_QUEUE( _messages, _size ) \
   _Configure_From_workspace( \
 ( _messages ) * ( _Configure_Align_up( _size, sizeof( uintptr_t ) ) \
-+ sizeof( CORE_message_queue_Buffer_control ) ) )
++ sizeof( CORE_message_queue_Buffer ) ) )
 
 #ifndef CONFIGURE_MESSAGE_BUFFER_MEMORY
   #define CONFIGURE_MESSAGE_BUFFER_MEMORY 0
diff --git a/cpukit/include/rtems/rtems/msgmp.h 
b/cpukit/include/rtems/rtems/msgmp.h
index 6b08c86971..8638e9748e 100644
--- a/cpukit/include/rtems/rtems/msgmp.h
+++ b/cpukit/include/rtems/rtems/msgmp.h
@@ -71,13 +71,12 @@ typedef struct {
   rtems_option   option_set;
   Objects_Id proxy_id;
   uint32_t   count;
-  size_t size;
-  uint32_t   pad0;
-  CORE_message_queue_Buffer  Buffer;
+  uint32_t   size;
+  uint32_t   buffer[ RTEMS_ZERO_LENGTH_ARRAY ];
 }   Message_queue_MP_Packet;
 
 #define MESSAGE_QUEUE_MP_PACKET_SIZE \
-  offsetof(Message_queue_MP_Packet, Buffer.buffer)
+  offsetof(Message_queue_MP_Packet, buffer)
 
 RTEMS_INLINE_ROUTINE bool _Message_queue_MP_Is_remote( Objects_Id id )
 {
diff --git a/cpukit/include/rtems/score/coremsg.h 
b/cpukit/include/rtems/score/coremsg.h
index cabf08b0ca..2131fa0765 100644
--- a/cpukit/include/rtems/score/coremsg.h
+++ b/cpukit/include/rtems/score/coremsg.h
@@ -68,37 +68,34 @@ extern "C" {
 typedef struct CORE_message_queue_Control CORE_message_queue_Control;
 
 /**
- *  @brief Data types needed to manipulate the contents of message buffers.
- *
- *  The following defines the data types needed to manipulate
- *  the contents of message buffers.
- *
- *  @note  The buffer field is normally longer than a single uint32_t
- * but since messages are variable length we just make a ptr to 1.
+ * @brief The structure is used to organize message buffers of a message queue.
  */
 typedef struct {
-  /** This field is the size of this message. */
-  size_t  size;
-  /** This field contains the actual message. */
-  uint32_tbuffer[1];
-} CORE_message_queue_Buffer;
+  /**
+   * @brief This member is used to enqueue the buffer in the pending or free
+   *   buffer queue of a message queue.
+   */
+  Chain_Node Node;
 
-/**
- *  @brief The organization of a message buffer.
- *
- *  The following records define the organization of a message
- *  buffer.
- */
-typedef struct {
-  /** This element allows this structure to be placed on chains. */
-  Chain_Node Node;
-  #if defined(RTEMS_SCORE_COREMSG_ENABLE_MESSAGE_PRIORITY)
-/** This field is the priority of this message. */
-intpriority;
-  #endif
-  /** This field points to the contents of the message. */
-  CORE_message_queue_Buffer  Contents;
-}   CORE_message_queue_Buffer_control;
+  /** @brief This member defines the size of this message. */
+  size_t size;
+
+#if defined(RTEMS_SCORE_COREMSG_ENABLE_MESSAGE_PRIORITY)
+  /** @brief This member defines the priority of this message. */
+  int priority;
+#endif
+
+  /**
+   * @brief This member contains the actual message.
+   *
+   * This is a zero-length array since the maximum message size is defined by
+   * the user.  Use a size_t array to make sure that the member offset is at
+   * the structure end.  This enables a more efficient memcpy() on 64-bit
+   * targets and makes it easier to inspect the message buffers with a
+   * debugger.
+   */
+  size_t buffer[ RTEMS_ZERO_LENGTH_ARRAY ];
+} CORE_message_queue_Buffer;
 
 /**
  *  @brief The possible blocking disciplines for a message queue.
diff --git a/cpukit/include/rtems/score/coremsgimpl.h 
b/cpukit/include/rtems/score/coremsgimpl.h
index 9403fb95fc..cb84bfb207 100644
--- a/cpukit/include/rtems/score/coremsgimpl.h
+++ b/cpukit/include/rtems/score/coremsgimpl.h
@@ -276,7 +276,7 @@ Status

[PATCH 4/8] score: Improve _CORE_message_queue_Initialize()

2020-09-24 Thread Sebastian Huber
Return a status code and differentiate between error conditions.

Update #4007.
---
 cpukit/include/rtems/score/coremsgimpl.h | 29 
 cpukit/include/rtems/score/status.h  |  4 
 cpukit/posix/src/mqueueopen.c| 17 +++---
 cpukit/rtems/src/msgqcreate.c| 17 --
 cpukit/score/src/coremsg.c   | 10 
 testsuites/sptests/sp77/init.c   |  2 +-
 testsuites/sptests/spmsgq_err01/init.c   | 11 +
 7 files changed, 50 insertions(+), 40 deletions(-)

diff --git a/cpukit/include/rtems/score/coremsgimpl.h 
b/cpukit/include/rtems/score/coremsgimpl.h
index e598dce96a..9403fb95fc 100644
--- a/cpukit/include/rtems/score/coremsgimpl.h
+++ b/cpukit/include/rtems/score/coremsgimpl.h
@@ -71,24 +71,25 @@ typedef int CORE_message_queue_Submit_types;
 /**
  * @brief Initializes a message queue.
  *
- * This package is the implementation of the CORE Message Queue Handler.
- * This core object provides task synchronization and communication functions
- * via messages passed to queue objects.
+ * @param[out] the_message_queue is the message queue to initialize.
+ *
+ * @param discipline is the blocking discipline for the message queue.
+ *
+ * @param maximum_pending_messages is the maximum number of messages that will
+ *   be allowed to be pending at any given time.
+ *
+ * @param maximum_message_size is the size of the largest message that may be
+ *   sent to this message queue instance.
  *
- * This routine initializes @a the_message_queue
- *based on the parameters passed.
+ * @retval STATUS_SUCCESSFUL The message queue was initialized.
  *
- * @param[out] the_message_queue The message queue to initialize.
- * @param discipline The blocking discipline for the message queue.
- * @param maximum_pending_messages The maximum number of messages
- *that will be allowed to pend at any given time.
- * @param maximum_message_size The size of the largest message that
- *may be sent to this message queue instance.
+ * @retval STATUS_MESSAGE_QUEUE_INVALID_SIZE Calculations with the maximum
+ *   pending messages or maximum message size produced an integer overflow.
  *
- * @retval true The message queue can be initialized.
- * @retval false Memory for the pending messages cannot be allocated.
+ * @retval STATUS_MESSAGE_QUEUE_NO_MEMORY There was not enough memory to
+ *   allocate the message buffers.
  */
-bool _CORE_message_queue_Initialize(
+Status_Control _CORE_message_queue_Initialize(
   CORE_message_queue_Control *the_message_queue,
   CORE_message_queue_Disciplines  discipline,
   uint32_tmaximum_pending_messages,
diff --git a/cpukit/include/rtems/score/status.h 
b/cpukit/include/rtems/score/status.h
index b257ccc5db..bc374a5467 100644
--- a/cpukit/include/rtems/score/status.h
+++ b/cpukit/include/rtems/score/status.h
@@ -91,6 +91,10 @@ typedef enum {
 STATUS_BUILD( STATUS_CLASSIC_INTERNAL_ERROR, EOVERFLOW ),
   STATUS_MESSAGE_INVALID_SIZE =
 STATUS_BUILD( STATUS_CLASSIC_INVALID_SIZE, EMSGSIZE ),
+  STATUS_MESSAGE_QUEUE_INVALID_SIZE =
+STATUS_BUILD( STATUS_CLASSIC_INVALID_SIZE, ENOSPC ),
+  STATUS_MESSAGE_QUEUE_NO_MEMORY =
+STATUS_BUILD( STATUS_CLASSIC_UNSATISFIED, ENOSPC ),
   STATUS_MESSAGE_QUEUE_WAIT_IN_ISR =
 STATUS_BUILD( STATUS_CLASSIC_INTERNAL_ERROR, EAGAIN ),
   STATUS_MESSAGE_QUEUE_WAS_DELETED =
diff --git a/cpukit/posix/src/mqueueopen.c b/cpukit/posix/src/mqueueopen.c
index 35b8c923b1..af8abebea8 100644
--- a/cpukit/posix/src/mqueueopen.c
+++ b/cpukit/posix/src/mqueueopen.c
@@ -60,6 +60,7 @@ static mqd_t _POSIX_Message_queue_Create(
 {
   POSIX_Message_queue_Control  *the_mq;
   char *name;
+  Status_Controlstatus;
 
   /* length of name has already been validated */
 
@@ -97,14 +98,14 @@ static mqd_t _POSIX_Message_queue_Create(
*  Joel: Cite POSIX or OpenGroup on above statement so we can determine
*if it is a real requirement.
*/
-  if (
-!_CORE_message_queue_Initialize(
-  &the_mq->Message_queue,
-  CORE_MESSAGE_QUEUE_DISCIPLINES_FIFO,
-  attr->mq_maxmsg,
-  attr->mq_msgsize
-)
-  ) {
+  status = _CORE_message_queue_Initialize(
+&the_mq->Message_queue,
+CORE_MESSAGE_QUEUE_DISCIPLINES_FIFO,
+attr->mq_maxmsg,
+attr->mq_msgsize
+  );
+
+  if ( status != STATUS_SUCCESSFUL ) {
 _POSIX_Message_queue_Free( the_mq );
 _Workspace_Free( name );
 rtems_set_errno_and_return_value( ENOSPC, MQ_OPEN_FAILED );
diff --git a/cpukit/rtems/src/msgqcreate.c b/cpukit/rtems/src/msgqcreate.c
index 3741347cc9..79b198199e 100644
--- a/cpukit/rtems/src/msgqcreate.c
+++ b/cpukit/rtems/src/msgqcreate.c
@@ -41,6 +41,7 @@ rtems_status_code rtems_message_queue_create(
 {
   Message_queue_Control  *the_message_queue;
   CORE_message_queue_Disciplines  discipline;
+  Status_Control  status;
 #if defined(RTEMS_MULTIPROCESSING)
   bool 

Re: Need help debugging sp02.exe run on Strong APA scheduler

2020-09-24 Thread Richi Dubey
>
> Deleting a suspended thread would not require any actions on the Ready set
> of threads, for example.

This is exactly what I was wondering.

I'll look into data structures as you suggested. Thanks.


On Thu, Sep 24, 2020 at 2:57 AM Joel Sherrill  wrote:

>
>
> On Wed, Sep 23, 2020 at 11:54 AM Richi Dubey  wrote:
>
>> Thanks for the advice.
>>
>> I feel something is going wrong when we're trying to delete a suspended
>> task because maybe I'm not handling the suspension/deletion of tasks
>> properly in my code. Do you think this might be true for my code
>> 
>> ?
>>
>
> That's a specific scheduler action and combination of object states. It is
> quite possible something is not processed correctly by your scheduler.
> Deleting a suspended thread would not require any actions on the Ready set
> of threads, for example.
>
> --joel
>
>
>
>>
>> On Wed, Sep 23, 2020 at 12:41 AM Joel Sherrill  wrote:
>>
>>> This isn't a proper solution but a debug technique. When stepping
>>> and running result in different behavior, it is sometimes useful to
>>> run to a specific point and look at data structures for anomalies.
>>>
>>> Since TA1 never prints, I wonder if something went wrong with the
>>> data structures before INIT deletes itself at the bottom.
>>>
>>> --joel
>>>
>>>
>>> On Tue, Sep 22, 2020 at 12:40 PM Richi Dubey 
>>> wrote:
>>>
 Hi,

 I've been trying to debug why sp02 keeps failing on Strong APA
 scheduler and it's hard for me to debug because there are different points
 at which the same program breaks on gdb even though this is a single
 processor test. I have attached the different error logs. In error.txt, we
 can see that the execution fails somewhere in _Context_Switch while it is
 not the case when I step inside in case II, and other random things like
 these keep happening. I'd appreciate it if you direct my thoughts.

 I'm testing the source over this
  and
 this
 
 patch.

 Thanks,
 Richi.
 ___
 devel mailing list
 devel@rtems.org
 http://lists.rtems.org/mailman/listinfo/devel
>>>
>>>
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

Re: [PATCH 2/8] score: Fix allocation size calculation

2020-09-24 Thread Gedare Bloom
On Thu, Sep 24, 2020 at 6:13 AM Sebastian Huber
 wrote:
>
> The previous multiplication error check is broken on 64-bit machines.  Use the
> recommended check from SEI CERT C Coding Standard, "INT30-C. Ensure that
> unsigned integer operations do not wrap".
>
> Make sure the message size computation does not overflow.
>
> Update #4007.
> ---
>  cpukit/score/src/coremsg.c | 74 --
>  1 file changed, 23 insertions(+), 51 deletions(-)
>
> diff --git a/cpukit/score/src/coremsg.c b/cpukit/score/src/coremsg.c
> index af8dbd6583..137d9973f4 100644
> --- a/cpukit/score/src/coremsg.c
> +++ b/cpukit/score/src/coremsg.c
> @@ -19,28 +19,12 @@
>  #endif
>
>  #include 
> +#include 
>  #include 
>
> -/*
> - *  size_t_mult32_with_overflow
> - *
> - *  This method multiplies two size_t 32-bit numbers and checks
> - *  for overflow.  It returns false if an overflow occurred and
> - *  the result is bad.
> - */
> -static inline bool size_t_mult32_with_overflow(
> -  size_t  a,
> -  size_t  b,
> -  size_t *c
> -)
> -{
> -  long long x = (long long)a*b;
> -
> -  if ( x > SIZE_MAX )
> -return false;
> -  *c = (size_t) x;
> -  return true;
> -}
> +#define MESSAGE_SIZE_LIMIT \
> +  ( SIZE_MAX - sizeof( uintptr_t ) - 1 \
Minor: should it be - ( sizeof( uintptr_t ) - 1 )?
Or: - sizeof(uintptr_t) + 1

The alignment up can add at most sizeof(uintptr_t)-1 bytes overhead I
think is what this is trying to capture?

> +- sizeof( CORE_message_queue_Buffer_control ) )
>
>  bool _CORE_message_queue_Initialize(
>CORE_message_queue_Control *the_message_queue,
> @@ -49,48 +33,36 @@ bool _CORE_message_queue_Initialize(
>size_t  maximum_message_size
>  )
>  {
> -  size_t message_buffering_required = 0;
> -  size_t aligned_message_size;
> +  size_t buffer_size;
>
>the_message_queue->maximum_pending_messages   = maximum_pending_messages;
>the_message_queue->number_of_pending_messages = 0;
>the_message_queue->maximum_message_size   = maximum_message_size;
>_CORE_message_queue_Set_notify( the_message_queue, NULL );
>
> -  /*
> -   * Align up the maximum message size to be an integral multiple of the
> -   * pointer size.
> -   */
> -  aligned_message_size = RTEMS_ALIGN_UP(
> -maximum_message_size,
> -sizeof( uintptr_t )
> -  );
> -
> -  /*
> -   * Check for an integer overflow.  It can occur while aligning up the 
> maximum
> -   * message size.
> -   */
> -  if (aligned_message_size < maximum_message_size)
> +  /* Make sure the message size computation does not overflow */
> +  if ( maximum_message_size > MESSAGE_SIZE_LIMIT ) {
>  return false;
> +  }
>
> -  /*
> -   *  Calculate how much total memory is required for message buffering and
> -   *  check for overflow on the multiplication.
> -   */
> -  if ( !size_t_mult32_with_overflow(
> -(size_t) maximum_pending_messages,
> -aligned_message_size + sizeof(CORE_message_queue_Buffer_control),
> -&message_buffering_required ) )
> +  buffer_size = RTEMS_ALIGN_UP( maximum_message_size, sizeof( uintptr_t ) );
> +  _Assert( buffer_size >= maximum_message_size );
> +
> +  buffer_size += sizeof( CORE_message_queue_Buffer_control );
> +  _Assert( buffer_size >= sizeof( CORE_message_queue_Buffer_control ) );
> +
> +  /* Make sure the memory allocation size computation does not overflow */
> +  if ( maximum_pending_messages > SIZE_MAX / buffer_size ) {

optimization: can we use mult instead?
  if ( maximum_pending_messages * buffer_size > SIZE_MAX )
save a few cycles...

>  return false;
> +  }
>
> -  /*
> -   *  Attempt to allocate the message memory
> -   */
> -  the_message_queue->message_buffers = (CORE_message_queue_Buffer *)
> - _Workspace_Allocate( message_buffering_required );
> +  the_message_queue->message_buffers = _Workspace_Allocate(
> +(size_t) maximum_pending_messages * buffer_size
... and the compiler should propagate that value to here to save even
more cycles. Or it could be put in a variable for simpler code.


> +  );
>
> -  if (the_message_queue->message_buffers == 0)
> +  if ( the_message_queue->message_buffers == NULL ) {
>  return false;
> +  }
>
>/*
> *  Initialize the pool of inactive messages, pending messages,
> @@ -100,7 +72,7 @@ bool _CORE_message_queue_Initialize(
>  &the_message_queue->Inactive_messages,
>  the_message_queue->message_buffers,
>  (size_t) maximum_pending_messages,
> -aligned_message_size + sizeof( CORE_message_queue_Buffer_control )
> +buffer_size
>);
>
>_Chain_Initialize_empty( &the_message_queue->Pending_messages );
> --
> 2.26.2
>
> ___
> devel mailing list
> devel@rtems.org
> http://lists.rtems.org/mailman/listinfo/devel
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


Re: [PATCH 4/8] score: Improve _CORE_message_queue_Initialize()

2020-09-24 Thread Gedare Bloom
On Thu, Sep 24, 2020 at 6:13 AM Sebastian Huber
 wrote:
>
> Return a status code and differentiate between error conditions.
>
> Update #4007.
> ---
>  cpukit/include/rtems/score/coremsgimpl.h | 29 
>  cpukit/include/rtems/score/status.h  |  4 
>  cpukit/posix/src/mqueueopen.c| 17 +++---
>  cpukit/rtems/src/msgqcreate.c| 17 --
>  cpukit/score/src/coremsg.c   | 10 
>  testsuites/sptests/sp77/init.c   |  2 +-
>  testsuites/sptests/spmsgq_err01/init.c   | 11 +
>  7 files changed, 50 insertions(+), 40 deletions(-)
>
> diff --git a/cpukit/include/rtems/score/coremsgimpl.h 
> b/cpukit/include/rtems/score/coremsgimpl.h
> index e598dce96a..9403fb95fc 100644
> --- a/cpukit/include/rtems/score/coremsgimpl.h
> +++ b/cpukit/include/rtems/score/coremsgimpl.h
> @@ -71,24 +71,25 @@ typedef int CORE_message_queue_Submit_types;
>  /**
>   * @brief Initializes a message queue.
>   *
> - * This package is the implementation of the CORE Message Queue Handler.
> - * This core object provides task synchronization and communication functions
> - * via messages passed to queue objects.
> + * @param[out] the_message_queue is the message queue to initialize.
> + *
> + * @param discipline is the blocking discipline for the message queue.
> + *
> + * @param maximum_pending_messages is the maximum number of messages that 
> will
> + *   be allowed to be pending at any given time.
> + *
> + * @param maximum_message_size is the size of the largest message that may be
> + *   sent to this message queue instance.
>   *
> - * This routine initializes @a the_message_queue
> - *based on the parameters passed.
> + * @retval STATUS_SUCCESSFUL The message queue was initialized.
>   *
> - * @param[out] the_message_queue The message queue to initialize.
> - * @param discipline The blocking discipline for the message queue.
> - * @param maximum_pending_messages The maximum number of messages
> - *that will be allowed to pend at any given time.
> - * @param maximum_message_size The size of the largest message that
> - *may be sent to this message queue instance.
> + * @retval STATUS_MESSAGE_QUEUE_INVALID_SIZE Calculations with the maximum
> + *   pending messages or maximum message size produced an integer overflow.
>   *
> - * @retval true The message queue can be initialized.
> - * @retval false Memory for the pending messages cannot be allocated.
> + * @retval STATUS_MESSAGE_QUEUE_NO_MEMORY There was not enough memory to
> + *   allocate the message buffers.
>   */
> -bool _CORE_message_queue_Initialize(
> +Status_Control _CORE_message_queue_Initialize(
>CORE_message_queue_Control *the_message_queue,
>CORE_message_queue_Disciplines  discipline,
>uint32_tmaximum_pending_messages,
> diff --git a/cpukit/include/rtems/score/status.h 
> b/cpukit/include/rtems/score/status.h
> index b257ccc5db..bc374a5467 100644
> --- a/cpukit/include/rtems/score/status.h
> +++ b/cpukit/include/rtems/score/status.h
> @@ -91,6 +91,10 @@ typedef enum {
>  STATUS_BUILD( STATUS_CLASSIC_INTERNAL_ERROR, EOVERFLOW ),
>STATUS_MESSAGE_INVALID_SIZE =
>  STATUS_BUILD( STATUS_CLASSIC_INVALID_SIZE, EMSGSIZE ),
> +  STATUS_MESSAGE_QUEUE_INVALID_SIZE =
> +STATUS_BUILD( STATUS_CLASSIC_INVALID_SIZE, ENOSPC ),
EINVAL maybe better?

@Joel: This is a bit outside the scope of the posix spec maybe, but
the intent seems to be to use EINVAL for an invalid size argument.

> +  STATUS_MESSAGE_QUEUE_NO_MEMORY =
> +STATUS_BUILD( STATUS_CLASSIC_UNSATISFIED, ENOSPC ),
>STATUS_MESSAGE_QUEUE_WAIT_IN_ISR =
>  STATUS_BUILD( STATUS_CLASSIC_INTERNAL_ERROR, EAGAIN ),
>STATUS_MESSAGE_QUEUE_WAS_DELETED =
> diff --git a/cpukit/posix/src/mqueueopen.c b/cpukit/posix/src/mqueueopen.c
> index 35b8c923b1..af8abebea8 100644
> --- a/cpukit/posix/src/mqueueopen.c
> +++ b/cpukit/posix/src/mqueueopen.c
> @@ -60,6 +60,7 @@ static mqd_t _POSIX_Message_queue_Create(
>  {
>POSIX_Message_queue_Control  *the_mq;
>char *name;
> +  Status_Controlstatus;
>
>/* length of name has already been validated */
>
> @@ -97,14 +98,14 @@ static mqd_t _POSIX_Message_queue_Create(
> *  Joel: Cite POSIX or OpenGroup on above statement so we can determine
> *if it is a real requirement.
> */
> -  if (
> -!_CORE_message_queue_Initialize(
> -  &the_mq->Message_queue,
> -  CORE_MESSAGE_QUEUE_DISCIPLINES_FIFO,
> -  attr->mq_maxmsg,
> -  attr->mq_msgsize
> -)
> -  ) {
> +  status = _CORE_message_queue_Initialize(
> +&the_mq->Message_queue,
> +CORE_MESSAGE_QUEUE_DISCIPLINES_FIFO,
> +attr->mq_maxmsg,
> +attr->mq_msgsize
> +  );
> +
> +  if ( status != STATUS_SUCCESSFUL ) {
>  _POSIX_Message_queue_Free( the_mq );
>  _Workspace_Free( name );
>  rtems_set_errno_and_return_value( ENOSPC, MQ_OPEN_FAILED );
translate the statu

Re: [PATCH 7/8] rtems: Remove Message_queue_Control::attribute_set

2020-09-24 Thread Gedare Bloom
There should be an mptest added for global mq

On Thu, Sep 24, 2020 at 6:13 AM Sebastian Huber
 wrote:
>
> Add Message_queue_Control::is_global if RTEMS_MULTIPROCESSING is defined.  
> This
> reduces the Message_queue_Control size in standard RTEMS configurations.
>
> Update #4007.
> ---
>  cpukit/include/rtems/rtems/messagedata.h |  6 --
>  cpukit/libmisc/monitor/mon-queue.c   | 16 +++-
>  cpukit/rtems/src/msgqcreate.c| 12 ++--
>  cpukit/rtems/src/msgqdelete.c|  2 +-
>  4 files changed, 26 insertions(+), 10 deletions(-)
>
> diff --git a/cpukit/include/rtems/rtems/messagedata.h 
> b/cpukit/include/rtems/rtems/messagedata.h
> index fa1f681473..8c72fba078 100644
> --- a/cpukit/include/rtems/rtems/messagedata.h
> +++ b/cpukit/include/rtems/rtems/messagedata.h
> @@ -40,8 +40,10 @@ typedef struct {
>Objects_Control Object;
>/** This field is the instance of the SuperCore Message Queue. */
>CORE_message_queue_Control  message_queue;
> -  /** This field is the attribute set as defined by the API. */
> -  rtems_attribute attribute_set;
> +#if defined(RTEMS_MULTIPROCESSING)
> +  /** This field is true if the message queue is offered globally */
> +  boolis_global;
> +#endif
>  }   Message_queue_Control;
>
>  /**
> diff --git a/cpukit/libmisc/monitor/mon-queue.c 
> b/cpukit/libmisc/monitor/mon-queue.c
> index 9430797c6c..aadfcd3989 100644
> --- a/cpukit/libmisc/monitor/mon-queue.c
> +++ b/cpukit/libmisc/monitor/mon-queue.c
> @@ -16,7 +16,21 @@ rtems_monitor_queue_canonical(
>  {
>  const Message_queue_Control *rtems_queue = (const Message_queue_Control 
> *) queue_void;
>
> -canonical_queue->attributes = rtems_queue->attribute_set;
> +canonical_queue->attributes = 0;
> +
> +if (
> +  rtems_queue->message_queue.operations
> +== &_Thread_queue_Operations_priority
> +) {
> +  canonical_queue->attributes |= RTEMS_PRIORITY;
> +}
> +
> +#if defined(RTEMS_MULTIPROCESSING)
> +if ( rtems_queue->is_global ) {
> +  canonical_queue->attributes |= RTEMS_GLOBAL;
> +}
> +#endif
> +
>  canonical_queue->maximum_message_size = 
> rtems_queue->message_queue.maximum_message_size;
>  canonical_queue->maximum_pending_messages = 
> rtems_queue->message_queue.maximum_pending_messages;
>  canonical_queue->number_of_pending_messages = 
> rtems_queue->message_queue.number_of_pending_messages;
> diff --git a/cpukit/rtems/src/msgqcreate.c b/cpukit/rtems/src/msgqcreate.c
> index 79b198199e..20787f00a6 100644
> --- a/cpukit/rtems/src/msgqcreate.c
> +++ b/cpukit/rtems/src/msgqcreate.c
> @@ -53,11 +53,11 @@ rtems_status_code rtems_message_queue_create(
>  return RTEMS_INVALID_ADDRESS;
>
>  #if defined(RTEMS_MULTIPROCESSING)
> -  if ( !_System_state_Is_multiprocessing ) {
> -attribute_set = _Attributes_Clear( attribute_set, RTEMS_GLOBAL );
> +  if ( _System_state_Is_multiprocessing ) {
> +is_global = _Attributes_Is_global( attribute_set );
> +  } else {
> +is_global = false;
>}
> -
> -  is_global = _Attributes_Is_global( attribute_set );
>  #endif
>
>if ( count == 0 )
> @@ -99,9 +99,9 @@ rtems_status_code rtems_message_queue_create(
>  _Objects_Allocator_unlock();
>  return RTEMS_TOO_MANY;
>}
> -#endif
>
> -  the_message_queue->attribute_set = attribute_set;
> +  the_message_queue->is_global = is_global;
> +#endif
>
>if (_Attributes_Is_priority( attribute_set ) )
>  discipline = CORE_MESSAGE_QUEUE_DISCIPLINES_PRIORITY;
> diff --git a/cpukit/rtems/src/msgqdelete.c b/cpukit/rtems/src/msgqdelete.c
> index 791f96e676..e1d57addc9 100644
> --- a/cpukit/rtems/src/msgqdelete.c
> +++ b/cpukit/rtems/src/msgqdelete.c
> @@ -60,7 +60,7 @@ rtems_status_code rtems_message_queue_delete(
>);
>
>  #if defined(RTEMS_MULTIPROCESSING)
> -  if ( _Attributes_Is_global( the_message_queue->attribute_set ) ) {
> +  if ( the_message_queue->is_global ) {
>  _Objects_MP_Close(
>&_Message_queue_Information,
>the_message_queue->Object.id
> --
> 2.26.2
>
> ___
> devel mailing list
> devel@rtems.org
> http://lists.rtems.org/mailman/listinfo/devel
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


Re: [PATCH 8/8] rtems: Add rtems_message_queue_construct()

2020-09-24 Thread Gedare Bloom
We'll need docs. The test case looks incomplete. Might want to
duplicate the current tests for constructed queues to exercise
default, priority; I guess the GLOBAL attribute is meaningless in an
sptest.

Everything else here looks fine beside what I commented on in the
earlier patches.

On Thu, Sep 24, 2020 at 6:13 AM Sebastian Huber
 wrote:
>
> In contrast to message queues created by rtems_message_queue_create(), the
> message queues constructed by this directive use a user-provided message 
> buffer
> storage area.
>
> Add RTEMS_MESSAGE_QUEUE_BUFFER() to define a message buffer type for message
> buffer storage areas.
>
> Update #4007.
> ---
>  cpukit/Makefile.am   |   2 +
>  cpukit/include/rtems/rtems/message.h | 124 +++
>  cpukit/include/rtems/rtems/messageimpl.h |  17 ++
>  cpukit/include/rtems/score/coremsg.h |  10 ++
>  cpukit/include/rtems/score/coremsgimpl.h |  67 +++-
>  cpukit/posix/src/mqueueopen.c|   4 +-
>  cpukit/rtems/src/msgqconstruct.c | 189 +++
>  cpukit/rtems/src/msgqcreate.c| 178 +
>  cpukit/score/src/coremsg.c   |  17 +-
>  cpukit/score/src/coremsgclose.c  |   7 +-
>  cpukit/score/src/coremsgwkspace.c|  53 +++
>  spec/build/cpukit/librtemscpu.yml|   2 +
>  testsuites/sptests/sp13/init.c   |  21 ++-
>  testsuites/sptests/sp13/system.h |   2 +-
>  14 files changed, 532 insertions(+), 161 deletions(-)
>  create mode 100644 cpukit/rtems/src/msgqconstruct.c
>  create mode 100644 cpukit/score/src/coremsgwkspace.c
>
> diff --git a/cpukit/Makefile.am b/cpukit/Makefile.am
> index e2bed4b844..2c35354e66 100644
> --- a/cpukit/Makefile.am
> +++ b/cpukit/Makefile.am
> @@ -706,6 +706,7 @@ librtemscpu_a_SOURCES += rtems/src/intrcatch.c
>  librtemscpu_a_SOURCES += rtems/src/modes.c
>  librtemscpu_a_SOURCES += rtems/src/msg.c
>  librtemscpu_a_SOURCES += rtems/src/msgqbroadcast.c
> +librtemscpu_a_SOURCES += rtems/src/msgqconstruct.c
>  librtemscpu_a_SOURCES += rtems/src/msgqcreate.c
>  librtemscpu_a_SOURCES += rtems/src/msgqdelete.c
>  librtemscpu_a_SOURCES += rtems/src/msgqflush.c
> @@ -839,6 +840,7 @@ librtemscpu_a_SOURCES += score/src/coremsgflushwait.c
>  librtemscpu_a_SOURCES += score/src/coremsginsert.c
>  librtemscpu_a_SOURCES += score/src/coremsgseize.c
>  librtemscpu_a_SOURCES += score/src/coremsgsubmit.c
> +librtemscpu_a_SOURCES += score/src/coremsgwkspace.c
>  librtemscpu_a_SOURCES += score/src/coremutexseize.c
>  librtemscpu_a_SOURCES += score/src/percpu.c
>  librtemscpu_a_SOURCES += score/src/percpuasm.c
> diff --git a/cpukit/include/rtems/rtems/message.h 
> b/cpukit/include/rtems/rtems/message.h
> index 675cd98acc..a576132d95 100644
> --- a/cpukit/include/rtems/rtems/message.h
> +++ b/cpukit/include/rtems/rtems/message.h
> @@ -21,6 +21,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>
>  #ifdef __cplusplus
>  extern "C" {
> @@ -65,6 +66,129 @@ rtems_status_code rtems_message_queue_create(
>rtems_id*id
>  );
>
> +/**
> + * @brief Defines a structure which can be used as a message queue buffer for
> + *   messages of the specified maximum size.
> + *
> + * Use this macro to define the message buffers for
> + * rtems_message_queue_construct().
> + *
> + * @param _maximum_message_size is the maximum message size in bytes.
> + */
> +#define RTEMS_MESSAGE_QUEUE_BUFFER( _maximum_message_size ) \
> +  struct { \
> +CORE_message_queue_Buffer _buffer; \
> +char _message[ _maximum_message_size ]; \
> +  }
> +
> +/**
> + * @brief This structure defines the configuration of a message queue
> + *   constructed by rtems_message_queue_construct().
> + */
> +typedef struct {
> +  /**
> +   * @brief This member defines the name of the message queue.
> +   */
> +  rtems_name name;
> +
> +  /**
> +   * @brief This member defines the maximum number of pending messages
> +   *   supported by the message queue.
> +   */
> +  uint32_t maximum_pending_messages;
> +
> +  /**
> +   * @brief This member defines the maximum message size supported by the
> +   *   message queue.
> +   */
> +  size_t maximum_message_size;
> +
> +  /**
> +   * @brief This member shall point to the message buffer storage area begin.
> +   *
> +   * The message buffer storage area for the message queue shall be an array 
> of
> +   * the type defined by RTEMS_MESSAGE_QUEUE_BUFFER() with a maximum message
> +   * size equal to the maximum message size of this configuration.
> +   */
> +  void *storage_area;
> +
> +  /**
> +   * @brief This member defines size of the message buffer storage area in
> +   *   bytes.
> +   */
> +  size_t storage_size;
> +
> +  /**
> +   * @brief This member defines the optional handler to free the message 
> buffer
> +   *   storage area.
> +   *
> +   * It is called when the message queue is deleted.  It is called from task
> +   * context under protection of the object allocator lock.  It is allowed to
> +   *

configure options translated to waf config.ini?

2020-09-24 Thread Joel Sherrill
Hi

I can't find any documentation which guides translating a
RTEMS configure command into the appropriate set of
options in a config.ini file for waf. The only example I could
find has BUILD_TESTS which implies it builds all tests
rather than just samples.

Guidance on translating configure options to config.ini
statements would be appreciated by me and I am sure
by others who will have to update their build procedures.

Guidance on the variables used to override configure.ac
values is also needed but that isn't quite as critical as
just translating the various enable/disable settings.

Thanks.

--joel
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

Re: [PATCH 2/8] score: Fix allocation size calculation

2020-09-24 Thread Gedare Bloom
On Thu, Sep 24, 2020 at 10:30 AM Gedare Bloom  wrote:
>
> On Thu, Sep 24, 2020 at 6:13 AM Sebastian Huber
>  wrote:
> >
> > The previous multiplication error check is broken on 64-bit machines.  Use 
> > the
> > recommended check from SEI CERT C Coding Standard, "INT30-C. Ensure that
> > unsigned integer operations do not wrap".
> >
> > Make sure the message size computation does not overflow.
> >
> > Update #4007.
> > ---
> >  cpukit/score/src/coremsg.c | 74 --
> >  1 file changed, 23 insertions(+), 51 deletions(-)
> >
> > diff --git a/cpukit/score/src/coremsg.c b/cpukit/score/src/coremsg.c
> > index af8dbd6583..137d9973f4 100644
> > --- a/cpukit/score/src/coremsg.c
> > +++ b/cpukit/score/src/coremsg.c
> > @@ -19,28 +19,12 @@
> >  #endif
> >
> >  #include 
> > +#include 
> >  #include 
> >
> > -/*
> > - *  size_t_mult32_with_overflow
> > - *
> > - *  This method multiplies two size_t 32-bit numbers and checks
> > - *  for overflow.  It returns false if an overflow occurred and
> > - *  the result is bad.
> > - */
> > -static inline bool size_t_mult32_with_overflow(
> > -  size_t  a,
> > -  size_t  b,
> > -  size_t *c
> > -)
> > -{
> > -  long long x = (long long)a*b;
> > -
> > -  if ( x > SIZE_MAX )
> > -return false;
> > -  *c = (size_t) x;
> > -  return true;
> > -}
> > +#define MESSAGE_SIZE_LIMIT \
> > +  ( SIZE_MAX - sizeof( uintptr_t ) - 1 \
> Minor: should it be - ( sizeof( uintptr_t ) - 1 )?
> Or: - sizeof(uintptr_t) + 1
>
> The alignment up can add at most sizeof(uintptr_t)-1 bytes overhead I
> think is what this is trying to capture?
>
> > +- sizeof( CORE_message_queue_Buffer_control ) )
> >
> >  bool _CORE_message_queue_Initialize(
> >CORE_message_queue_Control *the_message_queue,
> > @@ -49,48 +33,36 @@ bool _CORE_message_queue_Initialize(
> >size_t  maximum_message_size
> >  )
> >  {
> > -  size_t message_buffering_required = 0;
> > -  size_t aligned_message_size;
> > +  size_t buffer_size;
> >
> >the_message_queue->maximum_pending_messages   = maximum_pending_messages;
> >the_message_queue->number_of_pending_messages = 0;
> >the_message_queue->maximum_message_size   = maximum_message_size;
> >_CORE_message_queue_Set_notify( the_message_queue, NULL );
> >
> > -  /*
> > -   * Align up the maximum message size to be an integral multiple of the
> > -   * pointer size.
> > -   */
> > -  aligned_message_size = RTEMS_ALIGN_UP(
> > -maximum_message_size,
> > -sizeof( uintptr_t )
> > -  );
> > -
> > -  /*
> > -   * Check for an integer overflow.  It can occur while aligning up the 
> > maximum
> > -   * message size.
> > -   */
> > -  if (aligned_message_size < maximum_message_size)
> > +  /* Make sure the message size computation does not overflow */
> > +  if ( maximum_message_size > MESSAGE_SIZE_LIMIT ) {
> >  return false;
> > +  }
> >
> > -  /*
> > -   *  Calculate how much total memory is required for message buffering and
> > -   *  check for overflow on the multiplication.
> > -   */
> > -  if ( !size_t_mult32_with_overflow(
> > -(size_t) maximum_pending_messages,
> > -aligned_message_size + sizeof(CORE_message_queue_Buffer_control),
> > -&message_buffering_required ) )
> > +  buffer_size = RTEMS_ALIGN_UP( maximum_message_size, sizeof( uintptr_t ) 
> > );
> > +  _Assert( buffer_size >= maximum_message_size );
> > +
> > +  buffer_size += sizeof( CORE_message_queue_Buffer_control );
> > +  _Assert( buffer_size >= sizeof( CORE_message_queue_Buffer_control ) );
> > +
> > +  /* Make sure the memory allocation size computation does not overflow */
> > +  if ( maximum_pending_messages > SIZE_MAX / buffer_size ) {
>
> optimization: can we use mult instead?
>   if ( maximum_pending_messages * buffer_size > SIZE_MAX )
> save a few cycles...

Then again, maybe the division is needed here to ensure there isn't an
overflow later? This stuff gets a little tricky!

>
> >  return false;
> > +  }
> >
> > -  /*
> > -   *  Attempt to allocate the message memory
> > -   */
> > -  the_message_queue->message_buffers = (CORE_message_queue_Buffer *)
> > - _Workspace_Allocate( message_buffering_required );
> > +  the_message_queue->message_buffers = _Workspace_Allocate(
> > +(size_t) maximum_pending_messages * buffer_size
> ... and the compiler should propagate that value to here to save even
> more cycles. Or it could be put in a variable for simpler code.
>
>
> > +  );
> >
> > -  if (the_message_queue->message_buffers == 0)
> > +  if ( the_message_queue->message_buffers == NULL ) {
> >  return false;
> > +  }
> >
> >/*
> > *  Initialize the pool of inactive messages, pending messages,
> > @@ -100,7 +72,7 @@ bool _CORE_message_queue_Initialize(
> >  &the_message_queue->Inactive_messages,
> >  the_message_queue->message_buffers,
> >  (size_t) maximum_pending_messages,
> > -aligned_message_size + sizeof( CORE_message_queue_Buffer_control )
> > + 

Re: configure options translated to waf config.ini?

2020-09-24 Thread Chris Johns
On 25/9/20 2:48 am, Joel Sherrill wrote:
> I can't find any documentation which guides translating a 
> RTEMS configure command into the appropriate set of
> options in a config.ini file for waf. The only example I could
> find has BUILD_TESTS which implies it builds all tests 
> rather than just samples.
> 
> Guidance on translating configure options to config.ini
> statements would be appreciated by me and I am sure
> by others who will have to update their build procedures.
> 
> Guidance on the variables used to override configure.ac 
> values is also needed but that isn't quite as critical as 
> just translating the various enable/disable settings.
> 

I have not done this yet so I do not have a 1:1 translation for configure
options. Having this documented would be good.

I discussed with Sebastian earlier in the week how this is to work and this is
what I learnt ...

1. The `--rtems-bsps` option only seems to effect the `bsp_defaults` target. The
configure process uses the .ini file you provide via the `--rtems-config`
option. The default is `config.ini` if that option is not supplied.

2. The .ini file is only referenced by the configure phase of waf. It defines
all the BSPs to built and any overriding option. You normally only have options
in a .ini that are _not_ defaults. If you enter:

./waf bsp_defaults > config.ini

all BSPs will be built and with default options. This is not what you normally 
want.

3. You can have a `[DEFAULTS]` (all caps) section and any option in that section
applies to all BSP that support it. For example:

[DEFAULTS]
BUILD_TESTS = True

will build the testsuite for all defined BSPs.

4. To build a BSP using its defaults simply add the BSP name as a section
header. Note, BSP names use the RTEMS standard `arch/bsp` format. For example:

[DEFAULT]
BUILD_TESTS = True

[arm/beagleboneblack]

[arm/xilinx_zynq_a9_qemu]

[i386/pc686]

[sparc/erc32]

Will build 4 BSPs with tests.

5. To change a default option you first need to see what is supported for your
BSP. Currently the only option available is with ./waf and the `bsp_defaults`
target with the BSP name of interest. For example:

$ ./waf bsp_defaults --rtems-bsp=sparc/erc32

Examine the list and add the one you want to change to your .ini file. For
example to change the optimisation level:

[sparc/erc32]
OPTIMIZATION_FLAGS = -O -g -fdata-sections -ffunction-sections

Remember to run the waf configure command again so the build picks up the
changed option. In the case waf will see the compiler command has changed and it
will rebuild all effected object files.

6. The .ini can be located any where. It does not need to reside in the source
tree. The `--rtems-config` option can be used to point to any you have located
outside the source tree. You can keep them in a separate repo or tool you
maintain to build RTEMS.

Chris
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

Re: [EXTERNAL] Re: running pc686 samples on QEMU on RTEMS 5.1?

2020-09-24 Thread Cudmore, Alan P. (GSFC-5820)
Hi Karel,
Your suggested options fixed it! Our next release should be compatible with 
RTEMS 5.1.
The documentation is great too.. As a long time RTEMS user, I often fail to 
check the docs first!
Thanks,
Alan

On 9/23/20, 5:15 PM, "Karel Gardas"  wrote:

On 9/23/20 11:02 PM, Cudmore, Alan P. (GSFC-5820) wrote:
> NASA’s Core Flight System open source bundle has support for the RTEMS
> 4.11 pc686 BSP.
> 
> RTEMS is built with the following options:
> 
> ../rtems/configure --target=i386-rtems4.11 \
> 
> --enable-rtemsbsp=pc686 \
> 
> --prefix=${HOME}/rtems-4.11 \
> 
> --enable-networking \
> 
> --enable-cxx \
> 
> --disable-posix \
> 
> --disable-deprecated \
> 
> BSP_ENABLE_VGA=0 \
>


^ don't do that. Last time I've checked this option was buggy, e.g.
reset BSP happen instantly.

> CLOCK_DRIVER_USE_TSC=1 \
> 

^ do you need to do that? It's decided on runtime.

> USE_COM1_AS_CONSOLE=1 \
> 

^ this option is long gone, hence without any effect, you can remove it.

> BSP_PRESS_KEY_FOR_RESET=0 \
> 
> BSP_RESET_BOARD_AT_EXIT=1   
> 

^ no needed as you are using their default values.

> And the code (or samples such as ticker) are run with the following QEMU
> command:
> 
>  
> 
> qemu-system-i386 -m 128 \
> 
> -kernel core-cpu1.exe \
> 
> -drive file=fat:rw:${INSTALL_DIR}/cpu1,format=raw \
> 
> -nographic \
> 
> -no-reboot
> 

^ this looks fine, you can also try -append "--video=off
--console=/dev/com1" -- which would basically mean what you used to use
in 4.x with those BSP compile time options above. E.g. console on COM1.

But to have it working, you need to IIRC! remove disabling of VGA.

Please consult

https://urldefense.proofpoint.com/v2/url?u=https-3A__docs.rtems.org_branches_master_user_bsps_bsps-2Di386.html-23pc386&d=DwIDaQ&c=ApwzowJNAKKw3xye91w7BE1XMRKi2LN9kiMk5Csz9Zk&r=mW-jVVDIxBn4bZU1jogCo9FDuDuPszsoVj1mqBvCXzw&m=mZyehJFUJzxHMXG_kUbFQStltsXM16uEiZ3uSW5c7kM&s=FAmTQoeHjZlc8c2ZbSPvOZU8d1iccSPj-VjtdhuiIJI&e=
  --
for more information.

Hope this helps,
Karel

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

[PATCH 1/3] Move all python commands to use env python

2020-09-24 Thread chrisj
From: Chris Johns 

- If you host does not provide a python command consult the User
  manual for ways you can run the python commands.

- Full package paths are being used to avoid namespace pollution and
  crosstalk.
---
 tester/rt/cmd-run.py => misc/__init__.py  | 18 +--
 misc/rtems-boot-image | 31 ++--
 misc/rtems-tftp-proxy | 31 ++--
 misc/tools/{cmd-boot-image.py => __init__.py} | 18 +--
 misc/tools/boot.py|  2 +-
 misc/tools/cmd-tftpproxy.py   | 44 
 misc/tools/tftpproxy.py   |  6 +--
 misc/wscript  |  8 +--
 rtemstoolkit/rtems.py |  9 ++--
 tester/{rt/cmd-bsp-builder.py => __init__.py} | 19 +--
 tester/rt/cmd-test.py | 45 -
 tester/rt/config.py   | 30 +--
 tester/rt/console.py  |  8 +--
 tester/rt/coverage.py |  2 -
 tester/rt/gdb.py  | 14 +++---
 tester/rt/run.py  | 30 ++-
 tester/rt/test.py | 50 +--
 tester/rt/tftp.py | 14 +++---
 tester/rtems-bsp-builder  | 31 ++--
 tester/rtems-run  | 31 ++--
 tester/rtems-test | 31 ++--
 tester/rtems-tftp-server  | 12 ++---
 tester/wscript|  8 ++-
 23 files changed, 182 insertions(+), 310 deletions(-)
 rename tester/rt/cmd-run.py => misc/__init__.py (77%)
 mode change 100755 => 100644
 rename misc/tools/{cmd-boot-image.py => __init__.py} (77%)
 mode change 100755 => 100644
 delete mode 100755 misc/tools/cmd-tftpproxy.py
 rename tester/{rt/cmd-bsp-builder.py => __init__.py} (77%)
 mode change 100755 => 100644
 delete mode 100755 tester/rt/cmd-test.py

diff --git a/tester/rt/cmd-run.py b/misc/__init__.py
old mode 100755
new mode 100644
similarity index 77%
rename from tester/rt/cmd-run.py
rename to misc/__init__.py
index 221c3f8..6ff279c
--- a/tester/rt/cmd-run.py
+++ b/misc/__init__.py
@@ -1,6 +1,5 @@
-#
 # RTEMS Tools Project (http://www.rtems.org/)
-# Copyright 2017 Chris Johns (chr...@rtems.org)
+# Copyright 2020 Chris Johns (chr...@rtems.org)
 # All rights reserved.
 #
 # This file is part of the RTEMS Tools package in 'rtems-tools'.
@@ -28,17 +27,4 @@
 # POSSIBILITY OF SUCH DAMAGE.
 #
 
-from __future__ import print_function
-
-import sys, os
-
-base = os.path.dirname(os.path.dirname(os.path.abspath(sys.argv[0])))
-rtems = os.path.dirname(base)
-sys.path = [rtems] + sys.path
-
-try:
-import run
-run.run(sys.argv[1:], command_path = base)
-except ImportError:
-print("Incorrect RTEMS Tools installation", file = sys.stderr)
-sys.exit(1)
+all = []
diff --git a/misc/rtems-boot-image b/misc/rtems-boot-image
index aa23b2e..7f7ac0d 100755
--- a/misc/rtems-boot-image
+++ b/misc/rtems-boot-image
@@ -1,7 +1,7 @@
-#! /bin/sh
+#! /usr/bin/env python
 #
 # RTEMS Tools Project (http://www.rtems.org/)
-# Copyright 2019 Chris Johns (chr...@rtems.org)
+# Copyright 2019, 2020 Chris Johns (chr...@rtems.org)
 # All rights reserved.
 #
 # This file is part of the RTEMS Tools package in 'rtems-tools'.
@@ -28,15 +28,18 @@
 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 # POSSIBILITY OF SUCH DAMAGE.
 #
-set -e
-base=$(dirname $(dirname $0))
-cmd=misc/tools/cmd-boot-image.py
-PYTHON_WRAPPER=rtemstoolkit/python-wrapper.sh
-if test -f ${base}/${PYTHON_WRAPPER}; then
-  PYTHON_CMD=${base}/${cmd}
-  . ${base}/${PYTHON_WRAPPER}
-elif test -f ${base}/share/rtems/${PYTHON_WRAPPER}; then
-  PYTHON_CMD=${base}/share/rtems/${cmd}
-  . ${base}/share/rtems/${PYTHON_WRAPPER}
-fi
-echo "error: RTEMS Toolkit python wrapper not found, please report"
+
+from __future__ import print_function
+
+import sys, os
+
+base = os.path.dirname(os.path.dirname(os.path.abspath(sys.argv[0])))
+rtems = os.path.join(base, 'share', 'rtems')
+sys.path = sys.path[0:1] + [rtems, base] + sys.path[1:]
+
+try:
+import misc.tools.boot
+misc.tools.boot.run()
+except ImportError:
+print("Incorrect RTEMS Tools installation", file = sys.stderr)
+sys.exit(1)
diff --git a/misc/rtems-tftp-proxy b/misc/rtems-tftp-proxy
index 213311d..2125662 100755
--- a/misc/rtems-tftp-proxy
+++ b/misc/rtems-tftp-proxy
@@ -1,7 +1,7 @@
-#! /bin/sh
+#! /usr/bin/env python
 #
 # RTEMS Tools Project (http://www.rtems.org/)
-# Copyright 2019 Chris Johns (chr...@rtems.org)
+# Copyright 2019, 2020 Chris Johns (chr...@rtems.org)
 # All rights reserved.
 #
 # This file is part of the RTEMS Tools package in 'rtems-tools'.
@@ -28,15 +28,18 @@
 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 # POSSIBILITY OF SUCH DAMAGE.
 #
-set -e
-base=$(dirname $(dir

[PATCH 2/3] rtemstoolkit/configuration: Treat an empty variable as an empty list

2020-09-24 Thread chrisj
From: Chris Johns 

---
 rtemstoolkit/configuration.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/rtemstoolkit/configuration.py b/rtemstoolkit/configuration.py
index a73fd9b..1f57de4 100644
--- a/rtemstoolkit/configuration.py
+++ b/rtemstoolkit/configuration.py
@@ -140,7 +140,7 @@ class configuration:
 
 def comma_list(self, section, label, err = True):
 items = self.get_item(section, label, err)
-if items is None:
+if items is None or len(items) == 0:
 return []
 return sorted(set([a.strip() for a in items.split(',')]))
 
-- 
2.24.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH 3/3] rtemstoolkit/dwarf: Dump the DIE offset

2020-09-24 Thread chrisj
From: Chris Johns 

---
 rtemstoolkit/rld-dwarf.cpp | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/rtemstoolkit/rld-dwarf.cpp b/rtemstoolkit/rld-dwarf.cpp
index fc4399a..d9ac6f3 100644
--- a/rtemstoolkit/rld-dwarf.cpp
+++ b/rtemstoolkit/rld-dwarf.cpp
@@ -1429,7 +1429,11 @@ namespace rld
   const char* s;
   ::dwarf_get_TAG_name (tag (), &s);
   out << level_prefix.substr (0, level_prefix.length () - 1)
-  << "+- " << s << std::endl;
+  << "+- " << s << " ("
+  << std::hex << std::setfill ('0')
+  << std::setw (8) << offset_
+  << std::dec << std::setfill (' ')
+  << ')' << std::endl;
 
   dwarf_attribute* attributes;
   dwarf_signed attr_count;
-- 
2.24.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


Re: [PATCH 2/8] score: Fix allocation size calculation

2020-09-24 Thread Sebastian Huber

On 24/09/2020 18:50, Gedare Bloom wrote:


+  /* Make sure the memory allocation size computation does not overflow */
+  if ( maximum_pending_messages > SIZE_MAX / buffer_size ) {

optimization: can we use mult instead?
   if ( maximum_pending_messages * buffer_size > SIZE_MAX )
save a few cycles...

Then again, maybe the division is needed here to ensure there isn't an
overflow later? This stuff gets a little tricky!


I just used the code recommended by the SEI CERT C Coding Standard:

https://wiki.sei.cmu.edu/confluence/display/c/INT30-C.+Ensure+that+unsigned+integer+operations+do+not+wrap

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


Re: [PATCH 2/8] score: Fix allocation size calculation

2020-09-24 Thread Sebastian Huber

On 24/09/2020 18:30, Gedare Bloom wrote:


+#define MESSAGE_SIZE_LIMIT \
+  ( SIZE_MAX - sizeof( uintptr_t ) - 1 \

Minor: should it be - ( sizeof( uintptr_t ) - 1 )?
Or: - sizeof(uintptr_t) + 1

The alignment up can add at most sizeof(uintptr_t)-1 bytes overhead I
think is what this is trying to capture?


Oh, yes. Two minus are a plus.
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


Re: [PATCH 4/8] score: Improve _CORE_message_queue_Initialize()

2020-09-24 Thread Sebastian Huber

On 24/09/2020 18:39, Gedare Bloom wrote:


+  status = _CORE_message_queue_Initialize(
+&the_mq->Message_queue,
+CORE_MESSAGE_QUEUE_DISCIPLINES_FIFO,
+attr->mq_maxmsg,
+attr->mq_msgsize
+  );
+
+  if ( status != STATUS_SUCCESSFUL ) {
  _POSIX_Message_queue_Free( the_mq );
  _Workspace_Free( name );
  rtems_set_errno_and_return_value( ENOSPC, MQ_OPEN_FAILED );

translate the status in case we end up using something besides ENOSPC?

I checked the standard and there is no explicit error condition listed 
for sizes which lead to an integer overflow. If you do the calculations 
with real integers, then you can say, that a 4GB address space system 
has insufficient space for the creation of the new message queue needing 
5GB.

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


Re: [PATCH 7/8] rtems: Remove Message_queue_Control::attribute_set

2020-09-24 Thread Sebastian Huber

On 24/09/2020 18:45, Gedare Bloom wrote:


There should be an mptest added for global mq

This should be already covered by tests mp09 .. mp13.
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH] user: Add migration hints from old build system

2020-09-24 Thread Sebastian Huber
Update #3818.
---
 user/bld/index.rst | 84 --
 1 file changed, 82 insertions(+), 2 deletions(-)

diff --git a/user/bld/index.rst b/user/bld/index.rst
index b47cee8..376475c 100644
--- a/user/bld/index.rst
+++ b/user/bld/index.rst
@@ -1,7 +1,7 @@
 .. SPDX-License-Identifier: CC-BY-SA-4.0
 
-.. Copyright (C) 2019 embedded brains GmbH
-.. Copyright (C) 2019 Sebastian Huber
+.. Copyright (C) 2019, 2020 embedded brains GmbH
+.. Copyright (C) 2019, 2020 Sebastian Huber
 
 .. index:: BSP build system
 .. index:: build system
@@ -283,3 +283,83 @@ example configuration file, building of the tests is 
enabled for the
 [sparc/erc32]
 
 [riscv/griscv]
+
+Migration from Autoconf/Automake
+
+
+The Autoconf/Automake based build system used a ``configure`` command to
+configure a single BSP and ``make`` to build it.  The ``configure`` command is
+replaced by a ``./waf configure`` invocation with configuration file.  The
+``make`` command is replaced by ``./waf`` and ``make install`` is replaced by
+``./waf install``.
+
+Here are some hints how a configure command line can be converted to options in
+the configuration file of the ``waf`` based build system.  BSP options given at
+the configure command line have to be added to the BSP section in the
+configuration file.
+
+``--target=${arch}-rtems6`` ``--enable-rtembsp=${bsp}``
+To build a BSP add ``[${arch}/${bsp}]`` to the configuration file.
+
+``--enable-ada`` | ``--disable-ada``
+Set ``__RTEMS_ADA__`` to ``True`` or ``False`` in the BSP section of
+the configuration file.
+
+``--enable-multiprocessing`` | ``--disable-multiprocessing``
+Set ``RTEMS_MULTIPROCESSING`` to ``True`` or ``False`` in the BSP
+section of the configuration file.
+
+``--enable-networking`` | ``--disable-networking``
+Set ``RTEMS_NETWORKING`` to ``True`` or ``False`` in the BSP section of
+the configuration file.
+
+``--enable-posix`` | ``--disable-posix``
+Set ``RTEMS_POSIX_API`` to ``True`` or ``False`` in the BSP section of
+the configuration file.
+
+``--enable-rtems-debug`` | ``--disable-rtems-debug``
+Set ``RTEMS_DEBUG`` to ``True`` or ``False`` in the BSP section of the
+configuration file.
+
+``--enable-smp`` | ``--disable-smp``
+Set ``RTEMS_SMP`` to ``True`` or ``False`` in the BSP section of the
+configuration file.
+
+``--enable-tests`` | ``--disable-tests``
+Set ``BUILD_TESTS`` to ``True`` or ``False`` in the BSP section of the
+configuration file.
+
+``--enable-tests=samples``
+Set ``BUILD_SAMPLES`` to ``True`` or ``False`` in the BSP section of
+the configuration file.
+
+Please have a look at the following example configuration file.
+
+.. code-block:: ini
+
+# --target=sparc-rtems6 --enable-rtemsbsp=erc32
+[sparc/erc32]
+
+# --enable-ada
+__RTEMS_ADA__ = True
+
+# --enable-multiprocessing
+RTEMS_MULTIPROCESSING = False
+
+# --enable-networking
+RTEMS_NETWORKING = True
+
+# --disable-posix
+RTEMS_POSIX_API = False
+
+# --enable-rtems-debug
+RTEMS_DEBUG = True
+
+# --disable-smp
+RTEMS_SMP = False
+
+# --enable-tests
+BUILD_TESTS = True
+
+# BSP_POWER_DOWN_AT_FATAL_HALT=
+BSP_POWER_DOWN_AT_FATAL_HALT = False
-- 
2.26.2

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel