From 8e966546c1509734026811ea10316354d126b491 Mon Sep 17 00:00:00 2001 From: Gregory Nutt <gnutt@nuttx.org> Date: Tue, 3 Oct 2017 07:09:35 -0600 Subject: [PATCH] syscall/: The non-standard interface exec() is now enshrined as a official NuttX API. I really dislike doing this but I think that this is probably the only want to load programs in the protected mode. It is currently used by some example code under apps/ that generate their own symbol tables for linking. Other file execution APIs relay on a symbol table provided by the OS. In the protected mode, the OS cannot provide any meaning symbol table for execution of code in the user-space blob so that is they exec() is really needed in that build case. And, finally, the interface is completely useless and will not be supported in the KERNEL build mode where the contrary is true: An application process cannot provide any meaning symbolic information for use in linking a different process. --- include/sys/syscall.h | 28 +++++++++++++++++++--------- syscall/syscall.csv | 1 + syscall/syscall_lookup.h | 13 +++++++++---- syscall/syscall_stublookup.c | 4 ++-- 4 files changed, 31 insertions(+), 15 deletions(-) diff --git a/include/sys/syscall.h b/include/sys/syscall.h index 81d17e027c..feff102939 100644 --- a/include/sys/syscall.h +++ b/include/sys/syscall.h @@ -183,25 +183,35 @@ # define SYS_insmod __SYS_insmod # define SYS_rmmod (__SYS_insmod+1) # define SYS_modhandle (__SYS_insmod+2) -# define __SYS_posix_spawn (__SYS_insmod+3) +# define __SYS_exec (__SYS_insmod+3) #else -# define __SYS_posix_spawn __SYS_insmod +# define __SYS_exec __SYS_insmod #endif /* The following can only be defined if we are configured to execute * programs from a file system. */ -#if !defined(CONFIG_BINFMT_DISABLE) && defined(CONFIG_LIBC_EXECFUNCS) -# ifdef CONFIG_BINFMT_EXEPATH -# define SYS_posix_spawnp __SYS_posix_spawn +#ifndef CONFIG_BINFMT_DISABLE +# ifndef CONFIG_BUILD_KERNEL +# define SYS_exec __SYS_exec +# define __SYS_posix_spawn (__SYS_exec+1) # else -# define SYS_posix_spawn __SYS_posix_spawn +# define __SYS_posix_spawn __SYS_exec +# endif +# ifdef CONFIG_LIBC_EXECFUNCS +# ifdef CONFIG_BINFMT_EXEPATH +# define SYS_posix_spawnp __SYS_posix_spawn +# else +# define SYS_posix_spawn __SYS_posix_spawn +# endif +# define SYS_execv (__SYS_posix_spawn+1) +# define __SYS_signals (__SYS_posix_spawn+2) +# else +# define __SYS_signals __SYS_posix_spawn # endif -# define SYS_execv (__SYS_posix_spawn+1) -# define __SYS_signals (__SYS_posix_spawn+2) #else -# define __SYS_signals __SYS_posix_spawn +# define __SYS_signals __SYS_exec #endif /* The following are only defined is signals are supported in the NuttX diff --git a/syscall/syscall.csv b/syscall/syscall.csv index bfb950a8eb..b5efe96510 100644 --- a/syscall/syscall.csv +++ b/syscall/syscall.csv @@ -18,6 +18,7 @@ "connect","sys/socket.h","CONFIG_NSOCKET_DESCRIPTORS > 0 && defined(CONFIG_NET)","int","int","FAR const struct sockaddr*","socklen_t" "dup","unistd.h","CONFIG_NFILE_DESCRIPTORS > 0","int","int" "dup2","unistd.h","CONFIG_NFILE_DESCRIPTORS > 0","int","int","int" +"exec","nuttx/binfmt/binfmt.h","!defined(CONFIG_BINFMT_DISABLE) && !defined(CONFIG_BUILD_KERNEL)","int","FAR const char *","FAR char * const *","FAR const struct symtab_s *","int" "execv","unistd.h","!defined(CONFIG_BINFMT_DISABLE) && defined(CONFIG_LIBC_EXECFUNCS)","int","FAR const char *","FAR char *const []|FAR char *const *" "exit","stdlib.h","","void","int" "fcntl","fcntl.h","CONFIG_NFILE_DESCRIPTORS > 0","int","int","int","..." diff --git a/syscall/syscall_lookup.h b/syscall/syscall_lookup.h index 66a3153aa8..d6d7c70a8e 100644 --- a/syscall/syscall_lookup.h +++ b/syscall/syscall_lookup.h @@ -130,14 +130,19 @@ SYSCALL_LOOKUP(up_assert, 2, STUB_up_assert) * programs from a file system. */ -#if !defined(CONFIG_BINFMT_DISABLE) && defined(CONFIG_LIBC_EXECFUNCS) -# ifdef CONFIG_BINFMT_EXEPATH +#ifndef CONFIG_BINFMT_DISABLE +#ifndef CONFIG_BUILD_KERNEL + SYSCALL_LOOKUP(exec, 4, STUB_exec) +#endif +#ifdef CONFIG_LIBC_EXECFUNCS +#ifdef CONFIG_BINFMT_EXEPATH SYSCALL_LOOKUP(posix_spawnp, 6, STUB_posix_spawnp) -# else +#else SYSCALL_LOOKUP(posix_spawn, 6, STUB_posix_spawn) -# endif +#endif SYSCALL_LOOKUP(execv, 2, STUB_execv) #endif +#endif /* The following are only defined is signals are supported in the NuttX * configuration. diff --git a/syscall/syscall_stublookup.c b/syscall/syscall_stublookup.c index 289244e7a8..5cdda6e17d 100644 --- a/syscall/syscall_stublookup.c +++ b/syscall/syscall_stublookup.c @@ -119,16 +119,16 @@ uintptr_t STUB_waitid(int nbr, uintptr_t parm1, uintptr_t parm2, * OS modules from a file system. */ -#ifdef CONFIG_MODULE uintptr_t STUB_insmod(int nbr, uintptr_t parm1, uintptr_t parm2); uintptr_t STUB_rmmod(int nbr, uintptr_t parm1); uintptr_t STUB_modhandle(int nbr, uintptr_t parm1, uintptr_t parm2); -#endif /* The following can only be defined if we are configured to execute * programs from a file system. */ +uintptr_t STUB_exec(int nbr, uintptr_t parm1, uintptr_t parm2, + uintptr_t parm3, uintptr_t parm4); uintptr_t STUB_posix_spawn(int nbr, uintptr_t parm1, uintptr_t parm2, uintptr_t parm3, uintptr_t parm4, uintptr_t parm5, uintptr_t parm6); -- GitLab