mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@barebox.org>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@barebox.org>
Subject: [PATCH master 3/4] startup: track system state with regards to initcall/exitcalls
Date: Mon, 23 Jun 2025 08:20:31 +0200	[thread overview]
Message-ID: <20250623062032.3527006-3-a.fatoum@barebox.org> (raw)
In-Reply-To: <20250623062032.3527006-1-a.fatoum@barebox.org>

The operating system reclaims the barebox malloc area fully after it's
booted, so there is no point freeing memory while executing exitcalls.

To allow skipping memory freeing in that situation, maintain this
information in a new barebox_system_state variable.

Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
 common/startup.c  |  5 +++++
 include/barebox.h | 12 ++++++++++++
 2 files changed, 17 insertions(+)

diff --git a/common/startup.c b/common/startup.c
index 560a00c5699b..8d36ffceb47e 100644
--- a/common/startup.c
+++ b/common/startup.c
@@ -51,6 +51,7 @@ extern initcall_t __barebox_initcalls_start[], __barebox_early_initcalls_end[],
 
 extern exitcall_t __barebox_exitcalls_start[], __barebox_exitcalls_end[];
 
+enum system_states barebox_system_state;
 
 #if defined CONFIG_FS_RAMFS && defined CONFIG_FS_DEVFS
 static int mount_root(void)
@@ -404,8 +405,10 @@ void __noreturn start_barebox(void)
 					ERR_PTR(result));
 	}
 
+	barebox_system_state = BAREBOX_RUNNING;
 	pr_debug("initcalls done\n");
 
+
 	if (IS_ENABLED(CONFIG_SELFTEST_AUTORUN))
 		selftests_run();
 
@@ -435,6 +438,8 @@ void shutdown_barebox(void)
 {
 	exitcall_t *exitcall;
 
+	barebox_system_state = BAREBOX_EXITING;
+
 	for (exitcall = __barebox_exitcalls_start;
 			exitcall < __barebox_exitcalls_end; exitcall++) {
 		pr_debug("exitcall-> %pS\n", *exitcall);
diff --git a/include/barebox.h b/include/barebox.h
index 02228451c26e..1b291129e982 100644
--- a/include/barebox.h
+++ b/include/barebox.h
@@ -48,4 +48,16 @@ void shutdown_barebox(void);
 
 long get_ram_size(volatile long *base, long size);
 
+enum system_states {
+	BAREBOX_STARTING,
+	BAREBOX_RUNNING,
+	BAREBOX_EXITING,
+};
+
+#if IN_PROPER
+extern enum system_states barebox_system_state;
+#else
+#define barebox_system_state	BAREBOX_STARTING
+#endif
+
 #endif
-- 
2.39.5




  parent reply	other threads:[~2025-06-23  6:40 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-23  6:20 [PATCH master 1/4] commands: stat: fix leaking file descriptors on early exit Ahmad Fatoum
2025-06-23  6:20 ` [PATCH master 2/4] lib: idr: make idr_for_each_entry removal safe Ahmad Fatoum
2025-06-23  6:20 ` Ahmad Fatoum [this message]
2025-06-23  6:20 ` [PATCH master 4/4] fs: do not skip fs_remove when calling umount ramfs Ahmad Fatoum
2025-06-23  8:36 ` [PATCH master 1/4] commands: stat: fix leaking file descriptors on early exit Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250623062032.3527006-3-a.fatoum@barebox.org \
    --to=a.fatoum@barebox.org \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox