[PATCH] added malloc usable size and test

2022-03-04 Thread zack leung
closes #4503
---
 cpukit/include/rtems/libcsupport.h|  5 +++
 cpukit/libcsupport/src/mallocusablesize.c | 48 +++
 spec/build/cpukit/librtemscpu.yml |  1 +
 testsuites/libtests/malloctest/init.c | 15 ++-
 4 files changed, 68 insertions(+), 1 deletion(-)
 create mode 100644 cpukit/libcsupport/src/mallocusablesize.c

diff --git a/cpukit/include/rtems/libcsupport.h
b/cpukit/include/rtems/libcsupport.h
index f4be4cfc9a..5110ab0fbe 100644
--- a/cpukit/include/rtems/libcsupport.h
+++ b/cpukit/include/rtems/libcsupport.h
@@ -74,6 +74,11 @@ extern size_t malloc_free_space(void);
  */
 extern int malloc_info(Heap_Information_block *the_info);

+/**
+ * @brief Find the usable size of the block of memory .
+ */
+extern size_t malloc_usable_size(void *ptr);
+
 /*
  *  Prototypes required to install newlib reentrancy user extension
  */
diff --git a/cpukit/libcsupport/src/mallocusablesize.c
b/cpukit/libcsupport/src/mallocusablesize.c
new file mode 100644
index 00..b7e573023a
--- /dev/null
+++ b/cpukit/libcsupport/src/mallocusablesize.c
@@ -0,0 +1,48 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ *  Copyright (C) 2022 zacchaeus leung
+ *
+ * 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 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include 
+#include 
+#include 
+
+size_t malloc_usable_size( void *ptr ) {
+
+  Heap_Control *heap_ptr ;
+  size_t size;
+  if ( ptr == NULL ) {
+return 0;
+  }
+
+  heap_ptr = malloc_get_heap_pointer();
+  _Heap_Size_of_alloc_area( heap_ptr, ptr, &size );
+
+  return size;
+}
diff --git a/spec/build/cpukit/librtemscpu.yml
b/spec/build/cpukit/librtemscpu.yml
index c224937348..2ef11e7e2d 100644
--- a/spec/build/cpukit/librtemscpu.yml
+++ b/spec/build/cpukit/librtemscpu.yml
@@ -670,6 +670,7 @@ source:
 - cpukit/libcsupport/src/lseek.c
 - cpukit/libcsupport/src/lstat.c
 - cpukit/libcsupport/src/malloc.c
+- cpukit/libcsupport/src/mallocusablesize.c
 - cpukit/libcsupport/src/malloc_deferred.c
 - cpukit/libcsupport/src/malloc_dirtier.c
 - cpukit/libcsupport/src/malloc_walk.c
diff --git a/testsuites/libtests/malloctest/init.c
b/testsuites/libtests/malloctest/init.c
index a33764177d..871edb540e 100644
--- a/testsuites/libtests/malloctest/init.c
+++ b/testsuites/libtests/malloctest/init.c
@@ -1362,6 +1362,18 @@ static void test_alloc_zero_size(void)
   rtems_test_assert( p == NULL );
   rtems_test_assert( errno == -1 );
 }
+static void test_usablesize(void)
+{
+  int * a = malloc(sizeof( int )*100);
+  int alloc_size=sizeof( int ) *100 ;
+  rtems_test_assert( malloc_usable_size( a ) <= alloc_size +
CPU_HEAP_ALIGNMENT );
+  free(a);
+
+  char * b = malloc(sizeof ( char ) 100);
+  int alloc_size 2= sizeof ( char ) *100 ;
+  rtems_test_assert( malloc_usable_size ( b ) <= alloc_size2 +
CPU_HEAP_ALIGNMENT);
+  free( b );
+}

 rtems_task Init(
   rtems_task_argument argument
@@ -1405,6 +1417,7 @@ rtems_task Init(
   test_protected_heap_info();
   test_rtems_heap_allocate_aligned_with_boundary();
   test_rtems_malloc();
+  test_usablesize();
   test_rtems_calloc();
   test_greedy_allocate();
   test_alloc_zero_size();
@@ -1524,4 +1537,4 @@ RTEMS_SYSINIT_ITEM(
   test_early_malloc,
   RTEMS_SYSINIT_INITIAL_EXTENSIONS,
   RTEMS_SYSINIT_ORDER_FIRST
-);
+);
\ No newline at end of file
-- 
2.35.1
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH rtems-docs] cpu-supplement: Add note about device memory

