Keil™, An ARM® Company

RealView Libraries and Floating Point Support Guide

On-Line Manuals

RealView Libraries and Floating Point Support Guide

Preface
Introduction
The C and C++ Libraries
About the C and C++ libraries
Features of the C and C++ libraries
Namespaces
Writing reentrant and thread‑safe code
Introduction to reentrancy and thread‑safety
Use of static data in the C libraries
The __user_libspace static data area
Managing locks in multithreaded applications
Using the ARM C libraries with a multithreaded app
Thread‑safety in the ARM C libraries
Thread‑safety in the ARM C++ libraries
Building an application with the C library
Using the libraries with an application
Building an application for a semihosted environme
Building an application for a non semihosting envi
Building an application without the C library
Integer and FP helper functions
Bare machine integer C
Bare machine C with floating‑point
Exploiting the C library
The standalone C library functions
Tailoring the C library to a new execution environ
How C and C++ programs use the library functions
__rt_entry
Exiting from the program
__rt_exit()
__rt_lib_init()
__rt_lib_shutdown()
Tailoring static data access
Tailoring locale and CTYPE using assembler macros
Selecting locale at link time
Selecting locale at runtime
Defining a locale block
LC_CTYPE data block
LC_COLLATE data block
LC_MONETARY data block
LC_NUMERIC data block
LC_TIME data block
_get_lconv()
localeconv()
setlocale()
_findlocale()
The lconv structure
Tailoring locale and CTYPE using C macros
Selecting locale at link time
Selecting locale at runtime
Macros and utility functions
_get_lc_ctype()
_get_lc_collate()
_get_lc_monetary()
_get_lc_numeric()
_get_lc_time()
_get_lconv()
localeconv()
setlocale()
_findlocale()
__LC_CTYPE_DEF
__LC_COLLATE_DEF
__LC_TIME_DEF
__LC_NUMERIC_DEF
__LC_MONETARY_DEF
__LC_INDEX_END
The lconv structure
Tailoring error signaling, error handling, and pro
_sys_exit()
errno
__rt_errno_addr()
__raise()
__rt_raise()
__default_signal_handler()
_ttywrch()
__rt_fp_status_addr()
Tailoring storage management
Avoiding the ARM‑supplied heap and heap‑using
Support for malloc
Tailoring the runtime memory model
The memory models
Controlling the runtime memory model
Writing your own memory model
__user_initial_stackheap()
__user_setup_stackheap()
__user_heap_extend()
__user_heap_extent()
__user_stack_cleanup_space()
__rt_heap_extend()
__rt_stack_postlongjmp()
Tailoring the input/output functions
Dependencies on low‑level functions
Target‑dependent input/output support functions
_sys_open()
_sys_close()
_sys_read()
_sys_write()
_sys_ensure()
_sys_flen()
_sys_seek()
_sys_istty()
_sys_tmpnam()
_sys_command_string()
#pragma import(_main_redirection)
Tailoring other C library functions
clock()
_clock_init()
time()
remove()
rename()
system()
getenv()
_getenv_init()
Selecting real‑time division
ISO implementation definition
ISO C library implementation definition
Standard C++ library implementation definition
C library extensions
atoll()
strtoll()
strtoull()
printf()
snprintf()
vsnprintf()
lldiv()
llabs()
wcstombs()
alloca()
strlcpy()
strlcat()
_fisatty()
__heapstats()
__heapvalid()
Library naming conventions
Placing ARM libraries
Helper libraries
Identifying library variants
The C Micro-library
Floating‑point Support

Using the ARM C libraries with a multithreaded application

2.2.5. Using the ARM C libraries with a multithreaded application

In order to use the ARM library in a multithreaded environment, you must provide:

  • An implementation of __user_perthread_libspace() that returns a different block of memory for each thread. This can be achieved by either:

    • returning a different address depending on the thread it is called from

    • having a single __user_perthread_libspace block at a fixed address and swapping its contents when switching threads.

    You can use either approach to suit your environment.

    You do not have to re‑implement __user_perproc_libspace unless there is a specific reason to do so. In the majority of cases, there is no requirement to re‑implement this function.

  • Implementations of the three mutex functions (see Managing locks in multithreaded applications).

    In some applications these functions might not do anything useful. For example, a co‑operatively threaded program does not have to take any steps to ensure data integrity, provided it avoids calling its yield function during a critical section. However, in other types of application, for example where you are implementing pre‑emptive threading or in a Symmetric Multi‑Processor (SMP) model, these functions play an important part in handling locks.

  • A way to manage multiple stacks.

    A simple way to do this is to use the ARM two‑region memory model (see The memory models). Using this means that you keep the stack that belongs to the primary thread entirely separate from the heap. Then you must allocate further memory for additional stacks from the heap itself.

  • Thread management functions, for example, to create or destroy threads, to handle thread synchronization, and to retrieve exit codes.

    Note

    The ARM C libraries supply no thread management functions of their own and so you must supply any that are required.

  • A thread‑switching mechanism.

    Note

    The ARM C libraries supply no thread‑switching mechanisms of their own. This is because there are many different ways to do this and the libraries are designed to work with all of them.

If these requirements have been met, you can use the ARM C libraries in your multithreaded environment. Here:

  • some functions work independently in each thread

  • some functions automatically use the mutex functions to mediate multiple accesses to a shared resource

  • some functions are still non reentrant and so a reentrant equivalent is supplied

  • a few functions remain non reentrant and no alternative is available.

See Thread‑safety in the ARM C libraries and Thread‑safety in the ARM C++ libraries for more information.

Copyright © 2007 ARM Limited. All rights reserved.ARM DUI 0378A