On 5/30/2020 9:22 AM, Gregory Nutt wrote:
On 5/30/2020 3:44 AM, Xiang Xiao wrote:
It seems that the version inside sched/task/task_spawn.c need become
a static function.
I think that the version of task_spawn in lib/libc/spawn need to exist
only if CONFIG_LIB_SYSCALL is selected. In that case, the one in
sched/task/task_spawn.c should be static (really doesn't matter in
that case because they are build into separate blobs).
The version of task_spawn.c in libs/libc/spawn simply marshals the
parameters into a structure and calls nx_task_spawn(). If
CONFIG_LIB_SYSCALL is defined then nx_task_spawn() will un-marshal the
data can call the really task spawn. This nonsense is only necessary
because task_spawn has 8 parameters and the maximum number of
parameters in a system call is only 6.
Without syscalls: Application should call directly in task_spawn() in
sched/task/task_spawn.c
With syscalls: Application should call the marshalling task_spawn()
in libs/libc/spawn/lib_task_spawn.c -> That will call the
autogenerated nx_task_spawn() proxy -> And generate a system call ->
The system call will the unmarshalling nx_task_spawn() in
sched/task/task_spawn.c -> Which will, finally, call the real
task_spawn().
I will add that condition logic via a PR.
Greg
Update:
No changes are required in libs/libc/spawn because the conditional logic
is already in place. in Make.defs:
ifneq ($(CONFIG_BUILD_KERNEL),y)
CSRCS += lib_psa_getstacksize.c lib_psa_setstacksize.c
ifeq ($(CONFIG_LIB_SYSCALL),y)
CSRCS += lib_task_spawn.c
endif
endif
In libs/libc/spawn/task_spawn.c:
#if defined(CONFIG_LIB_SYSCALL) && !defined(CONFIG_BUILD_KERNEL)
Similarly in sched/task/task_spawn.c:
#ifdef CONFIG_LIB_SYSCALL
int nx_task_spawn(FAR const struct spawn_syscall_parms_s *parms)
{
...
}
#endif
Any static should be conditioned on CONFIG_LIB_SYSCALL for the
task_spawn() version in sched/task/task_spawn.c, however, that is not
really necessary either because that version is not linked into the same
binary as is the version in libs/libc/spawn.
I suppose a user could enable CONFIG_LIB_SYSCALL in a FLAT build. Then
both would be linked into the same blob, but that is kind of a useless
configuration.
The side-effect of making task_spawn() static is that it then cannot be
used within the OS. But as far as I can tell, nothing in the OS itself
currently uses task_spawn() so I think it is safe to make it
conditionally static. But that only protects from duplicate symbols in
the useless case mentioned above.
Greg