Implement sysconf for Arm

- add support for using sysconf to get page size in _mallocr.c via
  HAVE_SYSCONF_PAGESIZE flag set in configure.host
- set flag in configure.host for arm and add a default sysconf implementation
  in libc/sys/arm that returns the page size
- the default implementation can be overridden outside newlib to allow a
  different page size to improve malloc on devices with a small footprint
  without needing to rebuild newlib
- this patch is based on a contribution from Torbjorn Svensson and
  Niklas Dahlquist (https://ecos.sourceware.org/ml/newlib/current/017616.html)
This commit is contained in:
Jeff Johnston 2022-09-16 16:04:21 -04:00
parent eb5c631ead
commit 5230eb7f8c
4 changed files with 39 additions and 1 deletions

View File

@ -628,6 +628,7 @@ newlib_cflags="${newlib_cflags} -DCLOCK_PROVIDED -DMALLOC_PROVIDED -DEXIT_PROVID
;; ;;
arm*-*-pe) arm*-*-pe)
syscall_dir=syscalls syscall_dir=syscalls
newlib_cflags="${newlib_cflags} -DHAVE_SYSCONF_PAGESIZE"
;; ;;
arm*-*-*) arm*-*-*)
syscall_dir=syscalls syscall_dir=syscalls
@ -642,6 +643,7 @@ newlib_cflags="${newlib_cflags} -DCLOCK_PROVIDED -DMALLOC_PROVIDED -DEXIT_PROVID
# newlib_cflags="${newlib_cflags} -DARM_RDP_MONITOR" # newlib_cflags="${newlib_cflags} -DARM_RDP_MONITOR"
newlib_cflags="${newlib_cflags} -DARM_RDI_MONITOR" newlib_cflags="${newlib_cflags} -DARM_RDI_MONITOR"
fi fi
newlib_cflags="${newlib_cflags} -DHAVE_SYSCONF_PAGESIZE"
;; ;;
avr*) avr*)
newlib_cflags="${newlib_cflags} -DNO_EXEC -DSMALL_MEMORY -DMISSING_SYSCALL_NAMES" newlib_cflags="${newlib_cflags} -DNO_EXEC -DSMALL_MEMORY -DMISSING_SYSCALL_NAMES"

View File

@ -320,12 +320,14 @@ extern "C" {
#endif #endif
#ifndef _WIN32 #ifndef _WIN32
#ifndef HAVE_SYSCONF_PAGESIZE
#ifdef SMALL_MEMORY #ifdef SMALL_MEMORY
#define malloc_getpagesize (128) #define malloc_getpagesize (128)
#else #else
#define malloc_getpagesize (4096) #define malloc_getpagesize (4096)
#endif #endif
#endif #endif
#endif
#if __STD_C #if __STD_C
extern void __malloc_lock(struct _reent *); extern void __malloc_lock(struct _reent *);

View File

@ -1,6 +1,6 @@
AM_CPPFLAGS_%C% = -I$(srcdir)/libc/machine/arm AM_CPPFLAGS_%C% = -I$(srcdir)/libc/machine/arm
libc_a_SOURCES += %D%/access.c %D%/aeabi_atexit.c libc_a_SOURCES += %D%/access.c %D%/aeabi_atexit.c %D%/sysconf.c
if MAY_SUPPLY_SYSCALLS if MAY_SUPPLY_SYSCALLS
libc_a_SOURCES += %D%/libcfunc.c %D%/trap.S %D%/syscalls.c libc_a_SOURCES += %D%/libcfunc.c %D%/trap.S %D%/syscalls.c
endif endif

View File

@ -0,0 +1,34 @@
/* libc/sys/arm/sysconf.c - The sysconf function */
/* Copyright 2020, STMicroelectronics
*
* All rights reserved.
*
* Redistribution, modification, and use in source and binary forms is permitted
* provided that the above copyright notice and following paragraph are
* duplicated in all such forms.
*
* This file is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
#include <unistd.h>
#include <errno.h>
long sysconf(int name)
{
switch (name)
{
case _SC_PAGESIZE:
#ifdef SMALL_MEMORY
return 128;
#else
return 4096;
#endif
default:
errno = EINVAL;
return -1;
}
return -1; /* Can't get here */
}