From b94b34a97a491ffb2650d717c7cbbe245bbc5ab9 Mon Sep 17 00:00:00 2001 From: deadwood Date: Sun, 8 Nov 2015 17:16:51 +0000 Subject: [PATCH] linux/bootstrap: use Forbid/Permit only when thread is main AROS thread There can be more threads running in AROS process - for example threads started by linux-side libraries. Only the AROS thread (the initial thread created by AROS process) should call Forbid/Permit - otherwise the TDNestCnt can get uncontrolled values and AROS tasks might for example start executing in permanent Forbid state. git-svn-id: https://svn.aros.org/svn/aros/trunk/AROS@51202 fb15a70f-31f2-0310-bbcc-cdcc74a49acc --- arch/all-linux/bootstrap/malloc.c | 17 ++++++++++++++--- arch/all-linux/bootstrap/mmakefile.src | 2 +- arch/all-linux/bootstrap/preboot.c | 14 ++++++++++++++ arch/all-unix/bootstrap/kickstart.c | 1 + arch/all-unix/bootstrap/mmakefile.src | 2 +- arch/all-unix/bootstrap/platform.h | 1 + arch/all-unix/bootstrap/preboot.c | 11 +++++++++++ 7 files changed, 43 insertions(+), 5 deletions(-) create mode 100644 arch/all-linux/bootstrap/preboot.c create mode 100644 arch/all-unix/bootstrap/preboot.c diff --git a/arch/all-linux/bootstrap/malloc.c b/arch/all-linux/bootstrap/malloc.c index 4ee4d2a5a0..b2a1f000f5 100644 --- a/arch/all-linux/bootstrap/malloc.c +++ b/arch/all-linux/bootstrap/malloc.c @@ -22,9 +22,15 @@ #include #include +#include +#include + static int memnest; -#define MEMLOCK if (SysBase != NULL) Forbid(); -#define MEMUNLOCK if (SysBase != NULL) Permit(); +extern pid_t arostid; + +#define THREADID pid_t thistid = syscall(SYS_gettid); +#define MEMLOCK if (SysBase != NULL && thistid == arostid) Forbid(); +#define MEMUNLOCK if (SysBase != NULL && thistid == arostid) Permit(); extern struct ExecBase *SysBase; extern void * __libc_malloc(size_t); @@ -35,6 +41,7 @@ extern void * __libc_realloc(void * mem, size_t newsize); void * malloc(size_t size) { void *res; + THREADID MEMLOCK memnest++; @@ -47,6 +54,8 @@ void * malloc(size_t size) void free(void * addr) { + THREADID + MEMLOCK memnest++; __libc_free(addr); @@ -57,6 +66,7 @@ void free(void * addr) void * calloc(size_t n, size_t size) { void *res; + THREADID MEMLOCK memnest++; @@ -70,7 +80,8 @@ void * calloc(size_t n, size_t size) void *realloc(void *ptr, size_t size) { void *res; - + THREADID + MEMLOCK memnest++; res = __libc_realloc(ptr, size); diff --git a/arch/all-linux/bootstrap/mmakefile.src b/arch/all-linux/bootstrap/mmakefile.src index c281a4e61e..63cffd6dbe 100644 --- a/arch/all-linux/bootstrap/mmakefile.src +++ b/arch/all-linux/bootstrap/mmakefile.src @@ -1,7 +1,7 @@ # $Id$ include $(TOP)/config/make.cfg -FILES := malloc +FILES := malloc preboot USER_INCLUDES := -I$(SRCDIR)/arch/all-hosted/bootstrap \ -I$(GENINCDIR) diff --git a/arch/all-linux/bootstrap/preboot.c b/arch/all-linux/bootstrap/preboot.c new file mode 100644 index 0000000000..b4920bfa19 --- /dev/null +++ b/arch/all-linux/bootstrap/preboot.c @@ -0,0 +1,14 @@ +/* + Copyright © 2015, The AROS Development Team. All rights reserved. + $Id$ +*/ + +#include +#include + +pid_t arostid; + +void Host_PreBoot() +{ + arostid = syscall(SYS_gettid); +} diff --git a/arch/all-unix/bootstrap/kickstart.c b/arch/all-unix/bootstrap/kickstart.c index 66e4525cfa..537d5b5e79 100644 --- a/arch/all-unix/bootstrap/kickstart.c +++ b/arch/all-unix/bootstrap/kickstart.c @@ -58,6 +58,7 @@ int kick(int (*addr)(), struct TagItem *msg) case 0: fprintf(stderr, "[Bootstrap] Entering kernel at %p...\n", addr); + Host_PreBoot(); i = addr(msg, AROS_BOOT_MAGIC); exit(i); } diff --git a/arch/all-unix/bootstrap/mmakefile.src b/arch/all-unix/bootstrap/mmakefile.src index 625ffb2fbc..b95a8e8ec5 100644 --- a/arch/all-unix/bootstrap/mmakefile.src +++ b/arch/all-unix/bootstrap/mmakefile.src @@ -3,7 +3,7 @@ include $(TOP)/config/make.cfg EXEDIR := $(AROSDIR)/boot -FILES := hostinterface hostlib kickstart kputc memory shutdown support +FILES := hostinterface hostlib kickstart kputc memory preboot shutdown support USER_INCLUDES := -I$(SRCDIR)/arch/all-hosted/bootstrap \ -I$(SRCDIR)/arch/all-unix/kernel \ -I$(GENINCDIR) \ diff --git a/arch/all-unix/bootstrap/platform.h b/arch/all-unix/bootstrap/platform.h index f8ac6554bf..ca14493d3a 100644 --- a/arch/all-unix/bootstrap/platform.h +++ b/arch/all-unix/bootstrap/platform.h @@ -5,3 +5,4 @@ /* Prototypes for platform-specific functions */ void Host_FreeMem(void); void Host_ColdBoot(void); +void Host_PreBoot(void); diff --git a/arch/all-unix/bootstrap/preboot.c b/arch/all-unix/bootstrap/preboot.c new file mode 100644 index 0000000000..1b4861b846 --- /dev/null +++ b/arch/all-unix/bootstrap/preboot.c @@ -0,0 +1,11 @@ +/* + Copyright © 2015, The AROS Development Team. All rights reserved. + $Id$ +*/ + + +#include "platform.h" + +void Host_PreBoot() +{ +} -- 2.11.4.GIT