diff mbox series

[RFC,v7,04/21] um: host: implement os_initcalls and os_exitcalls

Message ID d3bfb0e0e4300bb5191ae51918dd0795de343dc2.1601960644.git.thehajime@gmail.com
State Not Applicable
Headers show
Series [RFC,v7,01/21] um: split build in kernel and host parts | expand

Commit Message

Hajime Tazaki Oct. 6, 2020, 9:44 a.m. UTC
From: Octavian Purdila <tavi@cs.pub.ro>

This patch implements the init and exit calls for host code. It uses
the automatic __start_<section> and __stop_<section> variables that
are defined by gcc / ld when using custom sections.

Note that this patch should be merged with "um: move arch/um/os-Linux
dir to tools/um" but for now it is separate to make the review easier.

Signed-off-by: Octavian Purdila <tavi@cs.pub.ro>
---
 tools/um/uml/util.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

Comments

Johannes Berg Oct. 7, 2020, 3:22 p.m. UTC | #1
On Tue, 2020-10-06 at 18:44 +0900, Hajime Tazaki wrote:

> Note that this patch should be merged with "um: move arch/um/os-Linux
> dir to tools/um" but for now it is separate to make the review easier.

Not a fan of that, I must say ...

> +extern void (*__start_os_exitcalls)(void);
> +extern void (*__stop_os_exitcalls)(void);
> +
> +void os_exitcalls(void)
> +{
> +	exitcall_t *call;
> +
> +	call = &__stop_os_exitcalls;
> +	while (--call >= &__start_os_exitcalls)
> +		(*call)();

You should check for and skip NULL pointers, there always are alignment
issues with automatic section filling like this, more so with clang than
gcc.

> +}
> +
> +extern int (*__start_os_initcalls)(void);
> +extern int (*__stop_os_initcalls)(void);
> +
> +int os_initcalls(void)
> +{
> +	initcall_t *call;
> +
> +	call = &__stop_os_initcalls;
> +	while (--call >= &__start_os_initcalls)
> +		(*call)();

Same here.

johannes
Hajime Tazaki Oct. 8, 2020, 1:16 p.m. UTC | #2
On Thu, 08 Oct 2020 00:22:18 +0900,
Johannes Berg wrote:
> 
> On Tue, 2020-10-06 at 18:44 +0900, Hajime Tazaki wrote:
> 
> > Note that this patch should be merged with "um: move arch/um/os-Linux
> > dir to tools/um" but for now it is separate to make the review easier.
> 
> Not a fan of that, I must say ...

Now I found that this patch should be together with the patch 02/21
um: add os init and exit calls.  I will do that from next time.

> > +extern void (*__start_os_exitcalls)(void);
> > +extern void (*__stop_os_exitcalls)(void);
> > +
> > +void os_exitcalls(void)
> > +{
> > +	exitcall_t *call;
> > +
> > +	call = &__stop_os_exitcalls;
> > +	while (--call >= &__start_os_exitcalls)
> > +		(*call)();
> 
> You should check for and skip NULL pointers, there always are alignment
> issues with automatic section filling like this, more so with clang than
> gcc.

Understand, I'll fix it.

> > +}
> > +
> > +extern int (*__start_os_initcalls)(void);
> > +extern int (*__stop_os_initcalls)(void);
> > +
> > +int os_initcalls(void)
> > +{
> > +	initcall_t *call;
> > +
> > +	call = &__stop_os_initcalls;
> > +	while (--call >= &__start_os_initcalls)
> > +		(*call)();
> 
> Same here.

Okay.

-- Hajime
diff mbox series

Patch

diff --git a/tools/um/uml/util.c b/tools/um/uml/util.c
index ecf2f390fad2..4011b36fee7e 100644
--- a/tools/um/uml/util.c
+++ b/tools/um/uml/util.c
@@ -186,3 +186,29 @@  void os_warn(const char *fmt, ...)
 	vfprintf(stderr, fmt, list);
 	va_end(list);
 }
+
+extern void (*__start_os_exitcalls)(void);
+extern void (*__stop_os_exitcalls)(void);
+
+void os_exitcalls(void)
+{
+	exitcall_t *call;
+
+	call = &__stop_os_exitcalls;
+	while (--call >= &__start_os_exitcalls)
+		(*call)();
+}
+
+extern int (*__start_os_initcalls)(void);
+extern int (*__stop_os_initcalls)(void);
+
+int os_initcalls(void)
+{
+	initcall_t *call;
+
+	call = &__stop_os_initcalls;
+	while (--call >= &__start_os_initcalls)
+		(*call)();
+
+	return 0;
+}