mirror of
https://sourceware.org/git/glibc.git
synced 2025-07-30 22:43:12 +03:00
Add __builtin_expect in many places.
This commit is contained in:
@ -57,7 +57,7 @@ _nl_find_locale (const char *locale_path, size_t locale_path_len,
|
|||||||
if ((*name)[0] == '\0'
|
if ((*name)[0] == '\0'
|
||||||
/* In SUID binaries we must not allow people to access files
|
/* In SUID binaries we must not allow people to access files
|
||||||
outside the dedicated locale directories. */
|
outside the dedicated locale directories. */
|
||||||
|| (__libc_enable_secure
|
|| (__builtin_expect (__libc_enable_secure, 0)
|
||||||
&& memchr (*name, '/', _nl_find_language (*name) - *name) != NULL))
|
&& memchr (*name, '/', _nl_find_language (*name) - *name) != NULL))
|
||||||
{
|
{
|
||||||
/* The user decides which locale to use by setting environment
|
/* The user decides which locale to use by setting environment
|
||||||
@ -71,7 +71,8 @@ _nl_find_locale (const char *locale_path, size_t locale_path_len,
|
|||||||
*name = (char *) _nl_C_name;
|
*name = (char *) _nl_C_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcmp (*name, _nl_C_name) == 0 || strcmp (*name, _nl_POSIX_name) == 0)
|
if (__builtin_expect (strcmp (*name, _nl_C_name), 1) == 0
|
||||||
|
|| __builtin_expect (strcmp (*name, _nl_POSIX_name), 1) == 0)
|
||||||
{
|
{
|
||||||
/* We need not load anything. The needed data is contained in
|
/* We need not load anything. The needed data is contained in
|
||||||
the library itself. */
|
the library itself. */
|
||||||
@ -159,10 +160,10 @@ _nl_find_locale (const char *locale_path, size_t locale_path_len,
|
|||||||
successors. */
|
successors. */
|
||||||
locale_file->successor[0] = locale_file->successor[cnt];
|
locale_file->successor[0] = locale_file->successor[cnt];
|
||||||
locale_file = locale_file->successor[cnt];
|
locale_file = locale_file->successor[cnt];
|
||||||
}
|
|
||||||
|
|
||||||
if (locale_file == NULL)
|
if (locale_file == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/* Determine the locale name for which loading succeeded. This
|
/* Determine the locale name for which loading succeeded. This
|
||||||
information comes from the file name. The form is
|
information comes from the file name. The form is
|
||||||
@ -214,7 +215,7 @@ _nl_remove_locale (int locale, struct locale_data *data)
|
|||||||
|
|
||||||
#ifdef _POSIX_MAPPED_FILES
|
#ifdef _POSIX_MAPPED_FILES
|
||||||
/* Really delete the data. First delete the real data. */
|
/* Really delete the data. First delete the real data. */
|
||||||
if (data->mmaped)
|
if (__builtin_expect (data->mmaped, 1))
|
||||||
{
|
{
|
||||||
/* Try to unmap the area. If this fails we mark the area as
|
/* Try to unmap the area. If this fails we mark the area as
|
||||||
permanent. */
|
permanent. */
|
||||||
|
@ -78,13 +78,13 @@ _nl_load_locale (struct loaded_l10nfile *file, int category)
|
|||||||
file->data = NULL;
|
file->data = NULL;
|
||||||
|
|
||||||
fd = __open (file->filename, O_RDONLY);
|
fd = __open (file->filename, O_RDONLY);
|
||||||
if (fd < 0)
|
if (__builtin_expect (fd, 0) < 0)
|
||||||
/* Cannot open the file. */
|
/* Cannot open the file. */
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (__fstat (fd, &st) < 0)
|
if (__builtin_expect (__fstat (fd, &st), 0) < 0)
|
||||||
goto puntfd;
|
goto puntfd;
|
||||||
if (S_ISDIR (st.st_mode))
|
if (__builtin_expect (S_ISDIR (st.st_mode), 0))
|
||||||
{
|
{
|
||||||
/* LOCALE/LC_foo is a directory; open LOCALE/LC_foo/SYS_LC_foo
|
/* LOCALE/LC_foo is a directory; open LOCALE/LC_foo/SYS_LC_foo
|
||||||
instead. */
|
instead. */
|
||||||
@ -102,10 +102,10 @@ _nl_load_locale (struct loaded_l10nfile *file, int category)
|
|||||||
_nl_category_name_sizes[category] + 1);
|
_nl_category_name_sizes[category] + 1);
|
||||||
|
|
||||||
fd = __open (newp, O_RDONLY);
|
fd = __open (newp, O_RDONLY);
|
||||||
if (fd < 0)
|
if (__builtin_expect (fd, 0) < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (__fstat (fd, &st) < 0)
|
if (__builtin_expect (__fstat (fd, &st), 0) < 0)
|
||||||
goto puntfd;
|
goto puntfd;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,15 +126,15 @@ _nl_load_locale (struct loaded_l10nfile *file, int category)
|
|||||||
# endif
|
# endif
|
||||||
filedata = (void *) __mmap ((caddr_t) 0, st.st_size, PROT_READ,
|
filedata = (void *) __mmap ((caddr_t) 0, st.st_size, PROT_READ,
|
||||||
MAP_FILE|MAP_COPY|MAP_INHERIT, fd, 0);
|
MAP_FILE|MAP_COPY|MAP_INHERIT, fd, 0);
|
||||||
if ((void *) filedata != MAP_FAILED)
|
if (__builtin_expect ((void *) filedata != MAP_FAILED, 1))
|
||||||
{
|
{
|
||||||
if (st.st_size < sizeof (*filedata))
|
if (__builtin_expect (st.st_size < sizeof (*filedata), 0))
|
||||||
/* This cannot be a locale data file since it's too small. */
|
/* This cannot be a locale data file since it's too small. */
|
||||||
goto puntfd;
|
goto puntfd;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (errno == ENOSYS)
|
if (__builtin_expect (errno, ENOSYS) == ENOSYS)
|
||||||
{
|
{
|
||||||
#endif /* _POSIX_MAPPED_FILES */
|
#endif /* _POSIX_MAPPED_FILES */
|
||||||
/* No mmap; allocate a buffer and read from the file. */
|
/* No mmap; allocate a buffer and read from the file. */
|
||||||
@ -148,7 +148,7 @@ _nl_load_locale (struct loaded_l10nfile *file, int category)
|
|||||||
while (to_read > 0)
|
while (to_read > 0)
|
||||||
{
|
{
|
||||||
nread = __read (fd, p, to_read);
|
nread = __read (fd, p, to_read);
|
||||||
if (nread <= 0)
|
if (__builtin_expect (nread, 1) <= 0)
|
||||||
{
|
{
|
||||||
free (filedata);
|
free (filedata);
|
||||||
if (nread == 0)
|
if (nread == 0)
|
||||||
@ -169,7 +169,7 @@ _nl_load_locale (struct loaded_l10nfile *file, int category)
|
|||||||
}
|
}
|
||||||
#endif /* _POSIX_MAPPED_FILES */
|
#endif /* _POSIX_MAPPED_FILES */
|
||||||
|
|
||||||
if (filedata->magic != LIMAGIC (category))
|
if (__builtin_expect (filedata->magic != LIMAGIC (category), 0))
|
||||||
/* Bad data file in either byte order. */
|
/* Bad data file in either byte order. */
|
||||||
{
|
{
|
||||||
puntmap:
|
puntmap:
|
||||||
@ -181,9 +181,11 @@ _nl_load_locale (struct loaded_l10nfile *file, int category)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filedata->nstrings < _nl_category_num_items[category] ||
|
if (__builtin_expect (filedata->nstrings < _nl_category_num_items[category],
|
||||||
(sizeof *filedata + filedata->nstrings * sizeof (unsigned int)
|
0)
|
||||||
>= (size_t) st.st_size))
|
|| (__builtin_expect (sizeof *filedata
|
||||||
|
+ filedata->nstrings * sizeof (unsigned int)
|
||||||
|
>= (size_t) st.st_size, 0)))
|
||||||
{
|
{
|
||||||
/* Insufficient data. */
|
/* Insufficient data. */
|
||||||
__set_errno (EINVAL);
|
__set_errno (EINVAL);
|
||||||
@ -192,7 +194,7 @@ _nl_load_locale (struct loaded_l10nfile *file, int category)
|
|||||||
|
|
||||||
newdata = malloc (sizeof *newdata
|
newdata = malloc (sizeof *newdata
|
||||||
+ filedata->nstrings * sizeof (union locale_data_value));
|
+ filedata->nstrings * sizeof (union locale_data_value));
|
||||||
if (! newdata)
|
if (newdata == NULL)
|
||||||
goto puntmap;
|
goto puntmap;
|
||||||
|
|
||||||
newdata->name = NULL; /* This will be filled if necessary in findlocale.c. */
|
newdata->name = NULL; /* This will be filled if necessary in findlocale.c. */
|
||||||
@ -204,13 +206,13 @@ _nl_load_locale (struct loaded_l10nfile *file, int category)
|
|||||||
for (cnt = 0; cnt < newdata->nstrings; ++cnt)
|
for (cnt = 0; cnt < newdata->nstrings; ++cnt)
|
||||||
{
|
{
|
||||||
off_t idx = filedata->strindex[cnt];
|
off_t idx = filedata->strindex[cnt];
|
||||||
if (idx > newdata->filesize)
|
if (__builtin_expect (idx > newdata->filesize, 0))
|
||||||
{
|
{
|
||||||
free (newdata);
|
free (newdata);
|
||||||
__set_errno (EINVAL);
|
__set_errno (EINVAL);
|
||||||
goto puntmap;
|
goto puntmap;
|
||||||
}
|
}
|
||||||
if (_nl_value_types[category][cnt] == word)
|
if (__builtin_expect (_nl_value_types[category][cnt] == word, 0))
|
||||||
newdata->values[cnt].word = *((u_int32_t *) (newdata->filedata + idx));
|
newdata->values[cnt].word = *((u_int32_t *) (newdata->filedata + idx));
|
||||||
else
|
else
|
||||||
newdata->values[cnt].string = newdata->filedata + idx;
|
newdata->values[cnt].string = newdata->filedata + idx;
|
||||||
@ -224,7 +226,7 @@ void
|
|||||||
_nl_unload_locale (struct locale_data *locale)
|
_nl_unload_locale (struct locale_data *locale)
|
||||||
{
|
{
|
||||||
#ifdef _POSIX_MAPPED_FILES
|
#ifdef _POSIX_MAPPED_FILES
|
||||||
if (locale->mmaped)
|
if (__builtin_expect (locale->mmaped, 1))
|
||||||
__munmap ((caddr_t) locale->filedata, locale->filesize);
|
__munmap ((caddr_t) locale->filedata, locale->filesize);
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user