When doing a FLAT build, do we ever build nx_start.c twice, once with
__KERNEL__ and once without? (In my configuration, it is built only
once.)
No

Regarding the code:

   /* Initialize the memory manager */

     {
       FAR void *heap_start;
       size_t heap_size;

#ifdef MM_KERNEL_USRHEAP_INIT
       /* Get the user-mode heap from the platform specific code and configure
        * the user-mode memory allocator.
        */

       up_allocate_heap(&heap_start, &heap_size);
       kumm_initialize(heap_start, heap_size);
#endif

#ifdef CONFIG_MM_KERNEL_HEAP
       /* Get the kernel-mode heap from the platform specific code and
        * configure the kernel-mode memory allocator.
        */

       up_allocate_kheap(&heap_start, &heap_size);
       kmm_initialize(heap_start, heap_size);
#endif

#ifdef CONFIG_MM_PGALLOC
       /* If there is a page allocator in the configuration, then get the page
        * heap information from the platform-specific code and configure the
        * page allocator.
        */

       up_allocate_pgheap(&heap_start, &heap_size);
       mm_pginitialize(heap_start, heap_size);
#endif
     }

Is it always mandatory to do one of the three?

No.. this code was broken with with commit eca70597858bc619d3114901d16e4a30f1ebffbe .  There is no point trying to make sense out of this.  It is just broken and needs to be fixed.

This is the change that broke it:

   diff --git a/sched/init/nx_start.c b/sched/init/nx_start.c
   index c74b09944a..75abaddb56 100644
   --- a/sched/init/nx_start.c
   +++ b/sched/init/nx_start.c
   @@ -545,8 +545,6 @@ void nx_start(void)

       nxsem_initialize();

   -#if defined(MM_KERNEL_USRHEAP_INIT) ||
   defined(CONFIG_MM_KERNEL_HEAP) || \
   -    defined(CONFIG_MM_PGALLOC)
       /* Initialize the memory manager */

         {
   @@ -571,10 +569,6 @@ void nx_start(void)
           kmm_initialize(heap_start, heap_size);
     #endif

   -#ifdef CONFIG_ARCH_USE_MODULE_TEXT
   -    up_module_text_init();
   -#endif
   -
     #ifdef CONFIG_MM_PGALLOC
           /* If there is a page allocator in the configuration, then
   get the page
            * heap information from the platform-specific code and
   configure the
   @@ -585,6 +579,9 @@ void nx_start(void)
           mm_pginitialize(heap_start, heap_size);
     #endif
         }
   +
   +#ifdef CONFIG_ARCH_USE_MODULE_TEXT
   +  up_module_text_init();
     #endif

     #ifdef CONFIG_MM_IOB

So there is not a lot of sense in us discussing the meaning of broken code.  It has not meaning.  It is just wrong and needs to be fixed.  Please submit a PR.  I think you just need to back out that portion of commit eca70597858bc619d3114901d16e4a30f1ebffbe


Reply via email to