From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2134) id 987DE3858D28; Mon, 19 Sep 2022 19:36:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 987DE3858D28 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1663616203; bh=HHEqaKciWHP8mk51eeaIfJJRLZhHPX0sEnLb9UhYmDA=; h=From:To:Subject:Date:From; b=bKIpjO+Ub+mwswxlRsGUoEplvw02Ns8xTPM1ZuU5Ejlz3/3c5Djg8okJHnCBCHQXK IPd1Yb/1jYn72XqqxNDAwghfXtc8N1OJev5zMEukF0b3ZMcLcUnfObT/E9jNMe5VP4 85slnjR70equpFBPnWrqUDdplBctZnpXub0XVdBo= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Jeff Johnston To: newlib-cvs@sourceware.org Subject: [newlib-cygwin] Implement sysconf for Arm X-Act-Checkin: newlib-cygwin X-Git-Author: Jeff Johnston X-Git-Refname: refs/heads/master X-Git-Oldrev: eb5c631ead537ac5640d7e4b1ea0edbef344d6d9 X-Git-Newrev: 5230eb7f8c6b43c71d7e38d138935c48de930b76 Message-Id: <20220919193643.987DE3858D28@sourceware.org> Date: Mon, 19 Sep 2022 19:36:43 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D5230eb7f8c6= b43c71d7e38d138935c48de930b76 commit 5230eb7f8c6b43c71d7e38d138935c48de930b76 Author: Jeff Johnston Date: Fri Sep 16 16:04:21 2022 -0400 Implement sysconf for Arm =20 - 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 implemen= tation 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 footpri= nt 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/01761= 6.html) Diff: --- newlib/configure.host | 2 ++ newlib/libc/stdlib/_mallocr.c | 2 ++ newlib/libc/sys/arm/Makefile.inc | 2 +- newlib/libc/sys/arm/sysconf.c | 34 ++++++++++++++++++++++++++++++++++ 4 files changed, 39 insertions(+), 1 deletion(-) diff --git a/newlib/configure.host b/newlib/configure.host index 98ce07d82..32d1436ba 100644 --- a/newlib/configure.host +++ b/newlib/configure.host @@ -628,6 +628,7 @@ newlib_cflags=3D"${newlib_cflags} -DCLOCK_PROVIDED -DMA= LLOC_PROVIDED -DEXIT_PROVID ;; arm*-*-pe) syscall_dir=3Dsyscalls + newlib_cflags=3D"${newlib_cflags} -DHAVE_SYSCONF_PAGESIZE" ;; arm*-*-*) syscall_dir=3Dsyscalls @@ -642,6 +643,7 @@ newlib_cflags=3D"${newlib_cflags} -DCLOCK_PROVIDED -DMA= LLOC_PROVIDED -DEXIT_PROVID # newlib_cflags=3D"${newlib_cflags} -DARM_RDP_MONITOR" newlib_cflags=3D"${newlib_cflags} -DARM_RDI_MONITOR" fi + newlib_cflags=3D"${newlib_cflags} -DHAVE_SYSCONF_PAGESIZE" ;; avr*) newlib_cflags=3D"${newlib_cflags} -DNO_EXEC -DSMALL_MEMORY -DMISSING_SYSC= ALL_NAMES" diff --git a/newlib/libc/stdlib/_mallocr.c b/newlib/libc/stdlib/_mallocr.c index 4b53997a3..1997b6db1 100644 --- a/newlib/libc/stdlib/_mallocr.c +++ b/newlib/libc/stdlib/_mallocr.c @@ -320,12 +320,14 @@ extern "C" { #endif =20 #ifndef _WIN32 +#ifndef HAVE_SYSCONF_PAGESIZE #ifdef SMALL_MEMORY #define malloc_getpagesize (128) #else #define malloc_getpagesize (4096) #endif #endif +#endif =20 #if __STD_C extern void __malloc_lock(struct _reent *); diff --git a/newlib/libc/sys/arm/Makefile.inc b/newlib/libc/sys/arm/Makefil= e.inc index 490a9630d..012295659 100644 --- a/newlib/libc/sys/arm/Makefile.inc +++ b/newlib/libc/sys/arm/Makefile.inc @@ -1,6 +1,6 @@ AM_CPPFLAGS_%C% =3D -I$(srcdir)/libc/machine/arm =20 -libc_a_SOURCES +=3D %D%/access.c %D%/aeabi_atexit.c +libc_a_SOURCES +=3D %D%/access.c %D%/aeabi_atexit.c %D%/sysconf.c if MAY_SUPPLY_SYSCALLS libc_a_SOURCES +=3D %D%/libcfunc.c %D%/trap.S %D%/syscalls.c endif diff --git a/newlib/libc/sys/arm/sysconf.c b/newlib/libc/sys/arm/sysconf.c new file mode 100644 index 000000000..0fbbe31dc --- /dev/null +++ b/newlib/libc/sys/arm/sysconf.c @@ -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 per= mitted + * 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 +#include + +long sysconf(int name) +{ + switch (name) + { + case _SC_PAGESIZE: +#ifdef SMALL_MEMORY + return 128; +#else + return 4096; +#endif + + default: + errno =3D EINVAL; + return -1; + } + return -1; /* Can't get here */ +}