⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 libc-implementation-details.html

📁 有关ecos2。0介绍了实时嵌入式的结构以及线程调度的实现和内存的管理等
💻 HTML
字号:
<!-- Copyright (C) 2003 Red Hat, Inc.                                --><!-- This material may be distributed only subject to the terms      --><!-- and conditions set forth in the Open Publication License, v1.0  --><!-- or later (the latest version is presently available at          --><!-- http://www.opencontent.org/openpub/).                           --><!-- Distribution of the work or derivative of the work in any       --><!-- standard (paper) book form is prohibited unless prior           --><!-- permission is obtained from the copyright holder.               --><HTML><HEAD><TITLE>Some implementation details</TITLE><meta name="MSSmartTagsPreventParsing" content="TRUE"><METANAME="GENERATOR"CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+"><LINKREL="HOME"TITLE="eCos Reference Manual"HREF="ecos-ref.html"><LINKREL="UP"TITLE="C and math library overview"HREF="c-and-math-library-overview.html"><LINKREL="PREVIOUS"TITLE="Math library compatibility modes"HREF="math-library-compatibility-modes.html"><LINKREL="NEXT"TITLE="Thread safety"HREF="libc-thread-safety.html"></HEAD><BODYCLASS="SECT1"BGCOLOR="#FFFFFF"TEXT="#000000"LINK="#0000FF"VLINK="#840084"ALINK="#0000FF"><DIVCLASS="NAVHEADER"><TABLESUMMARY="Header navigation table"WIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><THCOLSPAN="3"ALIGN="center">eCos Reference Manual</TH></TR><TR><TDWIDTH="10%"ALIGN="left"VALIGN="bottom"><AHREF="math-library-compatibility-modes.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom">Chapter 13. C and math library overview</TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="libc-thread-safety.html"ACCESSKEY="N">Next</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><DIVCLASS="SECT1"><H1CLASS="SECT1"><ANAME="LIBC-IMPLEMENTATION-DETAILS">Some implementation details</H1><P>Here are some details about the implementationwhich might be interesting, although they do not affect the ISO-definedsemantics of the library. </P><P></P><UL><LI><P>It is possible to configure <SPANCLASS="emphasis"><ICLASS="EMPHASIS">eCos</I></SPAN> to have the standard C library without the kernel. You might wantto do this to use less memory. But if you disable the kernel, youwill be unable to use memory allocation, thread-safety and certainstdio functions such as input. Other C library functionality isunaffected.</P></LI><LI><P>The opaque type returned by <TTCLASS="FUNCTION">clock()</TT> is called clock_t, and is implemented as a 64 bit integer.The value returned by <TTCLASS="FUNCTION">clock()</TT> is only correct if the kernel is configured with real-time clocksupport, as determined by the CYGVAR_KERNEL_COUNTERS_CLOCKconfiguration option in <TTCLASS="FILENAME">kernel.h</TT>.</P></LI><LI><P>The FILE type is not implemented as a structure, but ratheras a CYG_ADDRESS. </P></LI><LI><P>The GNU C compiler will place its own <SPANCLASS="emphasis"><ICLASS="EMPHASIS">built-in</I></SPAN> implementationsinstead of some C library functions. This can be turned off withthe <SPANCLASS="emphasis"><ICLASS="EMPHASIS">-fno-builtin</I></SPAN> option. The functions affectedby this are <TTCLASS="FUNCTION">abs()</TT>, <TTCLASS="FUNCTION">cos()</TT>, <TTCLASS="FUNCTION">fabs()</TT>, <TTCLASS="FUNCTION">labs()</TT>, <TTCLASS="FUNCTION">memcmp()</TT>, <TTCLASS="FUNCTION">memcpy()</TT>, <TTCLASS="FUNCTION">sin()</TT>, <TTCLASS="FUNCTION">sqrt()</TT>, <TTCLASS="FUNCTION">strcmp()</TT>, <TTCLASS="FUNCTION">strcpy()</TT>, and <TTCLASS="FUNCTION">strlen()</TT>.</P></LI><LI><P>For faster execution speed you should avoid this optionand let the compiler use its built-ins. This can be turned off byinvoking <SPANCLASS="emphasis"><ICLASS="EMPHASIS">GCC</I></SPAN> with the <SPANCLASS="emphasis"><ICLASS="EMPHASIS">-fno-builtin</I></SPAN> option. </P></LI><LI><P><TTCLASS="FUNCTION">memcpy()</TT> and <TTCLASS="FUNCTION">memset()</TT> are located in the infrastructure package, not in the C librarypackage. This is because the compiler calls these functions, andthe kernel needs to resolve them even if the C library is not configured. </P></LI><LI><P>Error codes such as EDOM and ERANGE, as well as <TTCLASS="FUNCTION">strerror()</TT>, are implemented in the <SPANCLASS="emphasis"><ICLASS="EMPHASIS">error</I></SPAN> package. Theerror package is separate from the rest of the C and math librariesso that the rest of <SPANCLASS="emphasis"><ICLASS="EMPHASIS">eCos</I></SPAN> can use these error handling facilities even if the C library isnot configured. </P></LI><LI><P>When <TTCLASS="FUNCTION">free()</TT> is invoked, heap memory will normally be coalesced. If the CYGSEM_KERNEL_MEMORY_COALESCEconfiguration parameter is not set, memory will not be coalesced,which might cause programs to fail. </P></LI><LI><P>Signals, as implemented by <TTCLASS="FILENAME">&lt;signal.h&gt;</TT>, are guaranteed to workcorrectly if raised using the<TTCLASS="FUNCTION">raise()</TT> function from a normal working program context. Using signals fromwithin an ISR or DSR context is not expected to work. Also, it isnot guaranteed that if CYGSEM_LIBC_SIGNALS_HWEXCEPTIONSis set, that handling a signal using <TTCLASS="FUNCTION">signal()</TT> will necessarily catch that form of exception. For example, itmay be expected that a divide-by-zero error would be caught by handling <TTCLASS="VARNAME">SIGFPE</TT>. However it depends on the underlying HAL implementation to implementthe required hardware exception. And indeed the hardware itselfmay not be capable of detecting these exceptions so it may not bepossible for the HAL implementer to do this in any case. Despitethis lack of guarantees in this respect, the signals implementationis still ISO C compliant since ISO C does not offer any such guaranteeseither. </P></LI><LI><P>The <TTCLASS="FUNCTION">getenv()</TT> function is implemented (unless the CYGPKG_LIBC_ENVIRONMENT configurationoption is turned off), but there is no shell or <TTCLASS="FUNCTION">putenv()</TT> function to set the environment dynamically. The environment isset in a global variable environ, declared as:</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">extern char **environ; // Standard environment definition</PRE></TD></TR></TABLE><P>The environment can be statically initialized at startup timeusing the CYGDAT_LIBC_DEFAULT_ENVIRONMENToption. If so, remember that the final entry of the array initializermust be NULL. </P></LI></UL><P>Here is a minimal <SPANCLASS="emphasis"><ICLASS="EMPHASIS">eCos</I></SPAN> program whichdemonstrates the use of environments (see also the test case in <TTCLASS="FILENAME">language/c/libc/current/tests/stdlib/getenv.c</TT>): </P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">#include &lt;stdio.h&gt;#include &lt;stdlib.h&gt; // Main header for stdlib functionsextern char **environ; // Standard environment definitionintmain( int argc, char *argv[] ){ char *str; char *env[] = { "PATH=/usr/local/bin:/usr/bin", "HOME=/home/fred", "TEST=1234=5678", "home=hatstand", NULL }; printf("Display the current PATH environment variable\n"); environ = (char **)&amp;env; str = getenv("PATH"); if (str==NULL) {  printf("The current PATH is unset\n"); } else {  printf("The current PATH is \"%s\"\n", str); } return 0;} </PRE></TD></TR></TABLE></DIV><DIVCLASS="NAVFOOTER"><HRALIGN="LEFT"WIDTH="100%"><TABLESUMMARY="Footer navigation table"WIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top"><AHREF="math-library-compatibility-modes.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="ecos-ref.html"ACCESSKEY="H">Home</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top"><AHREF="libc-thread-safety.html"ACCESSKEY="N">Next</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">Math library compatibility modes</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="c-and-math-library-overview.html"ACCESSKEY="U">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">Thread safety</TD></TR></TABLE></DIV></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -