This is an automated email from the ASF dual-hosted git repository. jerzy pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
commit 054d3c9d21931114a04f9b1bc6ffba7814d3562e Author: Jerzy Kasenberg <[email protected]> AuthorDate: Thu Jun 17 09:17:48 2021 +0200 hal: Make common native sbrk implementation All sbrk.c files for sim were identical. This moves code to one place --- hw/bsp/native-mips/src/sbrk.c | 60 ---------------------- hw/bsp/native/src/sbrk.c | 60 ---------------------- hw/hal/src/sbrk.c | 2 +- .../native-armv7/src/sbrk.c => hal/src/sbrk_sim.c} | 6 +++ 4 files changed, 7 insertions(+), 121 deletions(-) diff --git a/hw/bsp/native-mips/src/sbrk.c b/hw/bsp/native-mips/src/sbrk.c deleted file mode 100644 index f122dd8..0000000 --- a/hw/bsp/native-mips/src/sbrk.c +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -#include <sys/mman.h> -#include <unistd.h> - -#include <hal/hal_bsp.h> - -extern int getpagesize(void); - -static void *cont; -static int sys_pagesize; -static int cont_left; - -void * -_sbrk(int incr) -{ - void *result; - - if (!sys_pagesize) { - sys_pagesize = getpagesize(); - } - if (cont && incr <= cont_left) { - result = cont; - cont_left -= incr; - if (cont_left) { - cont = (char *)cont + incr; - } else { - cont = NULL; - } - return result; - } - result = mmap(NULL, incr, PROT_READ | PROT_WRITE, MAP_ANON | MAP_SHARED, - -1, 0); - if (result) { - cont_left = sys_pagesize - (incr % sys_pagesize); - if (cont_left) { - cont = (char *)result + incr; - } else { - cont = NULL; - } - } - return result; -} diff --git a/hw/bsp/native/src/sbrk.c b/hw/bsp/native/src/sbrk.c deleted file mode 100644 index f122dd8..0000000 --- a/hw/bsp/native/src/sbrk.c +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -#include <sys/mman.h> -#include <unistd.h> - -#include <hal/hal_bsp.h> - -extern int getpagesize(void); - -static void *cont; -static int sys_pagesize; -static int cont_left; - -void * -_sbrk(int incr) -{ - void *result; - - if (!sys_pagesize) { - sys_pagesize = getpagesize(); - } - if (cont && incr <= cont_left) { - result = cont; - cont_left -= incr; - if (cont_left) { - cont = (char *)cont + incr; - } else { - cont = NULL; - } - return result; - } - result = mmap(NULL, incr, PROT_READ | PROT_WRITE, MAP_ANON | MAP_SHARED, - -1, 0); - if (result) { - cont_left = sys_pagesize - (incr % sys_pagesize); - if (cont_left) { - cont = (char *)result + incr; - } else { - cont = NULL; - } - } - return result; -} diff --git a/hw/hal/src/sbrk.c b/hw/hal/src/sbrk.c index 1c11031..3a54b5e 100644 --- a/hw/hal/src/sbrk.c +++ b/hw/hal/src/sbrk.c @@ -19,7 +19,7 @@ #include <syscfg/syscfg.h> -#if MYNEWT_VAL(HAL_SBRK) +#if MYNEWT_VAL(HAL_SBRK) && !MYNEWT_VAL(BSP_SIMULATED) static char *sbrk_base; static char *sbrk_limit; diff --git a/hw/bsp/native-armv7/src/sbrk.c b/hw/hal/src/sbrk_sim.c similarity index 94% rename from hw/bsp/native-armv7/src/sbrk.c rename to hw/hal/src/sbrk_sim.c index f122dd8..2434a47 100644 --- a/hw/bsp/native-armv7/src/sbrk.c +++ b/hw/hal/src/sbrk_sim.c @@ -17,6 +17,10 @@ * under the License. */ +#include <syscfg/syscfg.h> + +#if MYNEWT_VAL(HAL_SBRK) && MYNEWT_VAL(BSP_SIMULATED) + #include <sys/mman.h> #include <unistd.h> @@ -58,3 +62,5 @@ _sbrk(int incr) } return result; } + +#endif
