Correct ctype(3) functions with NLS on NetBSD
Needs ReviewPublic

Authored by krytarowski on Fri, Jan 12, 4:39 PM.

Details

Summary

The setlocale(3) function reloads the ctype(3) arrays from
external files. This happens behind the scenes in the internals
of libc (citrus library, runes functions etc).

ctype(3) functions like isspace(3) can be provided with two
variations on NetBSD: inlined or via a global symbol in libc:

#if defined(_NETBSD_SOURCE) && !defined(_CTYPE_NOINLINE) && \
    !defined(__cplusplus)
#include <sys/ctype_inline.h>
#else
#include <sys/ctype_bits.h>
#endif

The in-lined versions are de-facto array lookup operations.

#define isspace(c)      ((int)((_ctype_tab_ + 1)[(c)] & _CTYPE_S))

After setting setlocale(3) the ctype(3) arrays (_ctype_tab_,
_toupper_tab_, _tolower_tab_) are reload behind the scenes
and they are required to be marked as initialized.

Set them initialized inside the common setlocale(3) interceptor.

The arrays are of size of 257 elements: 0..255 + 1 (EOF).

This corrects errors on NetBSD/amd64 in applications
prebuilt with MSan.

Sponsored by <The NetBSD Foundation>

Diff Detail

Repository
rL LLVM
krytarowski created this revision.Fri, Jan 12, 4:39 PM
krytarowski edited the summary of this revision. (Show Details)Fri, Jan 12, 4:40 PM
krytarowski edited the summary of this revision. (Show Details)