2022-03-04 Thread Kinsey Moore
Add information about restricted use of device memory for ARM and
AArch64.
---
 cpu-supplement/aarch64.rst | 5 +
 cpu-supplement/arm.rst | 6 ++
 2 files changed, 11 insertions(+)

diff --git a/cpu-supplement/aarch64.rst b/cpu-supplement/aarch64.rst
index 2b3d620..4576663 100644
--- a/cpu-supplement/aarch64.rst
+++ b/cpu-supplement/aarch64.rst
@@ -73,6 +73,11 @@ A flat 64-bit or 32-bit memory model is supported depending 
on the selected mult
 variant.  All AArch64 CPU variants support a built-in MMU for which basic 
initialization
 for a flat memory model is handled.
 
+Note that memcpy() and memset() must not be used on device memory as those
+functions are hand-optimized and will take advantage of unaligned accesses.
+"As per ARM"(https://developer.arm.com/documentation/ka004708/latest), 
unaligned
+accesses are not permitted for device memory.
+
 Interrupt Processing
 
 
diff --git a/cpu-supplement/arm.rst b/cpu-supplement/arm.rst
index ac9e8c6..03a2cd2 100644
--- a/cpu-supplement/arm.rst
+++ b/cpu-supplement/arm.rst
@@ -132,6 +132,12 @@ Memory Model
 A flat 32-bit memory model is supported.  The board support package must take
 care of initializing the MMU if necessary.
 
+Note that architecture variants which support unaligned accesses must not use
+memcpy() or memset() on device memory as those functions are hand-optimized and
+will take advantage of unaligned accesses where available. "As per ARM"
+(https://developer.arm.com/documentation/ddi0406/c/Application-Level-Architecture/Application-Level-Memory-Model/Alignment-support/Unaligned-data-access-restrictions-in-ARMv7-and-ARMv6),
+unaligned accesses are not permitted for device memory.
+
 Interrupt Processing
 
 
-- 
2.30.2

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


Relicense to BSD-2 Status Report

2022-03-04 Thread Joel Sherrill
Hi

A couple of weeks ago, I decided that we should have permission from
enough submitters to attempt to do bulk conversions to BSD-2 license in the
headers. I did a fair amount of the cpukit as you all may have noticed.
This led to some discoveries:

(1) There are still more people to get permission from. I hunted two down
and got permission and have one pending management permission. PLEASE
PLEASE PLEASE give permission if you have not already done so!!! If you
know someone who needs to, please ask them. All that is required is
granting permission on this ticket (https://devel.rtems.org/ticket/3053).
If they just want to send an email to myself, Chris, and Gedare, I'm happy
to put a PDF of the email on the ticket. Let's get through this.

(2) There is a LOT of inconsistency in the file headers. I did some work on
some of these issues and Christian is following up. He will post patches
for that next week.

Please please do what you can to help us push this forward. I'd like to
have it done before 6 branches. Permission is important.

I'll try to provide more detail on file counts in future status reports.

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


Re: [PATCH rtems-lwip] Add missing COPYING files from lwip and uLan

2022-03-04 Thread Vijay Kumar Banerjee
Hi Kinsey,

Thanks for the patch.

I was wondering if it would be a good idea to use this patch and add a
comment in the respective source files that they are based on an
external repository and the related copying files are
COPYING.something ?

On Fri, Mar 4, 2022 at 7:49 AM Kinsey Moore  wrote:
>
> These are the original COPYING files from the upstream projects.
> ---
>  COPYING.lwip | 25 +
>  COPYING.uLan | 33 +
>  2 files changed, 58 insertions(+)
>  create mode 100644 COPYING.lwip
>  create mode 100644 COPYING.uLan
>
> diff --git a/COPYING.lwip b/COPYING.lwip
> new file mode 100644
> index 000..90465f5
> --- /dev/null
> +++ b/COPYING.lwip
> @@ -0,0 +1,25 @@
> +Copyright (c) 2001, 2002 Swedish Institute of Computer Science.
> +All rights reserved.
> +
> +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.
> +3. The name of the author may not be used to endorse or promote products
> +   derived from this software without specific prior written permission.
> +
> +THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
> POSSIBILITY
> +OF SUCH DAMAGE.
> +
> diff --git a/COPYING.uLan b/COPYING.uLan
> new file mode 100644
> index 000..e23898b
> --- /dev/null
> +++ b/COPYING.uLan
> @@ -0,0 +1,33 @@
> +/*
> + * Copyright (c) 2001, 2002 Swedish Institute of Computer Science.
> + * All rights reserved.
> + *
> + * 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.
> + * 3. The name of the author may not be used to endorse or promote products
> + *derived from this software without specific prior written permission.
> + *
> + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
> POSSIBILITY
> + * OF SUCH DAMAGE.
> + *
> + * This file is part of the lwIP TCP/IP stack.
> + *
> + * Author: Adam Dunkels 
> + *
> + */
> +
> +
> --
> 2.30.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: rtems-lwip file locations and licensing

2022-03-04 Thread Vijay Kumar Banerjee
Hi Kinsey,

On Fri, Mar 4, 2022 at 9:47 AM Kinsey Moore  wrote:
>
> I was looking though the rtems-lwip tree in adding license files and it 
> struck me that we currently have code with possibly different licenses and 
> from different external sources merged into the same tree with possibly 
> differing paths from the original source locations. There is at least one 
> file in the uLan sources that does not have an embedded license and the 
> current setup makes discerning its license confusing. I could add what I 
> think is the correct license, but I'd much prefer not to add licenses to the 
> code given that I'm not the author.
>
> That said, I'd like to suggest that we keep code from each external source in 
> its own directory. Currently, the external sources are upstream lwIP and the 
> uLan projects with their code being merged into a single tree with some 
> changes to the location of uLan's files. My suggestion would move all uLan 
> code to a uLan/ directory in the root of the rtems-lwip repository and each 
> COPYING. license file as well. Each new driver source would get its 
> own directory and COPYING file in the root of the repository as necessary.
>
Sounds like a very reasonable approach and we can move the sources
according to the source of drivers. We might have to keep a list of
all directories in the waf, to keep the build system working. The
reason for keeping the files in one place was to have a similar
structure as the net-legacy. We can use a directory structure
according to the sources, but we will have to use a good way to make
sure that the directories/source files are easier to navigate for
humans and build system scripts.
> Thanks,
> Kinsey
> ___
> 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


rtems-lwip file locations and licensing

2022-03-04 Thread Kinsey Moore
I was looking though the rtems-lwip tree in adding license files and it struck 
me that we currently have code with possibly different licenses and from 
different external sources merged into the same tree with possibly differing 
paths from the original source locations. There is at least one file in the 
uLan sources that does not have an embedded license and the current setup makes 
discerning its license confusing. I could add what I think is the correct 
license, but I'd much prefer not to add licenses to the code given that I'm not 
the author.

That said, I'd like to suggest that we keep code from each external source in 
its own directory. Currently, the external sources are upstream lwIP and the 
uLan projects with their code being merged into a single tree with some changes 
to the location of uLan's files. My suggestion would move all uLan code to a 
uLan/ directory in the root of the rtems-lwip repository and each 
COPYING. license file as well. Each new driver source would get its own 
directory and COPYING file in the root of the repository as necessary.

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


[PATCH rtems-lwip] Add missing COPYING files from lwip and uLan

2022-03-04 Thread Kinsey Moore
These are the original COPYING files from the upstream projects.
---
 COPYING.lwip | 25 +
 COPYING.uLan | 33 +
 2 files changed, 58 insertions(+)
 create mode 100644 COPYING.lwip
 create mode 100644 COPYING.uLan

diff --git a/COPYING.lwip b/COPYING.lwip
new file mode 100644
index 000..90465f5
--- /dev/null
+++ b/COPYING.lwip
@@ -0,0 +1,25 @@
+Copyright (c) 2001, 2002 Swedish Institute of Computer Science.
+All rights reserved.
+
+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.
+3. The name of the author may not be used to endorse or promote products
+   derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+OF SUCH DAMAGE.
+
diff --git a/COPYING.uLan b/COPYING.uLan
new file mode 100644
index 000..e23898b
--- /dev/null
+++ b/COPYING.uLan
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2001, 2002 Swedish Institute of Computer Science.
+ * All rights reserved. 
+ * 
+ * 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.
+ * 3. The name of the author may not be used to endorse or promote products
+ *derived from this software without specific prior written permission. 
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
POSSIBILITY 
+ * OF SUCH DAMAGE.
+ *
+ * This file is part of the lwIP TCP/IP stack.
+ * 
+ * Author: Adam Dunkels 
+ *
+ */
+
+
-- 
2.30.2

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