Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change libphoenix initialization #313

Merged
merged 1 commit into from
Jan 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 57 additions & 20 deletions crt0-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,47 +5,84 @@
*
* Entrypoint
*
* Copyright 2017, 2018 Phoenix Systems
* Author: Pawel Pisarczyk, Aleksander Kaminski
* Copyright 2017, 2018, 2023 Phoenix Systems
* Author: Pawel Pisarczyk, Aleksander Kaminski, Hubert Badocha
*
* This file is part of Phoenix-RTOS.
*
* %LICENSE%
*/

#include <sys/file.h>
#include <stdlib.h>
#include <stdio.h>


extern void _malloc_init(void);
extern int _env_init(void);
extern void _signals_init(void);
extern void _file_init(void);
extern void _errno_init(void);
extern void _atexit_init(void);
extern void _init_array(void);
extern void _pthread_init(void);
extern void (*__preinit_array_start[])(void);
extern void (*__preinit_array_end[])(void);

extern void (*__init_array_start[])(void);
extern void (*__init_array_end[])(void);


extern void _init(void);


__attribute__((noinline)) static void _init_array(void)
{
size_t i, sz;

sz = __preinit_array_end - __preinit_array_start;
for (i = 0; i < sz; i++) {
__preinit_array_start[i]();
}

/* FIXME: change compilation settings to make access to _init() */
/* _init(); */

sz = __init_array_end - __init_array_start;
for (i = 0; i < sz; i++) {
__init_array_start[i]();
}
}


extern void (*__fini_array_start[])(void);
extern void (*__fini_array_end[])(void);


extern void _fini(void);


static void _fini_array(void)
{
size_t i, sz;

sz = __fini_array_end - __fini_array_start;
for (i = sz; i > 0; i--) {
__fini_array_start[i - 1]();
}

/* FIXME: change compilation settings to make access to _fini() */
/* _fini(); */
}


extern void _libc_init(void);
extern int main(int argc, char **argv);


char **environ;
const char *argv_progname;


void _startc(int argc, char **argv, char **env)
__attribute__((noreturn)) void _startc(int argc, char **argv, char **env)
{
environ = env;
argv_progname = *argv;

_atexit_init();
_errno_init();
_malloc_init();
_env_init();
_signals_init();
_file_init();
_libc_init();

atexit(_fini_array);
_init_array();
_pthread_init();

exit(main(argc, argv));
}
2 changes: 1 addition & 1 deletion misc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
# Copyright 2021 Phoenix Systems
#

OBJS += $(addprefix $(PREFIX_O)misc/, init.o fini.o)
OBJS += $(addprefix $(PREFIX_O)misc/, init.o)
36 changes: 0 additions & 36 deletions misc/fini.c

This file was deleted.

44 changes: 19 additions & 25 deletions misc/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,34 @@
*
* libphoenix
*
* init array
* init
*
* Copyright 2021 Phoenix Systems
* Author: Hubert Buczynski
* Copyright 2021, 2023 Phoenix Systems
* Author: Hubert Buczynski, Hubert Badocha
*
* This file is part of Phoenix-RTOS.
*
* %LICENSE%
*/


#include <stdlib.h>
extern void _malloc_init(void);
extern int _env_init(void);
extern void _signals_init(void);
extern void _file_init(void);
extern void _errno_init(void);
extern void _atexit_init(void);
extern void _init_array(void);
extern void _pthread_init(void);

extern void (*__preinit_array_start[])(void);
extern void (*__preinit_array_end[])(void);

extern void (*__init_array_start[])(void);
extern void (*__init_array_end[])(void);


extern void _init (void);

void _init_array(void)
void _libc_init(void)
{
size_t i, sz;

sz = __preinit_array_end - __preinit_array_start;
for (i = 0; i < sz; i++)
__preinit_array_start[i]();

/* FIXME: change compilation settings to make access to _init() */
/* _init(); */

sz = __init_array_end - __init_array_start;
for (i = 0; i < sz; i++)
__init_array_start[i]();
_atexit_init();
_errno_init();
_malloc_init();
_env_init();
_signals_init();
_file_init();
_pthread_init();
}
2 changes: 0 additions & 2 deletions stdlib/exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include <stdio.h>

extern void _atexit_call(void);
extern void _fini_array(void);
extern void sys_exit(int) __attribute__((noreturn));


Expand All @@ -37,7 +36,6 @@ void exit(int status)
{
fflush(NULL);
_atexit_call();
_fini_array();
_exit(status);
for(;;);
}
Loading