am 70d37e34: am ca045a19: Merge "Switch to upstream sleep(3) and usleep(3)."

* commit '70d37e343aa0c8c771e01259377c98958fbfd3ee':
  Switch to upstream sleep(3) and usleep(3).
This commit is contained in:
Elliott Hughes 2013-11-21 17:15:03 -08:00 committed by Android Git Automerger
commit a38dcc0210
11 changed files with 180 additions and 123 deletions

View File

@ -121,7 +121,6 @@ libc_common_src_files := \
bionic/siglist.c \
bionic/signame.c \
bionic/sigsetmask.c \
bionic/sleep.c \
bionic/strndup.c \
bionic/strntoimax.c \
bionic/strntoumax.c \
@ -133,7 +132,6 @@ libc_common_src_files := \
bionic/time64.c \
bionic/umount.c \
bionic/unlockpt.c \
bionic/usleep.c \
bionic/utmp.c \
bionic/wcscoll.c \
@ -311,6 +309,8 @@ libc_tzcode_src_files := \
tzcode/strptime.c \
libc_upstream_freebsd_src_files := \
upstream-freebsd/lib/libc/gen/sleep.c \
upstream-freebsd/lib/libc/gen/usleep.c \
upstream-freebsd/lib/libc/stdio/clrerr.c \
upstream-freebsd/lib/libc/stdio/fclose.c \
upstream-freebsd/lib/libc/stdio/fdopen.c \

View File

@ -1,52 +0,0 @@
/*
* Copyright (C) 2008 The Android Open Source Project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <time.h>
#include <errno.h>
unsigned int sleep(unsigned int seconds)
{
struct timespec t;
/* seconds is unsigned, while t.tv_sec is signed
* some people want to do sleep(UINT_MAX), so fake
* support for it by only sleeping 2 billion seconds
*/
if ((int)seconds < 0)
seconds = 0x7fffffff;
t.tv_sec = seconds;
t.tv_nsec = 0;
if ( !nanosleep( &t, &t ) )
return 0;
if ( errno == EINTR )
return t.tv_sec;
return -1;
}

View File

@ -1,55 +0,0 @@
/*
* Copyright (C) 2008 The Android Open Source Project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <time.h>
#include <errno.h>
int usleep(unsigned long usec)
{
struct timespec ts;
ts.tv_sec = usec/1000000UL;
#ifdef __arm__
/* avoid divisions and modulos on the ARM */
ts.tv_nsec = (usec - ts.tv_sec*1000000UL)*1000;
#else
ts.tv_nsec = (usec % 1000000UL) * 1000UL;
#endif
for (;;)
{
if ( nanosleep( &ts, &ts ) == 0 )
return 0;
// We try again if the nanosleep failure is EINTR.
// The other possible failures are EINVAL (which we should pass through),
// and ENOSYS, which doesn't happen.
if ( errno != EINTR )
return -1;
}
}

View File

