On Wed, Mar 24, 2021 at 2:08 PM Xiang Xiao <xiaoxiang781...@gmail.com>
wrote:

> On Wed, Mar 24, 2021 at 9:18 AM Matias N. <mat...@imap.cc> wrote:
>
> >
> > > > - devise a mechanism to mimic what would be done by OS in KERNEL mode
> > (add
> >
> > > some custom handler to APIs internally using globals, such as getopt,
> > that can be
> >
> > > called either manually by user or by the OS itself when the task is
> > started?)
>
>
> The custom handler isn't enough here, because the real problem is we need
> the global variables per task/process.
> As Greg suggests, we need something like TLS but per task/process not per
> thread(e.g. task_getspecific/task_setspecific).
> Once the mechanism is done, getopt can be converted to confirm the standard
> trivally.
>

I was looking at this exact issue last week (see comment in
https://github.com/apache/incubator-nuttx/pull/3054).

The basis for this mechanism exists in the way errno is handled. Perhaps a
structure defined for all libc globals added to TLS and a call from the
task creation code to initialise it?


> >
> > > - other?
>
> The transparent/standard solution is switched to the ELF binary(note: it
> doesn't depend on KERNEL mode), and then loses the XIP benefit(huge memory
> penalty). But, it's doable to XIP again by combining ELF loader and ROMFS.
>

Switching to ELF doesn't necessarily help - I encountered the problem
loading nsh as an ELF binary in a FLAT built. The globals optarg and optind
aren't in libc.csv. They'll be picked up and included in symtab_apps, but
those symbols will simply point to the (system) global variables, not a
per-task variable.

  Byron

Reply via email to