From b185f8d88982e070af76a9683c2cb5543feafb85 Mon Sep 17 00:00:00 2001
From: hujun5 <hujun5@xiaomi.com>
Date: Fri, 4 Aug 2023 11:33:29 +0800
Subject: [PATCH] binfmt: add enter_critical_section

adding enter_critical_section to ensure non preemption in smp
Signed-off-by: hujun5 <hujun5@xiaomi.com>
---
 binfmt/binfmt_exec.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/binfmt/binfmt_exec.c b/binfmt/binfmt_exec.c
index 2d281b6dce..ba1d2f3cb7 100644
--- a/binfmt/binfmt_exec.c
+++ b/binfmt/binfmt_exec.c
@@ -77,6 +77,7 @@ int exec_spawn(FAR const char *filename, FAR char * const *argv,
                FAR const posix_spawnattr_t *attr)
 {
   FAR struct binary_s *bin;
+  irqstate_t flags;
   int pid;
   int ret;
 
@@ -126,6 +127,7 @@ int exec_spawn(FAR const char *filename, FAR char * const *argv,
    * handler.
    */
 
+  flags = enter_critical_section();
   sched_lock();
 
   /* Then start the module */
@@ -160,10 +162,12 @@ int exec_spawn(FAR const char *filename, FAR char * const *argv,
 #endif
 
   sched_unlock();
+  leave_critical_section(flags);
   return pid;
 
 errout_with_lock:
   sched_unlock();
+  leave_critical_section(flags);
   unload_module(bin);
 errout_with_bin:
   kmm_free(bin);