@ -550,11 +550,4 @@
#endif
#define __BIONIC_FORTIFY_UNKNOWN_SIZE ((size_t) -1)
/* Android-added: for FreeBSD's libm. */
#define __weak_reference(sym,alias) \
__asm__(".weak " #alias); \
__asm__(".equ " #alias ", " #sym)
#define __strong_reference(sym,aliassym) \
extern __typeof (sym) aliassym __attribute__ ((__alias__ (#sym)))
#endif /* !_SYS_CDEFS_H_ */

View File

@ -55,6 +55,7 @@ typedef __kernel_dev_t dev_t;
typedef __kernel_fsblkcnt_t fsblkcnt_t;
typedef __kernel_fsfilcnt_t fsfilcnt_t;
typedef __kernel_gid32_t gid_t;
typedef __kernel_uid32_t uid_t;
typedef __kernel_id_t id_t;
typedef __kernel_ino_t ino_t;
typedef __kernel_key_t key_t;
@ -94,10 +95,10 @@ typedef .... pthread_t;
typedef __kernel_ssize_t ssize_t;
#endif
typedef __kernel_suseconds_t suseconds_t;
typedef __kernel_time_t time_t;
typedef __kernel_uid32_t uid_t;
typedef signed long useconds_t;
typedef __kernel_time_t time_t;
typedef __kernel_suseconds_t suseconds_t;
typedef unsigned long useconds_t;
typedef __kernel_daddr_t daddr_t;
typedef __kernel_timer_t timer_t;

View File

@ -159,7 +159,7 @@ extern int ftruncate64(int, off64_t);
extern int pause(void);
extern unsigned int alarm(unsigned int);
extern unsigned int sleep(unsigned int);
extern int usleep(unsigned long);
extern int usleep(useconds_t);
extern int gethostname(char *, size_t);

View File

@ -20,11 +20,31 @@
#define __USE_BSD
#define REPLACE_GETOPT
/*
* FreeBSD's libc has three symbols for every symbol:
*
* __f will be the actual implementation.
* _f will be a weak reference to __f (used for calls to f from within the library).
* f will be a weak reference to __f (used for calls to f from outside the library).
*
* We collapse this into just the one symbol, f.
*/
/* Prevent weak reference generation. */
#define __weak_reference(sym,alias)
/* Ensure that the implementation itself gets the underscore-free name. */
#define __sleep sleep
#define __usleep usleep
/* Redirect internal C library calls to the public function. */
#define _close close
#define _fcntl fcntl
#define _fstat fstat
#define _nanosleep nanosleep
#define _open open
#define _sseek __sseek /* Needed as long as we have a mix of OpenBSD and FreeBSD stdio. */
/* This one is only needed as long as we have a mix of OpenBSD and FreeBSD stdio. */
#define _sseek __sseek
#endif

View File

@ -0,0 +1,67 @@
/*
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)sleep.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include "namespace.h"
#include <errno.h>
#include <limits.h>
#include <time.h>
#include <unistd.h>
#include "un-namespace.h"
unsigned int
__sleep(unsigned int seconds)
{
struct timespec time_to_sleep;
struct timespec time_remaining;
/*
* Avoid overflow when `seconds' is huge. This assumes that
* the maximum value for a time_t is >= INT_MAX.
*/
if (seconds > INT_MAX)
return (seconds - INT_MAX + __sleep(INT_MAX));
time_to_sleep.tv_sec = seconds;
time_to_sleep.tv_nsec = 0;
if (_nanosleep(&time_to_sleep, &time_remaining) != -1)
return (0);
if (errno != EINTR)
return (seconds); /* best guess */
return (time_remaining.tv_sec +
(time_remaining.tv_nsec != 0)); /* round up */
}
__weak_reference(__sleep, sleep);
__weak_reference(__sleep, _sleep);

View File

@ -0,0 +1,52 @@
/*
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)usleep.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include "namespace.h"
#include <time.h>
#include <unistd.h>
#include "un-namespace.h"
int
__usleep(useconds_t useconds)
{
struct timespec time_to_sleep;
time_to_sleep.tv_nsec = (useconds % 1000000) * 1000;
time_to_sleep.tv_sec = useconds / 1000000;
return (_nanosleep(&time_to_sleep, NULL));
}
__weak_reference(__usleep, usleep);
__weak_reference(__usleep, _usleep);

View File

@ -217,7 +217,11 @@ libm_common_src_files += fake_long_double.c
# TODO: re-enable i387/e_sqrtf.S for x86, and maybe others.
libm_common_cflags := -DFLT_EVAL_METHOD=0 -std=c99
libm_common_cflags := \
-DFLT_EVAL_METHOD=0 \
-std=c99 \
-include $(LOCAL_PATH)/freebsd-compat.h \
libm_common_includes := $(LOCAL_PATH)/upstream-freebsd/lib/msun/src/
libm_arm_includes := $(LOCAL_PATH)/arm

27
libm/freebsd-compat.h Normal file
View File

@ -0,0 +1,27 @@
/*
* Copyright (C) 2013 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _BIONIC_LIBM_FREEBSD_COMPAT_H_included
#define _BIONIC_LIBM_FREEBSD_COMPAT_H_included
#define __weak_reference(sym,alias) \
__asm__(".weak " #alias); \
__asm__(".equ " #alias ", " #sym)
#define __strong_reference(sym,aliassym) \
extern __typeof (sym) aliassym __attribute__ ((__alias__ (#sym)))
#endif