~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/include/nolibc/crt.h

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* SPDX-License-Identifier: LGPL-2.1 OR MIT */
  2 /*
  3  * C Run Time support for NOLIBC
  4  * Copyright (C) 2023 Zhangjin Wu <falcon@tinylab.org>
  5  */
  6 
  7 #ifndef _NOLIBC_CRT_H
  8 #define _NOLIBC_CRT_H
  9 
 10 char **environ __attribute__((weak));
 11 const unsigned long *_auxv __attribute__((weak));
 12 
 13 static void __stack_chk_init(void);
 14 static void exit(int);
 15 
 16 extern void (*const __preinit_array_start[])(void) __attribute__((weak));
 17 extern void (*const __preinit_array_end[])(void) __attribute__((weak));
 18 
 19 extern void (*const __init_array_start[])(void) __attribute__((weak));
 20 extern void (*const __init_array_end[])(void) __attribute__((weak));
 21 
 22 extern void (*const __fini_array_start[])(void) __attribute__((weak));
 23 extern void (*const __fini_array_end[])(void) __attribute__((weak));
 24 
 25 __attribute__((weak))
 26 void _start_c(long *sp)
 27 {
 28         long argc;
 29         char **argv;
 30         char **envp;
 31         int exitcode;
 32         void (* const *func)(void);
 33         const unsigned long *auxv;
 34         /* silence potential warning: conflicting types for 'main' */
 35         int _nolibc_main(int, char **, char **) __asm__ ("main");
 36 
 37         /* initialize stack protector */
 38         __stack_chk_init();
 39 
 40         /*
 41          * sp  :    argc          <-- argument count, required by main()
 42          * argv:    argv[0]       <-- argument vector, required by main()
 43          *          argv[1]
 44          *          ...
 45          *          argv[argc-1]
 46          *          null
 47          * environ: environ[0]    <-- environment variables, required by main() and getenv()
 48          *          environ[1]
 49          *          ...
 50          *          null
 51          * _auxv:   _auxv[0]      <-- auxiliary vector, required by getauxval()
 52          *          _auxv[1]
 53          *          ...
 54          *          null
 55          */
 56 
 57         /* assign argc and argv */
 58         argc = *sp;
 59         argv = (void *)(sp + 1);
 60 
 61         /* find environ */
 62         environ = envp = argv + argc + 1;
 63 
 64         /* find _auxv */
 65         for (auxv = (void *)envp; *auxv++;)
 66                 ;
 67         _auxv = auxv;
 68 
 69         for (func = __preinit_array_start; func < __preinit_array_end; func++)
 70                 (*func)();
 71         for (func = __init_array_start; func < __init_array_end; func++)
 72                 (*func)();
 73 
 74         /* go to application */
 75         exitcode = _nolibc_main(argc, argv, envp);
 76 
 77         for (func = __fini_array_end; func > __fini_array_start;)
 78                 (*--func)();
 79 
 80         exit(exitcode);
 81 }
 82 
 83 #endif /* _NOLIBC_CRT_H */
 84 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php