pussuw commented on a change in pull request #5782:
URL: https://github.com/apache/incubator-nuttx/pull/5782#discussion_r837137782



##########
File path: arch/risc-v/src/common/riscv_pthread_start.c
##########
@@ -66,11 +66,17 @@
 void up_pthread_start(pthread_trampoline_t startup,
                       pthread_startroutine_t entrypt, pthread_addr_t arg)
 {
+#ifdef CONFIG_ARCH_USE_S_MODE
+  /* Let ksys_call3() do all of the work */
+
+  ksys_call3(SYS_pthread_start, (uintptr_t)startup, (uintptr_t)entrypt,
+             (uintptr_t)arg);
+#else
   /* Let sys_call3() do all of the work */
 
   sys_call3(SYS_pthread_start, (uintptr_t)startup, (uintptr_t)entrypt,

Review comment:
       Citation from kmalloc.h
   ```
   
   /* For a monolithic, kernel-mode NuttX build.  Special allocators must be
    * used.  Otherwise, the standard allocators prototyped in stdlib.h may
    * be used for both the kernel- and user-mode objects.
    */
   
   /* This family of allocators is used to manage user-accessible memory
    * from the kernel.  In the flat build, the following are declared in
    * stdlib.h and are directly callable.  In the kernel-phase of the kernel
    * build, the following are defined in userspace.h as macros that call
    * into user-space via a header at the beginning of the user-space blob.
    */
   
   #define kumm_initialize(h,s)     umm_initialize(h,s)
   #define kumm_addregion(h,s)      umm_addregion(h,s)
   
   #define kumm_calloc(n,s)         calloc(n,s);
   #define kumm_malloc(s)           malloc(s)
   #define kumm_malloc_size(p)      malloc_size(p)
   ```
   
   So there are indeed separate prototypes for the kernel to access user space. 
And below the mapping of kernel heap is done to the flat mode combined/shared 
heap, or to a dedicated kernel heap which is required in CONFIG_BUILD_KERNEL.
   
   ```
   /* This family of allocators is used to manage kernel protected memory */
   
   #ifndef CONFIG_MM_KERNEL_HEAP
   /* If this the kernel phase of a kernel build, and there are only user-space
    * allocators, then the following are defined in userspace.h as macros that
    * call into user-space via a header at the beginning of the user-space blob.
    */
   
   #  define kmm_initialize(h,s)    /* Initialization done by kumm_initialize */
   #  define kmm_addregion(h,s)     umm_addregion(h,s)
   
   #  define kmm_calloc(n,s)        calloc(n,s);
   #  define kmm_malloc(s)          malloc(s)
   #  define kmm_malloc_size(p)     malloc_size(p)
   #  define kmm_zalloc(s)          zalloc(s)
   #  define kmm_realloc(p,s)       realloc(p,s)
   #  define kmm_memalign(a,s)      memalign(a,s)
   #  define kmm_free(p)            free(p)
   #  define kmm_mallinfo()         mallinfo()
   
   #else
   /* Otherwise, the kernel-space allocators are declared in
    * include/nuttx/mm/mm.h and we can call them directly.
    */
   
   #endif
   ```
   
   I'm probably missing something, but if sys_callx is the only declaration, 
how do we ensure this does not happen ? It's the same build process for kernel 
and libc, right ?
   
   > Otherwise, the standard allocators prototyped in stdlib.h may be used for 
both the kernel- and user-mode objects.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to