This is the mail archive of the ecos-discuss@sourceware.org mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Re: uSTL hello world


>>>>> "Jifl" == Jonathan Larmour <jifl@jifvik.org> writes:

    <snip>
    
    >> Jifl, is there a preferred way to ensure initialisation of the
    >> stdio streams in the file descriptor table? I note that open()
    >> in the file I/O package uses:
    >> 
    >> CYG_REFERENCE_OBJECT(stdin);
    >> CYG_REFERENCE_OBJECT(stdout);
    >> CYG_REFERENCE_OBJECT(stderr);
    >> 
    >> Is this addressing the same issue that we're observing with
    >> uSTL?

    Jifl> I think there's a more fundamental problem, not specific to
    Jifl> uSTL (so I think Uwe's workaround isn't really appropriate).
    Jifl> That is that something like:

    Jifl>    write(STDOUT_FILENO, buf, n);

    Jifl> can't be guaranteed to just work, at present. That's a bug.

    Jifl> I think those CYG_REFERENCE_OBJECT lines (and surrounding
    Jifl> ifdef) need to move out of open() and into cyg_fd_init().
    Jifl> Theoretically cyg_fp_get() would be slightly better, but
    Jifl> that is called a lot, and there is a trivial but non-zero
    Jifl> overhead to CYG_REFERENCE_OBJECT. I'd appreciate Nick's
    Jifl> opinion on this proposal if possible though. It does mean
    Jifl> that including the fileio package at all in a configuration
    Jifl> would then guarantee pulling in stdin/stdout/stderr, even
    Jifl> irrespective of use. Maybe the number of people this would
    Jifl> affect is too small to care about. Maybe there should be a
    Jifl> default-enabled option, to allow it to be turned off to
    Jifl> remove that dependency.

    Jifl> Taking the usual principle of "leave it to the user", I
    Jifl> think I'd personally lean towards the latter.

I think there is another approach which might fit in better with
linker garbage collection. Instead of #define'ing STDOUT_FILENO as 1,
declare it as an extern const char. Then provide the variable
STDOUT_FILENO in some module which causes the necessary initialization
to happen. It is slightly more expensive: a bit of space for the const
variable, an extra memory access for the write() call. However it
would eliminate the need for CYG_REFERENCE_OBJECT's and it would allow
linker garbage collection to work as normal.

Obviously code which uses write(1, buf, n) would still be broken, and
http://www.opengroup.org/onlinepubs/009695399/basedefs/unistd.h.html
requires that STDOUT_FILENO be defined as 1. Hence my proposal would
not be fully standards-compliant.

Bart

-- 
Bart Veer                                   eCos Configuration Architect
eCosCentric Limited    The eCos experts      http://www.ecoscentric.com/
Barnwell House, Barnwell Drive, Cambridge, UK.      Tel: +44 1223 245571
Registered in England and Wales: Reg No 4422071.
 >>>> Visit us at ESC-Boston  http://www.embedded.com/esc/boston <<<<
 >>>> Sep 22-23 on Stand 226  at Hynes Convention Center, Boston <<<<

-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]