From 3d4edfc5992b7b2b581ad94eb9d79e93cd0c6895 Mon Sep 17 00:00:00 2001 From: David 'Digit' Turner Date: Fri, 19 Mar 2010 16:01:28 -0700 Subject: [PATCH 01/93] Update libthread_db for gdb-7.0 Change-Id: If8fbcea1cf6d06fc465a22d73671e6ff6aa1f312 --- libthread_db/include/thread_db.h | 23 +++++++++++- libthread_db/libthread_db.c | 61 ++++++++++++++++++++++++++------ 2 files changed, 73 insertions(+), 11 deletions(-) diff --git a/libthread_db/include/thread_db.h b/libthread_db/include/thread_db.h index 9c76d40d6..1b36cb2b4 100644 --- a/libthread_db/include/thread_db.h +++ b/libthread_db/include/thread_db.h @@ -10,6 +10,8 @@ #include #include +typedef void *psaddr_t; +typedef pid_t lwpid_t; #define TD_THR_ANY_USER_FLAGS 0xffffffff #define TD_THR_LOWEST_PRIORITY -20 @@ -67,6 +69,7 @@ typedef pthread_t thread_t; typedef struct { pid_t pid; + struct ps_prochandle *ph; } td_thragent_t; typedef struct @@ -123,19 +126,37 @@ struct ps_prochandle; extern "C"{ #endif -extern td_err_e td_ta_new(struct ps_prochandle const * proc_handle, td_thragent_t ** thread_agent); +extern td_err_e td_ta_new(struct ps_prochandle * proc_handle, td_thragent_t ** thread_agent); + +extern td_err_e td_ta_delete(td_thragent_t * ta); extern td_err_e td_ta_set_event(td_thragent_t const * agent, td_thr_events_t * event); extern td_err_e td_ta_event_addr(td_thragent_t const * agent, td_event_e event, td_notify_t * notify); +extern td_err_e td_ta_clear_event(const td_thragent_t * ta_arg, + td_thr_events_t * event); + extern td_err_e td_ta_event_getmsg(td_thragent_t const * agent, td_event_msg_t * event); +extern td_err_e td_ta_map_lwp2thr(td_thragent_t const * agent, lwpid_t lwpid, + td_thrhandle_t *th); + +extern td_err_e td_thr_get_info(td_thrhandle_t const * handle, + td_thrinfo_t * info); + +extern td_err_e td_thr_event_enable(td_thrhandle_t const * handle, + td_event_e event); + extern td_err_e td_ta_thr_iter(td_thragent_t const * agent, td_thr_iter_f * func, void * cookie, td_thr_state_e state, int32_t prio, sigset_t * sigmask, uint32_t user_flags); extern char const ** td_symbol_list(void); +extern td_err_e td_thr_tls_get_addr(const td_thrhandle_t * th, + psaddr_t map_address, size_t offset, + psaddr_t * address); + #ifdef __cplusplus } #endif diff --git a/libthread_db/libthread_db.c b/libthread_db/libthread_db.c index f1a78ac68..2cf4d3856 100644 --- a/libthread_db/libthread_db.c +++ b/libthread_db/libthread_db.c @@ -10,12 +10,7 @@ #include extern int ps_pglobal_lookup (void *, const char *obj, const char *name, void **sym_addr); - -struct ps_prochandle -{ - pid_t pid; -}; - +extern pid_t ps_getpid(struct ps_prochandle *ph); /* * This is the list of "special" symbols we care about whose addresses are @@ -41,7 +36,7 @@ td_symbol_list(void) td_err_e -td_ta_new(struct ps_prochandle const * proc_handle, td_thragent_t ** agent_out) +td_ta_new(struct ps_prochandle * proc_handle, td_thragent_t ** agent_out) { td_thragent_t * agent; @@ -50,13 +45,25 @@ td_ta_new(struct ps_prochandle const * proc_handle, td_thragent_t ** agent_out) return TD_MALLOC; } - agent->pid = proc_handle->pid; + agent->pid = ps_getpid(proc_handle); + agent->ph = proc_handle; *agent_out = agent; return TD_OK; } +td_err_e +td_ta_delete(td_thragent_t * ta) +{ + free(ta); + // FIXME: anything else to do? + return TD_OK; +} + + +/* NOTE: not used by gdb 7.0 */ + td_err_e td_ta_set_event(td_thragent_t const * agent, td_thr_events_t * events) { @@ -64,8 +71,11 @@ td_ta_set_event(td_thragent_t const * agent, td_thr_events_t * events) } +/* NOTE: not used by gdb 7.0 */ static td_thrhandle_t gEventMsgHandle; +/* NOTE: not used by gdb 7.0 */ + static int _event_getmsg_helper(td_thrhandle_t const * handle, void * bkpt_addr) { @@ -83,6 +93,8 @@ _event_getmsg_helper(td_thrhandle_t const * handle, void * bkpt_addr) return 0; } +/* NOTE: not used by gdb 7.0 */ + td_err_e td_ta_event_getmsg(td_thragent_t const * agent, td_event_msg_t * event) { @@ -106,6 +118,16 @@ td_ta_event_getmsg(td_thragent_t const * agent, td_event_msg_t * event) } +td_err_e +td_ta_map_lwp2thr(td_thragent_t const * agent, lwpid_t lwpid, + td_thrhandle_t *th) +{ + th->pid = ps_getpid(agent->ph); + th->tid = lwpid; + return TD_OK; +} + + td_err_e td_thr_get_info(td_thrhandle_t const * handle, td_thrinfo_t * info) { @@ -117,6 +139,8 @@ td_thr_get_info(td_thrhandle_t const * handle, td_thrinfo_t * info) } +/* NOTE: not used by gdb 7.0 */ + td_err_e td_thr_event_enable(td_thrhandle_t const * handle, td_event_e event) { @@ -125,6 +149,8 @@ td_thr_event_enable(td_thrhandle_t const * handle, td_event_e event) } +/* NOTE: not used by gdb 7.0 */ + td_err_e td_ta_event_addr(td_thragent_t const * agent, td_event_e event, td_notify_t * notify_out) { @@ -148,6 +174,15 @@ td_ta_event_addr(td_thragent_t const * agent, td_event_e event, td_notify_t * no } +td_err_e +td_ta_clear_event(const td_thragent_t * ta_arg, td_thr_events_t * event) +{ + /* Given that gdb 7.0 doesn't use thread events, + there's nothing we need to do here. */ + return TD_OK; +} + + td_err_e td_ta_thr_iter(td_thragent_t const * agent, td_thr_iter_f * func, void * cookie, td_thr_state_e state, int32_t prio, sigset_t * sigmask, uint32_t user_flags) @@ -170,8 +205,8 @@ td_ta_thr_iter(td_thragent_t const * agent, td_thr_iter_f * func, void * cookie, continue; } handle.tid = atoi(entry->d_name); - err = func(&handle, cookie); - if (err) { + if (func(&handle, cookie) != 0) { + err = TD_DBERR; break; } } @@ -181,3 +216,9 @@ td_ta_thr_iter(td_thragent_t const * agent, td_thr_iter_f * func, void * cookie, return err; } +td_err_e +td_thr_tls_get_addr(const td_thrhandle_t * th, + psaddr_t map_address, size_t offset, psaddr_t * address) +{ + return TD_NOAPLIC; // FIXME: TODO +} From 68b5f556710909d292b5b285ee2c5e4d30e6476e Mon Sep 17 00:00:00 2001 From: David 'Digit' Turner Date: Thu, 25 Mar 2010 09:54:33 -0700 Subject: [PATCH 02/93] Fix setjmp()/longjmp() to save FP registers on ARMv7. Change-Id: I8ec684c8f8ca1ae58c8feb330b97d1e2b81caeef --- libc/arch-arm/bionic/_setjmp.S | 53 ++++--- libc/arch-arm/bionic/setjmp.S | 62 ++++---- libc/arch-arm/include/machine/cpu-features.h | 13 ++ libc/arch-arm/include/machine/setjmp.h | 149 +++++++++---------- libc/docs/CHANGES.TXT | 2 + 5 files changed, 149 insertions(+), 130 deletions(-) diff --git a/libc/arch-arm/bionic/_setjmp.S b/libc/arch-arm/bionic/_setjmp.S index 6a27af24d..5626219d4 100644 --- a/libc/arch-arm/bionic/_setjmp.S +++ b/libc/arch-arm/bionic/_setjmp.S @@ -3,6 +3,7 @@ /* * Copyright (c) 1997 Mark Brinicombe + * Copyright (c) 2010 Android Open Source Project. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -35,6 +36,7 @@ #include #include +#include /* * C library -- _setjmp, _longjmp @@ -51,18 +53,20 @@ ENTRY(_setjmp) ldr r1, .L_setjmp_magic - str r1, [r0], #4 -#ifdef SOFTFLOAT - add r0, r0, #52 -#else - /* Store fp registers */ - sfm f4, 4, [r0], #48 - /* Store fpsr */ - rfs r1 - str r1, [r0], #0x0004 -#endif /* SOFTFLOAT */ - /* Store integer registers */ - stmia r0, {r4-r14} + str r1, [r0, #(_JB_MAGIC * 4)] + + /* Store core registers */ + add r1, r0, #(_JB_CORE_BASE * 4) + stmia r1, {r4-r14} + +#ifdef __ARM_HAVE_VFP + /* Store floating-point registers */ + add r1, r0, #(_JB_FLOAT_BASE * 4) + vstmia r1, {d8-d15} + /* Store floating-point state */ + fmrx r1, fpscr + str r1, [r0, #(_JB_FLOAT_STATE * 4)] +#endif /* __ARM_HAVE_VFP */ mov r0, #0x00000000 bx lr @@ -72,21 +76,22 @@ ENTRY(_setjmp) ENTRY(_longjmp) ldr r2, .L_setjmp_magic - ldr r3, [r0], #4 + ldr r3, [r0, #(_JB_MAGIC * 4)] teq r2, r3 bne botch -#ifdef SOFTFLOAT - add r0, r0, #52 -#else - /* Restore fp registers */ - lfm f4, 4, [r0], #48 - /* Restore fpsr */ - ldr r4, [r0], #0x0004 - wfs r4 -#endif /* SOFTFLOAT */ - /* Restore integer registers */ - ldmia r0, {r4-r14} +#ifdef __ARM_HAVE_VFP + /* Restore floating-point registers */ + add r2, r0, #(_JB_FLOAT_BASE * 4) + vldmia r2, {d8-d15} + /* Restore floating-point state */ + ldr r2, [r0, #(_JB_FLOAT_STATE * 4)] + fmxr fpscr, r2 +#endif /* __ARM_HAVE_VFP */ + + /* Restore core registers */ + add r2, r0, #(_JB_CORE_BASE * 4) + ldmia r2, {r4-r14} /* Validate sp and r14 */ teq sp, #0 diff --git a/libc/arch-arm/bionic/setjmp.S b/libc/arch-arm/bionic/setjmp.S index a9f6ea4c1..59aff6601 100644 --- a/libc/arch-arm/bionic/setjmp.S +++ b/libc/arch-arm/bionic/setjmp.S @@ -3,6 +3,7 @@ /* * Copyright (c) 1997 Mark Brinicombe + * Copyright (c) 2010 Android Open Source Project. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -35,6 +36,7 @@ #include #include +#include /* * C library -- setjmp, longjmp @@ -57,24 +59,26 @@ ENTRY(setjmp) ldmfd sp!, {r0, r14} /* Store signal mask */ - str r1, [r0, #(25 * 4)] + str r1, [r0, #(_JB_SIGMASK * 4)] ldr r1, .Lsetjmp_magic - str r1, [r0], #4 + str r1, [r0, #(_JB_MAGIC * 4)] -#ifdef SOFTFLOAT - add r0, r0, #52 -#else - /* Store fp registers */ - sfm f4, 4, [r0], #48 - /* Store fpsr */ - rfs r1 - str r1, [r0], #0x0004 -#endif /*SOFTFLOAT*/ - /* Store integer registers */ - stmia r0, {r4-r14} - mov r0, #0x00000000 - bx lr + /* Store core registers */ + add r1, r0, #(_JB_CORE_BASE * 4) + stmia r1, {r4-r14} + +#ifdef __ARM_HAVE_VFP + /* Store floating-point registers */ + add r1, r0, #(_JB_FLOAT_BASE * 4) + vstmia r1, {d8-d15} + /* Store floating-point state */ + fmrx r1, fpscr + str r1, [r0, #(_JB_FLOAT_STATE * 4)] +#endif /* __ARM_HAVE_VFP */ + + mov r0, #0x00000000 + bx lr .Lsetjmp_magic: .word _JB_MAGIC_SETJMP @@ -82,12 +86,12 @@ ENTRY(setjmp) ENTRY(longjmp) ldr r2, .Lsetjmp_magic - ldr r3, [r0] + ldr r3, [r0, #(_JB_MAGIC * 4)] teq r2, r3 bne botch /* Fetch signal mask */ - ldr r2, [r0, #(25 * 4)] + ldr r2, [r0, #(_JB_SIGMASK * 4)] /* Set signal mask */ stmfd sp!, {r0, r1, r14} @@ -99,18 +103,18 @@ ENTRY(longjmp) add sp, sp, #4 /* unalign the stack */ ldmfd sp!, {r0, r1, r14} - add r0, r0, #4 -#ifdef SOFTFLOAT - add r0, r0, #52 -#else - /* Restore fp registers */ - lfm f4, 4, [r0], #48 - /* Restore FPSR */ - ldr r4, [r0], #0x0004 - wfs r4 -#endif /* SOFTFLOAT */ - /* Restore integer registers */ - ldmia r0, {r4-r14} +#ifdef __ARM_HAVE_VFP + /* Restore floating-point registers */ + add r2, r0, #(_JB_FLOAT_BASE * 4) + vldmia r2, {d8-d15} + /* Restore floating-point state */ + ldr r2, [r0, #(_JB_FLOAT_STATE * 4)] + fmxr fpscr, r2 +#endif /* __ARM_HAVE_VFP */ + + /* Restore core registers */ + add r2, r0, #(_JB_CORE_BASE * 4) + ldmia r2, {r4-r14} /* Validate sp and r14 */ teq sp, #0 diff --git a/libc/arch-arm/include/machine/cpu-features.h b/libc/arch-arm/include/machine/cpu-features.h index ecf6ff6f3..abf226a68 100644 --- a/libc/arch-arm/include/machine/cpu-features.h +++ b/libc/arch-arm/include/machine/cpu-features.h @@ -156,6 +156,19 @@ # define _ARM_HAVE_LDREX_STREX #endif +/* define _ARM_HAVE_VFP if we have VFPv3 + */ +#if __ARM_ARCH__ >= 7 && defined __VFP_FP__ +# define __ARM_HAVE_VFP +#endif + +/* define _ARM_HAVE_NEON for ARMv7 architecture if we support the + * Neon SIMD instruction set extensions. This also implies + * that VFPv3-D32 is supported. + */ +#if __ARM_ARCH__ >= 7 && defined __ARM_NEON__ +# define __ARM_HAVE_NEON +#endif /* Assembly-only macros */ diff --git a/libc/arch-arm/include/machine/setjmp.h b/libc/arch-arm/include/machine/setjmp.h index f20cab2e9..0941202d5 100644 --- a/libc/arch-arm/include/machine/setjmp.h +++ b/libc/arch-arm/include/machine/setjmp.h @@ -1,87 +1,82 @@ -/* $OpenBSD: setjmp.h,v 1.1 2004/02/01 05:09:49 drahn Exp $ */ -/* $NetBSD: setjmp.h,v 1.2 2001/08/25 14:45:59 bjh21 Exp $ */ +/* + * Copyright (C) 2010 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. + */ /* * machine/setjmp.h: machine dependent setjmp-related information. */ -#ifdef __ELF__ -#define _JBLEN 64 /* size, in longs, of a jmp_buf */ -#else -#define _JBLEN 29 /* size, in longs, of a jmp_buf */ -#endif - -/* - * NOTE: The internal structure of a jmp_buf is *PRIVATE* - * This information is provided as there is software - * that fiddles with this with obtain the stack pointer - * (yes really ! and its commercial !). +/* _JBLEN is the size of a jmp_buf in longs. + * Do not modify this value or you will break the ABI ! * - * Description of the setjmp buffer - * - * word 0 magic number (dependant on creator) - * 1 - 3 f4 fp register 4 - * 4 - 6 f5 fp register 5 - * 7 - 9 f6 fp register 6 - * 10 - 12 f7 fp register 7 - * 13 fpsr fp status register - * 14 r4 register 4 - * 15 r5 register 5 - * 16 r6 register 6 - * 17 r7 register 7 - * 18 r8 register 8 - * 19 r9 register 9 - * 20 r10 register 10 (sl) - * 21 r11 register 11 (fp) - * 22 r12 register 12 (ip) - * 23 r13 register 13 (sp) - * 24 r14 register 14 (lr) - * 25 signal mask (dependant on magic) - * 26 (con't) - * 27 (con't) - * 28 (con't) - * - * The magic number number identifies the jmp_buf and - * how the buffer was created as well as providing - * a sanity check - * - * A side note I should mention - Please do not tamper - * with the floating point fields. While they are - * always saved and restored at the moment this cannot - * be garenteed especially if the compiler happens - * to be generating soft-float code so no fp - * registers will be used. - * - * Whilst this can be seen an encouraging people to - * use the setjmp buffer in this way I think that it - * is for the best then if changes occur compiles will - * break rather than just having new builds falling over - * mysteriously. + * This value comes from the original OpenBSD ARM-specific header + * that was replaced by this one. */ +#define _JBLEN 64 + +/* According to the ARM AAPCS document, we only need to save + * the following registers: + * + * Core r4-r14 + * + * VFP d8-d15 (see section 5.1.2.1) + * + * Registers s16-s31 (d8-d15, q4-q7) must be preserved across subroutine + * calls; registers s0-s15 (d0-d7, q0-q3) do not need to be preserved + * (and can be used for passing arguments or returning results in standard + * procedure-call variants). Registers d16-d31 (q8-q15), if present, do + * not need to be preserved. + * + * FPSCR saved because GLibc does saves it too. + * + */ + +/* The internal structure of a jmp_buf is totally private. + * Current layout (may change in the future): + * + * word name description + * 0 magic magic number + * 1 sigmask signal mask (not used with _setjmp / _longjmp) + * 2 float_base base of float registers (d8 to d15) + * 18 float_state floating-point status and control register + * 19 core_base base of core registers (r4 to r14) + * 30 reserved reserved entries (room to grow) + * 64 + * + * NOTE: float_base must be at an even word index, since the + * FP registers will be loaded/stored with instructions + * that expect 8-byte alignment. + */ + +#define _JB_MAGIC 0 +#define _JB_SIGMASK (_JB_MAGIC+1) +#define _JB_FLOAT_BASE (_JB_SIGMASK+1) +#define _JB_FLOAT_STATE (_JB_FLOAT_BASE + (15-8+1)*2) +#define _JB_CORE_BASE (_JB_FLOAT_STATE+1) #define _JB_MAGIC__SETJMP 0x4278f500 #define _JB_MAGIC_SETJMP 0x4278f501 - -/* Valid for all jmp_buf's */ - -#define _JB_MAGIC 0 -#define _JB_REG_F4 1 -#define _JB_REG_F5 4 -#define _JB_REG_F6 7 -#define _JB_REG_F7 10 -#define _JB_REG_FPSR 13 -#define _JB_REG_R4 14 -#define _JB_REG_R5 15 -#define _JB_REG_R6 16 -#define _JB_REG_R7 17 -#define _JB_REG_R8 18 -#define _JB_REG_R9 19 -#define _JB_REG_R10 20 -#define _JB_REG_R11 21 -#define _JB_REG_R12 22 -#define _JB_REG_R13 23 -#define _JB_REG_R14 24 - -/* Only valid with the _JB_MAGIC_SETJMP magic */ - -#define _JB_SIGMASK 25 diff --git a/libc/docs/CHANGES.TXT b/libc/docs/CHANGES.TXT index 90806851a..615904748 100644 --- a/libc/docs/CHANGES.TXT +++ b/libc/docs/CHANGES.TXT @@ -3,6 +3,8 @@ Bionic ChangeLog: Differences between current and Android 2.1: +- Support FP register save/load in setjmp()/longjmp() on ARMv7 builds. + - Add support for SH-4 CPU architecture ! - __atomic_swap(): use LDREX/STREX CPU instructions on ARMv6 and higher. From a418c3b8370cae1c80fbe9a06e7e53025da5d6f0 Mon Sep 17 00:00:00 2001 From: David 'Digit' Turner Date: Tue, 11 May 2010 16:39:22 -0700 Subject: [PATCH 03/93] Add pthread_rwlock_t implementation to the C library Change-Id: I14d0a112554756a7294a51fe88c1c408a16b5ff1 --- libc/Android.mk | 3 + libc/bionic/pthread-rwlocks.c | 347 ++++++++++++++++++++++++++++++++++ libc/docs/CHANGES.TXT | 7 +- libc/include/pthread.h | 35 ++++ 4 files changed, 391 insertions(+), 1 deletion(-) create mode 100644 libc/bionic/pthread-rwlocks.c diff --git a/libc/Android.mk b/libc/Android.mk index d8cc721ca..b5f693da4 100644 --- a/libc/Android.mk +++ b/libc/Android.mk @@ -320,6 +320,7 @@ libc_common_src_files += \ # up any thumb code. libc_common_src_files += \ bionic/pthread.c.arm \ + bionic/pthread-rwlocks.c.arm \ bionic/pthread-timers.c.arm \ bionic/ptrace.c.arm @@ -354,6 +355,7 @@ libc_common_src_files += \ arch-x86/string/strncmp_wrapper.S \ arch-x86/string/strlen.S \ bionic/pthread.c \ + bionic/pthread-rwlocks.c \ bionic/pthread-timers.c \ bionic/ptrace.c @@ -391,6 +393,7 @@ libc_common_src_files += \ string/strlen.c \ bionic/eabi.c \ bionic/pthread.c \ + bionic/pthread-rwlocks.c \ bionic/pthread-timers.c \ bionic/ptrace.c \ unistd/socketcalls.c diff --git a/libc/bionic/pthread-rwlocks.c b/libc/bionic/pthread-rwlocks.c new file mode 100644 index 000000000..ca3e95cda --- /dev/null +++ b/libc/bionic/pthread-rwlocks.c @@ -0,0 +1,347 @@ +/* + * Copyright (C) 2010 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 "pthread_internal.h" +#include + +/* Technical note: + * + * Possible states of a read/write lock: + * + * - no readers and no writer (unlocked) + * - one or more readers sharing the lock at the same time (read-locked) + * - one writer holding the lock (write-lock) + * + * Additionally: + * - trying to get the write-lock while there are any readers blocks + * - trying to get the read-lock while there is a writer blocks + * - a single thread can acquire the lock multiple times in the same mode + * + * - Posix states that behaviour is undefined it a thread tries to acquire + * the lock in two distinct modes (e.g. write after read, or read after write). + * + * - This implementation tries to avoid writer starvation by making the readers + * block as soon as there is a waiting writer on the lock. However, it cannot + * completely eliminate it: each time the lock is unlocked, all waiting threads + * are woken and battle for it, which one gets it depends on the kernel scheduler + * and is semi-random. + * + */ + +#define __likely(cond) __builtin_expect(!!(cond), 1) +#define __unlikely(cond) __builtin_expect(!!(cond), 0) + +#define RWLOCKATTR_DEFAULT 0 +#define RWLOCKATTR_SHARED_MASK 0x0010 + +extern pthread_internal_t* __get_thread(void); + +/* Return a global kernel ID for the current thread */ +static int __get_thread_id(void) +{ + return __get_thread()->kernel_id; +} + +int pthread_rwlockattr_init(pthread_rwlockattr_t *attr) +{ + if (!attr) + return EINVAL; + + *attr = PTHREAD_PROCESS_PRIVATE; + return 0; +} + +int pthread_rwlockattr_destroy(pthread_rwlockattr_t *attr) +{ + if (!attr) + return EINVAL; + + *attr = -1; + return 0; +} + +int pthread_rwlockattr_setpshared(pthread_rwlockattr_t *attr, int pshared) +{ + if (!attr) + return EINVAL; + + switch (pshared) { + case PTHREAD_PROCESS_PRIVATE: + case PTHREAD_PROCESS_SHARED: + *attr = pshared; + return 0; + default: + return EINVAL; + } +} + +int pthread_rwlockattr_getpshared(pthread_rwlockattr_t *attr, int *pshared) +{ + if (!attr || !pshared) + return EINVAL; + + *pshared = *attr; + return 0; +} + +int pthread_rwlock_init(pthread_rwlock_t *rwlock, const pthread_rwlockattr_t *attr) +{ + pthread_mutexattr_t* lock_attr = NULL; + pthread_condattr_t* cond_attr = NULL; + pthread_mutexattr_t lock_attr0; + pthread_condattr_t cond_attr0; + int ret; + + if (rwlock == NULL) + return EINVAL; + + if (attr && *attr == PTHREAD_PROCESS_SHARED) { + lock_attr = &lock_attr0; + pthread_mutexattr_init(lock_attr); + pthread_mutexattr_setpshared(lock_attr, PTHREAD_PROCESS_SHARED); + + cond_attr = &cond_attr0; + pthread_condattr_init(cond_attr); + pthread_condattr_setpshared(cond_attr, PTHREAD_PROCESS_SHARED); + } + + ret = pthread_mutex_init(&rwlock->lock, lock_attr); + if (ret != 0) + return ret; + + ret = pthread_cond_init(&rwlock->cond, cond_attr); + if (ret != 0) { + pthread_mutex_destroy(&rwlock->lock); + return ret; + } + + rwlock->numLocks = 0; + rwlock->pendingReaders = 0; + rwlock->pendingWriters = 0; + rwlock->writerThreadId = 0; + + return 0; +} + +int pthread_rwlock_destroy(pthread_rwlock_t *rwlock) +{ + int ret; + + if (rwlock == NULL) + return EINVAL; + + if (rwlock->numLocks > 0) + return EBUSY; + + pthread_cond_destroy(&rwlock->cond); + pthread_mutex_destroy(&rwlock->lock); + return 0; +} + +/* Returns TRUE iff we can acquire a read lock. */ +static __inline__ int read_precondition(pthread_rwlock_t *rwlock, int thread_id) +{ + /* We can't have the lock if any writer is waiting for it (writer bias). + * This tries to avoid starvation when there are multiple readers racing. + */ + if (rwlock->pendingWriters > 0) + return 0; + + /* We can have the lock if there is no writer, or if we write-own it */ + /* The second test avoids a self-dead lock in case of buggy code. */ + if (rwlock->writerThreadId == 0 || rwlock->writerThreadId == thread_id) + return 1; + + /* Otherwise, we can't have it */ + return 0; +} + +/* returns TRUE iff we can acquire a write lock. */ +static __inline__ int write_precondition(pthread_rwlock_t *rwlock, int thread_id) +{ + /* We can get the lock if nobody has it */ + if (rwlock->numLocks == 0) + return 1; + + /* Or if we already own it */ + if (rwlock->writerThreadId == thread_id) + return 1; + + /* Otherwise, not */ + return 0; +} + +/* This function is used to waken any waiting thread contending + * for the lock. One of them should be able to grab it after + * that. + */ +static void _pthread_rwlock_pulse(pthread_rwlock_t *rwlock) +{ + if (rwlock->pendingReaders > 0 || rwlock->pendingWriters > 0) + pthread_cond_broadcast(&rwlock->cond); +} + + +int pthread_rwlock_rdlock(pthread_rwlock_t *rwlock) +{ + return pthread_rwlock_timedrdlock(rwlock, NULL); +} + +int pthread_rwlock_tryrdlock(pthread_rwlock_t *rwlock) +{ + int ret = 0; + + if (rwlock == NULL) + return EINVAL; + + pthread_mutex_lock(&rwlock->lock); + if (__unlikely(!read_precondition(rwlock, __get_thread_id()))) + ret = EBUSY; + else + rwlock->numLocks ++; + pthread_mutex_unlock(&rwlock->lock); + + return ret; +} + +int pthread_rwlock_timedrdlock(pthread_rwlock_t *rwlock, const struct timespec *abs_timeout) +{ + int thread_id, ret = 0; + + if (rwlock == NULL) + return EINVAL; + + pthread_mutex_lock(&rwlock->lock); + thread_id = __get_thread_id(); + if (__unlikely(!read_precondition(rwlock, thread_id))) { + rwlock->pendingReaders += 1; + do { + ret = pthread_cond_timedwait(&rwlock->cond, &rwlock->lock, abs_timeout); + } while (ret == 0 && !read_precondition(rwlock, thread_id)); + rwlock->pendingReaders -= 1; + if (ret != 0) + goto EXIT; + } + rwlock->numLocks ++; +EXIT: + pthread_mutex_unlock(&rwlock->lock); + return ret; +} + + +int pthread_rwlock_wrlock(pthread_rwlock_t *rwlock) +{ + return pthread_rwlock_timedwrlock(rwlock, NULL); +} + +int pthread_rwlock_trywrlock(pthread_rwlock_t *rwlock) +{ + int thread_id, ret = 0; + + if (rwlock == NULL) + return EINVAL; + + pthread_mutex_lock(&rwlock->lock); + thread_id = __get_thread_id(); + if (__unlikely(!write_precondition(rwlock, thread_id))) { + ret = EBUSY; + } else { + rwlock->numLocks ++; + rwlock->writerThreadId = thread_id; + } + pthread_mutex_unlock(&rwlock->lock); + return ret; +} + +int pthread_rwlock_timedwrlock(pthread_rwlock_t *rwlock, const struct timespec *abs_timeout) +{ + int thread_id, ret = 0; + + if (rwlock == NULL) + return EINVAL; + + pthread_mutex_lock(&rwlock->lock); + thread_id = __get_thread_id(); + if (__unlikely(!write_precondition(rwlock, thread_id))) { + /* If we can't read yet, wait until the rwlock is unlocked + * and try again. Increment pendingReaders to get the + * cond broadcast when that happens. + */ + rwlock->pendingWriters += 1; + do { + ret = pthread_cond_timedwait(&rwlock->cond, &rwlock->lock, abs_timeout); + } while (ret == 0 && !write_precondition(rwlock, thread_id)); + rwlock->pendingWriters -= 1; + if (ret != 0) + goto EXIT; + } + rwlock->numLocks ++; + rwlock->writerThreadId = thread_id; +EXIT: + pthread_mutex_unlock(&rwlock->lock); + return ret; +} + + +int pthread_rwlock_unlock(pthread_rwlock_t *rwlock) +{ + int ret = 0; + + if (rwlock == NULL) + return EINVAL; + + pthread_mutex_lock(&rwlock->lock); + + /* The lock must be held */ + if (rwlock->numLocks == 0) { + ret = EPERM; + goto EXIT; + } + + /* If it has only readers, writerThreadId is 0 */ + if (rwlock->writerThreadId == 0) { + if (--rwlock->numLocks == 0) + _pthread_rwlock_pulse(rwlock); + } + /* Otherwise, it has only a single writer, which + * must be ourselves. + */ + else { + if (rwlock->writerThreadId != __get_thread_id()) { + ret = EPERM; + goto EXIT; + } + if (--rwlock->numLocks == 0) { + rwlock->writerThreadId = 0; + _pthread_rwlock_pulse(rwlock); + } + } +EXIT: + pthread_mutex_unlock(&rwlock->lock); + return ret; +} diff --git a/libc/docs/CHANGES.TXT b/libc/docs/CHANGES.TXT index 615904748..e72b422f0 100644 --- a/libc/docs/CHANGES.TXT +++ b/libc/docs/CHANGES.TXT @@ -1,7 +1,12 @@ Bionic ChangeLog: ----------------- -Differences between current and Android 2.1: +Differences between current and Android 2.2: + +- : Add reader/writer locks implementation. + +------------------------------------------------------------------------------- +Differences between Android 2.2. and Android 2.1: - Support FP register save/load in setjmp()/longjmp() on ARMv7 builds. diff --git a/libc/include/pthread.h b/libc/include/pthread.h index eb2d16997..33039b9f4 100644 --- a/libc/include/pthread.h +++ b/libc/include/pthread.h @@ -219,6 +219,41 @@ int pthread_cond_timeout_np(pthread_cond_t *cond, */ int pthread_mutex_lock_timeout_np(pthread_mutex_t *mutex, unsigned msecs); +/* read-write lock support */ + +typedef int pthread_rwlockattr_t; + +typedef struct { + pthread_mutex_t lock; + pthread_cond_t cond; + int numLocks; + int writerThreadId; + int pendingReaders; + int pendingWriters; + void* reserved[4]; /* for future extensibility */ +} pthread_rwlock_t; + +#define PTHREAD_RWLOCK_INITIALIZER { PTHREAD_MUTEX_INITIALIZER, 0, NULL, 0, 0 } + +int pthread_rwlockattr_init(pthread_rwlockattr_t *attr); +int pthread_rwlockattr_destroy(pthread_rwlockattr_t *attr); +int pthread_rwlockattr_setpshared(pthread_rwlockattr_t *attr, int pshared); +int pthread_rwlockattr_getpshared(pthread_rwlockattr_t *attr, int *pshared); + +int pthread_rwlock_init(pthread_rwlock_t *rwlock, const pthread_rwlockattr_t *attr); +int pthread_rwlock_destroy(pthread_rwlock_t *rwlock); + +int pthread_rwlock_rdlock(pthread_rwlock_t *rwlock); +int pthread_rwlock_tryrdlock(pthread_rwlock_t *rwlock); +int pthread_rwlock_timedrdlock(pthread_rwlock_t *rwlock, const struct timespec *abs_timeout); + +int pthread_rwlock_wrlock(pthread_rwlock_t *rwlock); +int pthread_rwlock_trywrlock(pthread_rwlock_t *rwlock); +int pthread_rwlock_timedwrlock(pthread_rwlock_t *rwlock, const struct timespec *abs_timeout); + +int pthread_rwlock_unlock(pthread_rwlock_t *rwlock); + + int pthread_key_create(pthread_key_t *key, void (*destructor_function)(void *)); int pthread_key_delete (pthread_key_t); int pthread_setspecific(pthread_key_t key, const void *value); From ddd235bd9c264f08dee7887e210d61ca2351cf86 Mon Sep 17 00:00:00 2001 From: David 'Digit' Turner Date: Wed, 19 May 2010 11:39:16 -0700 Subject: [PATCH 04/93] Add sincos() and sincosf() implementation. This is a GLibc-compatibility patch required to simplify our upcoming toolchain work/porting. Change-Id: I615a20a449763f86b6e2b0e4f5ab43fb029ceb6d --- libc/docs/CHANGES.TXT | 2 ++ libm/Android.mk | 1 + libm/include/math.h | 6 ++++++ libm/sincos.c | 40 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 49 insertions(+) create mode 100644 libm/sincos.c diff --git a/libc/docs/CHANGES.TXT b/libc/docs/CHANGES.TXT index e72b422f0..96da04444 100644 --- a/libc/docs/CHANGES.TXT +++ b/libc/docs/CHANGES.TXT @@ -5,6 +5,8 @@ Differences between current and Android 2.2: - : Add reader/writer locks implementation. +- : Added sincos() and sincosf() (GLibc compatibility). + ------------------------------------------------------------------------------- Differences between Android 2.2. and Android 2.1: diff --git a/libm/Android.mk b/libm/Android.mk index fa73aff59..28e8f334c 100644 --- a/libm/Android.mk +++ b/libm/Android.mk @@ -3,6 +3,7 @@ LOCAL_PATH:= $(call my-dir) libm_common_src_files:= \ isinf.c \ fpclassify.c \ + sincos.c \ bsdsrc/b_exp.c \ bsdsrc/b_log.c \ bsdsrc/b_tgamma.c \ diff --git a/libm/include/math.h b/libm/include/math.h index ef6a9e6bc..6c0d4eb20 100644 --- a/libm/include/math.h +++ b/libm/include/math.h @@ -480,6 +480,12 @@ long double tgammal(long double); #endif long double truncl(long double); +/* BIONIC: GLibc compatibility - required by the ARM toolchain */ +#ifdef _GNU_SOURCE +void sincos(double x, double *sin, double *cos); +void sincosf(float x, float *sin, float *cos); +#endif + /* #endif */ /* __ISO_C_VISIBLE >= 1999 */ __END_DECLS diff --git a/libm/sincos.c b/libm/sincos.c new file mode 100644 index 000000000..ddbc420dc --- /dev/null +++ b/libm/sincos.c @@ -0,0 +1,40 @@ +/*- + * Copyright (c) 2010 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: + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + */ +#define _GNU_SOURCE 1 +#include + +void sincos(double x, double *psin, double *pcos) +{ + *psin = sin(x); + *pcos = cos(x); +} + +void sincosf(float x, float *psin, float *pcos) +{ + *psin = sinf(x); + *pcos = cosf(x); +} From 5d726df15e1391b62f09e91f113f6a1555cd8f2b Mon Sep 17 00:00:00 2001 From: David 'Digit' Turner Date: Thu, 20 May 2010 10:55:45 -0700 Subject: [PATCH 05/93] Add missing sysinfo() implementation (already declared in ) Change-Id: Ie9168238c3a8e77daab4f39939756d4c53d8af37 --- libc/SYSCALLS.TXT | 1 + libc/arch-arm/syscalls.mk | 1 + libc/arch-arm/syscalls/sysinfo.S | 19 ++++++++++++++++++ libc/arch-sh/syscalls.mk | 1 + libc/arch-sh/syscalls/sysinfo.S | 32 +++++++++++++++++++++++++++++++ libc/arch-x86/syscalls.mk | 1 + libc/arch-x86/syscalls/sysinfo.S | 23 ++++++++++++++++++++++ libc/docs/CHANGES.TXT | 3 +++ libc/include/sys/linux-syscalls.h | 1 + libc/include/sys/linux-unistd.h | 1 + 10 files changed, 83 insertions(+) create mode 100644 libc/arch-arm/syscalls/sysinfo.S create mode 100644 libc/arch-sh/syscalls/sysinfo.S create mode 100644 libc/arch-x86/syscalls/sysinfo.S diff --git a/libc/SYSCALLS.TXT b/libc/SYSCALLS.TXT index 11407b9f4..bf65a6fd4 100644 --- a/libc/SYSCALLS.TXT +++ b/libc/SYSCALLS.TXT @@ -244,6 +244,7 @@ int __syslog:syslog(int, char *, int) 103 int init_module(void *, unsigned long, const char *) 128 int delete_module(const char*, unsigned int) 129 int klogctl:syslog(int, char *, int) 103 +int sysinfo(struct sysinfo *) 116 # futex int futex(void *, int, int, void *, void *, int) 240 diff --git a/libc/arch-arm/syscalls.mk b/libc/arch-arm/syscalls.mk index 9cdd28a92..f6312e5c0 100644 --- a/libc/arch-arm/syscalls.mk +++ b/libc/arch-arm/syscalls.mk @@ -161,6 +161,7 @@ syscall_src += arch-arm/syscalls/__syslog.S syscall_src += arch-arm/syscalls/init_module.S syscall_src += arch-arm/syscalls/delete_module.S syscall_src += arch-arm/syscalls/klogctl.S +syscall_src += arch-arm/syscalls/sysinfo.S syscall_src += arch-arm/syscalls/futex.S syscall_src += arch-arm/syscalls/epoll_create.S syscall_src += arch-arm/syscalls/epoll_ctl.S diff --git a/libc/arch-arm/syscalls/sysinfo.S b/libc/arch-arm/syscalls/sysinfo.S new file mode 100644 index 000000000..197324da7 --- /dev/null +++ b/libc/arch-arm/syscalls/sysinfo.S @@ -0,0 +1,19 @@ +/* autogenerated by gensyscalls.py */ +#include + + .text + .type sysinfo, #function + .globl sysinfo + .align 4 + .fnstart + +sysinfo: + .save {r4, r7} + stmfd sp!, {r4, r7} + ldr r7, =__NR_sysinfo + swi #0 + ldmfd sp!, {r4, r7} + movs r0, r0 + bxpl lr + b __set_syscall_errno + .fnend diff --git a/libc/arch-sh/syscalls.mk b/libc/arch-sh/syscalls.mk index ab2f3d1b2..a8a151a0b 100644 --- a/libc/arch-sh/syscalls.mk +++ b/libc/arch-sh/syscalls.mk @@ -150,6 +150,7 @@ syscall_src += arch-sh/syscalls/__syslog.S syscall_src += arch-sh/syscalls/init_module.S syscall_src += arch-sh/syscalls/delete_module.S syscall_src += arch-sh/syscalls/klogctl.S +syscall_src += arch-sh/syscalls/sysinfo.S syscall_src += arch-sh/syscalls/futex.S syscall_src += arch-sh/syscalls/epoll_create.S syscall_src += arch-sh/syscalls/epoll_ctl.S diff --git a/libc/arch-sh/syscalls/sysinfo.S b/libc/arch-sh/syscalls/sysinfo.S new file mode 100644 index 000000000..ae042ab6b --- /dev/null +++ b/libc/arch-sh/syscalls/sysinfo.S @@ -0,0 +1,32 @@ +/* autogenerated by gensyscalls.py */ +#include + + .text + .type sysinfo, @function + .globl sysinfo + .align 4 + +sysinfo: + + /* invoke trap */ + mov.l 0f, r3 /* trap num */ + trapa #(1 + 0x10) + + /* check return value */ + cmp/pz r0 + bt __NR_sysinfo_end + + /* keep error number */ + sts.l pr, @-r15 + mov.l 1f, r1 + jsr @r1 + mov r0, r4 + lds.l @r15+, pr + +__NR_sysinfo_end: + rts + nop + + .align 2 +0: .long __NR_sysinfo +1: .long __set_syscall_errno diff --git a/libc/arch-x86/syscalls.mk b/libc/arch-x86/syscalls.mk index ab026fe5f..bd9a9ab5a 100644 --- a/libc/arch-x86/syscalls.mk +++ b/libc/arch-x86/syscalls.mk @@ -164,6 +164,7 @@ syscall_src += arch-x86/syscalls/__syslog.S syscall_src += arch-x86/syscalls/init_module.S syscall_src += arch-x86/syscalls/delete_module.S syscall_src += arch-x86/syscalls/klogctl.S +syscall_src += arch-x86/syscalls/sysinfo.S syscall_src += arch-x86/syscalls/futex.S syscall_src += arch-x86/syscalls/epoll_create.S syscall_src += arch-x86/syscalls/epoll_ctl.S diff --git a/libc/arch-x86/syscalls/sysinfo.S b/libc/arch-x86/syscalls/sysinfo.S new file mode 100644 index 000000000..c60c37b37 --- /dev/null +++ b/libc/arch-x86/syscalls/sysinfo.S @@ -0,0 +1,23 @@ +/* autogenerated by gensyscalls.py */ +#include + + .text + .type sysinfo, @function + .globl sysinfo + .align 4 + +sysinfo: + pushl %ebx + mov 8(%esp), %ebx + movl $__NR_sysinfo, %eax + int $0x80 + cmpl $-129, %eax + jb 1f + negl %eax + pushl %eax + call __set_errno + addl $4, %esp + orl $-1, %eax +1: + popl %ebx + ret diff --git a/libc/docs/CHANGES.TXT b/libc/docs/CHANGES.TXT index 96da04444..05997887f 100644 --- a/libc/docs/CHANGES.TXT +++ b/libc/docs/CHANGES.TXT @@ -7,6 +7,9 @@ Differences between current and Android 2.2: - : Added sincos() and sincosf() (GLibc compatibility). +- : Added missing sysinfo() system call implementation + (the function was already declared in the header though). + ------------------------------------------------------------------------------- Differences between Android 2.2. and Android 2.1: diff --git a/libc/include/sys/linux-syscalls.h b/libc/include/sys/linux-syscalls.h index 6e373e05f..5f03863c3 100644 --- a/libc/include/sys/linux-syscalls.h +++ b/libc/include/sys/linux-syscalls.h @@ -126,6 +126,7 @@ #define __NR_init_module (__NR_SYSCALL_BASE + 128) #define __NR_delete_module (__NR_SYSCALL_BASE + 129) #define __NR_syslog (__NR_SYSCALL_BASE + 103) +#define __NR_sysinfo (__NR_SYSCALL_BASE + 116) #define __NR_futex (__NR_SYSCALL_BASE + 240) #define __NR_poll (__NR_SYSCALL_BASE + 168) diff --git a/libc/include/sys/linux-unistd.h b/libc/include/sys/linux-unistd.h index b0e7822df..27db2a96d 100644 --- a/libc/include/sys/linux-unistd.h +++ b/libc/include/sys/linux-unistd.h @@ -192,6 +192,7 @@ int __syslog (int, char *, int); int init_module (void *, unsigned long, const char *); int delete_module (const char*, unsigned int); int klogctl (int, char *, int); +int sysinfo (struct sysinfo *); int futex (void *, int, int, void *, void *, int); int epoll_create (int size); int epoll_ctl (int epfd, int op, int fd, struct epoll_event *event); From bd77d49812bb2eea20151c11041124b6d316c75e Mon Sep 17 00:00:00 2001 From: Jing Yu Date: Thu, 20 May 2010 20:25:48 -0700 Subject: [PATCH 06/93] Remove a gcc-4.5 compilation warning: bionic/libc/include/../include/stdlib.h: In function 'int grantpt(int)': bionic/libc/include/../include/stdlib.h:138:23: warning: parameter '__fd' set but not used [-Wunused-but-set-parameter] By adding __attribute((unused)) to __fd, the warning is gone, and this attribute is compatible with gcc-4.4.0, gcc-4.3.1 gcc-4.2.1. There is no any side effect. Change-Id: Id9d2b0aeefdd9c37132da0f00c48387f7d897e83 --- libc/include/stdlib.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libc/include/stdlib.h b/libc/include/stdlib.h index 41e8d26c4..5a991ac6f 100644 --- a/libc/include/stdlib.h +++ b/libc/include/stdlib.h @@ -135,7 +135,7 @@ extern char* ptsname(int); extern int ptsname_r(int, char*, size_t); extern int getpt(void); -static __inline__ int grantpt(int __fd) +static __inline__ int grantpt(int __fd __attribute((unused))) { (void)__fd; return 0; /* devpts does this all for us! */ From 1c7708ea7c1f2f8628c219e7b0955cd4ccec11d3 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Tue, 1 Jun 2010 17:45:50 -0700 Subject: [PATCH 07/93] Add headers for new kernel drivers Change-Id: I65e682cef2c20b12faa5e526e82e35ab3ca0c379 --- libc/kernel/common/linux/bmp085.h | 29 +++++++++++++ libc/kernel/common/linux/kxtf9.h | 70 +++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 libc/kernel/common/linux/bmp085.h create mode 100644 libc/kernel/common/linux/kxtf9.h diff --git a/libc/kernel/common/linux/bmp085.h b/libc/kernel/common/linux/bmp085.h new file mode 100644 index 000000000..650cb88a5 --- /dev/null +++ b/libc/kernel/common/linux/bmp085.h @@ -0,0 +1,29 @@ +/**************************************************************************** + **************************************************************************** + *** + *** This header was automatically generated from a Linux kernel header + *** of the same name, to make information necessary for userspace to + *** call into the kernel available to libc. It contains only constants, + *** structures, and macros generated from the original header, and thus, + *** contains no copyrightable information. + *** + **************************************************************************** + ****************************************************************************/ +#ifndef __BMP085_H__ +#define __BMP085_H__ + +#include + +#define BMP085_NAME "bmp085" + +#define BMP085_IOCTL_BASE 78 + +#define BMP085_IOCTL_SET_DELAY _IOW(BMP085_IOCTL_BASE, 0, int) +#define BMP085_IOCTL_GET_DELAY _IOR(BMP085_IOCTL_BASE, 1, int) +#define BMP085_IOCTL_SET_ENABLE _IOW(BMP085_IOCTL_BASE, 2, int) +#define BMP085_IOCTL_GET_ENABLE _IOR(BMP085_IOCTL_BASE, 3, int) +#define BMP085_IOCTL_ACCURACY _IOW(BMP085_IOCTL_BASE, 4, int) + +#endif + + diff --git a/libc/kernel/common/linux/kxtf9.h b/libc/kernel/common/linux/kxtf9.h new file mode 100644 index 000000000..914136437 --- /dev/null +++ b/libc/kernel/common/linux/kxtf9.h @@ -0,0 +1,70 @@ +/**************************************************************************** + **************************************************************************** + *** + *** This header was automatically generated from a Linux kernel header + *** of the same name, to make information necessary for userspace to + *** call into the kernel available to libc. It contains only constants, + *** structures, and macros generated from the original header, and thus, + *** contains no copyrightable information. + *** + **************************************************************************** + ****************************************************************************/ +#ifndef __KXTF9_H__ +#define __KXTF9_H__ + +#include + +#define KXTF9_IOCTL_BASE 77 + +#define KXTF9_IOCTL_SET_DELAY _IOW(KXTF9_IOCTL_BASE, 0, int) +#define KXTF9_IOCTL_GET_DELAY _IOR(KXTF9_IOCTL_BASE, 1, int) +#define KXTF9_IOCTL_SET_ENABLE _IOW(KXTF9_IOCTL_BASE, 2, int) +#define KXTF9_IOCTL_GET_ENABLE _IOR(KXTF9_IOCTL_BASE, 3, int) +#define KXTF9_IOCTL_SET_G_RANGE _IOW(KXTF9_IOCTL_BASE, 4, int) + +#define KXTF9_IOCTL_SET_TILT_ENABLE _IOW(KXTF9_IOCTL_BASE, 5, int) +#define KXTF9_IOCTL_SET_TAP_ENABLE _IOW(KXTF9_IOCTL_BASE, 6, int) +#define KXTF9_IOCTL_SET_WAKE_ENABLE _IOW(KXTF9_IOCTL_BASE, 7, int) +#define KXTF9_IOCTL_SET_PM_MODE _IOW(KXTF9_IOCTL_BASE, 8, int) +#define KXTF9_IOCTL_SELF_TEST _IOW(KXTF9_IOCTL_BASE, 9, int) +#define KXTF9_IOCTL_SET_SENSITIVITY _IOW(KXTF9_IOCTL_BASE, 10, int) + +#define RES_12BIT 0x40 +#define KXTF9_G_2G 0x00 +#define KXTF9_G_4G 0x08 +#define KXTF9_G_8G 0x10 +#define TPE 0x01 +#define WUFE 0x02 +#define TDTE 0x04 + +#define OTP1_6 0x00 +#define OTP6_3 0x20 +#define OTP12_5 0x40 +#define OTP50 0x60 +#define OWUF25 0x00 +#define OWUF50 0x01 +#define OWUF100 0x02 +#define OWUF200 0x03 +#define OTDT50 0x00 +#define OTDT100 0x04 +#define OTDT200 0x08 +#define OTDT400 0x0C + +#define IEN 0x20 +#define IEA 0x10 +#define IEL 0x08 +#define IEU 0x04 + +#define ODR800 0x06 +#define ODR400 0x05 +#define ODR200 0x04 +#define ODR100 0x03 +#define ODR50 0x02 +#define ODR25 0x01 +#define ODR12_5 0x00 + +#define SENSITIVITY_REGS 0x07 + +#endif + + From 9946750609c858dad0150da55645c4331392cf0d Mon Sep 17 00:00:00 2001 From: Jing Yu Date: Thu, 3 Jun 2010 14:05:51 -0700 Subject: [PATCH 08/93] Add sincosl() function to bionic. So that sincos optimization can be enabled. Change-Id: I19671a407dc96a92417c719da938ee0c1669bfb8 --- libc/docs/CHANGES.TXT | 2 +- libm/include/math.h | 1 + libm/sincos.c | 6 ++++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/libc/docs/CHANGES.TXT b/libc/docs/CHANGES.TXT index 05997887f..6799525a4 100644 --- a/libc/docs/CHANGES.TXT +++ b/libc/docs/CHANGES.TXT @@ -5,7 +5,7 @@ Differences between current and Android 2.2: - : Add reader/writer locks implementation. -- : Added sincos() and sincosf() (GLibc compatibility). +- : Added sincos(), sincosf() and sincosl() (GLibc compatibility). - : Added missing sysinfo() system call implementation (the function was already declared in the header though). diff --git a/libm/include/math.h b/libm/include/math.h index 6c0d4eb20..3b5660f30 100644 --- a/libm/include/math.h +++ b/libm/include/math.h @@ -484,6 +484,7 @@ long double truncl(long double); #ifdef _GNU_SOURCE void sincos(double x, double *sin, double *cos); void sincosf(float x, float *sin, float *cos); +void sincosl(long double x, long double *sin, long double *cos); #endif /* #endif */ /* __ISO_C_VISIBLE >= 1999 */ diff --git a/libm/sincos.c b/libm/sincos.c index ddbc420dc..116b151e2 100644 --- a/libm/sincos.c +++ b/libm/sincos.c @@ -38,3 +38,9 @@ void sincosf(float x, float *psin, float *pcos) *psin = sinf(x); *pcos = cosf(x); } + +void sincosl(long double x, long double *psin, long double *pcos) +{ + *psin = sin(x); + *pcos = cos(x); +} From 84baa86362e2ef2fb3ec435e5095f51b17cea52d Mon Sep 17 00:00:00 2001 From: Bruce Beare Date: Fri, 4 Jun 2010 08:14:44 -0700 Subject: [PATCH 09/93] Add missing termios defns to bring on par with ARM Change-Id: Ied1871aa0a2e33473b89a4ac6d54e3c44be7f457 --- libc/kernel/arch-x86/asm/termios.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/libc/kernel/arch-x86/asm/termios.h b/libc/kernel/arch-x86/asm/termios.h index 4a38aeecd..6542c781a 100644 --- a/libc/kernel/arch-x86/asm/termios.h +++ b/libc/kernel/arch-x86/asm/termios.h @@ -47,4 +47,21 @@ struct termio { #define TIOCM_OUT2 0x4000 #define TIOCM_LOOP 0x8000 +#define N_TTY 0 +#define N_SLIP 1 +#define N_MOUSE 2 +#define N_PPP 3 +#define N_STRIP 4 +#define N_AX25 5 +#define N_X25 6 +#define N_6PACK 7 +#define N_MASC 8 +#define N_R3964 9 +#define N_PROFIBUS_FDL 10 +#define N_IRDA 11 +#define N_SMSBLOCK 12 +#define N_HDLC 13 +#define N_SYNC_PPP 14 +#define N_HCI 15 + #endif From b508876e4cead5430288d489a2aa50d7f0078f0d Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Wed, 9 Jun 2010 15:51:43 -0700 Subject: [PATCH 10/93] Add headers for new sensors Change-Id: I1de2bf65310920b3496c58f05b3c39158de4c51d --- libc/kernel/common/linux/akm8975.h | 72 +++++++++++++++++++++++++++++ libc/kernel/common/linux/l3g4200d.h | 27 +++++++++++ libc/kernel/common/linux/max9635.h | 23 +++++++++ 3 files changed, 122 insertions(+) create mode 100644 libc/kernel/common/linux/akm8975.h create mode 100644 libc/kernel/common/linux/l3g4200d.h create mode 100644 libc/kernel/common/linux/max9635.h diff --git a/libc/kernel/common/linux/akm8975.h b/libc/kernel/common/linux/akm8975.h new file mode 100644 index 000000000..1815f75a9 --- /dev/null +++ b/libc/kernel/common/linux/akm8975.h @@ -0,0 +1,72 @@ +/**************************************************************************** + **************************************************************************** + *** + *** This header was automatically generated from a Linux kernel header + *** of the same name, to make information necessary for userspace to + *** call into the kernel available to libc. It contains only constants, + *** structures, and macros generated from the original header, and thus, + *** contains no copyrightable information. + *** + **************************************************************************** + ****************************************************************************/ +#ifndef AKM8975_H +#define AKM8975_H + +#include + +#define AK8975_MODE_SNG_MEASURE 0x01 +#define AK8975_MODE_SELF_TEST 0x08 +#define AK8975_MODE_FUSE_ACCESS 0x0F +#define AK8975_MODE_POWER_DOWN 0x00 + +#define RBUFF_SIZE 8 + +#define AK8975_REG_WIA 0x00 +#define AK8975_REG_INFO 0x01 +#define AK8975_REG_ST1 0x02 +#define AK8975_REG_HXL 0x03 +#define AK8975_REG_HXH 0x04 +#define AK8975_REG_HYL 0x05 +#define AK8975_REG_HYH 0x06 +#define AK8975_REG_HZL 0x07 +#define AK8975_REG_HZH 0x08 +#define AK8975_REG_ST2 0x09 +#define AK8975_REG_CNTL 0x0A +#define AK8975_REG_RSV 0x0B +#define AK8975_REG_ASTC 0x0C +#define AK8975_REG_TS1 0x0D +#define AK8975_REG_TS2 0x0E +#define AK8975_REG_I2CDIS 0x0F + +#define AK8975_FUSE_ASAX 0x10 +#define AK8975_FUSE_ASAY 0x11 +#define AK8975_FUSE_ASAZ 0x12 + +#define AKMIO 0xA1 + +#define ECS_IOCTL_WRITE _IOW(AKMIO, 0x02, char[5]) +#define ECS_IOCTL_READ _IOWR(AKMIO, 0x03, char[5]) +#define ECS_IOCTL_GETDATA _IOR(AKMIO, 0x08, char[RBUFF_SIZE]) +#define ECS_IOCTL_SET_YPR _IOW(AKMIO, 0x0C, short[12]) +#define ECS_IOCTL_GET_OPEN_STATUS _IOR(AKMIO, 0x0D, int) +#define ECS_IOCTL_GET_CLOSE_STATUS _IOR(AKMIO, 0x0E, int) +#define ECS_IOCTL_GET_DELAY _IOR(AKMIO, 0x30, short) + +#define ECS_IOCTL_APP_SET_MFLAG _IOW(AKMIO, 0x11, short) +#define ECS_IOCTL_APP_GET_MFLAG _IOW(AKMIO, 0x12, short) +#define ECS_IOCTL_APP_SET_AFLAG _IOW(AKMIO, 0x13, short) +#define ECS_IOCTL_APP_GET_AFLAG _IOR(AKMIO, 0x14, short) +#define ECS_IOCTL_APP_SET_DELAY _IOW(AKMIO, 0x18, short) +#define ECS_IOCTL_APP_GET_DELAY ECS_IOCTL_GET_DELAY +#define ECS_IOCTL_APP_SET_MVFLAG _IOW(AKMIO, 0x19, short) +#define ECS_IOCTL_APP_GET_MVFLAG _IOR(AKMIO, 0x1A, short) +#define ECS_IOCTL_APP_SET_TFLAG _IOR(AKMIO, 0x15, short) + +#define ECS_INTR 140 + +struct akm8975_platform_data { + int intr; +}; + +#endif + diff --git a/libc/kernel/common/linux/l3g4200d.h b/libc/kernel/common/linux/l3g4200d.h new file mode 100644 index 000000000..0a0f8cd2f --- /dev/null +++ b/libc/kernel/common/linux/l3g4200d.h @@ -0,0 +1,27 @@ +/**************************************************************************** + **************************************************************************** + *** + *** This header was automatically generated from a Linux kernel header + *** of the same name, to make information necessary for userspace to + *** call into the kernel available to libc. It contains only constants, + *** structures, and macros generated from the original header, and thus, + *** contains no copyrightable information. + *** + **************************************************************************** + ****************************************************************************/ +#ifndef __L3G4200D_H__ +#define __L3G4200D_H__ + +#include + +#define L3G4200D_NAME "l3g4200d" + +#define L3G4200D_IOCTL_BASE 77 + +#define L3G4200D_IOCTL_SET_DELAY _IOW(L3G4200D_IOCTL_BASE, 0, int) +#define L3G4200D_IOCTL_GET_DELAY _IOR(L3G4200D_IOCTL_BASE, 1, int) +#define L3G4200D_IOCTL_SET_ENABLE _IOW(L3G4200D_IOCTL_BASE, 2, int) +#define L3G4200D_IOCTL_GET_ENABLE _IOR(L3G4200D_IOCTL_BASE, 3, int) + +#endif + diff --git a/libc/kernel/common/linux/max9635.h b/libc/kernel/common/linux/max9635.h new file mode 100644 index 000000000..e696fa9ec --- /dev/null +++ b/libc/kernel/common/linux/max9635.h @@ -0,0 +1,23 @@ +/**************************************************************************** + **************************************************************************** + *** + *** This header was automatically generated from a Linux kernel header + *** of the same name, to make information necessary for userspace to + *** call into the kernel available to libc. It contains only constants, + *** structures, and macros generated from the original header, and thus, + *** contains no copyrightable information. + *** + **************************************************************************** + ****************************************************************************/ +#ifndef _LINUX_MAX9635_H__ +#define _LINUX_MAX9635_H__ + +#define MAX9635_NAME "MAX9635_als" +#define FOPS_MAX9635_NAME "MAX9635" + +#define MAX9635_IO 0xA3 + +#define MAX9635_IOCTL_GET_ENABLE _IOR(MAX9635_IO, 0x00, char) +#define MAX9635_IOCTL_SET_ENABLE _IOW(MAX9635_IO, 0x01, char) + +#endif From 4032c1e2dfcc99613fe3e509a8153191e35aec12 Mon Sep 17 00:00:00 2001 From: Szymon Jakubczak Date: Wed, 9 Jun 2010 15:53:28 -0400 Subject: [PATCH 11/93] added missing ether_aton and ether_ntoa Change-Id: I32ee448abde4d5693d393030ed77ddc6d2ad1dfc --- libc/Android.mk | 2 + libc/include/net/if_ether.h | 2 + libc/inet/ether_aton.c | 89 +++++++++++++++++++++++++++++++++++++ libc/inet/ether_ntoa.c | 55 +++++++++++++++++++++++ 4 files changed, 148 insertions(+) create mode 100644 libc/inet/ether_aton.c create mode 100644 libc/inet/ether_ntoa.c diff --git a/libc/Android.mk b/libc/Android.mk index 8dd124e14..37112ccf0 100644 --- a/libc/Android.mk +++ b/libc/Android.mk @@ -207,6 +207,8 @@ libc_common_src_files := \ inet/inet_ntoa.c \ inet/inet_ntop.c \ inet/inet_pton.c \ + inet/ether_aton.c \ + inet/ether_ntoa.c \ tzcode/asctime.c \ tzcode/difftime.c \ tzcode/localtime.c \ diff --git a/libc/include/net/if_ether.h b/libc/include/net/if_ether.h index 121f9ac97..8daa16b6c 100644 --- a/libc/include/net/if_ether.h +++ b/libc/include/net/if_ether.h @@ -34,6 +34,8 @@ #ifndef _NET_IF_ETHER_H_ #define _NET_IF_ETHER_H_ +#include + #ifdef _KERNEL #ifdef _KERNEL_OPT #include "opt_mbuftrace.h" diff --git a/libc/inet/ether_aton.c b/libc/inet/ether_aton.c new file mode 100644 index 000000000..6540c0736 --- /dev/null +++ b/libc/inet/ether_aton.c @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2010 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 +#include +#include +#include +#include + +static inline int +xdigit (char c) { + unsigned d; + d = (unsigned)(c-'0'); + if (d < 10) return (int)d; + d = (unsigned)(c-'a'); + if (d < 6) return (int)(10+d); + d = (unsigned)(c-'A'); + if (d < 6) return (int)(10+d); + return -1; +} + +/* + * Convert Ethernet address in the standard hex-digits-and-colons to binary + * representation. + * Re-entrant version (GNU extensions) + */ +struct ether_addr * +ether_aton_r (const char *asc, struct ether_addr * addr) +{ + int i, val0, val1; + for (i = 0; i < ETHER_ADDR_LEN; ++i) { + val0 = xdigit(*asc); + asc++; + if (val0 < 0) + return NULL; + + val1 = xdigit(*asc); + asc++; + if (val1 < 0) + return NULL; + + addr->ether_addr_octet[i] = (u_int8_t)((val0 << 4) + val1); + + if (i < ETHER_ADDR_LEN - 1) { + if (*asc != ':') + return NULL; + asc++; + } + } + if (*asc != '\0') + return NULL; + return addr; +} + +/* + * Convert Ethernet address in the standard hex-digits-and-colons to binary + * representation. + */ +struct ether_addr * +ether_aton (const char *asc) +{ + static struct ether_addr addr; + return ether_aton_r(asc, &addr); +} diff --git a/libc/inet/ether_ntoa.c b/libc/inet/ether_ntoa.c new file mode 100644 index 000000000..f56e48b24 --- /dev/null +++ b/libc/inet/ether_ntoa.c @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2010 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 +#include +#include + +/* + * Convert Ethernet address to standard hex-digits-and-colons printable form. + * Re-entrant version (GNU extensions). + */ +char * +ether_ntoa_r (const struct ether_addr *addr, char * buf) +{ + snprintf(buf, 18, "%02x:%02x:%02x:%02x:%02x:%02x", + addr->ether_addr_octet[0], addr->ether_addr_octet[1], + addr->ether_addr_octet[2], addr->ether_addr_octet[3], + addr->ether_addr_octet[4], addr->ether_addr_octet[5]); + return buf; +} + +/* + * Convert Ethernet address to standard hex-digits-and-colons printable form. + */ +char * +ether_ntoa (const struct ether_addr *addr) +{ + static char buf[18]; + return ether_ntoa_r(addr, buf); +} From 70465614e14a87f547cdd1b82b0b270b87d215c1 Mon Sep 17 00:00:00 2001 From: Kristian Monsen Date: Wed, 16 Jun 2010 14:51:52 +0100 Subject: [PATCH 12/93] Just link fixes for b 2763938. Added wcsxfrm.c and wmemcmp.c to the src files in Android.mk and removed wcsxfrm from wchar.c Change-Id: Iab9b45cf78c27880d2941c360340a7af6b8964fe --- libc/Android.mk | 2 ++ libc/stdlib/wchar.c | 6 ------ 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/libc/Android.mk b/libc/Android.mk index b0301ef67..4cfa17c66 100644 --- a/libc/Android.mk +++ b/libc/Android.mk @@ -229,7 +229,9 @@ libc_common_src_files := \ wchar/wcsstr.c \ wchar/wcstok.c \ wchar/wcswidth.c \ + wchar/wcsxfrm.c \ wchar/wmemchr.c \ + wchar/wmemcmp.c \ wchar/wmemcpy.c \ wchar/wmemmove.c \ wchar/wmemset.c \ diff --git a/libc/stdlib/wchar.c b/libc/stdlib/wchar.c index 148021295..d83613a6b 100644 --- a/libc/stdlib/wchar.c +++ b/libc/stdlib/wchar.c @@ -302,12 +302,6 @@ wchar_t *wcswcs(const wchar_t *ws1, const wchar_t *ws2) return (wchar_t*) strstr( (const char*)ws1, (const char*)ws2 ); } -size_t wcsxfrm(wchar_t *ws1, const wchar_t *ws2, size_t n) -{ - memcpy( (char*)ws1, (const char*)ws2, n ); - return n; -} - int wctob(wint_t c) { return c; From b44fcd6e8f661e7e795212a3b68aa171ab6e49c9 Mon Sep 17 00:00:00 2001 From: Mikael Ohlson Date: Fri, 21 May 2010 11:20:39 +0200 Subject: [PATCH 13/93] Fix for incorrect reply from sysconf(_SC_NPROCESSORS_ONLN) When calling sysconf with _SC_NPROCESSORS_ONLN, the value one (1) was returned on systems with two or more cores, since '/proc/stat' was incorrectly parsed. The function line_parser_getc (LineParser* p) read 128 characters of input for each invocation. The proper and probably aimed for behavior is to read 128 characters at the first call, then for each subsequent call only return the next buffered character until a new read is needed and only then read another 128 characters. Due to a flipped comparison between the two variables in_len and in_pos that track the number of bytes of data read into the input buffer and how much of it has been parsed, a new group of 128 characters were read at almost every call to line_parser_getc, overwriting the still unhandled bytes from the previous call to read. This caused the lines to be read to be sampled more than parsed. Change-Id: I93eec3c8c9b9f19ef798748579d0977111b5c0bb Signed-off-by: Christian Bejram --- libc/unistd/sysconf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libc/unistd/sysconf.c b/libc/unistd/sysconf.c index d3089a4a4..dedc5bc17 100644 --- a/libc/unistd/sysconf.c +++ b/libc/unistd/sysconf.c @@ -317,7 +317,7 @@ line_parser_addc( LineParser* p, int c ) static int line_parser_getc( LineParser* p ) { - if (p->in_len >= p->in_pos) { + if (p->in_pos >= p->in_len) { int ret; p->in_len = p->in_pos = 0; From 2bf607d599b703604cb1caf5beeb2e70c44682fb Mon Sep 17 00:00:00 2001 From: Chris Peterson Date: Sun, 27 Jun 2010 20:53:04 -0700 Subject: [PATCH 14/93] Change-Id: I68cc462aeb2460345a53bdb9941ce4bfc10456fb bionic: fix clearenv() compiler warning and related comment typos --- libc/bionic/clearenv.c | 8 ++++---- libc/bionic/libc_init_common.c | 2 +- libc/bionic/libc_init_dynamic.c | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/libc/bionic/clearenv.c b/libc/bionic/clearenv.c index ffc58d9fe..9a3b2a1d9 100644 --- a/libc/bionic/clearenv.c +++ b/libc/bionic/clearenv.c @@ -30,10 +30,10 @@ extern char** environ; int clearenv(void) { - char **P = environ; - int offset; + char **P; - for (P = &environ[offset]; *P; ++P) + for (P = environ; *P; ++P) *P = 0; - return 0; + + return 0; } diff --git a/libc/bionic/libc_init_common.c b/libc/bionic/libc_init_common.c index d78d673f0..dd6e027f8 100644 --- a/libc/bionic/libc_init_common.c +++ b/libc/bionic/libc_init_common.c @@ -62,7 +62,7 @@ void __libc_init_common(uintptr_t *elfdata) static pthread_internal_t thread; static void* tls_area[BIONIC_TLS_SLOTS]; - /* setup pthread runtime and maint thread descriptor */ + /* setup pthread runtime and main thread descriptor */ unsigned stacktop = (__get_sp() & ~(PAGE_SIZE - 1)) + PAGE_SIZE; unsigned stacksize = 128 * 1024; unsigned stackbottom = stacktop - stacksize; diff --git a/libc/bionic/libc_init_dynamic.c b/libc/bionic/libc_init_dynamic.c index 682ebcfd3..97e80eaec 100644 --- a/libc/bionic/libc_init_dynamic.c +++ b/libc/bionic/libc_init_dynamic.c @@ -61,7 +61,7 @@ void __attribute__((constructor)) __libc_prenit(void); void __libc_prenit(void) { - /* Read the ELF data pointer form a special slot of the + /* Read the ELF data pointer from a special slot of the * TLS area, then call __libc_init_common with it. * * Note that: From c1a534ba0bc58c74bf06e7735c6fb0ffb27a6652 Mon Sep 17 00:00:00 2001 From: Vilmos Nebehaj Date: Mon, 28 Jun 2010 15:13:23 +0200 Subject: [PATCH 15/93] Regenerate linux/netfilter_ipv6/ip6_tables.h. Add ip6t_get_target() to kernel_known_generic_statics in libc/kernel/tools/defaults.py to be able to build ip6tables. Change-Id: Iadb885db3faa85b2d0070dc2e0ac493af6e62bb6 --- libc/kernel/common/linux/netfilter_ipv6/ip6_tables.h | 9 +++++++++ libc/kernel/tools/defaults.py | 1 + 2 files changed, 10 insertions(+) diff --git a/libc/kernel/common/linux/netfilter_ipv6/ip6_tables.h b/libc/kernel/common/linux/netfilter_ipv6/ip6_tables.h index 1687e4fea..d76a52926 100644 --- a/libc/kernel/common/linux/netfilter_ipv6/ip6_tables.h +++ b/libc/kernel/common/linux/netfilter_ipv6/ip6_tables.h @@ -173,6 +173,15 @@ struct ip6t_get_entries #define IP6T_ERROR_TARGET XT_ERROR_TARGET +static __inline__ struct ip6t_entry_target * +ip6t_get_target(struct ip6t_entry *e) +{ + return (void *)e + e->target_offset; +} + #define IP6T_MATCH_ITERATE(e, fn, args...) ({ unsigned int __i; int __ret = 0; struct ip6t_entry_match *__m; for (__i = sizeof(struct ip6t_entry); __i < (e)->target_offset; __i += __m->u.match_size) { __m = (void *)(e) + __i; __ret = fn(__m , ## args); if (__ret != 0) break; } __ret; }) + #define IP6T_ENTRY_ITERATE(entries, size, fn, args...) ({ unsigned int __i; int __ret = 0; struct ip6t_entry *__e; for (__i = 0; __i < (size); __i += __e->next_offset) { __e = (void *)(entries) + __i; __ret = fn(__e , ## args); if (__ret != 0) break; } __ret; }) + #endif + diff --git a/libc/kernel/tools/defaults.py b/libc/kernel/tools/defaults.py index 4227de74c..b35f72b5a 100644 --- a/libc/kernel/tools/defaults.py +++ b/libc/kernel/tools/defaults.py @@ -71,6 +71,7 @@ kernel_known_generic_statics = set( "__cmsg_nxthdr", # linux/socket.h "cmsg_nxthdr", # linux/socket.h "ipt_get_target", + "ip6t_get_target", ] ) From ccc3d1eea124cbeb1ec2d711d5892db1dd4445d3 Mon Sep 17 00:00:00 2001 From: Wink Saville Date: Mon, 28 Jun 2010 11:41:16 -0700 Subject: [PATCH 16/93] Use a recursive lock for pthread_once. bug: 2292366 Change-Id: I9fc8b790dcfcb30ca94a0beb340d43fe5cd6c22e --- libc/bionic/pthread.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libc/bionic/pthread.c b/libc/bionic/pthread.c index 061cce1e8..a60da2703 100644 --- a/libc/bionic/pthread.c +++ b/libc/bionic/pthread.c @@ -1861,15 +1861,15 @@ int pthread_getcpuclockid(pthread_t tid, clockid_t *clockid) */ int pthread_once( pthread_once_t* once_control, void (*init_routine)(void) ) { - static pthread_mutex_t once_lock = PTHREAD_MUTEX_INITIALIZER; + static pthread_mutex_t once_lock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER; if (*once_control == PTHREAD_ONCE_INIT) { - _normal_lock( &once_lock ); + pthread_mutex_lock( &once_lock ); if (*once_control == PTHREAD_ONCE_INIT) { (*init_routine)(); *once_control = ~PTHREAD_ONCE_INIT; } - _normal_unlock( &once_lock ); + pthread_mutex_unlock( &once_lock ); } return 0; } From 3b43f87d2949a340e2c19cb735af7727157d8274 Mon Sep 17 00:00:00 2001 From: David 'Digit' Turner Date: Thu, 1 Jul 2010 23:09:28 -0700 Subject: [PATCH 17/93] Allow dlclose() to properly call static C++ destructors. With this patch _and_ an upcoming build/ patch, the destruction of static C++ objects contained in shared libraries will happen properly when dlclose() is called. Note that this change introduces crtbegin_so.S and crtend_so.S which are currently ignored by the build system. + move definition of __dso_handle to the right place (before that, all shared libraries used the __dso_handle global variable from the C library). Note that we keep a 'weak' __dso_handle in aeabi.c to avoid breaking the build until the next patch to build/core/combo/ appears. We will be able to remove that later. + move bionic/aeabi.c to arch-arm/bionic/ (its proper location) NOTE: The NDK will need to be modified to enable this feature in the shared libraries that are generated through it. Change-Id: I99cd801375bbaef0581175893d1aa0943211b9bc --- libc/Android.mk | 22 +++++++--- libc/arch-arm/bionic/crtbegin_dynamic.S | 11 ++--- libc/arch-arm/bionic/crtbegin_so.S | 55 +++++++++++++++++++++++++ libc/arch-arm/bionic/crtbegin_static.S | 10 ++--- libc/arch-arm/bionic/crtend_so.S | 38 +++++++++++++++++ libc/{ => arch-arm}/bionic/eabi.c | 16 ++++++- libc/arch-sh/bionic/crtbegin_dynamic.S | 6 ++- libc/arch-sh/bionic/crtbegin_static.S | 9 +--- libc/arch-x86/bionic/crtbegin_dynamic.S | 3 +- libc/arch-x86/bionic/crtbegin_so.S | 10 +++++ libc/arch-x86/bionic/crtbegin_static.S | 7 +--- libc/private/__dso_handle.S | 37 +++++++++++++++++ 12 files changed, 186 insertions(+), 38 deletions(-) create mode 100644 libc/arch-arm/bionic/crtbegin_so.S create mode 100644 libc/arch-arm/bionic/crtend_so.S rename libc/{ => arch-arm}/bionic/eabi.c (83%) create mode 100644 libc/private/__dso_handle.S diff --git a/libc/Android.mk b/libc/Android.mk index 772aa07a2..8994ebc9b 100644 --- a/libc/Android.mk +++ b/libc/Android.mk @@ -291,7 +291,6 @@ libc_common_src_files := \ # ========================================================= ifeq ($(TARGET_ARCH),arm) libc_common_src_files += \ - bionic/eabi.c \ bionic/bionic_clone.c \ arch-arm/bionic/__get_pc.S \ arch-arm/bionic/__get_sp.S \ @@ -299,6 +298,7 @@ libc_common_src_files += \ arch-arm/bionic/_setjmp.S \ arch-arm/bionic/atomics_arm.S \ arch-arm/bionic/clone.S \ + arch-arm/bionic/eabi.c \ arch-arm/bionic/ffs.S \ arch-arm/bionic/kill.S \ arch-arm/bionic/libgcc_compat.c \ @@ -393,7 +393,6 @@ libc_common_src_files += \ string/strncmp.c \ string/memcmp.c \ string/strlen.c \ - bionic/eabi.c \ bionic/pthread.c \ bionic/pthread-timers.c \ bionic/ptrace.c \ @@ -461,16 +460,27 @@ libc_common_c_includes := \ $(LOCAL_PATH)/string \ $(LOCAL_PATH)/stdio +# Needed to access private/__dso_handle.S from +# crtbegin_xxx.S and crtend_xxx.S +# +libc_crt_target_cflags += -I$(LOCAL_PATH)/private # Define the libc run-time (crt) support object files that must be built, # which are needed to build all other objects (shared/static libs and # executables) # ========================================================================== -ifeq ($(TARGET_ARCH),x86) -# we only need begin_so/end_so for x86, since it needs an appropriate .init -# section in the shared library with a function to call all the entries in -# .ctors section. ARM uses init_array, and does not need the function. +ifneq ($(filter arm x86,$(TARGET_ARCH)),) +# ARM and x86 need crtbegin_so/crtend_so. +# +# For x86, the .init section must point to a function that calls all +# entries in the .ctors section. (on ARM this is done through the +# .init_array section instead). +# +# For both platforms, the .fini_array section must point to a function +# that will call __cxa_finalize(&__dso_handle) in order to ensure that +# static C++ destructors are properly called on dlclose(). +# GEN := $(TARGET_OUT_STATIC_LIBRARIES)/crtbegin_so.o $(GEN): $(LOCAL_PATH)/arch-$(TARGET_ARCH)/bionic/crtbegin_so.S @mkdir -p $(dir $@) diff --git a/libc/arch-arm/bionic/crtbegin_dynamic.S b/libc/arch-arm/bionic/crtbegin_dynamic.S index e26592317..d18e715f5 100644 --- a/libc/arch-arm/bionic/crtbegin_dynamic.S +++ b/libc/arch-arm/bionic/crtbegin_dynamic.S @@ -31,7 +31,7 @@ .globl _start # this is the small startup code that is first run when -# any executable that is statically-linked with Bionic +# any executable that is dynamically-linked with Bionic # runs. # # it's purpose is to call __libc_init with appropriate @@ -63,13 +63,7 @@ _start: .long __INIT_ARRAY__ .long __FINI_ARRAY__ .long __CTOR_LIST__ - -# the .ctors section contains a list of pointers to "constructor" -# functions that need to be called in order during C library initialization, -# just before the program is being run. This is a C++ requirement -# -# the last entry shall be 0, and is defined in crtend.S -# + .section .preinit_array, "aw" .globl __PREINIT_ARRAY__ __PREINIT_ARRAY__: @@ -90,3 +84,4 @@ __FINI_ARRAY__: __CTOR_LIST__: .long -1 +#include "__dso_handle.S" diff --git a/libc/arch-arm/bionic/crtbegin_so.S b/libc/arch-arm/bionic/crtbegin_so.S new file mode 100644 index 000000000..bb6b3e2c3 --- /dev/null +++ b/libc/arch-arm/bionic/crtbegin_so.S @@ -0,0 +1,55 @@ +/* + * 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. + */ + +# Implement static C++ destructors when the shared +# library is unloaded through dlclose(). +# +# A call to this function must be the first entry +# in the .fini_array. See 3.3.5.3.C of C++ ABI +# standard. +# +__on_dlclose: + adr r0, 0f + ldr r0, [r0] + b __cxa_finalize + +0: + .long __dso_handle + + .section .init_array, "aw" + .globl __INIT_ARRAY__ +__INIT_ARRAY__: + .long -1 + + .section .fini_array, "aw" + .globl __FINI_ARRAY__ +__FINI_ARRAY__: + .long -1 + .long __on_dlclose + +#include "__dso_handle.S" diff --git a/libc/arch-arm/bionic/crtbegin_static.S b/libc/arch-arm/bionic/crtbegin_static.S index e26592317..6f9cf25dd 100644 --- a/libc/arch-arm/bionic/crtbegin_static.S +++ b/libc/arch-arm/bionic/crtbegin_static.S @@ -63,13 +63,7 @@ _start: .long __INIT_ARRAY__ .long __FINI_ARRAY__ .long __CTOR_LIST__ - -# the .ctors section contains a list of pointers to "constructor" -# functions that need to be called in order during C library initialization, -# just before the program is being run. This is a C++ requirement -# -# the last entry shall be 0, and is defined in crtend.S -# + .section .preinit_array, "aw" .globl __PREINIT_ARRAY__ __PREINIT_ARRAY__: @@ -90,3 +84,5 @@ __FINI_ARRAY__: __CTOR_LIST__: .long -1 + +#include "__dso_handle.S" diff --git a/libc/arch-arm/bionic/crtend_so.S b/libc/arch-arm/bionic/crtend_so.S new file mode 100644 index 000000000..a1281c402 --- /dev/null +++ b/libc/arch-arm/bionic/crtend_so.S @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2010 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. + */ + +/* This is the same than crtend.S except that a shared library + * cannot have a .preinit_array + */ + + .section .init_array, "aw" + .long 0 + + .section .fini_array, "aw" + .long 0 + diff --git a/libc/bionic/eabi.c b/libc/arch-arm/bionic/eabi.c similarity index 83% rename from libc/bionic/eabi.c rename to libc/arch-arm/bionic/eabi.c index a5f662746..3f26f2b45 100644 --- a/libc/bionic/eabi.c +++ b/libc/arch-arm/bionic/eabi.c @@ -30,7 +30,21 @@ extern int __cxa_atexit(void (*)(void*), void*, void* ); -void* __dso_handle = 0; +/* Temporary hack: this variable should not be part of the C library + * itself, but placed in the .bss section of each executable or + * shared library instead. + * + * We keep it here temporarily until the build system has been + * modified properly to use crtbegin_so.S and crtend_so.S when + * generating shared libraries. + * + * It must be a 'weak' symbol to avoid conflicts with the definitions + * that have been moved to crtbegin_static.S and crtbegin_dynamic.S + * + * For the record, it is used for static C++ object construction + * and destruction. See http://www.codesourcery.com/public/cxx-abi/abi.html#dso-dtor + */ +void* __attribute__((weak)) __dso_handle; /* The "C++ ABI for ARM" document states that static C++ constructors, * which are called from the .init_array, should manually call diff --git a/libc/arch-sh/bionic/crtbegin_dynamic.S b/libc/arch-sh/bionic/crtbegin_dynamic.S index dc485dda5..daf6c8b5b 100644 --- a/libc/arch-sh/bionic/crtbegin_dynamic.S +++ b/libc/arch-sh/bionic/crtbegin_dynamic.S @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009 The Android Open Source Project + * Copyright (C) 2009-2010 The Android Open Source Project * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -31,7 +31,7 @@ .globl _start # this is the small startup code that is first run when -# any executable that is statically-linked with Bionic +# any executable that is dynamically-linked with Bionic # runs. # # it's purpose is to call __libc_init with appropriate @@ -93,3 +93,5 @@ __FINI_ARRAY__: .globl __CTOR_LIST__ __CTOR_LIST__: .long -1 + +#include "__dso_handle.S" diff --git a/libc/arch-sh/bionic/crtbegin_static.S b/libc/arch-sh/bionic/crtbegin_static.S index 97db1e45a..1d3fdf839 100644 --- a/libc/arch-sh/bionic/crtbegin_static.S +++ b/libc/arch-sh/bionic/crtbegin_static.S @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009 The Android Open Source Project + * Copyright (C) 2009-2010 The Android Open Source Project * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -68,12 +68,6 @@ _start: .long __FINI_ARRAY__ .long __CTOR_LIST__ -# the .ctors section contains a list of pointers to "constructor" -# functions that need to be called in order during C library initialization, -# just before the program is being run. This is a C++ requirement -# -# the last entry shall be 0, and is defined in crtend.S -# .section .preinit_array, "aw" .globl __PREINIT_ARRAY__ __PREINIT_ARRAY__: @@ -94,3 +88,4 @@ __FINI_ARRAY__: __CTOR_LIST__: .long -1 +#include "__dso_handle.S" diff --git a/libc/arch-x86/bionic/crtbegin_dynamic.S b/libc/arch-x86/bionic/crtbegin_dynamic.S index 3b47b18ef..88e7e6a0a 100644 --- a/libc/arch-x86/bionic/crtbegin_dynamic.S +++ b/libc/arch-x86/bionic/crtbegin_dynamic.S @@ -30,7 +30,7 @@ .globl _start # this is the small startup code that is first run when -# any executable that is statically-linked with Bionic +# any executable that is dynamically-linked with Bionic # runs. # # it's purpose is to call __libc_init with appropriate @@ -94,3 +94,4 @@ __FINI_ARRAY__: __CTOR_LIST__: .long -1 +#include "__dso_handle.S" diff --git a/libc/arch-x86/bionic/crtbegin_so.S b/libc/arch-x86/bionic/crtbegin_so.S index d49e9df83..d879feff0 100644 --- a/libc/arch-x86/bionic/crtbegin_so.S +++ b/libc/arch-x86/bionic/crtbegin_so.S @@ -1,3 +1,10 @@ +# This function is to be called when the shared library +# is unloaded through dlclose() +_on_dlclose: + lea __dso_handle, %eax + call __cxa_finalize + ret + /* we put the _init() function here in case the user files for the shared * libs want to drop things into .init section. * We then will call our ctors from crtend_so.o */ @@ -20,6 +27,7 @@ __INIT_ARRAY__: .globl __FINI_ARRAY__ __FINI_ARRAY__: .long -1 + .long _on_dlclose .section .ctors, "aw" .align 4 @@ -27,3 +35,5 @@ __FINI_ARRAY__: .globl __CTOR_LIST__ __CTOR_LIST__: .long -1 + +#include "__dso_handle.S" diff --git a/libc/arch-x86/bionic/crtbegin_static.S b/libc/arch-x86/bionic/crtbegin_static.S index eb4acee8f..3f8446ec7 100644 --- a/libc/arch-x86/bionic/crtbegin_static.S +++ b/libc/arch-x86/bionic/crtbegin_static.S @@ -67,12 +67,6 @@ _start: .long __FINI_ARRAY__ .long __CTOR_LIST__ -# the .ctors section contains a list of pointers to "constructor" -# functions that need to be called in order during C library initialization, -# just before the program is being run. This is a C++ requirement -# -# the last entry shall be 0, and is defined in crtend.S -# .section .preinit_array, "aw" .globl __PREINIT_ARRAY__ __PREINIT_ARRAY__: @@ -93,3 +87,4 @@ __FINI_ARRAY__: __CTOR_LIST__: .long -1 +#include "__dso_handle.S" diff --git a/libc/private/__dso_handle.S b/libc/private/__dso_handle.S new file mode 100644 index 000000000..fcebab642 --- /dev/null +++ b/libc/private/__dso_handle.S @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2010 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. + */ + +# The __dso_handle global variable is used by static +# C++ constructors and destructors in the binary. +# See http://www.codesourcery.com/public/cxx-abi/abi.html#dso-dtor +# + .section .bss + .align 4 + .globl __dso_handle +__dso_handle: + .long 0 From 16984423bc67cd334d74b585bac2c01e44583624 Mon Sep 17 00:00:00 2001 From: Bruce Beare Date: Fri, 25 Jun 2010 09:02:10 -0700 Subject: [PATCH 18/93] Fix missing NL Change-Id: Ic210fe9f740b9a8235a66d479ad4eddc869998bb Signed-off-by: Bruce Beare --- libc/arch-x86/bionic/clone.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libc/arch-x86/bionic/clone.S b/libc/arch-x86/bionic/clone.S index 3b50cc3d3..44fce1e4a 100644 --- a/libc/arch-x86/bionic/clone.S +++ b/libc/arch-x86/bionic/clone.S @@ -52,4 +52,4 @@ __pthread_clone: /* XXX: TODO: Add __bionic_clone here * See bionic/bionic_clone.c and arch-arm/bionic/clone.S * for more details... - */ \ No newline at end of file + */ From aa46fa24035f3ab020f9a7abd86c25ae2196bb32 Mon Sep 17 00:00:00 2001 From: Bruce Beare Date: Thu, 8 Jul 2010 14:47:50 -0700 Subject: [PATCH 19/93] Fix undefined reference to dl_iterate_phdr for x86 Change-Id: I22410b27939e8f54da932d7a1104102550c4685f Signed-off-by: Bruce Beare --- libc/Android.mk | 1 + 1 file changed, 1 insertion(+) diff --git a/libc/Android.mk b/libc/Android.mk index 8994ebc9b..7a7d9e30d 100644 --- a/libc/Android.mk +++ b/libc/Android.mk @@ -640,6 +640,7 @@ LOCAL_MODULE:= libc_malloc_debug_leak LOCAL_SHARED_LIBRARIES := libc LOCAL_WHOLE_STATIC_LIBRARIES := libc_common LOCAL_SYSTEM_SHARED_LIBRARIES := +LOCAL_ALLOW_UNDEFINED_SYMBOLS := true # Don't prelink LOCAL_PRELINK_MODULE := false # Don't install on release build From 42f160ddfa54d438849e12ff84094222799ed258 Mon Sep 17 00:00:00 2001 From: Mike Lockwood Date: Thu, 15 Jul 2010 12:33:44 -0400 Subject: [PATCH 20/93] Add header for MTP kernel driver. Change-Id: I072e476c28535198689afbe2320a291fa42fe05b Signed-off-by: Mike Lockwood --- libc/kernel/common/linux/usb/f_mtp.h | 42 ++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 libc/kernel/common/linux/usb/f_mtp.h diff --git a/libc/kernel/common/linux/usb/f_mtp.h b/libc/kernel/common/linux/usb/f_mtp.h new file mode 100644 index 000000000..e155e7e0a --- /dev/null +++ b/libc/kernel/common/linux/usb/f_mtp.h @@ -0,0 +1,42 @@ +/**************************************************************************** + **************************************************************************** + *** + *** This header was automatically generated from a Linux kernel header + *** of the same name, to make information necessary for userspace to + *** call into the kernel available to libc. It contains only constants, + *** structures, and macros generated from the original header, and thus, + *** contains no copyrightable information. + *** + **************************************************************************** + ****************************************************************************/ +#ifndef __LINUX_USB_F_MTP_H +#define __LINUX_USB_F_MTP_H + +#define MTP_INTERFACE_MODE_MTP 0 +#define MTP_INTERFACE_MODE_PTP 1 + +struct mtp_file_range { + + int fd; + + loff_t offset; + + size_t length; +}; + +struct mtp_event { + + size_t length; + + void *data; +}; + +#define MTP_SEND_FILE _IOW('M', 0, struct mtp_file_range) + +#define MTP_RECEIVE_FILE _IOW('M', 1, struct mtp_file_range) + +#define MTP_SET_INTERFACE_MODE _IOW('M', 2, int) + +#define MTP_SEND_EVENT _IOW('M', 3, struct mtp_event) + +#endif From e73a571fd9b60315681eacbef5857f0f0b1ece18 Mon Sep 17 00:00:00 2001 From: "Banavathu, Srinivas Naik" Date: Tue, 29 Jun 2010 11:57:29 -0700 Subject: [PATCH 21/93] Add kernel header file ipv6_route.h in bionic. The header file is needed to add route to an IPv6 host from user space Change-Id: I25c8a8d8e48013f127542199bc027f976b9672c1 --- libc/kernel/common/linux/ipv6_route.h | 55 +++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 libc/kernel/common/linux/ipv6_route.h diff --git a/libc/kernel/common/linux/ipv6_route.h b/libc/kernel/common/linux/ipv6_route.h new file mode 100644 index 000000000..3791e8752 --- /dev/null +++ b/libc/kernel/common/linux/ipv6_route.h @@ -0,0 +1,55 @@ +/**************************************************************************** + **************************************************************************** + *** + *** This header was automatically generated from a Linux kernel header + *** of the same name, to make information necessary for userspace to + *** call into the kernel available to libc. It contains only constants, + *** structures, and macros generated from the original header, and thus, + *** contains no copyrightable information. + *** + **************************************************************************** + ****************************************************************************/ +#ifndef _LINUX_IPV6_ROUTE_H +#define _LINUX_IPV6_ROUTE_H + +#include + +#define RTF_DEFAULT 0x00010000 +#define RTF_ALLONLINK 0x00020000 +#define RTF_ADDRCONF 0x00040000 +#define RTF_PREFIX_RT 0x00080000 +#define RTF_ANYCAST 0x00100000 + +#define RTF_NONEXTHOP 0x00200000 +#define RTF_EXPIRES 0x00400000 + +#define RTF_ROUTEINFO 0x00800000 + +#define RTF_CACHE 0x01000000 +#define RTF_FLOW 0x02000000 +#define RTF_POLICY 0x04000000 + +#define RTF_PREF(pref) ((pref) << 27) +#define RTF_PREF_MASK 0x18000000 + +#define RTF_LOCAL 0x80000000 + +struct in6_rtmsg { + struct in6_addr rtmsg_dst; + struct in6_addr rtmsg_src; + struct in6_addr rtmsg_gateway; + __u32 rtmsg_type; + __u16 rtmsg_dst_len; + __u16 rtmsg_src_len; + __u32 rtmsg_metric; + unsigned long rtmsg_info; + __u32 rtmsg_flags; + int rtmsg_ifindex; +}; + +#define RTMSG_NEWDEVICE 0x11 +#define RTMSG_DELDEVICE 0x12 +#define RTMSG_NEWROUTE 0x21 +#define RTMSG_DELROUTE 0x22 + +#endif From 4f086aeb4aa06e13079b7fec71a8178ceeacf318 Mon Sep 17 00:00:00 2001 From: Matt Fischer Date: Fri, 25 Jun 2010 14:36:39 -0500 Subject: [PATCH 22/93] Implemented pthread_atfork() Change-Id: Ie6c0bf593315d3507b3c4a6c8903a74a1fa053db --- libc/Android.mk | 3 + libc/bionic/fork.c | 4 ++ libc/bionic/pthread-atfork.c | 123 +++++++++++++++++++++++++++++++++ libc/bionic/pthread_internal.h | 3 + libc/docs/CHANGES.TXT | 8 ++- libc/include/pthread.h | 2 + 6 files changed, 142 insertions(+), 1 deletion(-) create mode 100644 libc/bionic/pthread-atfork.c diff --git a/libc/Android.mk b/libc/Android.mk index 7a7d9e30d..568cc9473 100644 --- a/libc/Android.mk +++ b/libc/Android.mk @@ -324,6 +324,7 @@ libc_common_src_files += \ # up any thumb code. libc_common_src_files += \ bionic/pthread.c.arm \ + bionic/pthread-atfork.c.arm \ bionic/pthread-timers.c.arm \ bionic/ptrace.c.arm @@ -358,6 +359,7 @@ libc_common_src_files += \ arch-x86/string/strncmp_wrapper.S \ arch-x86/string/strlen.S \ bionic/pthread.c \ + bionic/pthread-atfork.c \ bionic/pthread-timers.c \ bionic/ptrace.c @@ -394,6 +396,7 @@ libc_common_src_files += \ string/memcmp.c \ string/strlen.c \ bionic/pthread.c \ + bionic/pthread-atfork.c \ bionic/pthread-timers.c \ bionic/ptrace.c \ unistd/socketcalls.c diff --git a/libc/bionic/fork.c b/libc/bionic/fork.c index e20f548d0..8d3ea4b67 100644 --- a/libc/bionic/fork.c +++ b/libc/bionic/fork.c @@ -40,9 +40,12 @@ int fork(void) * of error, or in the parent process */ __timer_table_start_stop(1); + __bionic_atfork_run_prepare(); + ret = __fork(); if (ret != 0) { /* not a child process */ __timer_table_start_stop(0); + __bionic_atfork_run_parent(); } else { /* * Newly created process must update cpu accounting. @@ -51,6 +54,7 @@ int fork(void) * as a parameter. */ cpuacct_add(getuid()); + __bionic_atfork_run_child(); } return ret; } diff --git a/libc/bionic/pthread-atfork.c b/libc/bionic/pthread-atfork.c new file mode 100644 index 000000000..3a5189d8c --- /dev/null +++ b/libc/bionic/pthread-atfork.c @@ -0,0 +1,123 @@ +/* + * 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 +#include +#include +#include + +static pthread_mutex_t handler_mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER; + +struct atfork_t +{ + CIRCLEQ_ENTRY(atfork_t) entries; + + void (*prepare)(void); + void (*child)(void); + void (*parent)(void); +}; +static CIRCLEQ_HEAD(atfork_head_t, atfork_t) atfork_head = \ + CIRCLEQ_HEAD_INITIALIZER(atfork_head); + +void __bionic_atfork_run_prepare() +{ + struct atfork_t *cursor; + + /* We will lock this here, and unlock it in the parent and child functions. + * This ensures that nobody can modify the handler array between the calls + * to the prepare and parent/child handlers. + * + * TODO: If a handler mucks with the list, it could cause problems. Right + * now it's ok because all they can do is add new items to the end + * of the list, but if/when we implement cleanup in dlclose() things + * will get more interesting... + */ + pthread_mutex_lock(&handler_mutex); + + /* Call pthread_atfork() prepare handlers. Posix states that the prepare + * handlers should be called in the reverse order of the parent/child + * handlers, so we iterate backwards. + */ + for (cursor = atfork_head.cqh_last; + cursor != (void*)&atfork_head; + cursor = cursor->entries.cqe_prev) { + if (cursor->prepare != NULL) { + cursor->prepare(); + } + } +} + +void __bionic_atfork_run_child() +{ + struct atfork_t *cursor; + + /* Call pthread_atfork() child handlers */ + for (cursor = atfork_head.cqh_first; + cursor != (void*)&atfork_head; + cursor = cursor->entries.cqe_next) { + if (cursor->child != NULL) { + cursor->child(); + } + } + + pthread_mutex_unlock(&handler_mutex); +} + +void __bionic_atfork_run_parent() +{ + struct atfork_t *cursor; + + /* Call pthread_atfork() parent handlers */ + for (cursor = atfork_head.cqh_first; + cursor != (void*)&atfork_head; + cursor = cursor->entries.cqe_next) { + if (cursor->parent != NULL) { + cursor->parent(); + } + } + + pthread_mutex_unlock(&handler_mutex); +} + +int pthread_atfork(void (*prepare)(void), void (*parent)(void), void(*child)(void)) +{ + struct atfork_t *entry = malloc(sizeof(struct atfork_t)); + + if (entry == NULL) { + return ENOMEM; + } + + entry->prepare = prepare; + entry->parent = parent; + entry->child = child; + + pthread_mutex_lock(&handler_mutex); + CIRCLEQ_INSERT_TAIL(&atfork_head, entry, entries); + pthread_mutex_unlock(&handler_mutex); + + return 0; +} diff --git a/libc/bionic/pthread_internal.h b/libc/bionic/pthread_internal.h index eb4e80ccc..655b8f341 100644 --- a/libc/bionic/pthread_internal.h +++ b/libc/bionic/pthread_internal.h @@ -109,6 +109,9 @@ extern int __pthread_cond_timedwait_relative(pthread_cond_t*, /* needed by fork.c */ extern void __timer_table_start_stop(int stop); +extern void __bionic_atfork_run_prepare(); +extern void __bionic_atfork_run_child(); +extern void __bionic_atfork_run_parent(); __END_DECLS diff --git a/libc/docs/CHANGES.TXT b/libc/docs/CHANGES.TXT index 90806851a..b0725ed12 100644 --- a/libc/docs/CHANGES.TXT +++ b/libc/docs/CHANGES.TXT @@ -1,7 +1,13 @@ Bionic ChangeLog: ----------------- -Differences between current and Android 2.1: +Differences between current and Android 2.2: + +- Added an implementation of pthread_atfork() + + +------------------------------------------------------------------------------- +Differences between Android 2.2 and Android 2.1: - Add support for SH-4 CPU architecture ! diff --git a/libc/include/pthread.h b/libc/include/pthread.h index 944bb68ee..ecabdb10e 100644 --- a/libc/include/pthread.h +++ b/libc/include/pthread.h @@ -233,6 +233,8 @@ int pthread_once(pthread_once_t *once_control, void (*init_routine)(void)); int pthread_setname_np(pthread_t thid, const char *thname); +int pthread_atfork(void (*prepare)(void), void (*parent)(void), void(*child)(void)); + typedef void (*__pthread_cleanup_func_t)(void*); typedef struct __pthread_cleanup_t { From 26c15a8eb9a445527d679935b86960211bbb85a8 Mon Sep 17 00:00:00 2001 From: Chih-Wei Huang Date: Mon, 26 Jul 2010 11:29:08 +0800 Subject: [PATCH 23/93] Move the atom optimization flags into TARGET_linux-x86.mk. Setting libc_crt_target_cflags to be non-recursive is necessary. Change-Id: I5310d86e705f23da126c21ecb33a97a074da584a --- libc/Android.mk | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/libc/Android.mk b/libc/Android.mk index 568cc9473..a034c5069 100644 --- a/libc/Android.mk +++ b/libc/Android.mk @@ -447,13 +447,7 @@ ifeq ($(TARGET_ARCH),arm) libc_common_cflags += -DHAVE_ARM_TLS_REGISTER endif else # !arm - ifeq ($(TARGET_ARCH),x86) - libc_crt_target_cflags := -m32 - - # Enable recent IA friendly memory routines (such as for Atom) - # These will not work on the earlier x86 machines - libc_common_cflags += -mtune=i686 -DUSE_SSSE3 -DUSE_SSE2 - endif # x86 + libc_crt_target_cflags := endif # !arm # Define some common includes From 1a48b588c6de8ae43903768adf53b32545f69986 Mon Sep 17 00:00:00 2001 From: Thomas Tuttle Date: Mon, 2 Aug 2010 16:00:59 -0700 Subject: [PATCH 24/93] ublock: add cleaned version of linux/ublock.h to libc kernel headers Change-Id: I8ebc7530690ff47f3160c72f42b8e0822f55a57e --- libc/kernel/common/linux/ublock.h | 81 +++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 libc/kernel/common/linux/ublock.h diff --git a/libc/kernel/common/linux/ublock.h b/libc/kernel/common/linux/ublock.h new file mode 100644 index 000000000..aa19a813e --- /dev/null +++ b/libc/kernel/common/linux/ublock.h @@ -0,0 +1,81 @@ +/**************************************************************************** + **************************************************************************** + *** + *** This header was automatically generated from a Linux kernel header + *** of the same name, to make information necessary for userspace to + *** call into the kernel available to libc. It contains only constants, + *** structures, and macros generated from the original header, and thus, + *** contains no copyrightable information. + *** + **************************************************************************** + ****************************************************************************/ +#ifndef __UBLOCK_H_ +#define __UBLOCK_H_ + +#include + +#define UBLOCK_VERSION 0 + +enum { + UBLOCK_INIT_IN = 0, + UBLOCK_INIT_OUT = 1, + UBLOCK_READY_IN = 2, + UBLOCK_READY_OUT = 3, + UBLOCK_READ_IN = 4, + UBLOCK_READ_OUT = 5, + UBLOCK_WRITE_IN = 6, + UBLOCK_WRITE_OUT = 7, +}; + +struct ublock_in_header { + __u32 seq; + __u32 opcode; +}; + +struct ublock_out_header { + __u32 seq; + __u32 opcode; +}; + +struct ublock_init_in { + __u32 version; + __u32 max_buf; + __u32 index; +}; + +struct ublock_init_out { + __u32 version; + __u32 max_buf; + __u64 size; +}; + +struct ublock_ready_in { + __u32 _unused; +}; + +struct ublock_ready_out { + __u32 _unused; +}; + +struct ublock_read_in { + __u64 offset; + __u64 length; +}; + +struct ublock_read_out { + __s32 status; + __u8 data[]; +}; + +struct ublock_write_in { + __u64 offset; + __u64 length; + __u8 data[]; +}; + +struct ublock_write_out { + __s32 status; +}; + +#endif + From 63673645c4da1cf97938d5018d7d373837563174 Mon Sep 17 00:00:00 2001 From: Dima Zavin Date: Fri, 6 Aug 2010 11:45:43 -0700 Subject: [PATCH 25/93] libc: make lseek64 proto be glibc compatible (loff_t -> off64_t) Change-Id: Ib79b99be9ca8d4b1f95ceeba416b6abc04187c3c Signed-off-by: Dima Zavin --- libc/include/unistd.h | 2 +- libc/unistd/lseek64.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libc/include/unistd.h b/libc/include/unistd.h index 75541980d..d90e73717 100644 --- a/libc/include/unistd.h +++ b/libc/include/unistd.h @@ -131,7 +131,7 @@ extern int sync(void); extern int close(int); extern off_t lseek(int, off_t, int); -extern loff_t lseek64(int, loff_t, int); +extern off64_t lseek64(int, off64_t, int); extern ssize_t read(int, void *, size_t); extern ssize_t write(int, const void *, size_t); diff --git a/libc/unistd/lseek64.c b/libc/unistd/lseek64.c index 017b33185..db0c41352 100644 --- a/libc/unistd/lseek64.c +++ b/libc/unistd/lseek64.c @@ -29,7 +29,7 @@ extern int __llseek(int fd, unsigned long offset_hi, unsigned long offset_lo, loff_t* result, int whence); -loff_t lseek64(int fd, loff_t off, int whence) +off64_t lseek64(int fd, off64_t off, int whence) { loff_t result; From 45fe7a42f8cff24c30e91f3ef3859ed0d435b312 Mon Sep 17 00:00:00 2001 From: Rebecca Schultz Zavin Date: Fri, 6 Aug 2010 19:14:45 -0700 Subject: [PATCH 26/93] Adding cleaned tegrafb header Change-Id: Iba616e64cc26fb8c2d469bdd3f9f4b048391cc53 Signed-off-by: Rebecca Schultz Zavin --- libc/kernel/common/linux/tegrafb.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 libc/kernel/common/linux/tegrafb.h diff --git a/libc/kernel/common/linux/tegrafb.h b/libc/kernel/common/linux/tegrafb.h new file mode 100644 index 000000000..2985d6182 --- /dev/null +++ b/libc/kernel/common/linux/tegrafb.h @@ -0,0 +1,30 @@ +/**************************************************************************** + **************************************************************************** + *** + *** This header was automatically generated from a Linux kernel header + *** of the same name, to make information necessary for userspace to + *** call into the kernel available to libc. It contains only constants, + *** structures, and macros generated from the original header, and thus, + *** contains no copyrightable information. + *** + **************************************************************************** + ****************************************************************************/ +#ifndef _LINUX_TEGRAFB_H_ +#define _LINUX_TEGRAFB_H_ + +#include +#include + +struct tegra_fb_flip_args { + __u32 buff_id; + __u32 pre_syncpt_id; + __u32 pre_syncpt_val; + __u32 post_syncpt_id; + __u32 post_syncpt_val; +}; + +#define FBIO_TEGRA_SET_NVMAP_FD _IOW('F', 0x40, __u32) +#define FBIO_TEGRA_FLIP _IOW('F', 0x41, struct tegra_fb_flip_args) + +#endif + From a1727092595a65e4dd9d9a6bae3778ad8c31d77f Mon Sep 17 00:00:00 2001 From: Jim Huang Date: Mon, 9 Aug 2010 05:35:11 +0800 Subject: [PATCH 27/93] bionic: Rename _ARM_HAVE_LDREX_STREX to __ARM_HAVE_LDREX_STREX for consistency The patch follows the naming manner in existing macros with prefix __ARM_HAVE. Change-Id: I6763ce2bf3ee85fd1da112c719543061d8d19bf4 --- libc/arch-arm/bionic/atomics_arm.S | 2 +- libc/arch-arm/include/machine/cpu-features.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libc/arch-arm/bionic/atomics_arm.S b/libc/arch-arm/bionic/atomics_arm.S index 047541fc2..f2e369d0b 100644 --- a/libc/arch-arm/bionic/atomics_arm.S +++ b/libc/arch-arm/bionic/atomics_arm.S @@ -142,7 +142,7 @@ __atomic_inc: /* r0(new) r1(addr) -> r0(old) */ /* replaced swp instruction with ldrex/strex for ARMv6 & ARMv7 */ __atomic_swap: -#if defined (_ARM_HAVE_LDREX_STREX) +#if defined (__ARM_HAVE_LDREX_STREX) 1: ldrex r2, [r1] strex r3, r0, [r1] teq r3, #0 diff --git a/libc/arch-arm/include/machine/cpu-features.h b/libc/arch-arm/include/machine/cpu-features.h index ecf6ff6f3..5af325bb2 100644 --- a/libc/arch-arm/include/machine/cpu-features.h +++ b/libc/arch-arm/include/machine/cpu-features.h @@ -149,11 +149,11 @@ # define __ARM_HAVE_PC_INTERWORK #endif -/* define _ARM_HAVE_LDREX_STREX for ARMv6 and ARMv7 architecure to be +/* define __ARM_HAVE_LDREX_STREX for ARMv6 and ARMv7 architecure to be * used in replacement of depricated swp instruction */ #if __ARM_ARCH__ >= 6 -# define _ARM_HAVE_LDREX_STREX +# define __ARM_HAVE_LDREX_STREX #endif From 2304a0bf86f224efdd67e38f34c97f35c5cf3c56 Mon Sep 17 00:00:00 2001 From: Jeff Hamilton Date: Wed, 11 Aug 2010 11:28:26 -0500 Subject: [PATCH 28/93] Fix pwrite to take a const void* instead of void* for the buffer. Change-Id: I10b315946b8f8f7e34825410dfef37e0220edbee --- libc/include/sys/linux-unistd.h | 2 +- libc/include/unistd.h | 2 +- libc/unistd/pwrite.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libc/include/sys/linux-unistd.h b/libc/include/sys/linux-unistd.h index 6bd9ac7e9..a439e0f65 100644 --- a/libc/include/sys/linux-unistd.h +++ b/libc/include/sys/linux-unistd.h @@ -53,7 +53,7 @@ int acct (const char* filepath); ssize_t read (int, void*, size_t); ssize_t write (int, const void*, size_t); ssize_t __pread64 (int, void *, size_t, off_t, off_t); -ssize_t __pwrite64 (int, void *, size_t, off_t, off_t); +ssize_t __pwrite64 (int, const void *, size_t, off_t, off_t); int __open (const char*, int, mode_t); int __openat (int, const char*, int, mode_t); int close (int); diff --git a/libc/include/unistd.h b/libc/include/unistd.h index d90e73717..b801b9d71 100644 --- a/libc/include/unistd.h +++ b/libc/include/unistd.h @@ -136,7 +136,7 @@ extern off64_t lseek64(int, off64_t, int); extern ssize_t read(int, void *, size_t); extern ssize_t write(int, const void *, size_t); extern ssize_t pread(int, void *, size_t, off_t); -extern ssize_t pwrite(int, void *, size_t, off_t); +extern ssize_t pwrite(int, const void *, size_t, off_t); extern int dup(int); extern int dup2(int, int); diff --git a/libc/unistd/pwrite.c b/libc/unistd/pwrite.c index ea080d26a..223e1b37f 100644 --- a/libc/unistd/pwrite.c +++ b/libc/unistd/pwrite.c @@ -28,9 +28,9 @@ #include #include -extern int __pwrite64(int fd, void *buf, size_t nbytes, loff_t offset); +extern int __pwrite64(int fd, const void *buf, size_t nbytes, loff_t offset); -ssize_t pwrite(int fd, void *buf, size_t nbytes, off_t offset) +ssize_t pwrite(int fd, const void *buf, size_t nbytes, off_t offset) { return __pwrite64(fd, buf, nbytes, offset); } From b3765b2ee701492afd83cef5a60b47cce0f1c4a4 Mon Sep 17 00:00:00 2001 From: Nick Pelly Date: Mon, 16 Aug 2010 15:31:01 -0700 Subject: [PATCH 29/93] Add clean kernel headers for cpcap and hid. Change-Id: I83d7395634eea8cb28c2fcf86c6855bb17f9fabb Signed-off-by: Nick Pelly --- libc/kernel/common/linux/hid.h | 36 ++ libc/kernel/common/linux/hidraw.h | 41 ++ libc/kernel/common/linux/spi/cpcap.h | 561 +++++++++++++++++++++++++++ 3 files changed, 638 insertions(+) create mode 100644 libc/kernel/common/linux/hid.h create mode 100644 libc/kernel/common/linux/hidraw.h create mode 100644 libc/kernel/common/linux/spi/cpcap.h diff --git a/libc/kernel/common/linux/hid.h b/libc/kernel/common/linux/hid.h new file mode 100644 index 000000000..450db19cf --- /dev/null +++ b/libc/kernel/common/linux/hid.h @@ -0,0 +1,36 @@ +/**************************************************************************** + **************************************************************************** + *** + *** This header was automatically generated from a Linux kernel header + *** of the same name, to make information necessary for userspace to + *** call into the kernel available to libc. It contains only constants, + *** structures, and macros generated from the original header, and thus, + *** contains no copyrightable information. + *** + **************************************************************************** + ****************************************************************************/ +#ifndef __HID_H +#define __HID_H + +#define USB_INTERFACE_CLASS_HID 3 + +#define USB_INTERFACE_SUBCLASS_BOOT 1 +#define USB_INTERFACE_PROTOCOL_KEYBOARD 1 +#define USB_INTERFACE_PROTOCOL_MOUSE 2 + +#define HID_REQ_GET_REPORT 0x01 +#define HID_REQ_GET_IDLE 0x02 +#define HID_REQ_GET_PROTOCOL 0x03 +#define HID_REQ_SET_REPORT 0x09 +#define HID_REQ_SET_IDLE 0x0A +#define HID_REQ_SET_PROTOCOL 0x0B + +#define HID_DT_HID (USB_TYPE_CLASS | 0x01) +#define HID_DT_REPORT (USB_TYPE_CLASS | 0x02) +#define HID_DT_PHYSICAL (USB_TYPE_CLASS | 0x03) + +#define HID_MAX_DESCRIPTOR_SIZE 4096 + +#endif + + diff --git a/libc/kernel/common/linux/hidraw.h b/libc/kernel/common/linux/hidraw.h new file mode 100644 index 000000000..0681ece09 --- /dev/null +++ b/libc/kernel/common/linux/hidraw.h @@ -0,0 +1,41 @@ +/**************************************************************************** + **************************************************************************** + *** + *** This header was automatically generated from a Linux kernel header + *** of the same name, to make information necessary for userspace to + *** call into the kernel available to libc. It contains only constants, + *** structures, and macros generated from the original header, and thus, + *** contains no copyrightable information. + *** + **************************************************************************** + ****************************************************************************/ +#ifndef _HIDRAW_H +#define _HIDRAW_H + +#include +#include + +struct hidraw_report_descriptor { + __u32 size; + __u8 value[HID_MAX_DESCRIPTOR_SIZE]; +}; + +struct hidraw_devinfo { + __u32 bustype; + __s16 vendor; + __s16 product; +}; + +#define HIDIOCGRDESCSIZE _IOR('H', 0x01, int) +#define HIDIOCGRDESC _IOR('H', 0x02, struct hidraw_report_descriptor) +#define HIDIOCGRAWINFO _IOR('H', 0x03, struct hidraw_devinfo) +#define HIDIOCGRAWNAME(len) _IOC(_IOC_READ, 'H', 0x04, len) +#define HIDIOCGRAWPHYS(len) _IOC(_IOC_READ, 'H', 0x05, len) + +#define HIDRAW_FIRST_MINOR 0 +#define HIDRAW_MAX_DEVICES 64 + +#define HIDRAW_BUFFER_SIZE 64 + +#endif + diff --git a/libc/kernel/common/linux/spi/cpcap.h b/libc/kernel/common/linux/spi/cpcap.h new file mode 100644 index 000000000..5119bcf2f --- /dev/null +++ b/libc/kernel/common/linux/spi/cpcap.h @@ -0,0 +1,561 @@ +/**************************************************************************** + **************************************************************************** + *** + *** This header was automatically generated from a Linux kernel header + *** of the same name, to make information necessary for userspace to + *** call into the kernel available to libc. It contains only constants, + *** structures, and macros generated from the original header, and thus, + *** contains no copyrightable information. + *** + **************************************************************************** + ****************************************************************************/ +#ifndef _LINUX_SPI_CPCAP_H +#define _LINUX_SPI_CPCAP_H + +#include + +#define CPCAP_DEV_NAME "cpcap" +#define CPCAP_NUM_REG_CPCAP (CPCAP_REG_END - CPCAP_REG_START + 1) + +#define CPCAP_IRQ_INT1_INDEX 0 +#define CPCAP_IRQ_INT2_INDEX 16 +#define CPCAP_IRQ_INT3_INDEX 32 +#define CPCAP_IRQ_INT4_INDEX 48 +#define CPCAP_IRQ_INT5_INDEX 64 + +#define CPCAP_WHISPER_MODE_PU 0x00000001 +#define CPCAP_WHISPER_ENABLE_UART 0x00000002 +#define CPCAP_WHISPER_ACCY_MASK 0xF8000000 +#define CPCAP_WHISPER_ACCY_SHFT 27 +#define CPCAP_WHISPER_ID_SIZE 16 + +enum cpcap_regulator_id { + CPCAP_SW2, + CPCAP_SW4, + CPCAP_SW5, + CPCAP_VCAM, + CPCAP_VCSI, + CPCAP_VDAC, + CPCAP_VDIG, + CPCAP_VFUSE, + CPCAP_VHVIO, + CPCAP_VSDIO, + CPCAP_VPLL, + CPCAP_VRF1, + CPCAP_VRF2, + CPCAP_VRFREF, + CPCAP_VWLAN1, + CPCAP_VWLAN2, + CPCAP_VSIM, + CPCAP_VSIMCARD, + CPCAP_VVIB, + CPCAP_VUSB, + CPCAP_VAUDIO, + CPCAP_NUM_REGULATORS +}; + +enum cpcap_reg { + CPCAP_REG_START, + + CPCAP_REG_INT1 = CPCAP_REG_START, + CPCAP_REG_INT2, + CPCAP_REG_INT3, + CPCAP_REG_INT4, + CPCAP_REG_INTM1, + CPCAP_REG_INTM2, + CPCAP_REG_INTM3, + CPCAP_REG_INTM4, + CPCAP_REG_INTS1, + CPCAP_REG_INTS2, + CPCAP_REG_INTS3, + CPCAP_REG_INTS4, + CPCAP_REG_ASSIGN1, + CPCAP_REG_ASSIGN2, + CPCAP_REG_ASSIGN3, + CPCAP_REG_ASSIGN4, + CPCAP_REG_ASSIGN5, + CPCAP_REG_ASSIGN6, + CPCAP_REG_VERSC1, + CPCAP_REG_VERSC2, + + CPCAP_REG_MI1, + CPCAP_REG_MIM1, + CPCAP_REG_MI2, + CPCAP_REG_MIM2, + CPCAP_REG_UCC1, + CPCAP_REG_UCC2, + CPCAP_REG_PC1, + CPCAP_REG_PC2, + CPCAP_REG_BPEOL, + CPCAP_REG_PGC, + CPCAP_REG_MT1, + CPCAP_REG_MT2, + CPCAP_REG_MT3, + CPCAP_REG_PF, + + CPCAP_REG_SCC, + CPCAP_REG_SW1, + CPCAP_REG_SW2, + CPCAP_REG_UCTM, + CPCAP_REG_TOD1, + CPCAP_REG_TOD2, + CPCAP_REG_TODA1, + CPCAP_REG_TODA2, + CPCAP_REG_DAY, + CPCAP_REG_DAYA, + CPCAP_REG_VAL1, + CPCAP_REG_VAL2, + + CPCAP_REG_SDVSPLL, + CPCAP_REG_SI2CC1, + CPCAP_REG_Si2CC2, + CPCAP_REG_S1C1, + CPCAP_REG_S1C2, + CPCAP_REG_S2C1, + CPCAP_REG_S2C2, + CPCAP_REG_S3C, + CPCAP_REG_S4C1, + CPCAP_REG_S4C2, + CPCAP_REG_S5C, + CPCAP_REG_S6C, + CPCAP_REG_VCAMC, + CPCAP_REG_VCSIC, + CPCAP_REG_VDACC, + CPCAP_REG_VDIGC, + CPCAP_REG_VFUSEC, + CPCAP_REG_VHVIOC, + CPCAP_REG_VSDIOC, + CPCAP_REG_VPLLC, + CPCAP_REG_VRF1C, + CPCAP_REG_VRF2C, + CPCAP_REG_VRFREFC, + CPCAP_REG_VWLAN1C, + CPCAP_REG_VWLAN2C, + CPCAP_REG_VSIMC, + CPCAP_REG_VVIBC, + CPCAP_REG_VUSBC, + CPCAP_REG_VUSBINT1C, + CPCAP_REG_VUSBINT2C, + CPCAP_REG_URT, + CPCAP_REG_URM1, + CPCAP_REG_URM2, + + CPCAP_REG_VAUDIOC, + CPCAP_REG_CC, + CPCAP_REG_CDI, + CPCAP_REG_SDAC, + CPCAP_REG_SDACDI, + CPCAP_REG_TXI, + CPCAP_REG_TXMP, + CPCAP_REG_RXOA, + CPCAP_REG_RXVC, + CPCAP_REG_RXCOA, + CPCAP_REG_RXSDOA, + CPCAP_REG_RXEPOA, + CPCAP_REG_RXLL, + CPCAP_REG_A2LA, + CPCAP_REG_MIPIS1, + CPCAP_REG_MIPIS2, + CPCAP_REG_MIPIS3, + CPCAP_REG_LVAB, + + CPCAP_REG_CCC1, + CPCAP_REG_CRM, + CPCAP_REG_CCCC2, + CPCAP_REG_CCS1, + CPCAP_REG_CCS2, + CPCAP_REG_CCA1, + CPCAP_REG_CCA2, + CPCAP_REG_CCM, + CPCAP_REG_CCO, + CPCAP_REG_CCI, + + CPCAP_REG_ADCC1, + CPCAP_REG_ADCC2, + CPCAP_REG_ADCD0, + CPCAP_REG_ADCD1, + CPCAP_REG_ADCD2, + CPCAP_REG_ADCD3, + CPCAP_REG_ADCD4, + CPCAP_REG_ADCD5, + CPCAP_REG_ADCD6, + CPCAP_REG_ADCD7, + CPCAP_REG_ADCAL1, + CPCAP_REG_ADCAL2, + + CPCAP_REG_USBC1, + CPCAP_REG_USBC2, + CPCAP_REG_USBC3, + CPCAP_REG_UVIDL, + CPCAP_REG_UVIDH, + CPCAP_REG_UPIDL, + CPCAP_REG_UPIDH, + CPCAP_REG_UFC1, + CPCAP_REG_UFC2, + CPCAP_REG_UFC3, + CPCAP_REG_UIC1, + CPCAP_REG_UIC2, + CPCAP_REG_UIC3, + CPCAP_REG_USBOTG1, + CPCAP_REG_USBOTG2, + CPCAP_REG_USBOTG3, + CPCAP_REG_UIER1, + CPCAP_REG_UIER2, + CPCAP_REG_UIER3, + CPCAP_REG_UIEF1, + CPCAP_REG_UIEF2, + CPCAP_REG_UIEF3, + CPCAP_REG_UIS, + CPCAP_REG_UIL, + CPCAP_REG_USBD, + CPCAP_REG_SCR1, + CPCAP_REG_SCR2, + CPCAP_REG_SCR3, + CPCAP_REG_VMC, + CPCAP_REG_OWDC, + CPCAP_REG_GPIO0, + CPCAP_REG_GPIO1, + CPCAP_REG_GPIO2, + CPCAP_REG_GPIO3, + CPCAP_REG_GPIO4, + CPCAP_REG_GPIO5, + CPCAP_REG_GPIO6, + + CPCAP_REG_MDLC, + CPCAP_REG_KLC, + CPCAP_REG_ADLC, + CPCAP_REG_REDC, + CPCAP_REG_GREENC, + CPCAP_REG_BLUEC, + CPCAP_REG_CFC, + CPCAP_REG_ABC, + CPCAP_REG_BLEDC, + CPCAP_REG_CLEDC, + + CPCAP_REG_OW1C, + CPCAP_REG_OW1D, + CPCAP_REG_OW1I, + CPCAP_REG_OW1IE, + CPCAP_REG_OW1, + CPCAP_REG_OW2C, + CPCAP_REG_OW2D, + CPCAP_REG_OW2I, + CPCAP_REG_OW2IE, + CPCAP_REG_OW2, + CPCAP_REG_OW3C, + CPCAP_REG_OW3D, + CPCAP_REG_OW3I, + CPCAP_REG_OW3IE, + CPCAP_REG_OW3, + CPCAP_REG_GCAIC, + CPCAP_REG_GCAIM, + CPCAP_REG_LGDIR, + CPCAP_REG_LGPU, + CPCAP_REG_LGPIN, + CPCAP_REG_LGMASK, + CPCAP_REG_LDEB, + CPCAP_REG_LGDET, + CPCAP_REG_LMISC, + CPCAP_REG_LMACE, + + CPCAP_REG_END = CPCAP_REG_LMACE, + + CPCAP_REG_MAX + = CPCAP_REG_END, + + CPCAP_REG_SIZE = CPCAP_REG_MAX + 1, + CPCAP_REG_UNUSED = CPCAP_REG_MAX + 2, +}; + +enum { + CPCAP_IOCTL_NUM_TEST__START, + CPCAP_IOCTL_NUM_TEST_READ_REG, + CPCAP_IOCTL_NUM_TEST_WRITE_REG, + CPCAP_IOCTL_NUM_TEST__END, + + CPCAP_IOCTL_NUM_ADC__START, + CPCAP_IOCTL_NUM_ADC_PHASE, + CPCAP_IOCTL_NUM_ADC__END, + + CPCAP_IOCTL_NUM_BATT__START, + CPCAP_IOCTL_NUM_BATT_DISPLAY_UPDATE, + CPCAP_IOCTL_NUM_BATT_ATOD_ASYNC, + CPCAP_IOCTL_NUM_BATT_ATOD_SYNC, + CPCAP_IOCTL_NUM_BATT_ATOD_READ, + CPCAP_IOCTL_NUM_BATT__END, + + CPCAP_IOCTL_NUM_UC__START, + CPCAP_IOCTL_NUM_UC_MACRO_START, + CPCAP_IOCTL_NUM_UC_MACRO_STOP, + CPCAP_IOCTL_NUM_UC_GET_VENDOR, + CPCAP_IOCTL_NUM_UC_SET_TURBO_MODE, + CPCAP_IOCTL_NUM_UC__END, + + CPCAP_IOCTL_NUM_ACCY__START, + CPCAP_IOCTL_NUM_ACCY_WHISPER, + CPCAP_IOCTL_NUM_ACCY__END, +}; + +enum cpcap_irqs { + CPCAP_IRQ__START, + CPCAP_IRQ_HSCLK = CPCAP_IRQ_INT1_INDEX, + CPCAP_IRQ_PRIMAC, + CPCAP_IRQ_SECMAC, + CPCAP_IRQ_LOWBPL, + CPCAP_IRQ_SEC2PRI, + CPCAP_IRQ_LOWBPH, + CPCAP_IRQ_EOL, + CPCAP_IRQ_TS, + CPCAP_IRQ_ADCDONE, + CPCAP_IRQ_HS, + CPCAP_IRQ_MB2, + CPCAP_IRQ_VBUSOV, + CPCAP_IRQ_RVRS_CHRG, + CPCAP_IRQ_CHRG_DET, + CPCAP_IRQ_IDFLOAT, + CPCAP_IRQ_IDGND, + + CPCAP_IRQ_SE1 = CPCAP_IRQ_INT2_INDEX, + CPCAP_IRQ_SESSEND, + CPCAP_IRQ_SESSVLD, + CPCAP_IRQ_VBUSVLD, + CPCAP_IRQ_CHRG_CURR1, + CPCAP_IRQ_CHRG_CURR2, + CPCAP_IRQ_RVRS_MODE, + CPCAP_IRQ_ON, + CPCAP_IRQ_ON2, + CPCAP_IRQ_CLK, + CPCAP_IRQ_1HZ, + CPCAP_IRQ_PTT, + CPCAP_IRQ_SE0CONN, + CPCAP_IRQ_CHRG_SE1B, + CPCAP_IRQ_UART_ECHO_OVERRUN, + CPCAP_IRQ_EXTMEMHD, + + CPCAP_IRQ_WARM = CPCAP_IRQ_INT3_INDEX, + CPCAP_IRQ_SYSRSTR, + CPCAP_IRQ_SOFTRST, + CPCAP_IRQ_DIEPWRDWN, + CPCAP_IRQ_DIETEMPH, + CPCAP_IRQ_PC, + CPCAP_IRQ_OFLOWSW, + CPCAP_IRQ_TODA, + CPCAP_IRQ_OPT_SEL_DTCH, + CPCAP_IRQ_OPT_SEL_STATE, + CPCAP_IRQ_ONEWIRE1, + CPCAP_IRQ_ONEWIRE2, + CPCAP_IRQ_ONEWIRE3, + CPCAP_IRQ_UCRESET, + CPCAP_IRQ_PWRGOOD, + CPCAP_IRQ_USBDPLLCLK, + + CPCAP_IRQ_DPI = CPCAP_IRQ_INT4_INDEX, + CPCAP_IRQ_DMI, + CPCAP_IRQ_UCBUSY, + CPCAP_IRQ_GCAI_CURR1, + CPCAP_IRQ_GCAI_CURR2, + CPCAP_IRQ_SB_MAX_RETRANSMIT_ERR, + CPCAP_IRQ_BATTDETB, + CPCAP_IRQ_PRIHALT, + CPCAP_IRQ_SECHALT, + CPCAP_IRQ_CC_CAL, + + CPCAP_IRQ_UC_PRIROMR = CPCAP_IRQ_INT5_INDEX, + CPCAP_IRQ_UC_PRIRAMW, + CPCAP_IRQ_UC_PRIRAMR, + CPCAP_IRQ_UC_USEROFF, + CPCAP_IRQ_UC_PRIMACRO_4, + CPCAP_IRQ_UC_PRIMACRO_5, + CPCAP_IRQ_UC_PRIMACRO_6, + CPCAP_IRQ_UC_PRIMACRO_7, + CPCAP_IRQ_UC_PRIMACRO_8, + CPCAP_IRQ_UC_PRIMACRO_9, + CPCAP_IRQ_UC_PRIMACRO_10, + CPCAP_IRQ_UC_PRIMACRO_11, + CPCAP_IRQ_UC_PRIMACRO_12, + CPCAP_IRQ_UC_PRIMACRO_13, + CPCAP_IRQ_UC_PRIMACRO_14, + CPCAP_IRQ_UC_PRIMACRO_15, + CPCAP_IRQ__NUM +}; + +enum cpcap_adc_bank0 { + CPCAP_ADC_AD0_BATTDETB, + CPCAP_ADC_BATTP, + CPCAP_ADC_VBUS, + CPCAP_ADC_AD3, + CPCAP_ADC_BPLUS_AD4, + CPCAP_ADC_CHG_ISENSE, + CPCAP_ADC_BATTI_ADC, + CPCAP_ADC_USB_ID, + + CPCAP_ADC_BANK0_NUM, +}; + +enum cpcap_adc_bank1 { + CPCAP_ADC_AD8, + CPCAP_ADC_AD9, + CPCAP_ADC_LICELL, + CPCAP_ADC_HV_BATTP, + CPCAP_ADC_TSX1_AD12, + CPCAP_ADC_TSX2_AD13, + CPCAP_ADC_TSY1_AD14, + CPCAP_ADC_TSY2_AD15, + + CPCAP_ADC_BANK1_NUM, +}; + +enum cpcap_adc_format { + CPCAP_ADC_FORMAT_RAW, + CPCAP_ADC_FORMAT_PHASED, + CPCAP_ADC_FORMAT_CONVERTED, +}; + +enum cpcap_adc_timing { + CPCAP_ADC_TIMING_IMM, + CPCAP_ADC_TIMING_IN, + CPCAP_ADC_TIMING_OUT, +}; + +enum cpcap_adc_type { + CPCAP_ADC_TYPE_BANK_0, + CPCAP_ADC_TYPE_BANK_1, + CPCAP_ADC_TYPE_BATT_PI, +}; + +enum cpcap_macro { + CPCAP_MACRO_ROMR, + CPCAP_MACRO_RAMW, + CPCAP_MACRO_RAMR, + CPCAP_MACRO_USEROFF, + CPCAP_MACRO_4, + CPCAP_MACRO_5, + CPCAP_MACRO_6, + CPCAP_MACRO_7, + CPCAP_MACRO_8, + CPCAP_MACRO_9, + CPCAP_MACRO_10, + CPCAP_MACRO_11, + CPCAP_MACRO_12, + CPCAP_MACRO_13, + CPCAP_MACRO_14, + CPCAP_MACRO_15, + + CPCAP_MACRO__END, +}; + +enum cpcap_vendor { + CPCAP_VENDOR_ST, + CPCAP_VENDOR_TI, +}; + +enum cpcap_revision { + CPCAP_REVISION_1_0 = 0x08, + CPCAP_REVISION_1_1 = 0x09, + CPCAP_REVISION_2_0 = 0x10, + CPCAP_REVISION_2_1 = 0x11, +}; + +enum cpcap_batt_usb_model { + CPCAP_BATT_USB_MODEL_NONE, + CPCAP_BATT_USB_MODEL_USB, + CPCAP_BATT_USB_MODEL_FACTORY, +}; + +struct cpcap_spi_init_data { + enum cpcap_reg reg; + unsigned short data; +}; + +struct cpcap_adc_ato { + unsigned short ato_in; + unsigned short atox_in; + unsigned short adc_ps_factor_in; + unsigned short atox_ps_factor_in; + unsigned short ato_out; + unsigned short atox_out; + unsigned short adc_ps_factor_out; + unsigned short atox_ps_factor_out; +}; + +struct cpcap_batt_data { + int status; + int health; + int present; + int capacity; + int batt_volt; + int batt_temp; +}; + +struct cpcap_batt_ac_data { + int online; +}; + +struct cpcap_batt_usb_data { + int online; + int current_now; + enum cpcap_batt_usb_model model; +}; + +struct cpcap_device; + +struct cpcap_adc_us_request { + enum cpcap_adc_format format; + enum cpcap_adc_timing timing; + enum cpcap_adc_type type; + int status; + int result[CPCAP_ADC_BANK0_NUM]; +}; + +struct cpcap_adc_phase { + signed char offset_batti; + unsigned char slope_batti; + signed char offset_chrgi; + unsigned char slope_chrgi; + signed char offset_battp; + unsigned char slope_battp; + signed char offset_bp; + unsigned char slope_bp; + signed char offset_battt; + unsigned char slope_battt; + signed char offset_chrgv; + unsigned char slope_chrgv; +}; + +struct cpcap_regacc { + unsigned short reg; + unsigned short value; + unsigned short mask; +}; + +struct cpcap_whisper_request { + unsigned int cmd; + char dock_id[CPCAP_WHISPER_ID_SIZE]; +}; + +#define CPCAP_IOCTL_TEST_READ_REG _IOWR(0, CPCAP_IOCTL_NUM_TEST_READ_REG, struct cpcap_regacc*) + +#define CPCAP_IOCTL_TEST_WRITE_REG _IOWR(0, CPCAP_IOCTL_NUM_TEST_WRITE_REG, struct cpcap_regacc*) + +#define CPCAP_IOCTL_ADC_PHASE _IOWR(0, CPCAP_IOCTL_NUM_ADC_PHASE, struct cpcap_adc_phase*) + +#define CPCAP_IOCTL_BATT_DISPLAY_UPDATE _IOW(0, CPCAP_IOCTL_NUM_BATT_DISPLAY_UPDATE, struct cpcap_batt_data*) + +#define CPCAP_IOCTL_BATT_ATOD_ASYNC _IOW(0, CPCAP_IOCTL_NUM_BATT_ATOD_ASYNC, struct cpcap_adc_us_request*) + +#define CPCAP_IOCTL_BATT_ATOD_SYNC _IOWR(0, CPCAP_IOCTL_NUM_BATT_ATOD_SYNC, struct cpcap_adc_us_request*) + +#define CPCAP_IOCTL_BATT_ATOD_READ _IOWR(0, CPCAP_IOCTL_NUM_BATT_ATOD_READ, struct cpcap_adc_us_request*) + +#define CPCAP_IOCTL_UC_MACRO_START _IOWR(0, CPCAP_IOCTL_NUM_UC_MACRO_START, enum cpcap_macro) + +#define CPCAP_IOCTL_UC_MACRO_STOP _IOWR(0, CPCAP_IOCTL_NUM_UC_MACRO_STOP, enum cpcap_macro) + +#define CPCAP_IOCTL_UC_GET_VENDOR _IOWR(0, CPCAP_IOCTL_NUM_UC_GET_VENDOR, enum cpcap_vendor) + +#define CPCAP_IOCTL_UC_SET_TURBO_MODE _IOW(0, CPCAP_IOCTL_NUM_UC_SET_TURBO_MODE, unsigned short) + +#define CPCAP_IOCTL_ACCY_WHISPER _IOW(0, CPCAP_IOCTL_NUM_ACCY_WHISPER, struct cpcap_whisper_request*) + +#endif + From 3871d57ba581236142c9bf2f8be2d34cce7c5829 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Queru Date: Wed, 18 Aug 2010 11:15:39 -0700 Subject: [PATCH 30/93] Revert "added missing ether_aton and ether_ntoa" This reverts commit 4032c1e2dfcc99613fe3e509a8153191e35aec12. --- libc/Android.mk | 2 - libc/include/net/if_ether.h | 2 - libc/inet/ether_aton.c | 89 ------------------------------------- libc/inet/ether_ntoa.c | 55 ----------------------- 4 files changed, 148 deletions(-) delete mode 100644 libc/inet/ether_aton.c delete mode 100644 libc/inet/ether_ntoa.c diff --git a/libc/Android.mk b/libc/Android.mk index 32bf9322e..b3f95c55b 100644 --- a/libc/Android.mk +++ b/libc/Android.mk @@ -240,8 +240,6 @@ libc_common_src_files := \ inet/inet_ntoa.c \ inet/inet_ntop.c \ inet/inet_pton.c \ - inet/ether_aton.c \ - inet/ether_ntoa.c \ tzcode/asctime.c \ tzcode/difftime.c \ tzcode/localtime.c \ diff --git a/libc/include/net/if_ether.h b/libc/include/net/if_ether.h index 8daa16b6c..121f9ac97 100644 --- a/libc/include/net/if_ether.h +++ b/libc/include/net/if_ether.h @@ -34,8 +34,6 @@ #ifndef _NET_IF_ETHER_H_ #define _NET_IF_ETHER_H_ -#include - #ifdef _KERNEL #ifdef _KERNEL_OPT #include "opt_mbuftrace.h" diff --git a/libc/inet/ether_aton.c b/libc/inet/ether_aton.c deleted file mode 100644 index 6540c0736..000000000 --- a/libc/inet/ether_aton.c +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (C) 2010 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 -#include -#include -#include -#include - -static inline int -xdigit (char c) { - unsigned d; - d = (unsigned)(c-'0'); - if (d < 10) return (int)d; - d = (unsigned)(c-'a'); - if (d < 6) return (int)(10+d); - d = (unsigned)(c-'A'); - if (d < 6) return (int)(10+d); - return -1; -} - -/* - * Convert Ethernet address in the standard hex-digits-and-colons to binary - * representation. - * Re-entrant version (GNU extensions) - */ -struct ether_addr * -ether_aton_r (const char *asc, struct ether_addr * addr) -{ - int i, val0, val1; - for (i = 0; i < ETHER_ADDR_LEN; ++i) { - val0 = xdigit(*asc); - asc++; - if (val0 < 0) - return NULL; - - val1 = xdigit(*asc); - asc++; - if (val1 < 0) - return NULL; - - addr->ether_addr_octet[i] = (u_int8_t)((val0 << 4) + val1); - - if (i < ETHER_ADDR_LEN - 1) { - if (*asc != ':') - return NULL; - asc++; - } - } - if (*asc != '\0') - return NULL; - return addr; -} - -/* - * Convert Ethernet address in the standard hex-digits-and-colons to binary - * representation. - */ -struct ether_addr * -ether_aton (const char *asc) -{ - static struct ether_addr addr; - return ether_aton_r(asc, &addr); -} diff --git a/libc/inet/ether_ntoa.c b/libc/inet/ether_ntoa.c deleted file mode 100644 index f56e48b24..000000000 --- a/libc/inet/ether_ntoa.c +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (C) 2010 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 -#include -#include - -/* - * Convert Ethernet address to standard hex-digits-and-colons printable form. - * Re-entrant version (GNU extensions). - */ -char * -ether_ntoa_r (const struct ether_addr *addr, char * buf) -{ - snprintf(buf, 18, "%02x:%02x:%02x:%02x:%02x:%02x", - addr->ether_addr_octet[0], addr->ether_addr_octet[1], - addr->ether_addr_octet[2], addr->ether_addr_octet[3], - addr->ether_addr_octet[4], addr->ether_addr_octet[5]); - return buf; -} - -/* - * Convert Ethernet address to standard hex-digits-and-colons printable form. - */ -char * -ether_ntoa (const struct ether_addr *addr) -{ - static char buf[18]; - return ether_ntoa_r(addr, buf); -} From 053febdd3bcf0586d38c5f3f46d7d0588ade2a4d Mon Sep 17 00:00:00 2001 From: Rebecca Schultz Zavin Date: Wed, 18 Aug 2010 16:20:09 -0700 Subject: [PATCH 31/93] Headers for tegra_camera device Change-Id: Iaea67ee157b6ecd7a4485c8f716515da5c56601f Signed-off-by: Rebecca Schultz Zavin --- libc/kernel/common/media/tegra_camera.h | 33 +++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 libc/kernel/common/media/tegra_camera.h diff --git a/libc/kernel/common/media/tegra_camera.h b/libc/kernel/common/media/tegra_camera.h new file mode 100644 index 000000000..0f6303570 --- /dev/null +++ b/libc/kernel/common/media/tegra_camera.h @@ -0,0 +1,33 @@ +/**************************************************************************** + **************************************************************************** + *** + *** This header was automatically generated from a Linux kernel header + *** of the same name, to make information necessary for userspace to + *** call into the kernel available to libc. It contains only constants, + *** structures, and macros generated from the original header, and thus, + *** contains no copyrightable information. + *** + **************************************************************************** + ****************************************************************************/ +enum { + TEGRA_CAMERA_MODULE_ISP = 0, + TEGRA_CAMERA_MODULE_VI, + TEGRA_CAMERA_MODULE_CSI, +}; + +enum { + TEGRA_CAMERA_VI_CLK, + TEGRA_CAMERA_VI_SENSOR_CLK, +}; + +struct tegra_camera_clk_info { + uint id; + uint clk_id; + unsigned long rate; +}; + +#define TEGRA_CAMERA_IOCTL_ENABLE _IOWR('i', 1, uint) +#define TEGRA_CAMERA_IOCTL_DISABLE _IOWR('i', 2, uint) +#define TEGRA_CAMERA_IOCTL_CLK_SET_RATE _IOWR('i', 3, struct tegra_camera_clk_info) +#define TEGRA_CAMERA_IOCTL_RESET _IOWR('i', 4, uint) + From a169e31a0681c47fd52cbc40db7d419ad8642acc Mon Sep 17 00:00:00 2001 From: Iliyan Malchev Date: Mon, 23 Aug 2010 21:01:55 -0700 Subject: [PATCH 32/93] bionic: add processed audio-driver (i2s & cpcap) headers Change-Id: Ib7db8aded1d41f54bbd681df116571c1996c569c Signed-off-by: Iliyan Malchev --- libc/kernel/common/linux/cpcap_audio.h | 54 +++++++++++++++++++++++++ libc/kernel/common/linux/tegra_audio.h | 55 ++++++++++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 libc/kernel/common/linux/cpcap_audio.h create mode 100644 libc/kernel/common/linux/tegra_audio.h diff --git a/libc/kernel/common/linux/cpcap_audio.h b/libc/kernel/common/linux/cpcap_audio.h new file mode 100644 index 000000000..33d843921 --- /dev/null +++ b/libc/kernel/common/linux/cpcap_audio.h @@ -0,0 +1,54 @@ +/**************************************************************************** + **************************************************************************** + *** + *** This header was automatically generated from a Linux kernel header + *** of the same name, to make information necessary for userspace to + *** call into the kernel available to libc. It contains only constants, + *** structures, and macros generated from the original header, and thus, + *** contains no copyrightable information. + *** + **************************************************************************** + ****************************************************************************/ +#ifndef _CPCAP_AUDIO_H +#define _CPCAP_AUDIO_H + +#include + +#define CPCAP_AUDIO_MAGIC 'c' + +#define CPCAP_AUDIO_OUT_SPEAKER 0 +#define CPCAP_AUDIO_OUT_HEADSET 1 +#define CPCAP_AUDIO_OUT_MAX 1 + +struct cpcap_audio_output { + int id; + int on; +}; + +#define CPCAP_AUDIO_OUT_SET_OUTPUT _IOW(CPCAP_AUDIO_MAGIC, 0, struct cpcap_audio_output *) + +#define CPCAP_AUDIO_OUT_VOL_MIN 0 +#define CPCAP_AUDIO_OUT_VOL_MAX 15 + +#define CPCAP_AUDIO_OUT_SET_VOLUME _IOW(CPCAP_AUDIO_MAGIC, 1, unsigned int) + +#define CPCAP_AUDIO_OUT_GET_OUTPUT _IOR(CPCAP_AUDIO_MAGIC, 2, unsigned int *) +#define CPCAP_AUDIO_OUT_GET_VOLUME _IOR(CPCAP_AUDIO_MAGIC, 3, unsigned int *) + +#define CPCAP_AUDIO_IN_MIC1 0 +#define CPCAP_AUDIO_IN_MIC2 1 +#define CPCAP_AUDIO_IN_MAX 1 + +#define CPCAP_AUDIO_IN_SET_INPUT _IOW(CPCAP_AUDIO_MAGIC, 4, unsigned int) + +#define CPCAP_AUDIO_IN_GET_INPUT _IOR(CPCAP_AUDIO_MAGIC, 5, unsigned int *) + +#define CPCAP_AUDIO_IN_VOL_MIN 0 +#define CPCAP_AUDIO_IN_VOL_MAX 31 + +#define CPCAP_AUDIO_IN_SET_VOLUME _IOW(CPCAP_AUDIO_MAGIC, 6, unsigned int) + +#define CPCAP_AUDIO_IN_GET_VOLUME _IOR(CPCAP_AUDIO_MAGIC, 7, unsigned int *) + +#endif + diff --git a/libc/kernel/common/linux/tegra_audio.h b/libc/kernel/common/linux/tegra_audio.h new file mode 100644 index 000000000..302e1392a --- /dev/null +++ b/libc/kernel/common/linux/tegra_audio.h @@ -0,0 +1,55 @@ +/**************************************************************************** + **************************************************************************** + *** + *** This header was automatically generated from a Linux kernel header + *** of the same name, to make information necessary for userspace to + *** call into the kernel available to libc. It contains only constants, + *** structures, and macros generated from the original header, and thus, + *** contains no copyrightable information. + *** + **************************************************************************** + ****************************************************************************/ +#ifndef _TEGRA_AUDIO_H +#define _TEGRA_AUDIO_H + +#include + +#define TEGRA_AUDIO_MAGIC 't' + +#define TEGRA_AUDIO_IN_START _IO(TEGRA_AUDIO_MAGIC, 0) +#define TEGRA_AUDIO_IN_STOP _IO(TEGRA_AUDIO_MAGIC, 1) + +struct tegra_audio_in_config { + int rate; + int stereo; +}; + +#define TEGRA_AUDIO_IN_SET_CONFIG _IOW(TEGRA_AUDIO_MAGIC, 2, const struct tegra_audio_in_config *) +#define TEGRA_AUDIO_IN_GET_CONFIG _IOR(TEGRA_AUDIO_MAGIC, 3, struct tegra_audio_in_config *) + +struct tegra_audio_buf_config { + unsigned size; + unsigned threshold; + unsigned chunk; +}; + +#define TEGRA_AUDIO_IN_SET_BUF_CONFIG _IOW(TEGRA_AUDIO_MAGIC, 4, const struct tegra_audio_buf_config *) +#define TEGRA_AUDIO_IN_GET_BUF_CONFIG _IOR(TEGRA_AUDIO_MAGIC, 5, struct tegra_audio_buf_config *) + +#define TEGRA_AUDIO_OUT_SET_BUF_CONFIG _IOW(TEGRA_AUDIO_MAGIC, 6, const struct tegra_audio_buf_config *) +#define TEGRA_AUDIO_OUT_GET_BUF_CONFIG _IOR(TEGRA_AUDIO_MAGIC, 7, struct tegra_audio_buf_config *) + +#define TEGRA_AUDIO_IN_GET_ERROR_COUNT _IOR(TEGRA_AUDIO_MAGIC, 8, unsigned *) + +#define TEGRA_AUDIO_OUT_GET_ERROR_COUNT _IOR(TEGRA_AUDIO_MAGIC, 9, unsigned *) + +struct tegra_audio_out_preload { + void *data; + size_t len; + size_t len_written; +}; + +#define TEGRA_AUDIO_OUT_PRELOAD_FIFO _IOWR(TEGRA_AUDIO_MAGIC, 10, struct tegra_audio_out_preload *) + +#endif + From 976c44be65338fc8327b4c3684937b7fedaa2ff4 Mon Sep 17 00:00:00 2001 From: Nick Pelly Date: Mon, 23 Aug 2010 14:47:38 -0700 Subject: [PATCH 33/93] Add clean kernel header perf_event.h Change-Id: I0d0e9da7579b1cccb9492ad8d594fe24dc1296e3 Signed-off-by: Nick Pelly --- libc/kernel/common/linux/perf_event.h | 240 ++++++++++++++++++++++++++ 1 file changed, 240 insertions(+) create mode 100644 libc/kernel/common/linux/perf_event.h diff --git a/libc/kernel/common/linux/perf_event.h b/libc/kernel/common/linux/perf_event.h new file mode 100644 index 000000000..9d3cd140d --- /dev/null +++ b/libc/kernel/common/linux/perf_event.h @@ -0,0 +1,240 @@ +/**************************************************************************** + **************************************************************************** + *** + *** This header was automatically generated from a Linux kernel header + *** of the same name, to make information necessary for userspace to + *** call into the kernel available to libc. It contains only constants, + *** structures, and macros generated from the original header, and thus, + *** contains no copyrightable information. + *** + **************************************************************************** + ****************************************************************************/ +#ifndef _LINUX_PERF_EVENT_H +#define _LINUX_PERF_EVENT_H + +#include +#include +#include + +enum perf_type_id { + PERF_TYPE_HARDWARE = 0, + PERF_TYPE_SOFTWARE = 1, + PERF_TYPE_TRACEPOINT = 2, + PERF_TYPE_HW_CACHE = 3, + PERF_TYPE_RAW = 4, + PERF_TYPE_BREAKPOINT = 5, + + PERF_TYPE_MAX, +}; + +enum perf_hw_id { + + PERF_COUNT_HW_CPU_CYCLES = 0, + PERF_COUNT_HW_INSTRUCTIONS = 1, + PERF_COUNT_HW_CACHE_REFERENCES = 2, + PERF_COUNT_HW_CACHE_MISSES = 3, + PERF_COUNT_HW_BRANCH_INSTRUCTIONS = 4, + PERF_COUNT_HW_BRANCH_MISSES = 5, + PERF_COUNT_HW_BUS_CYCLES = 6, + + PERF_COUNT_HW_MAX, +}; + +enum perf_hw_cache_id { + PERF_COUNT_HW_CACHE_L1D = 0, + PERF_COUNT_HW_CACHE_L1I = 1, + PERF_COUNT_HW_CACHE_LL = 2, + PERF_COUNT_HW_CACHE_DTLB = 3, + PERF_COUNT_HW_CACHE_ITLB = 4, + PERF_COUNT_HW_CACHE_BPU = 5, + + PERF_COUNT_HW_CACHE_MAX, +}; + +enum perf_hw_cache_op_id { + PERF_COUNT_HW_CACHE_OP_READ = 0, + PERF_COUNT_HW_CACHE_OP_WRITE = 1, + PERF_COUNT_HW_CACHE_OP_PREFETCH = 2, + + PERF_COUNT_HW_CACHE_OP_MAX, +}; + +enum perf_hw_cache_op_result_id { + PERF_COUNT_HW_CACHE_RESULT_ACCESS = 0, + PERF_COUNT_HW_CACHE_RESULT_MISS = 1, + + PERF_COUNT_HW_CACHE_RESULT_MAX, +}; + +enum perf_sw_ids { + PERF_COUNT_SW_CPU_CLOCK = 0, + PERF_COUNT_SW_TASK_CLOCK = 1, + PERF_COUNT_SW_PAGE_FAULTS = 2, + PERF_COUNT_SW_CONTEXT_SWITCHES = 3, + PERF_COUNT_SW_CPU_MIGRATIONS = 4, + PERF_COUNT_SW_PAGE_FAULTS_MIN = 5, + PERF_COUNT_SW_PAGE_FAULTS_MAJ = 6, + PERF_COUNT_SW_ALIGNMENT_FAULTS = 7, + PERF_COUNT_SW_EMULATION_FAULTS = 8, + + PERF_COUNT_SW_MAX, +}; + +enum perf_event_sample_format { + PERF_SAMPLE_IP = 1U << 0, + PERF_SAMPLE_TID = 1U << 1, + PERF_SAMPLE_TIME = 1U << 2, + PERF_SAMPLE_ADDR = 1U << 3, + PERF_SAMPLE_READ = 1U << 4, + PERF_SAMPLE_CALLCHAIN = 1U << 5, + PERF_SAMPLE_ID = 1U << 6, + PERF_SAMPLE_CPU = 1U << 7, + PERF_SAMPLE_PERIOD = 1U << 8, + PERF_SAMPLE_STREAM_ID = 1U << 9, + PERF_SAMPLE_RAW = 1U << 10, + + PERF_SAMPLE_MAX = 1U << 11, +}; + +enum perf_event_read_format { + PERF_FORMAT_TOTAL_TIME_ENABLED = 1U << 0, + PERF_FORMAT_TOTAL_TIME_RUNNING = 1U << 1, + PERF_FORMAT_ID = 1U << 2, + PERF_FORMAT_GROUP = 1U << 3, + + PERF_FORMAT_MAX = 1U << 4, +}; + +#define PERF_ATTR_SIZE_VER0 64 + +struct perf_event_attr { + + __u32 type; + + __u32 size; + + __u64 config; + + union { + __u64 sample_period; + __u64 sample_freq; + }; + + __u64 sample_type; + __u64 read_format; + + __u64 disabled : 1, + inherit : 1, + pinned : 1, + exclusive : 1, + exclude_user : 1, + exclude_kernel : 1, + exclude_hv : 1, + exclude_idle : 1, + mmap : 1, + comm : 1, + freq : 1, + inherit_stat : 1, + enable_on_exec : 1, + task : 1, + watermark : 1, + + precise_ip : 2, + + __reserved_1 : 47; + + union { + __u32 wakeup_events; + __u32 wakeup_watermark; + }; + + __u32 bp_type; + __u64 bp_addr; + __u64 bp_len; +}; + +#define PERF_EVENT_IOC_ENABLE _IO ('$', 0) +#define PERF_EVENT_IOC_DISABLE _IO ('$', 1) +#define PERF_EVENT_IOC_REFRESH _IO ('$', 2) +#define PERF_EVENT_IOC_RESET _IO ('$', 3) +#define PERF_EVENT_IOC_PERIOD _IOW('$', 4, __u64) +#define PERF_EVENT_IOC_SET_OUTPUT _IO ('$', 5) +#define PERF_EVENT_IOC_SET_FILTER _IOW('$', 6, char *) + +enum perf_event_ioc_flags { + PERF_IOC_FLAG_GROUP = 1U << 0, +}; + +struct perf_event_mmap_page { + __u32 version; + __u32 compat_version; + + __u32 lock; + __u32 index; + __s64 offset; + __u64 time_enabled; + __u64 time_running; + + __u64 __reserved[123]; + + __u64 data_head; + __u64 data_tail; +}; + +#define PERF_RECORD_MISC_CPUMODE_MASK (7 << 0) +#define PERF_RECORD_MISC_CPUMODE_UNKNOWN (0 << 0) +#define PERF_RECORD_MISC_KERNEL (1 << 0) +#define PERF_RECORD_MISC_USER (2 << 0) +#define PERF_RECORD_MISC_HYPERVISOR (3 << 0) +#define PERF_RECORD_MISC_GUEST_KERNEL (4 << 0) +#define PERF_RECORD_MISC_GUEST_USER (5 << 0) + +#define PERF_RECORD_MISC_EXACT_IP (1 << 14) + +#define PERF_RECORD_MISC_EXT_RESERVED (1 << 15) + +struct perf_event_header { + __u32 type; + __u16 misc; + __u16 size; +}; + +enum perf_event_type { + + PERF_RECORD_MMAP = 1, + + PERF_RECORD_LOST = 2, + + PERF_RECORD_COMM = 3, + + PERF_RECORD_EXIT = 4, + + PERF_RECORD_THROTTLE = 5, + PERF_RECORD_UNTHROTTLE = 6, + + PERF_RECORD_FORK = 7, + + PERF_RECORD_READ = 8, + + PERF_RECORD_SAMPLE = 9, + + PERF_RECORD_MAX, +}; + +enum perf_callchain_context { + PERF_CONTEXT_HV = (__u64)-32, + PERF_CONTEXT_KERNEL = (__u64)-128, + PERF_CONTEXT_USER = (__u64)-512, + + PERF_CONTEXT_GUEST = (__u64)-2048, + PERF_CONTEXT_GUEST_KERNEL = (__u64)-2176, + PERF_CONTEXT_GUEST_USER = (__u64)-2560, + + PERF_CONTEXT_MAX = (__u64)-4095, +}; + +#define PERF_FLAG_FD_NO_GROUP (1U << 0) +#define PERF_FLAG_FD_OUTPUT (1U << 1) + +#endif + From 41e533af4a2720c1dc228ba40b6582ca53085c3a Mon Sep 17 00:00:00 2001 From: Szymon Jakubczak Date: Wed, 9 Jun 2010 15:53:28 -0400 Subject: [PATCH 34/93] added missing ether_aton and ether_ntoa Change-Id: I32ee448abde4d5693d393030ed77ddc6d2ad1dfc --- libc/Android.mk | 2 + libc/include/net/if_ether.h | 2 + libc/inet/ether_aton.c | 89 +++++++++++++++++++++++++++++++++++++ libc/inet/ether_ntoa.c | 55 +++++++++++++++++++++++ 4 files changed, 148 insertions(+) create mode 100644 libc/inet/ether_aton.c create mode 100644 libc/inet/ether_ntoa.c diff --git a/libc/Android.mk b/libc/Android.mk index b3f95c55b..32bf9322e 100644 --- a/libc/Android.mk +++ b/libc/Android.mk @@ -240,6 +240,8 @@ libc_common_src_files := \ inet/inet_ntoa.c \ inet/inet_ntop.c \ inet/inet_pton.c \ + inet/ether_aton.c \ + inet/ether_ntoa.c \ tzcode/asctime.c \ tzcode/difftime.c \ tzcode/localtime.c \ diff --git a/libc/include/net/if_ether.h b/libc/include/net/if_ether.h index 121f9ac97..8daa16b6c 100644 --- a/libc/include/net/if_ether.h +++ b/libc/include/net/if_ether.h @@ -34,6 +34,8 @@ #ifndef _NET_IF_ETHER_H_ #define _NET_IF_ETHER_H_ +#include + #ifdef _KERNEL #ifdef _KERNEL_OPT #include "opt_mbuftrace.h" diff --git a/libc/inet/ether_aton.c b/libc/inet/ether_aton.c new file mode 100644 index 000000000..6540c0736 --- /dev/null +++ b/libc/inet/ether_aton.c @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2010 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 +#include +#include +#include +#include + +static inline int +xdigit (char c) { + unsigned d; + d = (unsigned)(c-'0'); + if (d < 10) return (int)d; + d = (unsigned)(c-'a'); + if (d < 6) return (int)(10+d); + d = (unsigned)(c-'A'); + if (d < 6) return (int)(10+d); + return -1; +} + +/* + * Convert Ethernet address in the standard hex-digits-and-colons to binary + * representation. + * Re-entrant version (GNU extensions) + */ +struct ether_addr * +ether_aton_r (const char *asc, struct ether_addr * addr) +{ + int i, val0, val1; + for (i = 0; i < ETHER_ADDR_LEN; ++i) { + val0 = xdigit(*asc); + asc++; + if (val0 < 0) + return NULL; + + val1 = xdigit(*asc); + asc++; + if (val1 < 0) + return NULL; + + addr->ether_addr_octet[i] = (u_int8_t)((val0 << 4) + val1); + + if (i < ETHER_ADDR_LEN - 1) { + if (*asc != ':') + return NULL; + asc++; + } + } + if (*asc != '\0') + return NULL; + return addr; +} + +/* + * Convert Ethernet address in the standard hex-digits-and-colons to binary + * representation. + */ +struct ether_addr * +ether_aton (const char *asc) +{ + static struct ether_addr addr; + return ether_aton_r(asc, &addr); +} diff --git a/libc/inet/ether_ntoa.c b/libc/inet/ether_ntoa.c new file mode 100644 index 000000000..f56e48b24 --- /dev/null +++ b/libc/inet/ether_ntoa.c @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2010 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 +#include +#include + +/* + * Convert Ethernet address to standard hex-digits-and-colons printable form. + * Re-entrant version (GNU extensions). + */ +char * +ether_ntoa_r (const struct ether_addr *addr, char * buf) +{ + snprintf(buf, 18, "%02x:%02x:%02x:%02x:%02x:%02x", + addr->ether_addr_octet[0], addr->ether_addr_octet[1], + addr->ether_addr_octet[2], addr->ether_addr_octet[3], + addr->ether_addr_octet[4], addr->ether_addr_octet[5]); + return buf; +} + +/* + * Convert Ethernet address to standard hex-digits-and-colons printable form. + */ +char * +ether_ntoa (const struct ether_addr *addr) +{ + static char buf[18]; + return ether_ntoa_r(addr, buf); +} From aa35095517b78b3d2e8ee282cab93ef058479fcf Mon Sep 17 00:00:00 2001 From: Jim Huang Date: Tue, 31 Aug 2010 14:51:44 +0800 Subject: [PATCH 35/93] Use ARMv6 instruction for handling byte order ARMv6 ISA has several instructions to handle data in different byte order. For endian conversion (byte swapping) of single data words, it might be a good idea to use the REV/REV16 instruction simply. Change-Id: Ic4a5ed6254e082763e54aa70d428f59a0088636e --- libc/arch-arm/include/endian.h | 83 ++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/libc/arch-arm/include/endian.h b/libc/arch-arm/include/endian.h index 04204ed4c..e34872fcb 100644 --- a/libc/arch-arm/include/endian.h +++ b/libc/arch-arm/include/endian.h @@ -1,5 +1,86 @@ /* $OpenBSD: endian.h,v 1.3 2005/12/13 00:35:23 millert Exp $ */ +/* + * Copyright (C) 2010 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. + */ + +#ifndef _ARM_ENDIAN_H_ +#define _ARM_ENDIAN_H_ + +#ifdef __GNUC__ + +/* NOTE: header could not be included directly + * since it defines extra macros, such as PLD. + */ +#if defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__) || \ + defined(__ARM_ARCH_7__) || \ + defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) || \ + defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6Z__) || \ + defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_6T2__) + +/* According to RealView Assembler User's Guide, REV and REV16 are available + * in Thumb code and 16-bit instructions when used in Thumb-2 code. + * + * REV Rd, Rm + * Rd and Rm must both be Lo registers. + * + * REV16 Rd, Rm + * Rd and Rm must both be Lo registers. + */ +#ifdef __thumb__ +#define REV_LO_REG asm("r4") +#else +#define REV_LO_REG +#endif + +#define __swap16md(x) ({ \ + register u_int16_t _x REV_LO_REG = (x); \ + __asm volatile ("rev16 %0, %0" : "+r" (_x)); \ + _x; \ +}) + +#define __swap32md(x) ({ \ + register u_int32_t _x REV_LO_REG = (x); \ + __asm volatile ("rev %0, %0" : "+r" (_x)); \ + _x; \ +}) + +#define __swap64md(x) ({ \ + u_int64_t _x = (x); \ + (u_int64_t) __swap32md(_x >> 32) | \ + (u_int64_t) __swap32md(_x & 0xffffffff) << 32; \ +}) + +/* Tell sys/endian.h we have MD variants of the swap macros. */ +#define MD_SWAP + +#endif /* __ARM_ARCH__ */ +#endif /* __GNUC__ */ + #ifdef __ARMEB__ #define _BYTE_ORDER _BIG_ENDIAN #else @@ -8,3 +89,5 @@ #define __STRICT_ALIGNMENT #include #include + +#endif /* !_ARM_ENDIAN_H_ */ From 3a1bbee36b773862e88c6f1895b607c0cd81b499 Mon Sep 17 00:00:00 2001 From: Keith Deacon Date: Tue, 31 Aug 2010 16:16:01 -0500 Subject: [PATCH 36/93] Add eventfd system call support --- libc/SYSCALLS.TXT | 2 ++ libc/arch-arm/syscalls.mk | 1 + libc/arch-arm/syscalls/eventfd.S | 19 +++++++++++++++++++ libc/include/sys/eventfd.h | 14 ++++++++++++++ libc/include/sys/linux-syscalls.h | 3 +++ libc/include/sys/linux-unistd.h | 1 + 6 files changed, 40 insertions(+) create mode 100644 libc/arch-arm/syscalls/eventfd.S create mode 100644 libc/include/sys/eventfd.h diff --git a/libc/SYSCALLS.TXT b/libc/SYSCALLS.TXT index 11407b9f4..b5a3bbe9e 100644 --- a/libc/SYSCALLS.TXT +++ b/libc/SYSCALLS.TXT @@ -262,3 +262,5 @@ int poll(struct pollfd *, unsigned int, long) 168 # ARM-specific ARM_NR_BASE == 0x0f0000 == 983040 int __set_tls:ARM_set_tls(void*) 983045,-1 int cacheflush:ARM_cacheflush(long start, long end, long flags) 983042,-1 + +int eventfd(int count, int flags) 351,323 diff --git a/libc/arch-arm/syscalls.mk b/libc/arch-arm/syscalls.mk index 9cdd28a92..9bfe70a91 100644 --- a/libc/arch-arm/syscalls.mk +++ b/libc/arch-arm/syscalls.mk @@ -171,3 +171,4 @@ syscall_src += arch-arm/syscalls/inotify_rm_watch.S syscall_src += arch-arm/syscalls/poll.S syscall_src += arch-arm/syscalls/__set_tls.S syscall_src += arch-arm/syscalls/cacheflush.S +syscall_src += arch-arm/syscalls/eventfd.S diff --git a/libc/arch-arm/syscalls/eventfd.S b/libc/arch-arm/syscalls/eventfd.S new file mode 100644 index 000000000..fb0912f26 --- /dev/null +++ b/libc/arch-arm/syscalls/eventfd.S @@ -0,0 +1,19 @@ +/* autogenerated by gensyscalls.py */ +#include + + .text + .type eventfd, #function + .globl eventfd + .align 4 + .fnstart + +eventfd: + .save {r4, r7} + stmfd sp!, {r4, r7} + ldr r7, =__NR_eventfd + swi #0 + ldmfd sp!, {r4, r7} + movs r0, r0 + bxpl lr + b __set_syscall_errno + .fnend diff --git a/libc/include/sys/eventfd.h b/libc/include/sys/eventfd.h new file mode 100644 index 000000000..0e142fdf0 --- /dev/null +++ b/libc/include/sys/eventfd.h @@ -0,0 +1,14 @@ +#ifndef _SYS_EVENTFD_H_ +#define _SYS_EVENTFD_H_ + +#include +#include +#include + +__BEGIN_DECLS + +extern int eventfd(int count, int flags); + +__END_DECLS + +#endif /* _SYS_EVENTFD_H_ */ diff --git a/libc/include/sys/linux-syscalls.h b/libc/include/sys/linux-syscalls.h index 6e373e05f..9fefd869b 100644 --- a/libc/include/sys/linux-syscalls.h +++ b/libc/include/sys/linux-syscalls.h @@ -181,6 +181,7 @@ #define __NR_inotify_rm_watch (__NR_SYSCALL_BASE + 318) #define __NR_ARM_set_tls (__NR_SYSCALL_BASE + 983045) #define __NR_ARM_cacheflush (__NR_SYSCALL_BASE + 983042) +#define __NR_eventfd (__NR_SYSCALL_BASE + 351) #endif #ifdef __i386__ @@ -222,6 +223,7 @@ #define __NR_inotify_init (__NR_SYSCALL_BASE + 291) #define __NR_inotify_add_watch (__NR_SYSCALL_BASE + 292) #define __NR_inotify_rm_watch (__NR_SYSCALL_BASE + 293) +#define __NR_eventfd (__NR_SYSCALL_BASE + 323) #endif #if defined(__SH3__) || defined(__SH4__) @@ -279,6 +281,7 @@ #define __NR_inotify_init (__NR_SYSCALL_BASE + 290) #define __NR_inotify_add_watch (__NR_SYSCALL_BASE + 291) #define __NR_inotify_rm_watch (__NR_SYSCALL_BASE + 292) +#define __NR_eventfd (__NR_SYSCALL_BASE + 323) #endif #endif diff --git a/libc/include/sys/linux-unistd.h b/libc/include/sys/linux-unistd.h index b0e7822df..de5c2bbe8 100644 --- a/libc/include/sys/linux-unistd.h +++ b/libc/include/sys/linux-unistd.h @@ -202,6 +202,7 @@ int inotify_rm_watch (int, unsigned int); int poll (struct pollfd *, unsigned int, long); int __set_tls (void*); int cacheflush (long start, long end, long flags); +int eventfd (int count, int flags); #ifdef __cplusplus } #endif From e2ac89869f9b459faa22640fb1bb41e818c1dd55 Mon Sep 17 00:00:00 2001 From: Andy McFadden Date: Thu, 2 Sep 2010 13:34:53 -0700 Subject: [PATCH 37/93] Add a memory barrier to cond var signaling. This adds an explicit memory barrier to condition variable signaling. It's a little murky as to whether it's strictly required, but it seems like a wise thing to do. Change-Id: Id0faa542d61e4b8ffa775e4adf68e4d7471f4fb7 --- libc/bionic/pthread.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/libc/bionic/pthread.c b/libc/bionic/pthread.c index b28cd9f65..dd8d75810 100644 --- a/libc/bionic/pthread.c +++ b/libc/bionic/pthread.c @@ -196,6 +196,9 @@ void __thread_entry(int (*func)(void*), void *arg, void **tls) // Wait for our creating thread to release us. This lets it have time to // notify gdb about this thread before it starts doing anything. + // + // This also provides the memory barrier needed to ensure that all memory + // accesses previously made by the creating thread are visible to us. pthread_mutex_t * start_mutex = (pthread_mutex_t *)&tls[TLS_SLOT_SELF]; pthread_mutex_lock(start_mutex); pthread_mutex_destroy(start_mutex); @@ -264,7 +267,7 @@ done: } /* - * Create a new thread. The thread's stack is layed out like so: + * Create a new thread. The thread's stack is laid out like so: * * +---------------------------+ * | pthread_internal_t | @@ -334,6 +337,10 @@ int pthread_create(pthread_t *thread_out, pthread_attr_t const * attr, // Create a mutex for the thread in TLS_SLOT_SELF to wait on once it starts so we can keep // it from doing anything until after we notify the debugger about it + // + // This also provides the memory barrier we need to ensure that all + // memory accesses previously performed by this thread are visible to + // the new thread. start_mutex = (pthread_mutex_t *) &tls[TLS_SLOT_SELF]; pthread_mutex_init(start_mutex, NULL); pthread_mutex_lock(start_mutex); @@ -1421,6 +1428,18 @@ __pthread_cond_pulse(pthread_cond_t *cond, int counter) break; } + /* + * Ensure that all memory accesses previously made by this thread are + * visible to the woken thread(s). On the other side, the "wait" + * code will issue any necessary barriers when locking the mutex. + * + * This may not strictly be necessary -- if the caller follows + * recommended practice and holds the mutex before signaling the cond + * var, the mutex ops will provide correct semantics. If they don't + * hold the mutex, they're subject to race conditions anyway. + */ + ANDROID_MEMBAR_FULL(); + __futex_wake_ex(&cond->value, COND_IS_SHARED(cond), counter); return 0; } From 94962b9c9cce58ce37c8cc7e5e89205f1d9689bd Mon Sep 17 00:00:00 2001 From: Antti Hatala Date: Thu, 2 Sep 2010 04:27:18 -0700 Subject: [PATCH 38/93] Fix libthread_db linkage libthread_db depends on libc but since unresolved symbols were allowed in the makefile this problem was never realized until gdbserver tried to link with it, failing in the runtime. Change-Id: If2ee319a2503c81abf3010829444f920c7c0c227 --- libthread_db/Android.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libthread_db/Android.mk b/libthread_db/Android.mk index 3091bbc3f..922b9cf1b 100644 --- a/libthread_db/Android.mk +++ b/libthread_db/Android.mk @@ -21,7 +21,7 @@ include $(CLEAR_VARS) LOCAL_WHOLE_STATIC_LIBRARIES := libthread_db LOCAL_MODULE:=libthread_db -LOCAL_SHARED_LIBRARIES := libdl +LOCAL_SHARED_LIBRARIES := libdl libc # NOTE: Using --no-undefined results in a missing symbol that is defined inside # gdbserver and is resolved at runtime. Since there is no library containing From 575d6b3f10c47e4d94e3408ca0418a059c0a88e0 Mon Sep 17 00:00:00 2001 From: Iliyan Malchev Date: Fri, 3 Sep 2010 10:09:37 -0700 Subject: [PATCH 39/93] bionic: update processed cpcap_audio.h Change-Id: I6ef25c4c95aaebdf4efc2561a726a0ce1c90032e Signed-off-by: Iliyan Malchev --- libc/kernel/common/linux/cpcap_audio.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/libc/kernel/common/linux/cpcap_audio.h b/libc/kernel/common/linux/cpcap_audio.h index 33d843921..5879567e4 100644 --- a/libc/kernel/common/linux/cpcap_audio.h +++ b/libc/kernel/common/linux/cpcap_audio.h @@ -18,14 +18,15 @@ #define CPCAP_AUDIO_OUT_SPEAKER 0 #define CPCAP_AUDIO_OUT_HEADSET 1 -#define CPCAP_AUDIO_OUT_MAX 1 +#define CPCAP_AUDIO_OUT_HEADSET_AND_SPEAKER 2 +#define CPCAP_AUDIO_OUT_MAX 2 -struct cpcap_audio_output { - int id; +struct cpcap_audio_stream { + unsigned id; int on; }; -#define CPCAP_AUDIO_OUT_SET_OUTPUT _IOW(CPCAP_AUDIO_MAGIC, 0, struct cpcap_audio_output *) +#define CPCAP_AUDIO_OUT_SET_OUTPUT _IOW(CPCAP_AUDIO_MAGIC, 0, const struct cpcap_audio_stream *) #define CPCAP_AUDIO_OUT_VOL_MIN 0 #define CPCAP_AUDIO_OUT_VOL_MAX 15 @@ -39,9 +40,9 @@ struct cpcap_audio_output { #define CPCAP_AUDIO_IN_MIC2 1 #define CPCAP_AUDIO_IN_MAX 1 -#define CPCAP_AUDIO_IN_SET_INPUT _IOW(CPCAP_AUDIO_MAGIC, 4, unsigned int) +#define CPCAP_AUDIO_IN_SET_INPUT _IOW(CPCAP_AUDIO_MAGIC, 4, const struct cpcap_audio_stream *) -#define CPCAP_AUDIO_IN_GET_INPUT _IOR(CPCAP_AUDIO_MAGIC, 5, unsigned int *) +#define CPCAP_AUDIO_IN_GET_INPUT _IOR(CPCAP_AUDIO_MAGIC, 5, struct cpcap_audio_stream *) #define CPCAP_AUDIO_IN_VOL_MIN 0 #define CPCAP_AUDIO_IN_VOL_MAX 31 From 2a8245c91415a652f98b2e206c9dbac25c024bb2 Mon Sep 17 00:00:00 2001 From: Dmitry Shmidt Date: Wed, 8 Sep 2010 11:32:16 -0700 Subject: [PATCH 40/93] Update if.h, if_vlan,h and add in_route.h Change-Id: I557a5ab71ea8dee18f5666b660fc73889c759851 Signed-off-by: Dmitry Shmidt --- libc/kernel/common/linux/if.h | 30 +++++++++++++-------- libc/kernel/common/linux/if_vlan.h | 7 +++++ libc/kernel/common/linux/in_route.h | 41 +++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 11 deletions(-) create mode 100644 libc/kernel/common/linux/in_route.h diff --git a/libc/kernel/common/linux/if.h b/libc/kernel/common/linux/if.h index 47c29d99d..7db4888e7 100644 --- a/libc/kernel/common/linux/if.h +++ b/libc/kernel/common/linux/if.h @@ -17,6 +17,7 @@ #include #define IFNAMSIZ 16 +#define IFALIASZ 256 #include #define IFF_UP 0x1 @@ -42,13 +43,24 @@ #define IFF_LOWER_UP 0x10000 #define IFF_DORMANT 0x20000 -#define IFF_VOLATILE (IFF_LOOPBACK|IFF_POINTOPOINT|IFF_BROADCAST| IFF_MASTER|IFF_SLAVE|IFF_RUNNING|IFF_LOWER_UP|IFF_DORMANT) +#define IFF_ECHO 0x40000 + +#define IFF_VOLATILE (IFF_LOOPBACK|IFF_POINTOPOINT|IFF_BROADCAST|IFF_ECHO| IFF_MASTER|IFF_SLAVE|IFF_RUNNING|IFF_LOWER_UP|IFF_DORMANT) #define IFF_802_1Q_VLAN 0x1 #define IFF_EBRIDGE 0x2 #define IFF_SLAVE_INACTIVE 0x4 #define IFF_MASTER_8023AD 0x8 #define IFF_MASTER_ALB 0x10 +#define IFF_BONDING 0x20 +#define IFF_SLAVE_NEEDARP 0x40 +#define IFF_ISATAP 0x80 +#define IFF_MASTER_ARPMON 0x100 +#define IFF_WAN_HDLC 0x200 +#define IFF_XMIT_DST_RELEASE 0x400 +#define IFF_DONT_BRIDGE 0x800 +#define IFF_IN_NETPOLL 0x1000 +#define IFF_DISABLE_NETPOLL 0x2000 #define IF_GET_IFACE 0x0001 #define IF_GET_PROTO 0x0002 @@ -90,8 +102,7 @@ enum { IF_LINK_MODE_DORMANT, }; -struct ifmap -{ +struct ifmap { unsigned long mem_start; unsigned long mem_end; unsigned short base_addr; @@ -101,8 +112,7 @@ struct ifmap }; -struct if_settings -{ +struct if_settings { unsigned int type; unsigned int size; union { @@ -118,8 +128,7 @@ struct if_settings } ifs_ifsu; }; -struct ifreq -{ +struct ifreq { #define IFHWADDRLEN 6 union { @@ -161,11 +170,9 @@ struct ifreq #define ifr_newname ifr_ifru.ifru_newname #define ifr_settings ifr_ifru.ifru_settings -struct ifconf -{ +struct ifconf { int ifc_len; - union - { + union { char __user *ifcu_buf; struct ifreq __user *ifcu_req; } ifc_ifcu; @@ -174,3 +181,4 @@ struct ifconf #define ifc_req ifc_ifcu.ifcu_req #endif + diff --git a/libc/kernel/common/linux/if_vlan.h b/libc/kernel/common/linux/if_vlan.h index d3d2df239..ab3b17495 100644 --- a/libc/kernel/common/linux/if_vlan.h +++ b/libc/kernel/common/linux/if_vlan.h @@ -25,6 +25,12 @@ enum vlan_ioctl_cmds { GET_VLAN_VID_CMD }; +enum vlan_flags { + VLAN_FLAG_REORDER_HDR = 0x1, + VLAN_FLAG_GVRP = 0x2, + VLAN_FLAG_LOOSE_BINDING = 0x4, +}; + enum vlan_name_types { VLAN_NAME_TYPE_PLUS_VID, VLAN_NAME_TYPE_RAW_PLUS_VID, @@ -50,3 +56,4 @@ struct vlan_ioctl_args { }; #endif + diff --git a/libc/kernel/common/linux/in_route.h b/libc/kernel/common/linux/in_route.h new file mode 100644 index 000000000..34e14d6df --- /dev/null +++ b/libc/kernel/common/linux/in_route.h @@ -0,0 +1,41 @@ +/**************************************************************************** + **************************************************************************** + *** + *** This header was automatically generated from a Linux kernel header + *** of the same name, to make information necessary for userspace to + *** call into the kernel available to libc. It contains only constants, + *** structures, and macros generated from the original header, and thus, + *** contains no copyrightable information. + *** + **************************************************************************** + ****************************************************************************/ +#ifndef _LINUX_IN_ROUTE_H +#define _LINUX_IN_ROUTE_H + +#define RTCF_DEAD RTNH_F_DEAD +#define RTCF_ONLINK RTNH_F_ONLINK + +#define RTCF_NOPMTUDISC RTM_F_NOPMTUDISC + +#define RTCF_NOTIFY 0x00010000 +#define RTCF_DIRECTDST 0x00020000 +#define RTCF_REDIRECTED 0x00040000 +#define RTCF_TPROXY 0x00080000 + +#define RTCF_FAST 0x00200000 +#define RTCF_MASQ 0x00400000 +#define RTCF_SNAT 0x00800000 +#define RTCF_DOREDIRECT 0x01000000 +#define RTCF_DIRECTSRC 0x04000000 +#define RTCF_DNAT 0x08000000 +#define RTCF_BROADCAST 0x10000000 +#define RTCF_MULTICAST 0x20000000 +#define RTCF_REJECT 0x40000000 +#define RTCF_LOCAL 0x80000000 + +#define RTCF_NAT (RTCF_DNAT|RTCF_SNAT) + +#define RT_TOS(tos) ((tos)&IPTOS_TOS_MASK) + +#endif + From 614628b018543809734a4475650dae4bdd9aae24 Mon Sep 17 00:00:00 2001 From: Erik Gilling Date: Wed, 8 Sep 2010 15:29:08 -0700 Subject: [PATCH 41/93] update linux/tegrafb.h Change-Id: I5edab909e5fe491a95729aa89b2f37c02af6bcba --- libc/kernel/common/linux/tegrafb.h | 49 +++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/libc/kernel/common/linux/tegrafb.h b/libc/kernel/common/linux/tegrafb.h index 2985d6182..27bb28686 100644 --- a/libc/kernel/common/linux/tegrafb.h +++ b/libc/kernel/common/linux/tegrafb.h @@ -15,10 +15,57 @@ #include #include -struct tegra_fb_flip_args { +#define TEGRA_FB_WIN_FMT_P1 0 +#define TEGRA_FB_WIN_FMT_P2 1 +#define TEGRA_FB_WIN_FMT_P4 2 +#define TEGRA_FB_WIN_FMT_P8 3 +#define TEGRA_FB_WIN_FMT_B4G4R4A4 4 +#define TEGRA_FB_WIN_FMT_B5G5R5A 5 +#define TEGRA_FB_WIN_FMT_B5G6R5 6 +#define TEGRA_FB_WIN_FMT_AB5G5R5 7 +#define TEGRA_FB_WIN_FMT_B8G8R8A8 12 +#define TEGRA_FB_WIN_FMT_R8G8B8A8 13 +#define TEGRA_FB_WIN_FMT_B6x2G6x2R6x2A8 14 +#define TEGRA_FB_WIN_FMT_R6x2G6x2B6x2A8 15 +#define TEGRA_FB_WIN_FMT_YCbCr422 16 +#define TEGRA_FB_WIN_FMT_YUV422 17 +#define TEGRA_FB_WIN_FMT_YCbCr420P 18 +#define TEGRA_FB_WIN_FMT_YUV420P 19 +#define TEGRA_FB_WIN_FMT_YCbCr422P 20 +#define TEGRA_FB_WIN_FMT_YUV422P 21 +#define TEGRA_FB_WIN_FMT_YCbCr422R 22 +#define TEGRA_FB_WIN_FMT_YUV422R 23 +#define TEGRA_FB_WIN_FMT_YCbCr422RA 24 +#define TEGRA_FB_WIN_FMT_YUV422RA 25 + +#define TEGRA_FB_WIN_BLEND_NONE 0 +#define TEGRA_FB_WIN_BLEND_PREMULT 1 +#define TEGRA_FB_WIN_BLEND_COVERAGE 2 + +struct tegra_fb_windowattr { + __s32 index; __u32 buff_id; + __u32 blend; + __u32 offset; + __u32 stride; + __u32 pixformat; + __u32 x; + __u32 y; + __u32 w; + __u32 h; + __u32 out_x; + __u32 out_y; + __u32 out_w; + __u32 out_h; + __u32 z; __u32 pre_syncpt_id; __u32 pre_syncpt_val; +}; + +#define TEGRA_FB_FLIP_N_WINDOWS 3 + +struct tegra_fb_flip_args { + struct tegra_fb_windowattr win[TEGRA_FB_FLIP_N_WINDOWS]; __u32 post_syncpt_id; __u32 post_syncpt_val; }; From 5797e016f9f56df99fdf0a97c5a3916d8aa051e4 Mon Sep 17 00:00:00 2001 From: Iliyan Malchev Date: Tue, 14 Sep 2010 13:02:59 -0700 Subject: [PATCH 42/93] bionic: update processed kernel header cpcap_audio.h Change-Id: I1f428e6513b144b5e78233c590b4a8e276cf55b7 Signed-off-by: Iliyan Malchev --- libc/kernel/common/linux/cpcap_audio.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libc/kernel/common/linux/cpcap_audio.h b/libc/kernel/common/linux/cpcap_audio.h index 5879567e4..65c728365 100644 --- a/libc/kernel/common/linux/cpcap_audio.h +++ b/libc/kernel/common/linux/cpcap_audio.h @@ -19,7 +19,8 @@ #define CPCAP_AUDIO_OUT_SPEAKER 0 #define CPCAP_AUDIO_OUT_HEADSET 1 #define CPCAP_AUDIO_OUT_HEADSET_AND_SPEAKER 2 -#define CPCAP_AUDIO_OUT_MAX 2 +#define CPCAP_AUDIO_OUT_STANDBY 3 +#define CPCAP_AUDIO_OUT_MAX 3 struct cpcap_audio_stream { unsigned id; @@ -33,16 +34,17 @@ struct cpcap_audio_stream { #define CPCAP_AUDIO_OUT_SET_VOLUME _IOW(CPCAP_AUDIO_MAGIC, 1, unsigned int) -#define CPCAP_AUDIO_OUT_GET_OUTPUT _IOR(CPCAP_AUDIO_MAGIC, 2, unsigned int *) +#define CPCAP_AUDIO_OUT_GET_OUTPUT _IOR(CPCAP_AUDIO_MAGIC, 2, struct cpcap_audio_stream *) #define CPCAP_AUDIO_OUT_GET_VOLUME _IOR(CPCAP_AUDIO_MAGIC, 3, unsigned int *) #define CPCAP_AUDIO_IN_MIC1 0 #define CPCAP_AUDIO_IN_MIC2 1 -#define CPCAP_AUDIO_IN_MAX 1 +#define CPCAP_AUDIO_IN_STANDBY 2 +#define CPCAP_AUDIO_IN_MAX 2 #define CPCAP_AUDIO_IN_SET_INPUT _IOW(CPCAP_AUDIO_MAGIC, 4, const struct cpcap_audio_stream *) -#define CPCAP_AUDIO_IN_GET_INPUT _IOR(CPCAP_AUDIO_MAGIC, 5, struct cpcap_audio_stream *) +#define CPCAP_AUDIO_IN_GET_INPUT _IOR(CPCAP_AUDIO_MAGIC, 5, struct cpcap_audio_stream *) #define CPCAP_AUDIO_IN_VOL_MIN 0 #define CPCAP_AUDIO_IN_VOL_MAX 31 From b1c9cc2f2d1b0478b07278cdef885cabf1cd2798 Mon Sep 17 00:00:00 2001 From: Andy McFadden Date: Thu, 23 Sep 2010 12:30:12 -0700 Subject: [PATCH 43/93] Add memory barriers to pthread_once. The implementation was using a double-checked locking approach that could break on SMP. In addition to the barriers I also switched to a volatile pointer. I don't think this will matter unless gcc can conclude that _normal_lock can't affect *once_control, but I figured it was better to be safe. (It seems to have no impact whatsoever on the generated code.) Bug 3022795. Change-Id: Ib91da25d57ff5bee4288526e39d457153ef6aacd --- libc/bionic/pthread.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/libc/bionic/pthread.c b/libc/bionic/pthread.c index dd8d75810..a1950183d 100644 --- a/libc/bionic/pthread.c +++ b/libc/bionic/pthread.c @@ -1886,12 +1886,16 @@ int pthread_getcpuclockid(pthread_t tid, clockid_t *clockid) int pthread_once( pthread_once_t* once_control, void (*init_routine)(void) ) { static pthread_mutex_t once_lock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER; + volatile pthread_once_t* ocptr = once_control; - if (*once_control == PTHREAD_ONCE_INIT) { + pthread_once_t tmp = *ocptr; + ANDROID_MEMBAR_FULL(); + if (tmp == PTHREAD_ONCE_INIT) { pthread_mutex_lock( &once_lock ); - if (*once_control == PTHREAD_ONCE_INIT) { + if (*ocptr == PTHREAD_ONCE_INIT) { (*init_routine)(); - *once_control = ~PTHREAD_ONCE_INIT; + ANDROID_MEMBAR_FULL(); + *ocptr = ~PTHREAD_ONCE_INIT; } pthread_mutex_unlock( &once_lock ); } From db21d7e4ed1089c798c5f1c1c57cdebd119712bb Mon Sep 17 00:00:00 2001 From: Rebecca Schultz Zavin Date: Thu, 23 Sep 2010 23:19:26 -0700 Subject: [PATCH 44/93] New headers for camera Change-Id: I1136aba4aa0d588c7c37da9774bd69a78bcac656 Signed-off-by: Rebecca Schultz Zavin --- libc/kernel/common/media/ov5650.h | 63 ++++++++++++++++++++++++++++++ libc/kernel/common/media/soc2030.h | 57 +++++++++++++++++++++++++++ 2 files changed, 120 insertions(+) create mode 100644 libc/kernel/common/media/ov5650.h create mode 100644 libc/kernel/common/media/soc2030.h diff --git a/libc/kernel/common/media/ov5650.h b/libc/kernel/common/media/ov5650.h new file mode 100644 index 000000000..3603dc2c1 --- /dev/null +++ b/libc/kernel/common/media/ov5650.h @@ -0,0 +1,63 @@ +/**************************************************************************** + **************************************************************************** + *** + *** This header was automatically generated from a Linux kernel header + *** of the same name, to make information necessary for userspace to + *** call into the kernel available to libc. It contains only constants, + *** structures, and macros generated from the original header, and thus, + *** contains no copyrightable information. + *** + **************************************************************************** + ****************************************************************************/ +#ifndef __OV5650_H__ +#define __OV5650_H__ + +#include + +#define OV5650_IOCTL_SET_MODE _IOW('o', 1, struct ov5650_mode) +#define OV5650_IOCTL_SET_FRAME_LENGTH _IOW('o', 2, __u32) +#define OV5650_IOCTL_SET_COARSE_TIME _IOW('o', 3, __u32) +#define OV5650_IOCTL_SET_GAIN _IOW('o', 4, __u16) +#define OV5650_IOCTL_GET_STATUS _IOR('o', 5, __u8) +#define OV5650_IOCTL_GET_OTP _IOR('o', 6, struct ov5650_otp_data) +#define OV5650_IOCTL_TEST_PATTERN _IOW('o', 7, enum ov5650_test_pattern) + +enum ov5650_test_pattern { + TEST_PATTERN_NONE, + TEST_PATTERN_COLORBARS, + TEST_PATTERN_CHECKERBOARD +}; + +struct ov5650_otp_data { + + __u8 sensor_serial_num[6]; + __u8 part_num[8]; + __u8 lens_id[1]; + __u8 manufacture_id[2]; + __u8 factory_id[2]; + __u8 manufacture_date[9]; + __u8 manufacture_line[2]; + + __u32 module_serial_num; + __u8 focuser_liftoff[2]; + __u8 focuser_macro[2]; + __u8 reserved1[12]; + __u8 shutter_cal[16]; + __u8 reserved2[183]; + + __u16 crc; + __u8 reserved3[3]; + __u8 auto_load[2]; +} __attribute__ ((packed)); + +struct ov5650_mode { + int xres; + int yres; + __u32 frame_length; + __u32 coarse_time; + __u16 gain; +}; + +#endif + + diff --git a/libc/kernel/common/media/soc2030.h b/libc/kernel/common/media/soc2030.h new file mode 100644 index 000000000..1e0e62629 --- /dev/null +++ b/libc/kernel/common/media/soc2030.h @@ -0,0 +1,57 @@ +/**************************************************************************** + **************************************************************************** + *** + *** This header was automatically generated from a Linux kernel header + *** of the same name, to make information necessary for userspace to + *** call into the kernel available to libc. It contains only constants, + *** structures, and macros generated from the original header, and thus, + *** contains no copyrightable information. + *** + **************************************************************************** + ****************************************************************************/ +#ifndef __SOC2030_H__ +#define __SOC2030_H__ + +#include + +#define SOC2030_IOCTL_SET_MODE _IOWR('o', 1, struct soc2030_mode) +#define SOC2030_IOCTL_GET_STATUS _IOC(_IOC_READ, 'o', 2, 10) +#define SOC2030_IOCTL_SET_PRIVATE _IOWR('o', 3, struct soc2030_regs) +#define SOC2030_IOCTL_GET_MODES _IO('o', 4) +#define SOC2030_IOCTL_GET_NUM_MODES _IOR('o', 5, unsigned int) + +#define SOC2030_POLL_WAITMS 50 +#define SOC2030_MAX_RETRIES 3 +#define SOC2030_POLL_RETRIES 5 + +#define SOC2030_MAX_PRIVATE_SIZE 1024 +#define SOC2030_MAX_NUM_MODES 6 + +enum { + REG_TABLE_END, + WRITE_REG_DATA, + WRITE_REG_BIT_H, + WRITE_REG_BIT_L, + POLL_REG_DATA, + POLL_REG_BIT_H, + POLL_REG_BIT_L, + POLL_VAR_DATA, + DELAY_MS, +}; + +struct soc2030_regs { + __u8 op; + __u16 addr; + __u16 val; +}; + +struct soc2030_mode { + int xres; + int yres; + int fps; + struct soc2030_regs *regset; +}; + +#endif + + From dd06eccffc981212a2d6e0727f70aed7b56ce30f Mon Sep 17 00:00:00 2001 From: Vinay Harugop Date: Sun, 26 Sep 2010 13:45:45 +0200 Subject: [PATCH 45/93] Support usage of __ARM_HAVE_LDREX_STREX The __ARM_HAVE_LDREX_STREX define is used to replace the swp instruction with ldrex/strex for ARM architecture greater than 6 (armv6, armv7 etc.). However the include file, cpu-features.h, which defines this flag was never included. Change-Id: Ia35e18e8b228ec830b2b42b08909515110753f18 Signed-off-by: Christian Bejram --- libc/arch-arm/bionic/atomics_arm.S | 1 + 1 file changed, 1 insertion(+) diff --git a/libc/arch-arm/bionic/atomics_arm.S b/libc/arch-arm/bionic/atomics_arm.S index f2e369d0b..78182285c 100644 --- a/libc/arch-arm/bionic/atomics_arm.S +++ b/libc/arch-arm/bionic/atomics_arm.S @@ -26,6 +26,7 @@ * SUCH DAMAGE. */ #include +#include .global __atomic_cmpxchg .type __atomic_cmpxchg, %function From 3cf53d1a7814e1520df09d24b009c16f4f27db0d Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Fri, 24 Sep 2010 17:55:58 -0700 Subject: [PATCH 46/93] Fixes for the ARM-specific bswap_16, bswap_32, and bswap_64. 1. Make the feature test work by excluding known-deficient processors, so we don't have to maintain a complete list of all the processors that support REV and REV16. 2. Don't abuse 'register' to get an effect similar to GCC's +l constraint, but which was unnecessarily restrictive. 3. Fix __swap64md so _x isn't clobbered, breaking 64-bit swaps. 4. Make (which declars bswap_16 and friends) use rather than , so we get the machine-dependent implementations. Change-Id: I6a38fad7a9fbe394aff141489617eb3883e1e944 --- libc/arch-arm/include/endian.h | 54 ++++++++++++++++------------------ libc/include/byteswap.h | 3 +- 2 files changed, 27 insertions(+), 30 deletions(-) diff --git a/libc/arch-arm/include/endian.h b/libc/arch-arm/include/endian.h index e34872fcb..6de0889ef 100644 --- a/libc/arch-arm/include/endian.h +++ b/libc/arch-arm/include/endian.h @@ -33,14 +33,14 @@ #ifdef __GNUC__ -/* NOTE: header could not be included directly - * since it defines extra macros, such as PLD. +/* + * REV and REV16 weren't available on ARM5 or ARM4. + * We don't include because it pollutes the + * namespace with macros like PLD. */ -#if defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__) || \ - defined(__ARM_ARCH_7__) || \ - defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) || \ - defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6Z__) || \ - defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_6T2__) +#if !defined __ARM_ARCH_5__ && !defined __ARM_ARCH_5T__ && \ + !defined __ARM_ARCH_5TE__ && !defined __ARM_ARCH_5TEJ__ && \ + !defined __ARM_ARCH_4T__ && !defined __ARM_ARCH_4__ /* According to RealView Assembler User's Guide, REV and REV16 are available * in Thumb code and 16-bit instructions when used in Thumb-2 code. @@ -50,44 +50,40 @@ * * REV16 Rd, Rm * Rd and Rm must both be Lo registers. + * + * The +l constraint takes care of this without constraining us in ARM mode. */ -#ifdef __thumb__ -#define REV_LO_REG asm("r4") -#else -#define REV_LO_REG -#endif - -#define __swap16md(x) ({ \ - register u_int16_t _x REV_LO_REG = (x); \ - __asm volatile ("rev16 %0, %0" : "+r" (_x)); \ - _x; \ +#define __swap16md(x) ({ \ + register u_int16_t _x = (x); \ + __asm volatile ("rev16 %0, %0" : "+l" (_x)); \ + _x; \ }) -#define __swap32md(x) ({ \ - register u_int32_t _x REV_LO_REG = (x); \ - __asm volatile ("rev %0, %0" : "+r" (_x)); \ - _x; \ +#define __swap32md(x) ({ \ + register u_int32_t _x = (x); \ + __asm volatile ("rev %0, %0" : "+l" (_x)); \ + _x; \ }) -#define __swap64md(x) ({ \ - u_int64_t _x = (x); \ - (u_int64_t) __swap32md(_x >> 32) | \ - (u_int64_t) __swap32md(_x & 0xffffffff) << 32; \ +#define __swap64md(x) ({ \ + u_int64_t _swap64md_x = (x); \ + (u_int64_t) __swap32md(_swap64md_x >> 32) | \ + (u_int64_t) __swap32md(_swap64md_x & 0xffffffff) << 32; \ }) /* Tell sys/endian.h we have MD variants of the swap macros. */ #define MD_SWAP -#endif /* __ARM_ARCH__ */ -#endif /* __GNUC__ */ +#endif /* __ARM_ARCH__ */ +#endif /* __GNUC__ */ #ifdef __ARMEB__ #define _BYTE_ORDER _BIG_ENDIAN #else #define _BYTE_ORDER _LITTLE_ENDIAN #endif -#define __STRICT_ALIGNMENT +#define __STRICT_ALIGNMENT #include #include -#endif /* !_ARM_ENDIAN_H_ */ +#endif /* !_ARM_ENDIAN_H_ */ diff --git a/libc/include/byteswap.h b/libc/include/byteswap.h index 16d2ad4f9..74b0e9180 100644 --- a/libc/include/byteswap.h +++ b/libc/include/byteswap.h @@ -28,7 +28,8 @@ #ifndef _BYTESWAP_H_ #define _BYTESWAP_H_ -#include +/* endian.h rather than sys/endian.h so we get the machine-specific file. */ +#include #define bswap_16(x) swap16(x) #define bswap_32(x) swap32(x) From 9d16a79b18f43faebbe8155dbc14896e9b7d8a2e Mon Sep 17 00:00:00 2001 From: Jim Huang Date: Mon, 27 Sep 2010 19:23:06 +0800 Subject: [PATCH 47/93] Hide the symbol of helper function __libc_android_abort Ideally __libc_android_abort would be static, but it could not be because gcc would not allow calling a static function from an asm statement. Instead, using GCC visibility is work around. Change-Id: Ifff6b9957ca3f0fc03c75c3e42582a48d43cefa2 --- libc/include/sys/cdefs_elf.h | 4 ++++ libc/unistd/abort.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/libc/include/sys/cdefs_elf.h b/libc/include/sys/cdefs_elf.h index e051b1d0e..1e5747010 100644 --- a/libc/include/sys/cdefs_elf.h +++ b/libc/include/sys/cdefs_elf.h @@ -95,6 +95,10 @@ __asm__(".section _sec\n\t.asciz _str\n\t.previous") #endif +/* GCC visibility helper macro */ +#define __LIBC_HIDDEN__ \ + __attribute__ ((visibility ("hidden"))) + #define __IDSTRING(_n,_s) __SECTIONSTRING(.ident,_s) #define __RCSID(_s) __IDSTRING(rcsid,_s) diff --git a/libc/unistd/abort.c b/libc/unistd/abort.c index 3e3aab0ea..8b8659b8b 100644 --- a/libc/unistd/abort.c +++ b/libc/unistd/abort.c @@ -40,7 +40,7 @@ __libc_android_log_print(ANDROID_LOG_DEBUG, "libc-abort", (format), ##__VA_ARGS__ ) #ifdef __arm__ -void +__LIBC_HIDDEN__ void __libc_android_abort(void) #else void From e5c35e075fad5b5c143971c4401a360f6eaf5470 Mon Sep 17 00:00:00 2001 From: Jim Huang Date: Mon, 27 Sep 2010 23:37:10 +0800 Subject: [PATCH 48/93] gethnamaddr: make helper functions static In order not to conflict with the symbols defined in file libc/netbsd/getaddrinfo.c, this patch makes the internal/helper functions static. Change-Id: I0f85599e0b4ce0a637d005ff1680e1805dec4380 --- libc/netbsd/gethnamaddr.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/libc/netbsd/gethnamaddr.c b/libc/netbsd/gethnamaddr.c index 1c219b2a2..3ebe53e2c 100644 --- a/libc/netbsd/gethnamaddr.c +++ b/libc/netbsd/gethnamaddr.c @@ -104,9 +104,9 @@ static void map_v4v6_address(const char *, char *); static void map_v4v6_hostent(struct hostent *, char **, char *); static void addrsort(char **, int, res_state); -void _sethtent(int); -void _endhtent(void); -struct hostent *_gethtent(void); +static void _sethtent(int); +static void _endhtent(void); +static struct hostent *_gethtent(void); void ht_sethostent(int); void ht_endhostent(void); struct hostent *ht_gethostbyname(char *); @@ -114,11 +114,11 @@ struct hostent *ht_gethostbyaddr(const char *, int, int); void dns_service(void); #undef dn_skipname int dn_skipname(const u_char *, const u_char *); -int _gethtbyaddr(void *, void *, va_list); -int _gethtbyname(void *, void *, va_list); -struct hostent *_gethtbyname2(const char *, int); -int _dns_gethtbyaddr(void *, void *, va_list); -int _dns_gethtbyname(void *, void *, va_list); +static int _gethtbyaddr(void *, void *, va_list); +static int _gethtbyname(void *, void *, va_list); +static struct hostent *_gethtbyname2(const char *, int); +static int _dns_gethtbyaddr(void *, void *, va_list); +static int _dns_gethtbyname(void *, void *, va_list); static struct hostent *gethostbyname_internal(const char *, int, res_state); @@ -692,7 +692,7 @@ gethostbyaddr(const char *addr, /* XXX should have been def'd as u_char! */ return hp; } -void +static void _sethtent(int f) { res_static rs = __res_get_static(); @@ -704,7 +704,7 @@ _sethtent(int f) rs->stayopen = f; } -void +static void _endhtent(void) { res_static rs = __res_get_static(); @@ -716,7 +716,7 @@ _endhtent(void) } } -struct hostent * +static struct hostent * _gethtent(void) { char *p; @@ -829,7 +829,7 @@ _gethtbyname(void *rv, void *cb_data, va_list ap) return NS_SUCCESS; } -struct hostent * +static struct hostent * _gethtbyname2(const char *name, int af) { struct hostent *p; @@ -920,7 +920,7 @@ _gethtbyname2(const char *name, int af) } /*ARGSUSED*/ -int +static int _gethtbyaddr(void *rv, void *cb_data, va_list ap) { struct hostent *p; @@ -1053,7 +1053,7 @@ gethostent(void) } /*ARGSUSED*/ -int +static int _dns_gethtbyname(void *rv, void *cb_data, va_list ap) { querybuf *buf; @@ -1113,7 +1113,7 @@ _dns_gethtbyname(void *rv, void *cb_data, va_list ap) } /*ARGSUSED*/ -int +static int _dns_gethtbyaddr(void *rv, void *cb_data, va_list ap) { char qbuf[MAXDNAME + 1], *qp, *ep; From 94e5c5ef3754fee833c527f12ddb18e639fe7cf2 Mon Sep 17 00:00:00 2001 From: Jim Huang Date: Fri, 1 Oct 2010 16:39:08 +0800 Subject: [PATCH 49/93] Reconcile assembly-only macros in The change explicitly isolates the assembly-only macros in header in order to prevent mis-inclusion in C/C++ source files. Change-Id: I0258e87c5ac3fd24944fb227290ac3b9cac4bfba --- libc/arch-arm/include/machine/cpu-features.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libc/arch-arm/include/machine/cpu-features.h b/libc/arch-arm/include/machine/cpu-features.h index 5af325bb2..902fe4543 100644 --- a/libc/arch-arm/include/machine/cpu-features.h +++ b/libc/arch-arm/include/machine/cpu-features.h @@ -158,6 +158,7 @@ /* Assembly-only macros */ +#ifdef __ASSEMBLY__ /* define a handy PLD(address) macro since the cache preload * is an optional opcode @@ -168,4 +169,6 @@ # define PLD(reg,offset) /* nothing */ #endif +#endif /* ! __ASSEMBLY__ */ + #endif /* _ARM_MACHINE_CPU_FEATURES_H */ From fff0c58e9aea925069bb6a8bb0ed363b616b402d Mon Sep 17 00:00:00 2001 From: Iliyan Malchev Date: Mon, 4 Oct 2010 22:54:47 -0700 Subject: [PATCH 50/93] bionic: update processed kernel header tegra_audio.h Change-Id: I23d03e0f651f26a1f6c170f982891dba2a2fe20d Signed-off-by: Iliyan Malchev --- libc/kernel/common/linux/tegra_audio.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/libc/kernel/common/linux/tegra_audio.h b/libc/kernel/common/linux/tegra_audio.h index 302e1392a..70c77bce1 100644 --- a/libc/kernel/common/linux/tegra_audio.h +++ b/libc/kernel/common/linux/tegra_audio.h @@ -39,9 +39,14 @@ struct tegra_audio_buf_config { #define TEGRA_AUDIO_OUT_SET_BUF_CONFIG _IOW(TEGRA_AUDIO_MAGIC, 6, const struct tegra_audio_buf_config *) #define TEGRA_AUDIO_OUT_GET_BUF_CONFIG _IOR(TEGRA_AUDIO_MAGIC, 7, struct tegra_audio_buf_config *) -#define TEGRA_AUDIO_IN_GET_ERROR_COUNT _IOR(TEGRA_AUDIO_MAGIC, 8, unsigned *) +struct tegra_audio_error_counts { + unsigned late_dma; + unsigned full_empty; +}; -#define TEGRA_AUDIO_OUT_GET_ERROR_COUNT _IOR(TEGRA_AUDIO_MAGIC, 9, unsigned *) +#define TEGRA_AUDIO_IN_GET_ERROR_COUNT _IOR(TEGRA_AUDIO_MAGIC, 8, struct tegra_audio_error_counts *) + +#define TEGRA_AUDIO_OUT_GET_ERROR_COUNT _IOR(TEGRA_AUDIO_MAGIC, 9, struct tegra_audio_error_counts *) struct tegra_audio_out_preload { void *data; From 9d8be5485c366b4f579bef0b88a4c99b899f21e1 Mon Sep 17 00:00:00 2001 From: tedbo Date: Tue, 5 Oct 2010 13:06:06 -0700 Subject: [PATCH 51/93] get_malloc_leak_info: Fix assumption that totalMemory out parameter was initialized to zero. The get_malloc_leak_info() currently asssumes that the totalMemory out parameter was pre-initialized to zero before the routine is called. If it is not then the accumulated totalMemory value will be incorrect. It is likely that many callers will simply allocate totalMemory on the stack with no initialization and assume that get_malloc_leak_info will set the proper value. As an example, the caller in frameworks/base/core/jni/android_os_Debug.cpp calls get_malloc_leak_info() with the address uninitiazed stack variable for totalMemory. It is probably best to fix this in get_malloc_leak_info. Change-Id: I84c927c3781419585794726115b7d34d8fdd24ae --- libc/bionic/malloc_debug_common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libc/bionic/malloc_debug_common.c b/libc/bionic/malloc_debug_common.c index f05576c4f..ebf0006a5 100644 --- a/libc/bionic/malloc_debug_common.c +++ b/libc/bionic/malloc_debug_common.c @@ -120,6 +120,7 @@ void get_malloc_leak_info(uint8_t** info, size_t* overallSize, totalMemory == NULL || backtraceSize == NULL) { return; } + *totalMemory = 0; pthread_mutex_lock(&gAllocationsMutex); @@ -127,7 +128,6 @@ void get_malloc_leak_info(uint8_t** info, size_t* overallSize, *info = NULL; *overallSize = 0; *infoSize = 0; - *totalMemory = 0; *backtraceSize = 0; goto done; } From b55ab95837b2a81449aa0eadac57ff600906550e Mon Sep 17 00:00:00 2001 From: Iliyan Malchev Date: Wed, 6 Oct 2010 20:34:09 -0700 Subject: [PATCH 52/93] bionic: update processed kernel header cpcap_audio.h Change-Id: If0aef2babd70c440456fb7f3e10c3c2ec6752c6e Signed-off-by: Iliyan Malchev --- libc/kernel/common/linux/cpcap_audio.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libc/kernel/common/linux/cpcap_audio.h b/libc/kernel/common/linux/cpcap_audio.h index 65c728365..0b586859b 100644 --- a/libc/kernel/common/linux/cpcap_audio.h +++ b/libc/kernel/common/linux/cpcap_audio.h @@ -44,7 +44,7 @@ struct cpcap_audio_stream { #define CPCAP_AUDIO_IN_SET_INPUT _IOW(CPCAP_AUDIO_MAGIC, 4, const struct cpcap_audio_stream *) -#define CPCAP_AUDIO_IN_GET_INPUT _IOR(CPCAP_AUDIO_MAGIC, 5, struct cpcap_audio_stream *) +#define CPCAP_AUDIO_IN_GET_INPUT _IOR(CPCAP_AUDIO_MAGIC, 5, struct cpcap_audio_stream *) #define CPCAP_AUDIO_IN_VOL_MIN 0 #define CPCAP_AUDIO_IN_VOL_MAX 31 @@ -53,5 +53,10 @@ struct cpcap_audio_stream { #define CPCAP_AUDIO_IN_GET_VOLUME _IOR(CPCAP_AUDIO_MAGIC, 7, unsigned int *) +#define CPCAP_AUDIO_OUT_GET_RATE _IOR(CPCAP_AUDIO_MAGIC, 8, unsigned int *) +#define CPCAP_AUDIO_OUT_SET_RATE _IOW(CPCAP_AUDIO_MAGIC, 9, unsigned int *) +#define CPCAP_AUDIO_IN_GET_RATE _IOR(CPCAP_AUDIO_MAGIC, 10, unsigned int *) +#define CPCAP_AUDIO_IN_SET_RATE _IOW(CPCAP_AUDIO_MAGIC, 11, unsigned int *) + #endif From 76a34d6628c1b0815cdf6bc6c0a724f9eb1118d4 Mon Sep 17 00:00:00 2001 From: Ying Wang Date: Fri, 8 Oct 2010 17:09:55 -0700 Subject: [PATCH 53/93] Remove duplicate item This elimates the makefile warning at the beginning of each build: libc_common_intermediates/arch-arm/syscalls/eventfd.o' given more than once in the same rule. Change-Id: I25cc0c373d55b5036dd17811a595c097fd6ca69a --- libc/arch-arm/syscalls.mk | 1 - 1 file changed, 1 deletion(-) diff --git a/libc/arch-arm/syscalls.mk b/libc/arch-arm/syscalls.mk index c3cf7859c..ba78c1846 100644 --- a/libc/arch-arm/syscalls.mk +++ b/libc/arch-arm/syscalls.mk @@ -175,4 +175,3 @@ syscall_src += arch-arm/syscalls/poll.S syscall_src += arch-arm/syscalls/eventfd.S syscall_src += arch-arm/syscalls/__set_tls.S syscall_src += arch-arm/syscalls/cacheflush.S -syscall_src += arch-arm/syscalls/eventfd.S From 124a542aa4d78040176f65b28f4958540b5d89aa Mon Sep 17 00:00:00 2001 From: Bruce Beare Date: Mon, 11 Oct 2010 12:24:41 -0700 Subject: [PATCH 54/93] Update ATOM string routines to latest Change-Id: I22a600e7f172681cfd38ff73a64e3fd07b284959 Signed-off-by: Lu, Hongjiu Signed-off-by: Bruce Beare --- libc/Android.mk | 2 +- libc/arch-x86/string/memcmp_wrapper.S | 2 +- libc/arch-x86/string/sse2-memset5-atom.S | 13 +- libc/arch-x86/string/sse2-strlen-atom.S | 369 ++++++++++++++++++ .../{ssse3-memcmp3.S => ssse3-memcmp3-new.S} | 142 +++---- libc/arch-x86/string/ssse3-memcpy5.S | 58 ++- .../{ssse3-strcmp.S => ssse3-strcmp-latest.S} | 29 +- libc/arch-x86/string/strcmp_wrapper.S | 2 +- libc/arch-x86/string/strlen_wrapper.S | 40 ++ libc/arch-x86/string/strncmp_wrapper.S | 2 +- 10 files changed, 567 insertions(+), 92 deletions(-) create mode 100644 libc/arch-x86/string/sse2-strlen-atom.S rename libc/arch-x86/string/{ssse3-memcmp3.S => ssse3-memcmp3-new.S} (95%) rename libc/arch-x86/string/{ssse3-strcmp.S => ssse3-strcmp-latest.S} (99%) create mode 100644 libc/arch-x86/string/strlen_wrapper.S diff --git a/libc/Android.mk b/libc/Android.mk index a034c5069..e6192671b 100644 --- a/libc/Android.mk +++ b/libc/Android.mk @@ -357,7 +357,7 @@ libc_common_src_files += \ arch-x86/string/memset_wrapper.S \ arch-x86/string/strcmp_wrapper.S \ arch-x86/string/strncmp_wrapper.S \ - arch-x86/string/strlen.S \ + arch-x86/string/strlen_wrapper.S \ bionic/pthread.c \ bionic/pthread-atfork.c \ bionic/pthread-timers.c \ diff --git a/libc/arch-x86/string/memcmp_wrapper.S b/libc/arch-x86/string/memcmp_wrapper.S index 7e28c1e7b..fa0c67259 100644 --- a/libc/arch-x86/string/memcmp_wrapper.S +++ b/libc/arch-x86/string/memcmp_wrapper.S @@ -31,7 +31,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #if defined(USE_SSSE3) # define MEMCMP memcmp -# include "ssse3-memcmp3.S" +# include "ssse3-memcmp3-new.S" #else diff --git a/libc/arch-x86/string/sse2-memset5-atom.S b/libc/arch-x86/string/sse2-memset5-atom.S index 59a598c36..4b7f71bca 100644 --- a/libc/arch-x86/string/sse2-memset5-atom.S +++ b/libc/arch-x86/string/sse2-memset5-atom.S @@ -49,7 +49,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #endif #ifndef cfi_restore -# define cfi_restore(reg) .cfi_restore (reg) +# define cfi_restore(reg) .cfi_restore reg #endif #ifndef cfi_adjust_cfa_offset @@ -285,7 +285,6 @@ L(32bytesormore): pxor %xmm0, %xmm0 #else movd %eax, %xmm0 - punpcklbw %xmm0, %xmm0 pshufd $0, %xmm0, %xmm0 #endif testl $0xf, %edx @@ -329,14 +328,17 @@ L(128bytesormore): #ifdef DATA_CACHE_SIZE POP (%ebx) +# define RESTORE_EBX_STATE CFI_PUSH (%ebx) cmp $DATA_CACHE_SIZE, %ecx #else # ifdef SHARED +# define RESTORE_EBX_STATE call __i686.get_pc_thunk.bx add $_GLOBAL_OFFSET_TABLE_, %ebx cmp __x86_data_cache_size@GOTOFF(%ebx), %ecx # else POP (%ebx) +# define RESTORE_EBX_STATE CFI_PUSH (%ebx) cmp __x86_data_cache_size, %ecx # endif #endif @@ -370,7 +372,7 @@ L(128bytesormore_normal): jae L(128bytesormore_normal) L(128bytesless_normal): - lea 128(%ecx), %ecx + add $128, %ecx BRANCH_TO_JMPTBL_ENTRY (L(table_16_128bytes)) ALIGN (4) @@ -393,8 +395,13 @@ L(128bytes_L2_normal): L(128bytesless_L2_normal): BRANCH_TO_JMPTBL_ENTRY (L(table_16_128bytes)) + RESTORE_EBX_STATE L(128bytesormore_nt_start): sub %ebx, %ecx + mov %ebx, %eax + and $0x7f, %eax + add %eax, %ecx + movd %xmm0, %eax ALIGN (4) L(128bytesormore_shared_cache_loop): prefetcht0 0x3c0(%edx) diff --git a/libc/arch-x86/string/sse2-strlen-atom.S b/libc/arch-x86/string/sse2-strlen-atom.S new file mode 100644 index 000000000..891186822 --- /dev/null +++ b/libc/arch-x86/string/sse2-strlen-atom.S @@ -0,0 +1,369 @@ +#define STRLEN sse2_strlen_atom + +#ifndef L +# define L(label) .L##label +#endif + +#ifndef cfi_startproc +# define cfi_startproc .cfi_startproc +#endif + +#ifndef cfi_endproc +# define cfi_endproc .cfi_endproc +#endif + +#ifndef cfi_rel_offset +# define cfi_rel_offset(reg, off) .cfi_rel_offset reg, off +#endif + +#ifndef cfi_restore +# define cfi_restore(reg) .cfi_restore reg +#endif + +#ifndef cfi_adjust_cfa_offset +# define cfi_adjust_cfa_offset(off) .cfi_adjust_cfa_offset off +#endif + +#ifndef cfi_remember_state +# define cfi_remember_state .cfi_remember_state +#endif + +#ifndef cfi_restore_state +# define cfi_restore_state .cfi_restore_state +#endif + +#ifndef ENTRY +# define ENTRY(name) \ + .type name, @function; \ + .globl name; \ + .p2align 4; \ +name: \ + cfi_startproc +#endif + +#ifndef END +# define END(name) \ + cfi_endproc; \ + .size name, .-name +#endif + +#define CFI_PUSH(REG) \ + cfi_adjust_cfa_offset (4); \ + cfi_rel_offset (REG, 0) + +#define CFI_POP(REG) \ + cfi_adjust_cfa_offset (-4); \ + cfi_restore (REG) + +#define PUSH(REG) pushl REG; CFI_PUSH (REG) +#define POP(REG) popl REG; CFI_POP (REG) +#define PARMS 4 +#define STR PARMS +#define ENTRANCE +#define RETURN ret + + .text +ENTRY (STRLEN) + ENTRANCE + mov STR(%esp), %edx + xor %eax, %eax + cmpb $0, (%edx) + jz L(exit_tail0) + cmpb $0, 1(%edx) + jz L(exit_tail1) + cmpb $0, 2(%edx) + jz L(exit_tail2) + cmpb $0, 3(%edx) + jz L(exit_tail3) + cmpb $0, 4(%edx) + jz L(exit_tail4) + cmpb $0, 5(%edx) + jz L(exit_tail5) + cmpb $0, 6(%edx) + jz L(exit_tail6) + cmpb $0, 7(%edx) + jz L(exit_tail7) + cmpb $0, 8(%edx) + jz L(exit_tail8) + cmpb $0, 9(%edx) + jz L(exit_tail9) + cmpb $0, 10(%edx) + jz L(exit_tail10) + cmpb $0, 11(%edx) + jz L(exit_tail11) + cmpb $0, 12(%edx) + jz L(exit_tail12) + cmpb $0, 13(%edx) + jz L(exit_tail13) + cmpb $0, 14(%edx) + jz L(exit_tail14) + cmpb $0, 15(%edx) + jz L(exit_tail15) + pxor %xmm0, %xmm0 + mov %edx, %eax + mov %edx, %ecx + and $-16, %eax + add $16, %ecx + add $16, %eax + + pcmpeqb (%eax), %xmm0 + pmovmskb %xmm0, %edx + pxor %xmm1, %xmm1 + test %edx, %edx + lea 16(%eax), %eax + jnz L(exit) + + pcmpeqb (%eax), %xmm1 + pmovmskb %xmm1, %edx + pxor %xmm2, %xmm2 + test %edx, %edx + lea 16(%eax), %eax + jnz L(exit) + + + pcmpeqb (%eax), %xmm2 + pmovmskb %xmm2, %edx + pxor %xmm3, %xmm3 + test %edx, %edx + lea 16(%eax), %eax + jnz L(exit) + + pcmpeqb (%eax), %xmm3 + pmovmskb %xmm3, %edx + test %edx, %edx + lea 16(%eax), %eax + jnz L(exit) + + pcmpeqb (%eax), %xmm0 + pmovmskb %xmm0, %edx + test %edx, %edx + lea 16(%eax), %eax + jnz L(exit) + + pcmpeqb (%eax), %xmm1 + pmovmskb %xmm1, %edx + test %edx, %edx + lea 16(%eax), %eax + jnz L(exit) + + pcmpeqb (%eax), %xmm2 + pmovmskb %xmm2, %edx + test %edx, %edx + lea 16(%eax), %eax + jnz L(exit) + + pcmpeqb (%eax), %xmm3 + pmovmskb %xmm3, %edx + test %edx, %edx + lea 16(%eax), %eax + jnz L(exit) + + pcmpeqb (%eax), %xmm0 + pmovmskb %xmm0, %edx + test %edx, %edx + lea 16(%eax), %eax + jnz L(exit) + + pcmpeqb (%eax), %xmm1 + pmovmskb %xmm1, %edx + test %edx, %edx + lea 16(%eax), %eax + jnz L(exit) + + pcmpeqb (%eax), %xmm2 + pmovmskb %xmm2, %edx + test %edx, %edx + lea 16(%eax), %eax + jnz L(exit) + + pcmpeqb (%eax), %xmm3 + pmovmskb %xmm3, %edx + test %edx, %edx + lea 16(%eax), %eax + jnz L(exit) + + pcmpeqb (%eax), %xmm0 + pmovmskb %xmm0, %edx + test %edx, %edx + lea 16(%eax), %eax + jnz L(exit) + + pcmpeqb (%eax), %xmm1 + pmovmskb %xmm1, %edx + test %edx, %edx + lea 16(%eax), %eax + jnz L(exit) + + pcmpeqb (%eax), %xmm2 + pmovmskb %xmm2, %edx + test %edx, %edx + lea 16(%eax), %eax + jnz L(exit) + + pcmpeqb (%eax), %xmm3 + pmovmskb %xmm3, %edx + test %edx, %edx + lea 16(%eax), %eax + jnz L(exit) + + and $-0x40, %eax + PUSH (%esi) + PUSH (%edi) + PUSH (%ebx) + PUSH (%ebp) + xor %ebp, %ebp +L(aligned_64): + pcmpeqb (%eax), %xmm0 + pcmpeqb 16(%eax), %xmm1 + pcmpeqb 32(%eax), %xmm2 + pcmpeqb 48(%eax), %xmm3 + pmovmskb %xmm0, %edx + pmovmskb %xmm1, %esi + pmovmskb %xmm2, %edi + pmovmskb %xmm3, %ebx + or %edx, %ebp + or %esi, %ebp + or %edi, %ebp + or %ebx, %ebp + lea 64(%eax), %eax + jz L(aligned_64) +L(48leave): + test %edx, %edx + jnz L(aligned_64_exit_16) + test %esi, %esi + jnz L(aligned_64_exit_32) + test %edi, %edi + jnz L(aligned_64_exit_48) + mov %ebx, %edx + lea (%eax), %eax + jmp L(aligned_64_exit) +L(aligned_64_exit_48): + lea -16(%eax), %eax + mov %edi, %edx + jmp L(aligned_64_exit) +L(aligned_64_exit_32): + lea -32(%eax), %eax + mov %esi, %edx + jmp L(aligned_64_exit) +L(aligned_64_exit_16): + lea -48(%eax), %eax +L(aligned_64_exit): + POP (%ebp) + POP (%ebx) + POP (%edi) + POP (%esi) +L(exit): + sub %ecx, %eax + test %dl, %dl + jz L(exit_high) + test $0x01, %dl + jnz L(exit_tail0) + + test $0x02, %dl + jnz L(exit_tail1) + + test $0x04, %dl + jnz L(exit_tail2) + + test $0x08, %dl + jnz L(exit_tail3) + + test $0x10, %dl + jnz L(exit_tail4) + + test $0x20, %dl + jnz L(exit_tail5) + + test $0x40, %dl + jnz L(exit_tail6) + add $7, %eax +L(exit_tail0): + RETURN + +L(exit_high): + add $8, %eax + test $0x01, %dh + jnz L(exit_tail0) + + test $0x02, %dh + jnz L(exit_tail1) + + test $0x04, %dh + jnz L(exit_tail2) + + test $0x08, %dh + jnz L(exit_tail3) + + test $0x10, %dh + jnz L(exit_tail4) + + test $0x20, %dh + jnz L(exit_tail5) + + test $0x40, %dh + jnz L(exit_tail6) + add $7, %eax + RETURN + + .p2align 4 +L(exit_tail1): + add $1, %eax + RETURN + +L(exit_tail2): + add $2, %eax + RETURN + +L(exit_tail3): + add $3, %eax + RETURN + +L(exit_tail4): + add $4, %eax + RETURN + +L(exit_tail5): + add $5, %eax + RETURN + +L(exit_tail6): + add $6, %eax + RETURN + +L(exit_tail7): + add $7, %eax + RETURN + +L(exit_tail8): + add $8, %eax + RETURN + +L(exit_tail9): + add $9, %eax + RETURN + +L(exit_tail10): + add $10, %eax + RETURN + +L(exit_tail11): + add $11, %eax + RETURN + +L(exit_tail12): + add $12, %eax + RETURN + +L(exit_tail13): + add $13, %eax + RETURN + +L(exit_tail14): + add $14, %eax + RETURN + +L(exit_tail15): + add $15, %eax + ret + +END (STRLEN) diff --git a/libc/arch-x86/string/ssse3-memcmp3.S b/libc/arch-x86/string/ssse3-memcmp3-new.S similarity index 95% rename from libc/arch-x86/string/ssse3-memcmp3.S rename to libc/arch-x86/string/ssse3-memcmp3-new.S index a7ce819ff..5ad879150 100644 --- a/libc/arch-x86/string/ssse3-memcmp3.S +++ b/libc/arch-x86/string/ssse3-memcmp3-new.S @@ -53,13 +53,21 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #endif #ifndef cfi_restore -# define cfi_restore(reg) .cfi_restore (reg) +# define cfi_restore(reg) .cfi_restore reg #endif #ifndef cfi_adjust_cfa_offset # define cfi_adjust_cfa_offset(off) .cfi_adjust_cfa_offset off #endif +#ifndef cfi_remember_state +# define cfi_remember_state .cfi_remember_state +#endif + +#ifndef cfi_restore_state +# define cfi_restore_state .cfi_restore_state +#endif + #ifndef ENTRY # define ENTRY(name) \ .type name, @function; \ @@ -91,8 +99,7 @@ name: \ #define BLK2 BLK1+4 #define LEN BLK2+4 #define RETURN_END POP (%edi); POP (%esi); POP (%ebx); ret -#define RETURN RETURN_END; CFI_PUSH (%ebx); CFI_PUSH (%edi); \ - CFI_PUSH (%esi) +#define RETURN RETURN_END; cfi_restore_state; cfi_remember_state .section .text.ssse3,"ax",@progbits ENTRY (MEMCMP) @@ -131,6 +138,7 @@ L(48bytesormore): PUSH (%ebx) PUSH (%esi) PUSH (%edi) + cfi_remember_state movdqu (%eax), %xmm3 movdqu (%edx), %xmm0 movl %eax, %edi @@ -211,8 +219,8 @@ L(shr_0): POP (%esi) jmp L(less48bytes) - CFI_PUSH (%esi) - CFI_PUSH (%edi) + cfi_restore_state + cfi_remember_state ALIGN (4) L(shr_0_gobble): lea -48(%ecx), %ecx @@ -257,8 +265,8 @@ L(shr_0_gobble_loop_next): POP (%esi) jmp L(less48bytes) - CFI_PUSH (%esi) - CFI_PUSH (%edi) + cfi_restore_state + cfi_remember_state ALIGN (4) L(shr_1): cmp $80, %ecx @@ -287,8 +295,8 @@ L(shr_1): POP (%esi) jmp L(less48bytes) - CFI_PUSH (%esi) - CFI_PUSH (%edi) + cfi_restore_state + cfi_remember_state ALIGN (4) L(shr_1_gobble): sub $32, %ecx @@ -340,8 +348,8 @@ L(shr_1_gobble_next): POP (%esi) jmp L(less48bytes) - CFI_PUSH (%esi) - CFI_PUSH (%edi) + cfi_restore_state + cfi_remember_state ALIGN (4) L(shr_2): cmp $80, %ecx @@ -370,8 +378,8 @@ L(shr_2): POP (%esi) jmp L(less48bytes) - CFI_PUSH (%esi) - CFI_PUSH (%edi) + cfi_restore_state + cfi_remember_state ALIGN (4) L(shr_2_gobble): sub $32, %ecx @@ -423,8 +431,8 @@ L(shr_2_gobble_next): POP (%esi) jmp L(less48bytes) - CFI_PUSH (%esi) - CFI_PUSH (%edi) + cfi_restore_state + cfi_remember_state ALIGN (4) L(shr_3): cmp $80, %ecx @@ -453,8 +461,8 @@ L(shr_3): POP (%esi) jmp L(less48bytes) - CFI_PUSH (%esi) - CFI_PUSH (%edi) + cfi_restore_state + cfi_remember_state ALIGN (4) L(shr_3_gobble): sub $32, %ecx @@ -506,8 +514,8 @@ L(shr_3_gobble_next): POP (%esi) jmp L(less48bytes) - CFI_PUSH (%esi) - CFI_PUSH (%edi) + cfi_restore_state + cfi_remember_state ALIGN (4) L(shr_4): cmp $80, %ecx @@ -536,8 +544,8 @@ L(shr_4): POP (%esi) jmp L(less48bytes) - CFI_PUSH (%esi) - CFI_PUSH (%edi) + cfi_restore_state + cfi_remember_state ALIGN (4) L(shr_4_gobble): sub $32, %ecx @@ -589,8 +597,8 @@ L(shr_4_gobble_next): POP (%esi) jmp L(less48bytes) - CFI_PUSH (%esi) - CFI_PUSH (%edi) + cfi_restore_state + cfi_remember_state ALIGN (4) L(shr_5): cmp $80, %ecx @@ -619,8 +627,8 @@ L(shr_5): POP (%esi) jmp L(less48bytes) - CFI_PUSH (%esi) - CFI_PUSH (%edi) + cfi_restore_state + cfi_remember_state ALIGN (4) L(shr_5_gobble): sub $32, %ecx @@ -672,8 +680,8 @@ L(shr_5_gobble_next): POP (%esi) jmp L(less48bytes) - CFI_PUSH (%esi) - CFI_PUSH (%edi) + cfi_restore_state + cfi_remember_state ALIGN (4) L(shr_6): cmp $80, %ecx @@ -702,8 +710,8 @@ L(shr_6): POP (%esi) jmp L(less48bytes) - CFI_PUSH (%esi) - CFI_PUSH (%edi) + cfi_restore_state + cfi_remember_state ALIGN (4) L(shr_6_gobble): sub $32, %ecx @@ -755,8 +763,8 @@ L(shr_6_gobble_next): POP (%esi) jmp L(less48bytes) - CFI_PUSH (%esi) - CFI_PUSH (%edi) + cfi_restore_state + cfi_remember_state ALIGN (4) L(shr_7): cmp $80, %ecx @@ -785,8 +793,8 @@ L(shr_7): POP (%esi) jmp L(less48bytes) - CFI_PUSH (%esi) - CFI_PUSH (%edi) + cfi_restore_state + cfi_remember_state ALIGN (4) L(shr_7_gobble): sub $32, %ecx @@ -838,8 +846,8 @@ L(shr_7_gobble_next): POP (%esi) jmp L(less48bytes) - CFI_PUSH (%esi) - CFI_PUSH (%edi) + cfi_restore_state + cfi_remember_state ALIGN (4) L(shr_8): cmp $80, %ecx @@ -868,8 +876,8 @@ L(shr_8): POP (%esi) jmp L(less48bytes) - CFI_PUSH (%esi) - CFI_PUSH (%edi) + cfi_restore_state + cfi_remember_state ALIGN (4) L(shr_8_gobble): sub $32, %ecx @@ -921,8 +929,8 @@ L(shr_8_gobble_next): POP (%esi) jmp L(less48bytes) - CFI_PUSH (%esi) - CFI_PUSH (%edi) + cfi_restore_state + cfi_remember_state ALIGN (4) L(shr_9): cmp $80, %ecx @@ -951,8 +959,8 @@ L(shr_9): POP (%esi) jmp L(less48bytes) - CFI_PUSH (%esi) - CFI_PUSH (%edi) + cfi_restore_state + cfi_remember_state ALIGN (4) L(shr_9_gobble): sub $32, %ecx @@ -1004,8 +1012,8 @@ L(shr_9_gobble_next): POP (%esi) jmp L(less48bytes) - CFI_PUSH (%esi) - CFI_PUSH (%edi) + cfi_restore_state + cfi_remember_state ALIGN (4) L(shr_10): cmp $80, %ecx @@ -1034,8 +1042,8 @@ L(shr_10): POP (%esi) jmp L(less48bytes) - CFI_PUSH (%esi) - CFI_PUSH (%edi) + cfi_restore_state + cfi_remember_state ALIGN (4) L(shr_10_gobble): sub $32, %ecx @@ -1087,8 +1095,8 @@ L(shr_10_gobble_next): POP (%esi) jmp L(less48bytes) - CFI_PUSH (%esi) - CFI_PUSH (%edi) + cfi_restore_state + cfi_remember_state ALIGN (4) L(shr_11): cmp $80, %ecx @@ -1117,8 +1125,8 @@ L(shr_11): POP (%esi) jmp L(less48bytes) - CFI_PUSH (%esi) - CFI_PUSH (%edi) + cfi_restore_state + cfi_remember_state ALIGN (4) L(shr_11_gobble): sub $32, %ecx @@ -1170,8 +1178,8 @@ L(shr_11_gobble_next): POP (%esi) jmp L(less48bytes) - CFI_PUSH (%esi) - CFI_PUSH (%edi) + cfi_restore_state + cfi_remember_state ALIGN (4) L(shr_12): cmp $80, %ecx @@ -1200,8 +1208,8 @@ L(shr_12): POP (%esi) jmp L(less48bytes) - CFI_PUSH (%esi) - CFI_PUSH (%edi) + cfi_restore_state + cfi_remember_state ALIGN (4) L(shr_12_gobble): sub $32, %ecx @@ -1253,8 +1261,8 @@ L(shr_12_gobble_next): POP (%esi) jmp L(less48bytes) - CFI_PUSH (%esi) - CFI_PUSH (%edi) + cfi_restore_state + cfi_remember_state ALIGN (4) L(shr_13): cmp $80, %ecx @@ -1283,8 +1291,8 @@ L(shr_13): POP (%esi) jmp L(less48bytes) - CFI_PUSH (%esi) - CFI_PUSH (%edi) + cfi_restore_state + cfi_remember_state ALIGN (4) L(shr_13_gobble): sub $32, %ecx @@ -1336,8 +1344,8 @@ L(shr_13_gobble_next): POP (%esi) jmp L(less48bytes) - CFI_PUSH (%esi) - CFI_PUSH (%edi) + cfi_restore_state + cfi_remember_state ALIGN (4) L(shr_14): cmp $80, %ecx @@ -1366,8 +1374,8 @@ L(shr_14): POP (%esi) jmp L(less48bytes) - CFI_PUSH (%esi) - CFI_PUSH (%edi) + cfi_restore_state + cfi_remember_state ALIGN (4) L(shr_14_gobble): sub $32, %ecx @@ -1419,8 +1427,8 @@ L(shr_14_gobble_next): POP (%esi) jmp L(less48bytes) - CFI_PUSH (%esi) - CFI_PUSH (%edi) + cfi_restore_state + cfi_remember_state ALIGN (4) L(shr_15): cmp $80, %ecx @@ -1449,8 +1457,8 @@ L(shr_15): POP (%esi) jmp L(less48bytes) - CFI_PUSH (%esi) - CFI_PUSH (%edi) + cfi_restore_state + cfi_remember_state ALIGN (4) L(shr_15_gobble): sub $32, %ecx @@ -1502,8 +1510,8 @@ L(shr_15_gobble_next): POP (%esi) jmp L(less48bytes) - CFI_PUSH (%esi) - CFI_PUSH (%edi) + cfi_restore_state + cfi_remember_state ALIGN (4) L(exit): pmovmskb %xmm1, %ebx diff --git a/libc/arch-x86/string/ssse3-memcpy5.S b/libc/arch-x86/string/ssse3-memcpy5.S index 6b9040266..b4773dfb1 100644 --- a/libc/arch-x86/string/ssse3-memcpy5.S +++ b/libc/arch-x86/string/ssse3-memcpy5.S @@ -53,13 +53,21 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #endif #ifndef cfi_restore -# define cfi_restore(reg) .cfi_restore (reg) +# define cfi_restore(reg) .cfi_restore reg #endif #ifndef cfi_adjust_cfa_offset # define cfi_adjust_cfa_offset(off) .cfi_adjust_cfa_offset off #endif +#ifndef cfi_remember_state +# define cfi_remember_state .cfi_remember_state +#endif + +#ifndef cfi_restore_state +# define cfi_restore_state .cfi_restore_state +#endif + #ifndef ENTRY # define ENTRY(name) \ .type name, @function; \ @@ -118,8 +126,8 @@ name: \ jmp *%ebx # define BRANCH_TO_JMPTBL_ENTRY_VALUE(TABLE) \ - addl $(TABLE - .), %ebx - + addl $(TABLE - .), %ebx + # define BRANCH_TO_JMPTBL_ENTRY_TAIL(TABLE, INDEX, SCALE) \ addl (%ebx,INDEX,SCALE), %ebx; \ /* We loaded the jump table. Go. */ \ @@ -146,7 +154,7 @@ __i686.get_pc_thunk.bx: # define BRANCH_TO_JMPTBL_ENTRY(TABLE, INDEX, SCALE) \ jmp *TABLE(,INDEX,SCALE) -# define BRANCH_TO_JMPTBL_ENTRY_VALUE(TABLE) +# define BRANCH_TO_JMPTBL_ENTRY_VALUE(TABLE) # define BRANCH_TO_JMPTBL_ENTRY_TAIL(TABLE, INDEX, SCALE) \ jmp *TABLE(,INDEX,SCALE) @@ -198,6 +206,7 @@ L(48bytesormore): movl %edx, %edi and $-16, %edx PUSH (%esi) + cfi_remember_state add $16, %edx movl %edi, %esi sub %edx, %edi @@ -223,6 +232,8 @@ L(48bytesormore): BRANCH_TO_JMPTBL_ENTRY (L(shl_table), %edi, 4) + cfi_restore_state + cfi_remember_state ALIGN (4) L(shl_0): movdqu %xmm0, (%esi) @@ -270,6 +281,7 @@ L(shl_0_end): POP (%edi) BRANCH_TO_JMPTBL_ENTRY (L(table_48bytes_fwd), %ecx, 4) + CFI_PUSH (%edi) L(shl_0_gobble): #ifdef DATA_CACHE_SIZE_HALF @@ -419,7 +431,8 @@ L(shl_0_mem_less_16bytes): add %ecx, %eax BRANCH_TO_JMPTBL_ENTRY (L(table_48bytes_fwd), %ecx, 4) - + cfi_restore_state + cfi_remember_state ALIGN (4) L(shl_1): BRANCH_TO_JMPTBL_ENTRY_VALUE(L(table_48bytes_fwd)) @@ -463,6 +476,8 @@ L(shl_1_end): POP (%edi) BRANCH_TO_JMPTBL_ENTRY_TAIL(L(table_48bytes_fwd), %ecx, 4) + cfi_restore_state + cfi_remember_state ALIGN (4) L(shl_2): BRANCH_TO_JMPTBL_ENTRY_VALUE(L(table_48bytes_fwd)) @@ -506,6 +521,8 @@ L(shl_2_end): POP (%edi) BRANCH_TO_JMPTBL_ENTRY_TAIL(L(table_48bytes_fwd), %ecx, 4) + cfi_restore_state + cfi_remember_state ALIGN (4) L(shl_3): BRANCH_TO_JMPTBL_ENTRY_VALUE(L(table_48bytes_fwd)) @@ -549,6 +566,8 @@ L(shl_3_end): POP (%edi) BRANCH_TO_JMPTBL_ENTRY_TAIL(L(table_48bytes_fwd), %ecx, 4) + cfi_restore_state + cfi_remember_state ALIGN (4) L(shl_4): BRANCH_TO_JMPTBL_ENTRY_VALUE(L(table_48bytes_fwd)) @@ -592,6 +611,8 @@ L(shl_4_end): POP (%edi) BRANCH_TO_JMPTBL_ENTRY_TAIL(L(table_48bytes_fwd), %ecx, 4) + cfi_restore_state + cfi_remember_state ALIGN (4) L(shl_5): BRANCH_TO_JMPTBL_ENTRY_VALUE(L(table_48bytes_fwd)) @@ -635,7 +656,8 @@ L(shl_5_end): POP (%edi) BRANCH_TO_JMPTBL_ENTRY_TAIL(L(table_48bytes_fwd), %ecx, 4) - + cfi_restore_state + cfi_remember_state ALIGN (4) L(shl_6): BRANCH_TO_JMPTBL_ENTRY_VALUE(L(table_48bytes_fwd)) @@ -679,6 +701,8 @@ L(shl_6_end): POP (%edi) BRANCH_TO_JMPTBL_ENTRY_TAIL(L(table_48bytes_fwd), %ecx, 4) + cfi_restore_state + cfi_remember_state ALIGN (4) L(shl_7): BRANCH_TO_JMPTBL_ENTRY_VALUE(L(table_48bytes_fwd)) @@ -722,6 +746,8 @@ L(shl_7_end): POP (%edi) BRANCH_TO_JMPTBL_ENTRY_TAIL(L(table_48bytes_fwd), %ecx, 4) + cfi_restore_state + cfi_remember_state ALIGN (4) L(shl_8): BRANCH_TO_JMPTBL_ENTRY_VALUE(L(table_48bytes_fwd)) @@ -765,6 +791,8 @@ L(shl_8_end): POP (%edi) BRANCH_TO_JMPTBL_ENTRY_TAIL(L(table_48bytes_fwd), %ecx, 4) + cfi_restore_state + cfi_remember_state ALIGN (4) L(shl_9): BRANCH_TO_JMPTBL_ENTRY_VALUE(L(table_48bytes_fwd)) @@ -808,6 +836,8 @@ L(shl_9_end): POP (%edi) BRANCH_TO_JMPTBL_ENTRY_TAIL(L(table_48bytes_fwd), %ecx, 4) + cfi_restore_state + cfi_remember_state ALIGN (4) L(shl_10): BRANCH_TO_JMPTBL_ENTRY_VALUE(L(table_48bytes_fwd)) @@ -851,6 +881,8 @@ L(shl_10_end): POP (%edi) BRANCH_TO_JMPTBL_ENTRY_TAIL(L(table_48bytes_fwd), %ecx, 4) + cfi_restore_state + cfi_remember_state ALIGN (4) L(shl_11): BRANCH_TO_JMPTBL_ENTRY_VALUE(L(table_48bytes_fwd)) @@ -894,6 +926,8 @@ L(shl_11_end): POP (%edi) BRANCH_TO_JMPTBL_ENTRY_TAIL(L(table_48bytes_fwd), %ecx, 4) + cfi_restore_state + cfi_remember_state ALIGN (4) L(shl_12): BRANCH_TO_JMPTBL_ENTRY_VALUE(L(table_48bytes_fwd)) @@ -937,6 +971,8 @@ L(shl_12_end): POP (%edi) BRANCH_TO_JMPTBL_ENTRY_TAIL(L(table_48bytes_fwd), %ecx, 4) + cfi_restore_state + cfi_remember_state ALIGN (4) L(shl_13): BRANCH_TO_JMPTBL_ENTRY_VALUE(L(table_48bytes_fwd)) @@ -980,6 +1016,8 @@ L(shl_13_end): POP (%edi) BRANCH_TO_JMPTBL_ENTRY_TAIL(L(table_48bytes_fwd), %ecx, 4) + cfi_restore_state + cfi_remember_state ALIGN (4) L(shl_14): BRANCH_TO_JMPTBL_ENTRY_VALUE(L(table_48bytes_fwd)) @@ -1023,7 +1061,8 @@ L(shl_14_end): POP (%edi) BRANCH_TO_JMPTBL_ENTRY_TAIL(L(table_48bytes_fwd), %ecx, 4) - + cfi_restore_state + cfi_remember_state ALIGN (4) L(shl_15): BRANCH_TO_JMPTBL_ENTRY_VALUE(L(table_48bytes_fwd)) @@ -1264,8 +1303,10 @@ L(fwd_write_3bytes): movl DEST(%esp), %eax # endif #endif - RETURN + RETURN_END + cfi_restore_state + cfi_remember_state ALIGN (4) L(large_page): movdqu (%eax), %xmm1 @@ -1688,6 +1729,7 @@ L(bk_write_less32bytes): L(bk_write_less32bytes_2): BRANCH_TO_JMPTBL_ENTRY (L(table_48_bytes_bwd), %ecx, 4) + CFI_PUSH (%esi) ALIGN (4) L(bk_align): cmp $8, %ecx diff --git a/libc/arch-x86/string/ssse3-strcmp.S b/libc/arch-x86/string/ssse3-strcmp-latest.S similarity index 99% rename from libc/arch-x86/string/ssse3-strcmp.S rename to libc/arch-x86/string/ssse3-strcmp-latest.S index cfb2e9ff2..69c6425be 100644 --- a/libc/arch-x86/string/ssse3-strcmp.S +++ b/libc/arch-x86/string/ssse3-strcmp-latest.S @@ -45,13 +45,21 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #endif #ifndef cfi_restore -# define cfi_restore(reg) .cfi_restore (reg) +# define cfi_restore(reg) .cfi_restore reg #endif #ifndef cfi_adjust_cfa_offset # define cfi_adjust_cfa_offset(off) .cfi_adjust_cfa_offset off #endif +#ifndef cfi_remember_state +# define cfi_remember_state .cfi_remember_state +#endif + +#ifndef cfi_restore_state +# define cfi_restore_state .cfi_restore_state +#endif + #ifndef ENTRY # define ENTRY(name) \ .type name, @function; \ @@ -201,6 +209,9 @@ L(crosspage): PUSH (%ebx) PUSH (%edi) PUSH (%esi) +#ifdef USE_AS_STRNCMP + cfi_remember_state +#endif movl %edx, %edi movl %eax, %ecx @@ -1521,17 +1532,18 @@ L(gobble_ashr_12): sub $0xffff, %esi jnz L(exit) +#ifdef USE_AS_STRNCMP + cmp $16, %ebp + lea -16(%ebp), %ebp + jbe L(more8byteseq) +#endif + add $16, %ecx movdqa %xmm4, %xmm3 add $16, %edi jg L(nibble_ashr_12) -#ifdef USE_AS_STRNCMP - cmp $16, %ebp - lea -16(%ebp), %ebp - jbe L(more8byteseq) -#endif movdqa (%eax, %ecx), %xmm1 movdqa (%edx, %ecx), %xmm2 movdqa %xmm2, %xmm4 @@ -2087,10 +2099,7 @@ L(neq_bigger): RETURN #ifdef USE_AS_STRNCMP - CFI_PUSH (%ebx) - CFI_PUSH (%edi) - CFI_PUSH (%esi) - + cfi_restore_state .p2align 4 L(more8byteseq): POP (%esi) diff --git a/libc/arch-x86/string/strcmp_wrapper.S b/libc/arch-x86/string/strcmp_wrapper.S index 69b7f0bed..20f3064e5 100644 --- a/libc/arch-x86/string/strcmp_wrapper.S +++ b/libc/arch-x86/string/strcmp_wrapper.S @@ -31,7 +31,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #if defined(USE_SSSE3) # define ssse3_strcmp_latest strcmp -# include "ssse3-strcmp.S" +# include "ssse3-strcmp-latest.S" #else diff --git a/libc/arch-x86/string/strlen_wrapper.S b/libc/arch-x86/string/strlen_wrapper.S new file mode 100644 index 000000000..e62786b9d --- /dev/null +++ b/libc/arch-x86/string/strlen_wrapper.S @@ -0,0 +1,40 @@ +/* +Copyright (c) 2010, Intel Corporation +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. + + * Neither the name of Intel Corporation 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 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. +*/ + +#if defined(USE_SSE2) + +# define sse2_strlen_atom strlen +# include "sse2-strlen-atom.S" + +#else + +# include "strlen.S" + +#endif diff --git a/libc/arch-x86/string/strncmp_wrapper.S b/libc/arch-x86/string/strncmp_wrapper.S index 205018420..191d7555e 100644 --- a/libc/arch-x86/string/strncmp_wrapper.S +++ b/libc/arch-x86/string/strncmp_wrapper.S @@ -32,7 +32,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # define USE_AS_STRNCMP # define ssse3_strcmp_latest strncmp -# include "ssse3-strcmp.S" +# include "ssse3-strcmp-latest.S" #else From 58f2b7ed660fdf7f251eaf926faa04f9e0e19b48 Mon Sep 17 00:00:00 2001 From: Bruce Beare Date: Mon, 11 Oct 2010 12:08:07 -0700 Subject: [PATCH 55/93] Use proper variable typing Change-Id: If5c33d90b33f538448ac12e7bee94b4b9173d39c Signed-off-by: Bruce Beare --- libm/i387/fenv.c | 3 ++- libm/include/i387/fenv.h | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/libm/i387/fenv.c b/libm/i387/fenv.c index 2794faf81..aabe270d5 100644 --- a/libm/i387/fenv.c +++ b/libm/i387/fenv.c @@ -153,7 +153,8 @@ feholdexcept(fenv_t *envp) int feupdateenv(const fenv_t *envp) { - int mxcsr, status; + int mxcsr; + short status; __fnstsw(&status); if (__HAS_SSE()) diff --git a/libm/include/i387/fenv.h b/libm/include/i387/fenv.h index b124366ac..4281f10eb 100644 --- a/libm/include/i387/fenv.h +++ b/libm/include/i387/fenv.h @@ -102,7 +102,7 @@ extern const fenv_t __fe_dfl_env; #define __fnclex() __asm __volatile("fnclex") #define __fnstenv(__env) __asm __volatile("fnstenv %0" : "=m" (*(__env))) #define __fnstcw(__cw) __asm __volatile("fnstcw %0" : "=m" (*(__cw))) -#define __fnstsw(__sw) __asm __volatile("fnstsw %0" : "=am" (*(__sw))) +#define __fnstsw(__sw) __asm __volatile("fnstsw %0" : "=a" (*(__sw))) #define __fwait() __asm __volatile("fwait") #define __ldmxcsr(__csr) __asm __volatile("ldmxcsr %0" : : "m" (__csr)) #define __stmxcsr(__csr) __asm __volatile("stmxcsr %0" : "=m" (*(__csr))) @@ -148,7 +148,8 @@ int feraiseexcept(int __excepts); static __inline int fetestexcept(int __excepts) { - int __mxcsr, __status; + int __mxcsr; + short __status; __fnstsw(&__status); if (__HAS_SSE()) From 52eed0aeb781511102c0893cb10c6d2a10f9db7f Mon Sep 17 00:00:00 2001 From: Bruce Beare Date: Mon, 11 Oct 2010 12:01:14 -0700 Subject: [PATCH 56/93] Remove extra/unneeded copy of fenv.h Change-Id: I80da2521c50df7e8967af48164cc834abf499c50 Signed-off-by: Bruce Beare --- libm/i387/fenv.h | 240 ----------------------------------------------- 1 file changed, 240 deletions(-) delete mode 100644 libm/i387/fenv.h diff --git a/libm/i387/fenv.h b/libm/i387/fenv.h deleted file mode 100644 index b124366ac..000000000 --- a/libm/i387/fenv.h +++ /dev/null @@ -1,240 +0,0 @@ -/*- - * Copyright (c) 2004-2005 David Schultz - * 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. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. - * - * $FreeBSD: src/lib/msun/i387/fenv.h,v 1.4 2005/03/17 22:21:46 das Exp $ - */ - -#ifndef _FENV_H_ -#define _FENV_H_ - -#include -#include - -/* - * To preserve binary compatibility with FreeBSD 5.3, we pack the - * mxcsr into some reserved fields, rather than changing sizeof(fenv_t). - */ -typedef struct { - __uint16_t __control; - __uint16_t __mxcsr_hi; - __uint16_t __status; - __uint16_t __mxcsr_lo; - __uint32_t __tag; - char __other[16]; -} fenv_t; - -#define __get_mxcsr(env) (((env).__mxcsr_hi << 16) | \ - ((env).__mxcsr_lo)) -#define __set_mxcsr(env, x) do { \ - (env).__mxcsr_hi = (__uint32_t)(x) >> 16; \ - (env).__mxcsr_lo = (__uint16_t)(x); \ -} while (0) - -typedef __uint16_t fexcept_t; - -/* Exception flags */ -#define FE_INVALID 0x01 -#define FE_DENORMAL 0x02 -#define FE_DIVBYZERO 0x04 -#define FE_OVERFLOW 0x08 -#define FE_UNDERFLOW 0x10 -#define FE_INEXACT 0x20 -#define FE_ALL_EXCEPT (FE_DIVBYZERO | FE_DENORMAL | FE_INEXACT | \ - FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW) - -/* Rounding modes */ -#define FE_TONEAREST 0x0000 -#define FE_DOWNWARD 0x0400 -#define FE_UPWARD 0x0800 -#define FE_TOWARDZERO 0x0c00 -#define _ROUND_MASK (FE_TONEAREST | FE_DOWNWARD | \ - FE_UPWARD | FE_TOWARDZERO) - -/* - * As compared to the x87 control word, the SSE unit's control word - * has the rounding control bits offset by 3 and the exception mask - * bits offset by 7. - */ -#define _SSE_ROUND_SHIFT 3 -#define _SSE_EMASK_SHIFT 7 - -/* After testing for SSE support once, we cache the result in __has_sse. */ -enum __sse_support { __SSE_YES, __SSE_NO, __SSE_UNK }; -extern enum __sse_support __has_sse; -int __test_sse(void); -#ifdef __SSE__ -#define __HAS_SSE() 1 -#else -#define __HAS_SSE() (__has_sse == __SSE_YES || \ - (__has_sse == __SSE_UNK && __test_sse())) -#endif - -__BEGIN_DECLS - -/* Default floating-point environment */ -extern const fenv_t __fe_dfl_env; -#define FE_DFL_ENV (&__fe_dfl_env) - -#define __fldcw(__cw) __asm __volatile("fldcw %0" : : "m" (__cw)) -#define __fldenv(__env) __asm __volatile("fldenv %0" : : "m" (__env)) -#define __fnclex() __asm __volatile("fnclex") -#define __fnstenv(__env) __asm __volatile("fnstenv %0" : "=m" (*(__env))) -#define __fnstcw(__cw) __asm __volatile("fnstcw %0" : "=m" (*(__cw))) -#define __fnstsw(__sw) __asm __volatile("fnstsw %0" : "=am" (*(__sw))) -#define __fwait() __asm __volatile("fwait") -#define __ldmxcsr(__csr) __asm __volatile("ldmxcsr %0" : : "m" (__csr)) -#define __stmxcsr(__csr) __asm __volatile("stmxcsr %0" : "=m" (*(__csr))) - -static __inline int -feclearexcept(int __excepts) -{ - fenv_t __env; - int __mxcsr; - - if (__excepts == FE_ALL_EXCEPT) { - __fnclex(); - } else { - __fnstenv(&__env); - __env.__status &= ~__excepts; - __fldenv(__env); - } - if (__HAS_SSE()) { - __stmxcsr(&__mxcsr); - __mxcsr &= ~__excepts; - __ldmxcsr(__mxcsr); - } - return (0); -} - -static __inline int -fegetexceptflag(fexcept_t *__flagp, int __excepts) -{ - int __mxcsr, __status; - - __fnstsw(&__status); - if (__HAS_SSE()) - __stmxcsr(&__mxcsr); - else - __mxcsr = 0; - *__flagp = (__mxcsr | __status) & __excepts; - return (0); -} - -int fesetexceptflag(const fexcept_t *__flagp, int __excepts); -int feraiseexcept(int __excepts); - -static __inline int -fetestexcept(int __excepts) -{ - int __mxcsr, __status; - - __fnstsw(&__status); - if (__HAS_SSE()) - __stmxcsr(&__mxcsr); - else - __mxcsr = 0; - return ((__status | __mxcsr) & __excepts); -} - -static __inline int -fegetround(void) -{ - int __control; - - /* - * We assume that the x87 and the SSE unit agree on the - * rounding mode. Reading the control word on the x87 turns - * out to be about 5 times faster than reading it on the SSE - * unit on an Opteron 244. - */ - __fnstcw(&__control); - return (__control & _ROUND_MASK); -} - -static __inline int -fesetround(int __round) -{ - int __mxcsr, __control; - - if (__round & ~_ROUND_MASK) - return (-1); - - __fnstcw(&__control); - __control &= ~_ROUND_MASK; - __control |= __round; - __fldcw(__control); - - if (__HAS_SSE()) { - __stmxcsr(&__mxcsr); - __mxcsr &= ~(_ROUND_MASK << _SSE_ROUND_SHIFT); - __mxcsr |= __round << _SSE_ROUND_SHIFT; - __ldmxcsr(__mxcsr); - } - - return (0); -} - -int fegetenv(fenv_t *__envp); -int feholdexcept(fenv_t *__envp); - -static __inline int -fesetenv(const fenv_t *__envp) -{ - fenv_t __env = *__envp; - int __mxcsr; - - __mxcsr = __get_mxcsr(__env); - __set_mxcsr(__env, 0xffffffff); - __fldenv(__env); - if (__HAS_SSE()) - __ldmxcsr(__mxcsr); - return (0); -} - -int feupdateenv(const fenv_t *__envp); - -#if __BSD_VISIBLE - -int feenableexcept(int __mask); -int fedisableexcept(int __mask); - -static __inline int -fegetexcept(void) -{ - int __control; - - /* - * We assume that the masks for the x87 and the SSE unit are - * the same. - */ - __fnstcw(&__control); - return (~__control & FE_ALL_EXCEPT); -} - -#endif /* __BSD_VISIBLE */ - -__END_DECLS - -#endif /* !_FENV_H_ */ From b4867734b06a18494976934c6f33ff2549595e3f Mon Sep 17 00:00:00 2001 From: Jim Huang Date: Fri, 15 Oct 2010 00:50:45 +0800 Subject: [PATCH 57/93] stdio: make internal symbols static/hidden Although header libc/stdio/local.h declares the macros and private variables of stdio, there are several internal symbols exposed unexpectedly. Change-Id: Ie7a07f85b70322fb9cd05b3c8e1bcc416061eb4b --- libc/stdio/fgetln.c | 2 +- libc/stdio/findfp.c | 2 +- libc/stdio/flockfile.c | 2 +- libc/stdio/fvwrite.c | 2 +- libc/stdio/mktemp.c | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/libc/stdio/fgetln.c b/libc/stdio/fgetln.c index 946e1b7d4..95a5b31d9 100644 --- a/libc/stdio/fgetln.c +++ b/libc/stdio/fgetln.c @@ -43,7 +43,7 @@ * so we add 1 here. #endif */ -int +static int __slbexpand(FILE *fp, size_t newsize) { void *p; diff --git a/libc/stdio/findfp.c b/libc/stdio/findfp.c index 039293fa6..1d0f9c5d8 100644 --- a/libc/stdio/findfp.c +++ b/libc/stdio/findfp.c @@ -55,7 +55,7 @@ static FILE usual[FOPEN_MAX - 3]; static struct __sfileext usualext[FOPEN_MAX - 3]; static struct glue uglue = { 0, FOPEN_MAX - 3, usual }; -struct __sfileext __sFext[3]; +static struct __sfileext __sFext[3]; FILE __sF[3] = { std(__SRD, STDIN_FILENO), /* stdin */ std(__SWR, STDOUT_FILENO), /* stdout */ diff --git a/libc/stdio/flockfile.c b/libc/stdio/flockfile.c index bfb081cde..e8c74c561 100644 --- a/libc/stdio/flockfile.c +++ b/libc/stdio/flockfile.c @@ -191,7 +191,7 @@ funlockfile(FILE * fp) /* called from fclose() to remove the file lock */ -void +__LIBC_HIDDEN__ void __fremovelock(FILE* fp) { LockTable* t = lock_table_lock(); diff --git a/libc/stdio/fvwrite.c b/libc/stdio/fvwrite.c index ee394006d..57a57e606 100644 --- a/libc/stdio/fvwrite.c +++ b/libc/stdio/fvwrite.c @@ -44,7 +44,7 @@ * This routine is large and unsightly, but most of the ugliness due * to the three different kinds of output buffering is handled here. */ -int +__LIBC_HIDDEN__ int __sfvwrite(FILE *fp, struct __suio *uio) { size_t len; diff --git a/libc/stdio/mktemp.c b/libc/stdio/mktemp.c index 951f803d4..aaa5640e3 100644 --- a/libc/stdio/mktemp.c +++ b/libc/stdio/mktemp.c @@ -65,7 +65,7 @@ mkdtemp(char *path) char *_mktemp(char *); -char * +__LIBC_HIDDEN__ char * _mktemp(char *path) { return(_gettemp(path, (int *)NULL, 0, 0) ? path : (char *)NULL); From cec75a765fbadc49668b0f72d885233cc95a0db7 Mon Sep 17 00:00:00 2001 From: Jim Huang Date: Fri, 15 Oct 2010 01:35:08 +0800 Subject: [PATCH 58/93] stdlib: strtod: Hide internal symbol __dtoa Change-Id: Iaaec7ea4d04c859fe98ad3331fd71e7d000c826b --- libc/stdlib/strtod.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libc/stdlib/strtod.c b/libc/stdlib/strtod.c index 9d599b059..28515062a 100644 --- a/libc/stdlib/strtod.c +++ b/libc/stdlib/strtod.c @@ -2062,7 +2062,7 @@ freedtoa(char *s) * calculation. */ - char * +__LIBC_HIDDEN__ char * __dtoa #ifdef KR_headers (_d, mode, ndigits, decpt, sign, rve) From 7cc5666d94615d9249163dc7ac0f58c2614497ce Mon Sep 17 00:00:00 2001 From: Jim Huang Date: Fri, 15 Oct 2010 02:02:57 +0800 Subject: [PATCH 59/93] resolv: make internal symbols static/hidden Change-Id: I988b83613e6252c0cc961555e81c10f856a38b37 --- libc/netbsd/resolv/res_cache.c | 2 +- libc/netbsd/resolv/res_data.c | 3 ++- libc/netbsd/resolv/res_debug.c | 4 ++-- libc/netbsd/resolv/res_init.c | 6 +++--- libc/netbsd/resolv/res_send.c | 2 +- libc/netbsd/resolv/res_state.c | 1 + 6 files changed, 10 insertions(+), 8 deletions(-) diff --git a/libc/netbsd/resolv/res_cache.c b/libc/netbsd/resolv/res_cache.c index 2621a7bbf..84194c249 100644 --- a/libc/netbsd/resolv/res_cache.c +++ b/libc/netbsd/resolv/res_cache.c @@ -1143,7 +1143,7 @@ _cache_flush_locked( Cache* cache ) "*************************"); } -struct resolv_cache* +static struct resolv_cache* _resolv_cache_create( void ) { struct resolv_cache* cache; diff --git a/libc/netbsd/resolv/res_data.c b/libc/netbsd/resolv/res_data.c index e60ecfdd8..014c99bf0 100644 --- a/libc/netbsd/resolv/res_data.c +++ b/libc/netbsd/resolv/res_data.c @@ -46,6 +46,7 @@ __RCSID("$NetBSD: res_data.c,v 1.8 2004/06/09 18:07:03 christos Exp $"); #include +__LIBC_HIDDEN__ const char * const _res_opcodes[] = { "QUERY", "IQUERY", @@ -82,7 +83,7 @@ extern struct __res_state _nres; int res_ourserver_p(const res_state, const struct sockaddr *); #ifdef ANDROID_CHANGES -int res_need_init() { +static int res_need_init() { return ((_nres.options & RES_INIT) == 0U) || res_get_dns_changed(); } #else diff --git a/libc/netbsd/resolv/res_debug.c b/libc/netbsd/resolv/res_debug.c index 84c6afc34..721e01556 100644 --- a/libc/netbsd/resolv/res_debug.c +++ b/libc/netbsd/resolv/res_debug.c @@ -385,7 +385,7 @@ const struct res_sym __p_class_syms[] = { /* * Names of message sections. */ -const struct res_sym __p_default_section_syms[] = { +static const struct res_sym __p_default_section_syms[] = { {ns_s_qd, "QUERY", (char *)0}, {ns_s_an, "ANSWER", (char *)0}, {ns_s_ns, "AUTHORITY", (char *)0}, @@ -393,7 +393,7 @@ const struct res_sym __p_default_section_syms[] = { {0, (char *)0, (char *)0} }; -const struct res_sym __p_update_section_syms[] = { +static const struct res_sym __p_update_section_syms[] = { {S_ZONE, "ZONE", (char *)0}, {S_PREREQ, "PREREQUISITE", (char *)0}, {S_UPDATE, "UPDATE", (char *)0}, diff --git a/libc/netbsd/resolv/res_init.c b/libc/netbsd/resolv/res_init.c index 81e570f77..2158f2062 100644 --- a/libc/netbsd/resolv/res_init.c +++ b/libc/netbsd/resolv/res_init.c @@ -113,8 +113,8 @@ __RCSID("$NetBSD: res_init.c,v 1.8 2006/03/19 03:10:08 christos Exp $"); #define DNS_PROP_NAME_PREFIX "net.dns" #define DNS_CHANGE_PROP_NAME "net.dnschange" #define DNS_SEARCH_PROP_NAME "net.dns.search" -const prop_info *dns_change_prop; -int dns_last_change_counter; +static const prop_info *dns_change_prop; +static int dns_last_change_counter; static int _get_dns_change_count(); #else #include @@ -170,7 +170,7 @@ res_ninit(res_state statp) { } #ifdef ANDROID_CHANGES -int load_domain_search_list(res_state statp) { +static int load_domain_search_list(res_state statp) { char propvalue[PROP_VALUE_MAX]; register char *cp, **pp; diff --git a/libc/netbsd/resolv/res_send.c b/libc/netbsd/resolv/res_send.c index 696f8cfeb..b11895621 100644 --- a/libc/netbsd/resolv/res_send.c +++ b/libc/netbsd/resolv/res_send.c @@ -222,7 +222,7 @@ static const int niflags = NI_NUMERICHOST | NI_NUMERICSERV; * author: * paul vixie, 29may94 */ -int +__LIBC_HIDDEN__ int res_ourserver_p(const res_state statp, const struct sockaddr *sa) { const struct sockaddr_in *inp, *srv; const struct sockaddr_in6 *in6p, *srv6; diff --git a/libc/netbsd/resolv/res_state.c b/libc/netbsd/resolv/res_state.c index 3a2301d2e..3209b6f1c 100644 --- a/libc/netbsd/resolv/res_state.c +++ b/libc/netbsd/resolv/res_state.c @@ -134,6 +134,7 @@ _res_thread_get(void) return rt; } +__LIBC_HIDDEN__ struct __res_state _nres; #if 0 From 8b2707a6a074e64a36ced73b45f5c5fbe774b63b Mon Sep 17 00:00:00 2001 From: Jim Huang Date: Fri, 15 Oct 2010 02:15:54 +0800 Subject: [PATCH 60/93] time64: make helper functions static Change-Id: I98d9a5f736482e52904228c171a1bdefd2f5b213 --- libc/bionic/time64.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libc/bionic/time64.c b/libc/bionic/time64.c index 1e1f88189..9aa5d4f2b 100644 --- a/libc/bionic/time64.c +++ b/libc/bionic/time64.c @@ -364,7 +364,7 @@ static int safe_year(const Year year) } -void copy_tm_to_TM(const struct tm *src, struct TM *dest) { +static void copy_tm_to_TM(const struct tm *src, struct TM *dest) { if( src == NULL ) { memset(dest, 0, sizeof(*dest)); } @@ -396,7 +396,7 @@ void copy_tm_to_TM(const struct tm *src, struct TM *dest) { } -void copy_TM_to_tm(const struct TM *src, struct tm *dest) { +static void copy_TM_to_tm(const struct TM *src, struct tm *dest) { if( src == NULL ) { memset(dest, 0, sizeof(*dest)); } @@ -735,14 +735,14 @@ struct TM *localtime64_r (const Time64_T *time, struct TM *local_tm) } -int valid_tm_wday( const struct TM* date ) { +static int valid_tm_wday( const struct TM* date ) { if( 0 <= date->tm_wday && date->tm_wday <= 6 ) return 1; else return 0; } -int valid_tm_mon( const struct TM* date ) { +static int valid_tm_mon( const struct TM* date ) { if( 0 <= date->tm_mon && date->tm_mon <= 11 ) return 1; else From c940945155fa8bf92e23bd1e8bd843cc41e9628d Mon Sep 17 00:00:00 2001 From: Jim Huang Date: Fri, 15 Oct 2010 02:21:14 +0800 Subject: [PATCH 61/93] bionic: stubs: Make internal symbol static Thread-specific state for the stubs functions should not be exposed to applications. Change-Id: I4d35dab6009dab8db7781671ac5cc9b5f6904e84 --- libc/bionic/stubs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libc/bionic/stubs.c b/libc/bionic/stubs.c index d4956747d..a01d64c2f 100644 --- a/libc/bionic/stubs.c +++ b/libc/bionic/stubs.c @@ -40,8 +40,8 @@ /** Thread-specific state for the stubs functions **/ -pthread_once_t the_once = PTHREAD_ONCE_INIT; -pthread_key_t the_key; +static pthread_once_t the_once = PTHREAD_ONCE_INIT; +static pthread_key_t the_key; typedef struct { struct passwd passwd; From c9a41a69971b10186f0c9947fd9868d4d570884f Mon Sep 17 00:00:00 2001 From: Jim Huang Date: Fri, 15 Oct 2010 02:27:50 +0800 Subject: [PATCH 62/93] pthread-timers: Hide internal symbol __timer_table_start_stop Change-Id: If99c5816fe6fa9107aa6bef4697048fabf92283f --- libc/bionic/pthread-timers.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libc/bionic/pthread-timers.c b/libc/bionic/pthread-timers.c index 7b9c99e1c..ae04029eb 100644 --- a/libc/bionic/pthread-timers.c +++ b/libc/bionic/pthread-timers.c @@ -260,7 +260,7 @@ __timer_table_get(void) ** requirements: the timers of fork child processes must be ** disarmed but not deleted. **/ -void +__LIBC_HIDDEN__ void __timer_table_start_stop( int stop ) { if (__timer_table != NULL) { From cd9c98dfda3e54fd7191e446079295cf4885f24e Mon Sep 17 00:00:00 2001 From: Jim Huang Date: Fri, 15 Oct 2010 03:05:25 +0800 Subject: [PATCH 63/93] __set_errno: Hide internal symbol __set_syscall_errno Change-Id: I21e7ef6bf0bca288069275add43bd53294c0760d --- libc/bionic/__set_errno.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libc/bionic/__set_errno.c b/libc/bionic/__set_errno.c index c72d4f7fd..163d40444 100644 --- a/libc/bionic/__set_errno.c +++ b/libc/bionic/__set_errno.c @@ -40,6 +40,7 @@ int __set_errno(int n) * (tail-called in the case of 0-4 arg versions) */ +__LIBC_HIDDEN__ int __set_syscall_errno(int n) { /* some syscalls, mmap() for example, have valid return From 4f0555bf26af3a5a5b0ca79b4e44755c3e0253ad Mon Sep 17 00:00:00 2001 From: David Deephanphongs Date: Tue, 19 Oct 2010 15:12:40 -0700 Subject: [PATCH 64/93] Clean up NOTICE files. Change Copyright date in libc/NOTICE to reflect the current modifications. Change-Id: I313d719656caaa449c1100d35dbb7d14c1489e1a --- libc/NOTICE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libc/NOTICE b/libc/NOTICE index e8076b5cc..d9e681891 100644 --- a/libc/NOTICE +++ b/libc/NOTICE @@ -1,5 +1,5 @@ -Copyright (c) 2005-2008, The Android Open Source Project +Copyright (c) 2005-2010, The Android Open Source Project All rights reserved. Redistribution and use in source and binary forms, with or without From 9883f396cc3bcb97657d79e4cffef57fa46cc137 Mon Sep 17 00:00:00 2001 From: Iliyan Malchev Date: Tue, 19 Oct 2010 15:23:42 -0700 Subject: [PATCH 65/93] bionic: update preprocessed kernel header tegra_audio.h Change-Id: I07fe566e3ec86be5d017e96cc37fa83d2e0a4eb8 Signed-off-by: Iliyan Malchev --- libc/kernel/common/linux/tegra_audio.h | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/libc/kernel/common/linux/tegra_audio.h b/libc/kernel/common/linux/tegra_audio.h index 70c77bce1..45e558aa1 100644 --- a/libc/kernel/common/linux/tegra_audio.h +++ b/libc/kernel/common/linux/tegra_audio.h @@ -48,13 +48,12 @@ struct tegra_audio_error_counts { #define TEGRA_AUDIO_OUT_GET_ERROR_COUNT _IOR(TEGRA_AUDIO_MAGIC, 9, struct tegra_audio_error_counts *) -struct tegra_audio_out_preload { - void *data; - size_t len; - size_t len_written; -}; +#define TEGRA_AUDIO_OUT_FLUSH _IO(TEGRA_AUDIO_MAGIC, 10) -#define TEGRA_AUDIO_OUT_PRELOAD_FIFO _IOWR(TEGRA_AUDIO_MAGIC, 10, struct tegra_audio_out_preload *) +#define TEGRA_AUDIO_BIT_FORMAT_DEFAULT 0 +#define TEGRA_AUDIO_BIT_FORMAT_DSP 1 +#define TEGRA_AUDIO_SET_BIT_FORMAT _IOW(TEGRA_AUDIO_MAGIC, 11, unsigned int *) +#define TEGRA_AUDIO_GET_BIT_FORMAT _IOR(TEGRA_AUDIO_MAGIC, 12, unsigned int *) #endif From 6858e651d4b308e5c10cc4720ca1abe455a54533 Mon Sep 17 00:00:00 2001 From: Rebecca Schultz Zavin Date: Fri, 22 Oct 2010 18:44:52 -0700 Subject: [PATCH 66/93] Update libc/kernel/common/media/soc2030.h Several ioctls have been added Change-Id: I33d4d5d0aaa96c2f95a909ec361b35b07ce6b5e0 Signed-off-by: Rebecca Schultz Zavin --- libc/kernel/common/media/soc2030.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/libc/kernel/common/media/soc2030.h b/libc/kernel/common/media/soc2030.h index 1e0e62629..ad0ddfcf2 100644 --- a/libc/kernel/common/media/soc2030.h +++ b/libc/kernel/common/media/soc2030.h @@ -19,6 +19,9 @@ #define SOC2030_IOCTL_SET_PRIVATE _IOWR('o', 3, struct soc2030_regs) #define SOC2030_IOCTL_GET_MODES _IO('o', 4) #define SOC2030_IOCTL_GET_NUM_MODES _IOR('o', 5, unsigned int) +#define SOC2030_IOCTL_SET_EFFECT _IOWR('o', 6, unsigned int) +#define SOC2030_IOCTL_SET_WHITEBALANCE _IOWR('o', 7, unsigned int) +#define SOC2030_IOCTL_SET_EXP_COMP _IOWR('o', 8, int) #define SOC2030_POLL_WAITMS 50 #define SOC2030_MAX_RETRIES 3 @@ -27,6 +30,10 @@ #define SOC2030_MAX_PRIVATE_SIZE 1024 #define SOC2030_MAX_NUM_MODES 6 +#define SOC_EV_MAX 2 +#define SOC_EV_MIN -2 +#define EXP_TARGET 0x32 + enum { REG_TABLE_END, WRITE_REG_DATA, @@ -35,10 +42,32 @@ enum { POLL_REG_DATA, POLL_REG_BIT_H, POLL_REG_BIT_L, + WRITE_VAR_DATA, POLL_VAR_DATA, DELAY_MS, }; +enum { + EFFECT_NONE, + EFFECT_BW, + EFFECT_NEGATIVE, + EFFECT_POSTERIZE, + EFFECT_SEPIA, + EFFECT_SOLARIZE, + EFFECT_AQUA, + EFFECT_MAX, +}; + +enum { + WB_AUTO, + WB_INCANDESCENT, + WB_FLUORESCENT, + WB_DAYLIGHT, + WB_CLOUDYDAYLIGHT, + WB_NIGHT, + WB_MAX, +}; + struct soc2030_regs { __u8 op; __u16 addr; From 70478100d5967f528e6514a42f98a76bb85b7e28 Mon Sep 17 00:00:00 2001 From: Jim Huang Date: Mon, 27 Sep 2010 22:42:28 +0800 Subject: [PATCH 67/93] Remove duplicated _rand48 implementation. Use stdlib version instead Originally, there are _rand48 (in libc/bionic/_rand48.c) and __rand48 (in libc/stdlib/_rand48.c) implemented in bionic. Besides the naming, the functionality is identical. This patch removes the duplicated _rand48. Also, drand48 and erand48 are modified accordingly. Change-Id: Ie5761a0a97f45df8538222a77edacb7c3e0125d7 --- libc/Android.mk | 1 - libc/bionic/_rand48.c | 47 ------------------------------------------- libc/bionic/drand48.c | 4 ++-- libc/bionic/erand48.c | 2 +- libc/bionic/rand48.h | 32 ----------------------------- 5 files changed, 3 insertions(+), 83 deletions(-) delete mode 100644 libc/bionic/_rand48.c delete mode 100644 libc/bionic/rand48.h diff --git a/libc/Android.mk b/libc/Android.mk index e6192671b..39c63a21b 100644 --- a/libc/Android.mk +++ b/libc/Android.mk @@ -220,7 +220,6 @@ libc_common_src_files := \ tzcode/strptime.c \ bionic/__errno.c \ bionic/__set_errno.c \ - bionic/_rand48.c \ bionic/cpuacct.c \ bionic/arc4random.c \ bionic/basename.c \ diff --git a/libc/bionic/_rand48.c b/libc/bionic/_rand48.c deleted file mode 100644 index e422781e4..000000000 --- a/libc/bionic/_rand48.c +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 1993 Martin Birgmeier - * All rights reserved. - * - * You may redistribute unmodified or modified versions of this source - * code provided that the above copyright notice and this and the - * following conditions are retained. - * - * This software is provided ``as is'', and comes with no warranties - * of any kind. I shall in no event be liable for anything that happens - * to anyone/anything when using this software. - */ - -#include -#include "rand48.h" - -unsigned short _rand48_seed[3] = { - RAND48_SEED_0, - RAND48_SEED_1, - RAND48_SEED_2 -}; -unsigned short _rand48_mult[3] = { - RAND48_MULT_0, - RAND48_MULT_1, - RAND48_MULT_2 -}; -unsigned short _rand48_add = RAND48_ADD; - -void -_dorand48(unsigned short xseed[3]) -{ - unsigned long accu; - unsigned short temp[2]; - - accu = (unsigned long) _rand48_mult[0] * (unsigned long) xseed[0] + - (unsigned long) _rand48_add; - temp[0] = (unsigned short) accu; /* lower 16 bits */ - accu >>= sizeof(unsigned short) * 8; - accu += (unsigned long) _rand48_mult[0] * (unsigned long) xseed[1] + - (unsigned long) _rand48_mult[1] * (unsigned long) xseed[0]; - temp[1] = (unsigned short) accu; /* middle 16 bits */ - accu >>= sizeof(unsigned short) * 8; - accu += _rand48_mult[0] * xseed[2] + _rand48_mult[1] * xseed[1] + _rand48_mult[2] * xseed[0]; - xseed[0] = temp[0]; - xseed[1] = temp[1]; - xseed[2] = (unsigned short) accu; -} diff --git a/libc/bionic/drand48.c b/libc/bionic/drand48.c index fd481966e..93272cf64 100644 --- a/libc/bionic/drand48.c +++ b/libc/bionic/drand48.c @@ -15,10 +15,10 @@ #include "rand48.h" -extern unsigned short _rand48_seed[3]; +extern unsigned short __rand48_seed[3]; double drand48(void) { - return erand48(_rand48_seed); + return erand48(__rand48_seed); } diff --git a/libc/bionic/erand48.c b/libc/bionic/erand48.c index 843ff3418..4ecbeadfc 100644 --- a/libc/bionic/erand48.c +++ b/libc/bionic/erand48.c @@ -18,7 +18,7 @@ double erand48(unsigned short xseed[3]) { - _dorand48(xseed); + __dorand48(xseed); return ldexp((double) xseed[0], -48) + ldexp((double) xseed[1], -32) + ldexp((double) xseed[2], -16); diff --git a/libc/bionic/rand48.h b/libc/bionic/rand48.h deleted file mode 100644 index 0a3d83d3c..000000000 --- a/libc/bionic/rand48.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 1993 Martin Birgmeier - * All rights reserved. - * - * You may redistribute unmodified or modified versions of this source - * code provided that the above copyright notice and this and the - * following conditions are retained. - * - * This software is provided ``as is'', and comes with no warranties - * of any kind. I shall in no event be liable for anything that happens - * to anyone/anything when using this software. - * - * $FreeBSD: src/lib/libc/gen/rand48.h,v 1.2 2002/02/01 01:32:19 obrien Exp $ - */ - -#ifndef _RAND48_H_ -#define _RAND48_H_ - -#include -#include - -void _dorand48(unsigned short[3]); - -#define RAND48_SEED_0 (0x330e) -#define RAND48_SEED_1 (0xabcd) -#define RAND48_SEED_2 (0x1234) -#define RAND48_MULT_0 (0xe66d) -#define RAND48_MULT_1 (0xdeec) -#define RAND48_MULT_2 (0x0005) -#define RAND48_ADD (0x000b) - -#endif /* _RAND48_H_ */ From 1ec041f09655709730399499ded2ebb0d9829575 Mon Sep 17 00:00:00 2001 From: Erik Gilling Date: Wed, 27 Oct 2010 17:43:36 -0700 Subject: [PATCH 68/93] update tegrafb Change-Id: I22308d65994ae4e06e5c65d2047299c8cd559c01 --- libc/kernel/common/linux/tegrafb.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libc/kernel/common/linux/tegrafb.h b/libc/kernel/common/linux/tegrafb.h index 27bb28686..e01e4d648 100644 --- a/libc/kernel/common/linux/tegrafb.h +++ b/libc/kernel/common/linux/tegrafb.h @@ -12,6 +12,7 @@ #ifndef _LINUX_TEGRAFB_H_ #define _LINUX_TEGRAFB_H_ +#include #include #include @@ -70,8 +71,14 @@ struct tegra_fb_flip_args { __u32 post_syncpt_val; }; +struct tegra_fb_modedb { + struct fb_var_screeninfo *modedb; + __u32 modedb_len; +}; + #define FBIO_TEGRA_SET_NVMAP_FD _IOW('F', 0x40, __u32) #define FBIO_TEGRA_FLIP _IOW('F', 0x41, struct tegra_fb_flip_args) +#define FBIO_TEGRA_GET_MODEDB _IOWR('F', 0x42, struct tegra_fb_modedb) #endif From a1dbf0b453801620565e5911f354f82706b0200d Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Wed, 27 Oct 2010 10:36:36 -0700 Subject: [PATCH 69/93] DNS proxy: the start. proxies getaddrinfo calls. Will also need to do gethostinfo, but that's probably about it. It was cleaner to do it at this level, rather than speaking in terms of DNS packets. Change-Id: I047cc459979ffb0170a3eb0d432a7e827fb71c26 --- libc/netbsd/net/getaddrinfo.c | 184 ++++++++++++++++++++++++++++++++++ 1 file changed, 184 insertions(+) diff --git a/libc/netbsd/net/getaddrinfo.c b/libc/netbsd/net/getaddrinfo.c index e7564c427..4fa92b74b 100644 --- a/libc/netbsd/net/getaddrinfo.c +++ b/libc/netbsd/net/getaddrinfo.c @@ -77,10 +77,13 @@ * friends. */ +#include #include #include +#include #include #include +#include #include #include #include @@ -371,6 +374,180 @@ _have_ipv6() { return have_ipv6; } +// Returns 0 on success, else returns non-zero on error (in which case +// getaddrinfo should continue as normal) +static int +android_getaddrinfo_proxy( + const char *hostname, const char *servname, + const struct addrinfo *hints, struct addrinfo **res) +{ + int sock; + const int one = 1; + struct sockaddr_un proxy_addr; + const char* cache_mode = getenv("ANDROID_DNS_MODE"); + FILE* proxy = NULL; + int success = 0; + + // Clear this at start, as we use its non-NULLness later (in the + // error path) to decide if we have to free up any memory we + // allocated in the process (before failing). + *res = NULL; + + if (cache_mode != NULL && strcmp(cache_mode, "local") == 0) { + // Don't use the proxy in local mode. This is used by the + // proxy itself. + return -1; + } + + // Bogus things we can't serialize. Don't use the proxy. + if ((hostname != NULL && + strcspn(hostname, " \n\r\t^'\"") != strlen(hostname)) || + (servname != NULL && + strcspn(servname, " \n\r\t^'\"") != strlen(servname))) { + return -1; + } + + sock = socket(AF_UNIX, SOCK_STREAM, 0); + if (sock < 0) { + return -1; + } + + setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)); + memset(&proxy_addr, 0, sizeof(proxy_addr)); + proxy_addr.sun_family = AF_UNIX; + strlcpy(proxy_addr.sun_path, "/dev/socket/dnsproxyd", + sizeof(proxy_addr.sun_path)); + if (TEMP_FAILURE_RETRY(connect(sock, + (const struct sockaddr*) &proxy_addr, + sizeof(proxy_addr))) != 0) { + close(sock); + return -1; + } + + // Send the request. + proxy = fdopen(sock, "r+"); + if (fprintf(proxy, "getaddrinfo %s %s %d %d %d %d", + hostname == NULL ? "^" : hostname, + servname == NULL ? "^" : servname, + hints == NULL ? -1 : hints->ai_flags, + hints == NULL ? -1 : hints->ai_family, + hints == NULL ? -1 : hints->ai_socktype, + hints == NULL ? -1 : hints->ai_protocol) < 0) { + goto exit; + } + // literal NULL byte at end, required by FrameworkListener + if (fputc(0, proxy) == EOF || + fflush(proxy) != 0) { + goto exit; + } + + int remote_rv; + if (fread(&remote_rv, sizeof(int), 1, proxy) != 1) { + goto exit; + } + + if (remote_rv != 0) { + goto exit; + } + + struct addrinfo* ai = NULL; + struct addrinfo** nextres = res; + while (1) { + uint32_t addrinfo_len; + if (fread(&addrinfo_len, sizeof(addrinfo_len), + 1, proxy) != 1) { + break; + } + addrinfo_len = ntohl(addrinfo_len); + if (addrinfo_len == 0) { + success = 1; + break; + } + + if (addrinfo_len < sizeof(struct addrinfo)) { + break; + } + struct addrinfo* ai = calloc(1, addrinfo_len + + sizeof(struct sockaddr_storage)); + if (ai == NULL) { + break; + } + + if (fread(ai, addrinfo_len, 1, proxy) != 1) { + // Error; fall through. + break; + } + + // Zero out the pointer fields we copied which aren't + // valid in this address space. + ai->ai_addr = NULL; + ai->ai_canonname = NULL; + ai->ai_next = NULL; + + // struct sockaddr + uint32_t addr_len; + if (fread(&addr_len, sizeof(addr_len), 1, proxy) != 1) { + break; + } + addr_len = ntohl(addr_len); + if (addr_len != 0) { + if (addr_len > sizeof(struct sockaddr_storage)) { + // Bogus; too big. + break; + } + struct sockaddr* addr = (struct sockaddr*)(ai + 1); + if (fread(addr, addr_len, 1, proxy) != 1) { + break; + } + ai->ai_addr = addr; + } + + // cannonname + uint32_t name_len; + if (fread(&name_len, sizeof(name_len), 1, proxy) != 1) { + break; + } + if (name_len != 0) { + ai->ai_canonname = (char*) malloc(name_len); + if (fread(ai->ai_canonname, name_len, 1, proxy) != 1) { + break; + } + if (ai->ai_canonname[name_len - 1] != '\0') { + // The proxy should be returning this + // NULL-terminated. + break; + } + } + + *nextres = ai; + nextres = &ai->ai_next; + ai = NULL; + } + + if (ai != NULL) { + // Clean up partially-built addrinfo that we never ended up + // attaching to the response. + freeaddrinfo(ai); + } +exit: + if (proxy != NULL) { + fclose(proxy); + } + + if (success) { + return 0; + } + + // Proxy failed; fall through to local + // resolver case. But first clean up any + // memory we might've allocated. + if (*res) { + freeaddrinfo(*res); + *res = NULL; + } + return -1; +} + int getaddrinfo(const char *hostname, const char *servname, const struct addrinfo *hints, struct addrinfo **res) @@ -517,6 +694,13 @@ getaddrinfo(const char *hostname, const char *servname, if (pai->ai_flags & AI_NUMERICHOST) ERR(EAI_NONAME); + /* + * BEGIN ANDROID CHANGES; proxying to the cache + */ + if (android_getaddrinfo_proxy(hostname, servname, hints, res) == 0) { + return 0; + } + /* * hostname as alphabetical name. * we would like to prefer AF_INET6 than AF_INET, so we'll make a From 7858564582ca134bd0101ffc725c0d0b1d29d645 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Thu, 28 Oct 2010 13:22:20 -0700 Subject: [PATCH 70/93] Don't proxy getaddrinfo when net.dns1.[MYPID] is set. Part of on-going DNS proxy/cache work. Bug: 1146676 Change-Id: I5e6028169c81c2223efc34c3b57e348c44f26d26 --- libc/netbsd/net/getaddrinfo.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/libc/netbsd/net/getaddrinfo.c b/libc/netbsd/net/getaddrinfo.c index 4fa92b74b..451065246 100644 --- a/libc/netbsd/net/getaddrinfo.c +++ b/libc/netbsd/net/getaddrinfo.c @@ -103,6 +103,10 @@ #include #include "nsswitch.h" +#ifdef ANDROID_CHANGES +#include +#endif /* ANDROID_CHANGES */ + typedef union sockaddr_union { struct sockaddr generic; struct sockaddr_in in; @@ -399,6 +403,16 @@ android_getaddrinfo_proxy( return -1; } + // Temporary cautious hack to disable the DNS proxy for processes + // requesting special treatment. Ideally the DNS proxy should + // accomodate these apps, though. + char propname[PROP_NAME_MAX]; + char propvalue[PROP_VALUE_MAX]; + snprintf(propname, sizeof(propname), "net.dns1.%d", getpid()); + if (__system_property_get(propname, propvalue) > 0) { + return -1; + } + // Bogus things we can't serialize. Don't use the proxy. if ((hostname != NULL && strcspn(hostname, " \n\r\t^'\"") != strlen(hostname)) || From 8465bf90ea7478731e335f68f6043b58befadd61 Mon Sep 17 00:00:00 2001 From: Iliyan Malchev Date: Mon, 1 Nov 2010 16:04:12 -0700 Subject: [PATCH 71/93] bionic: update processed cpcap_audio.h Change-Id: I8c8b917268cae4ff7a79e9f60522df59f8ed499a Signed-off-by: Iliyan Malchev --- libc/kernel/common/linux/cpcap_audio.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libc/kernel/common/linux/cpcap_audio.h b/libc/kernel/common/linux/cpcap_audio.h index 0b586859b..ea1e8022c 100644 --- a/libc/kernel/common/linux/cpcap_audio.h +++ b/libc/kernel/common/linux/cpcap_audio.h @@ -54,9 +54,11 @@ struct cpcap_audio_stream { #define CPCAP_AUDIO_IN_GET_VOLUME _IOR(CPCAP_AUDIO_MAGIC, 7, unsigned int *) #define CPCAP_AUDIO_OUT_GET_RATE _IOR(CPCAP_AUDIO_MAGIC, 8, unsigned int *) -#define CPCAP_AUDIO_OUT_SET_RATE _IOW(CPCAP_AUDIO_MAGIC, 9, unsigned int *) +#define CPCAP_AUDIO_OUT_SET_RATE _IOW(CPCAP_AUDIO_MAGIC, 9, unsigned int) #define CPCAP_AUDIO_IN_GET_RATE _IOR(CPCAP_AUDIO_MAGIC, 10, unsigned int *) -#define CPCAP_AUDIO_IN_SET_RATE _IOW(CPCAP_AUDIO_MAGIC, 11, unsigned int *) +#define CPCAP_AUDIO_IN_SET_RATE _IOW(CPCAP_AUDIO_MAGIC, 11, unsigned int) + +#define CPCAP_AUDIO_SET_BLUETOOTH_BYPASS _IOW(CPCAP_AUDIO_MAGIC, 12, unsigned int) #endif From bb3bcbc6dcca60633bf0a0b1fef0f7d56712367f Mon Sep 17 00:00:00 2001 From: Iliyan Malchev Date: Tue, 2 Nov 2010 15:58:36 -0700 Subject: [PATCH 72/93] bionic: update processed cpcap_audio.h and spi/cpcap.h headers Change-Id: Ied7210d4f03eec3218c51cea8ee2e667d2014153 Signed-off-by: Iliyan Malchev --- libc/kernel/common/linux/cpcap_audio.h | 3 ++- libc/kernel/common/linux/spi/cpcap.h | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/libc/kernel/common/linux/cpcap_audio.h b/libc/kernel/common/linux/cpcap_audio.h index ea1e8022c..a59550f97 100644 --- a/libc/kernel/common/linux/cpcap_audio.h +++ b/libc/kernel/common/linux/cpcap_audio.h @@ -20,7 +20,8 @@ #define CPCAP_AUDIO_OUT_HEADSET 1 #define CPCAP_AUDIO_OUT_HEADSET_AND_SPEAKER 2 #define CPCAP_AUDIO_OUT_STANDBY 3 -#define CPCAP_AUDIO_OUT_MAX 3 +#define CPCAP_AUDIO_OUT_ANLG_DOCK_HEADSET 4 +#define CPCAP_AUDIO_OUT_MAX 4 struct cpcap_audio_stream { unsigned id; diff --git a/libc/kernel/common/linux/spi/cpcap.h b/libc/kernel/common/linux/spi/cpcap.h index 5119bcf2f..24bc9180c 100644 --- a/libc/kernel/common/linux/spi/cpcap.h +++ b/libc/kernel/common/linux/spi/cpcap.h @@ -23,11 +23,36 @@ #define CPCAP_IRQ_INT4_INDEX 48 #define CPCAP_IRQ_INT5_INDEX 64 +#define CPCAP_HWCFG_NUM 2 + +#define CPCAP_HWCFG0_SEC_STBY_SW1 0x0001 +#define CPCAP_HWCFG0_SEC_STBY_SW2 0x0002 +#define CPCAP_HWCFG0_SEC_STBY_SW3 0x0004 +#define CPCAP_HWCFG0_SEC_STBY_SW4 0x0008 +#define CPCAP_HWCFG0_SEC_STBY_SW5 0x0010 +#define CPCAP_HWCFG0_SEC_STBY_VAUDIO 0x0020 +#define CPCAP_HWCFG0_SEC_STBY_VCAM 0x0040 +#define CPCAP_HWCFG0_SEC_STBY_VCSI 0x0080 +#define CPCAP_HWCFG0_SEC_STBY_VDAC 0x0100 +#define CPCAP_HWCFG0_SEC_STBY_VDIG 0x0200 +#define CPCAP_HWCFG0_SEC_STBY_VHVIO 0x0400 +#define CPCAP_HWCFG0_SEC_STBY_VPLL 0x0800 +#define CPCAP_HWCFG0_SEC_STBY_VRF1 0x1000 +#define CPCAP_HWCFG0_SEC_STBY_VRF2 0x2000 +#define CPCAP_HWCFG0_SEC_STBY_VRFREF 0x4000 +#define CPCAP_HWCFG0_SEC_STBY_VSDIO 0x8000 + +#define CPCAP_HWCFG1_SEC_STBY_VWLAN1 0x0001 +#define CPCAP_HWCFG1_SEC_STBY_VWLAN2 0x0002 +#define CPCAP_HWCFG1_SEC_STBY_VSIM 0x0004 +#define CPCAP_HWCFG1_SEC_STBY_VSIMCARD 0x0008 + #define CPCAP_WHISPER_MODE_PU 0x00000001 #define CPCAP_WHISPER_ENABLE_UART 0x00000002 #define CPCAP_WHISPER_ACCY_MASK 0xF8000000 #define CPCAP_WHISPER_ACCY_SHFT 27 #define CPCAP_WHISPER_ID_SIZE 16 +#define CPCAP_WHISPER_PROP_SIZE 7 enum cpcap_regulator_id { CPCAP_SW2, @@ -531,6 +556,7 @@ struct cpcap_regacc { struct cpcap_whisper_request { unsigned int cmd; char dock_id[CPCAP_WHISPER_ID_SIZE]; + char dock_prop[CPCAP_WHISPER_PROP_SIZE]; }; #define CPCAP_IOCTL_TEST_READ_REG _IOWR(0, CPCAP_IOCTL_NUM_TEST_READ_REG, struct cpcap_regacc*) From 459436f2f64640bbe066c689207f69be7ceb2bba Mon Sep 17 00:00:00 2001 From: Doug Kwan Date: Wed, 3 Nov 2010 16:51:32 -0700 Subject: [PATCH 73/93] Add missing PTRACE_SETVFPREGS. Change-Id: I070903ea7ceb90a3ff54fbae09c0ac70a7af1e3d --- libc/kernel/arch-arm/asm/ptrace.h | 1 + 1 file changed, 1 insertion(+) diff --git a/libc/kernel/arch-arm/asm/ptrace.h b/libc/kernel/arch-arm/asm/ptrace.h index b6be08cd3..3faf73892 100644 --- a/libc/kernel/arch-arm/asm/ptrace.h +++ b/libc/kernel/arch-arm/asm/ptrace.h @@ -30,6 +30,7 @@ #define PTRACE_SETCRUNCHREGS 26 #define PTRACE_GETVFPREGS 27 +#define PTRACE_SETVFPREGS 28 #define USR26_MODE 0x00000000 #define FIQ26_MODE 0x00000001 From ff590cadc269aea03d0f66ddec31ba35053cafa9 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Thu, 4 Nov 2010 17:53:06 -0700 Subject: [PATCH 74/93] Use a modern chdir(2)-free realpath(3) implementation. (This is the current OpenBSD implementation.) Bug: 3055824, 2281992 Change-Id: Iafa8f78e8d6e44c036a547c7210a13d559b7483a --- libc/bionic/realpath.c | 254 ++++++++++++++++++++++------------------- 1 file changed, 139 insertions(+), 115 deletions(-) diff --git a/libc/bionic/realpath.c b/libc/bionic/realpath.c index 274a3a097..4cb847b31 100644 --- a/libc/bionic/realpath.c +++ b/libc/bionic/realpath.c @@ -1,9 +1,6 @@ +/* $OpenBSD: realpath.c,v 1.13 2005/08/08 08:05:37 espie Exp $ */ /* - * Copyright (c) 1994 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Jan-Simon Pendry. + * Copyright (c) 2003 Constantin S. Svintsoff * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -13,18 +10,14 @@ * 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. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 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. + * 3. The names of the authors may not 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 + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR 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) @@ -34,133 +27,164 @@ * SUCH DAMAGE. */ -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)realpath.c 8.1 (Berkeley) 2/16/94"; -static char rcsid[] = -"$FreeBSD: /repoman/r/ncvs/src/lib/libc/stdlib/realpath.c,v 1.6.2.1 2003/08/03 23:47:39 nectar Exp $"; -#endif /* LIBC_SCCS and not lint */ - #include #include #include -#include #include #include #include /* - * char *realpath(const char *path, char resolved_path[MAXPATHLEN]); + * char *realpath(const char *path, char resolved[PATH_MAX]); * * Find the real name of path, by removing all ".", ".." and symlink * components. Returns (resolved) on success, or (NULL) on failure, * in which case the path which caused trouble is left in (resolved). */ char * -realpath(path, resolved) - const char *path; - char *resolved; +realpath(const char *path, char resolved[PATH_MAX]) { struct stat sb; - int fd, n, rootd, serrno; - char *p, *q, wbuf[MAXPATHLEN]; - int symlinks = 0; + char *p, *q, *s; + size_t left_len, resolved_len; + unsigned symlinks; + int serrno, slen; + char left[PATH_MAX], next_token[PATH_MAX], symlink[PATH_MAX]; - /* Save the starting point. */ - if ((fd = open(".", O_RDONLY)) < 0) { - (void)strcpy(resolved, "."); + serrno = errno; + symlinks = 0; + if (path[0] == '/') { + resolved[0] = '/'; + resolved[1] = '\0'; + if (path[1] == '\0') + return (resolved); + resolved_len = 1; + left_len = strlcpy(left, path + 1, sizeof(left)); + } else { + if (getcwd(resolved, PATH_MAX) == NULL) { + strlcpy(resolved, ".", PATH_MAX); + return (NULL); + } + resolved_len = strlen(resolved); + left_len = strlcpy(left, path, sizeof(left)); + } + if (left_len >= sizeof(left) || resolved_len >= PATH_MAX) { + errno = ENAMETOOLONG; return (NULL); } /* - * Find the dirname and basename from the path to be resolved. - * Change directory to the dirname component. - * lstat the basename part. - * if it is a symlink, read in the value and loop. - * if it is a directory, then change to that directory. - * get the current directory name and append the basename. + * Iterate over path components in `left'. */ - (void)strncpy(resolved, path, MAXPATHLEN - 1); - resolved[MAXPATHLEN - 1] = '\0'; -loop: - q = strrchr(resolved, '/'); - if (q != NULL) { - p = q + 1; - if (q == resolved) - q = "/"; - else { - do { - --q; - } while (q > resolved && *q == '/'); - q[1] = '\0'; - q = resolved; - } - if (chdir(q) < 0) - goto err1; - } else - p = resolved; - - /* Deal with the last component. */ - if (*p != '\0' && lstat(p, &sb) == 0) { - if (S_ISLNK(sb.st_mode)) { - if (++symlinks > MAXSYMLINKS) { - errno = ELOOP; - goto err1; - } - n = readlink(p, resolved, MAXPATHLEN - 1); - if (n < 0) - goto err1; - resolved[n] = '\0'; - goto loop; - } - if (S_ISDIR(sb.st_mode)) { - if (chdir(p) < 0) - goto err1; - p = ""; - } - } - - /* - * Save the last component name and get the full pathname of - * the current directory. - */ - (void)strcpy(wbuf, p); - if (getcwd(resolved, MAXPATHLEN) == 0) - goto err1; - - /* - * Join the two strings together, ensuring that the right thing - * happens if the last component is empty, or the dirname is root. - */ - if (resolved[0] == '/' && resolved[1] == '\0') - rootd = 1; - else - rootd = 0; - - if (*wbuf) { - if (strlen(resolved) + strlen(wbuf) + (1-rootd) + 1 > - MAXPATHLEN) { + while (left_len != 0) { + /* + * Extract the next path component and adjust `left' + * and its length. + */ + p = strchr(left, '/'); + s = p ? p : left + left_len; + if (s - left >= sizeof(next_token)) { errno = ENAMETOOLONG; - goto err1; + return (NULL); + } + memcpy(next_token, left, s - left); + next_token[s - left] = '\0'; + left_len -= s - left; + if (p != NULL) + memmove(left, s + 1, left_len + 1); + if (resolved[resolved_len - 1] != '/') { + if (resolved_len + 1 >= PATH_MAX) { + errno = ENAMETOOLONG; + return (NULL); + } + resolved[resolved_len++] = '/'; + resolved[resolved_len] = '\0'; + } + if (next_token[0] == '\0') + continue; + else if (strcmp(next_token, ".") == 0) + continue; + else if (strcmp(next_token, "..") == 0) { + /* + * Strip the last path component except when we have + * single "/" + */ + if (resolved_len > 1) { + resolved[resolved_len - 1] = '\0'; + q = strrchr(resolved, '/') + 1; + *q = '\0'; + resolved_len = q - resolved; + } + continue; + } + + /* + * Append the next path component and lstat() it. If + * lstat() fails we still can return successfully if + * there are no more path components left. + */ + resolved_len = strlcat(resolved, next_token, PATH_MAX); + if (resolved_len >= PATH_MAX) { + errno = ENAMETOOLONG; + return (NULL); + } + if (lstat(resolved, &sb) != 0) { + if (errno == ENOENT && p == NULL) { + errno = serrno; + return (resolved); + } + return (NULL); + } + if (S_ISLNK(sb.st_mode)) { + if (symlinks++ > MAXSYMLINKS) { + errno = ELOOP; + return (NULL); + } + slen = readlink(resolved, symlink, sizeof(symlink) - 1); + if (slen < 0) + return (NULL); + symlink[slen] = '\0'; + if (symlink[0] == '/') { + resolved[1] = 0; + resolved_len = 1; + } else if (resolved_len > 1) { + /* Strip the last path component. */ + resolved[resolved_len - 1] = '\0'; + q = strrchr(resolved, '/') + 1; + *q = '\0'; + resolved_len = q - resolved; + } + + /* + * If there are any path components left, then + * append them to symlink. The result is placed + * in `left'. + */ + if (p != NULL) { + if (symlink[slen - 1] != '/') { + if (slen + 1 >= sizeof(symlink)) { + errno = ENAMETOOLONG; + return (NULL); + } + symlink[slen] = '/'; + symlink[slen + 1] = 0; + } + left_len = strlcat(symlink, left, sizeof(left)); + if (left_len >= sizeof(left)) { + errno = ENAMETOOLONG; + return (NULL); + } + } + left_len = strlcpy(left, symlink, sizeof(left)); } - if (rootd == 0) - (void)strcat(resolved, "/"); - (void)strcat(resolved, wbuf); } - /* Go back to where we came from. */ - if (fchdir(fd) < 0) { - serrno = errno; - goto err2; - } - - /* It's okay if the close fails, what's an fd more or less? */ - (void)close(fd); + /* + * Remove trailing slash except when the resolved pathname + * is a single "/". + */ + if (resolved_len > 1 && resolved[resolved_len - 1] == '/') + resolved[resolved_len - 1] = '\0'; return (resolved); - -err1: serrno = errno; - (void)fchdir(fd); -err2: (void)close(fd); - errno = serrno; - return (NULL); } From fddaafcedaac344845afd24f0b00660a846d0eba Mon Sep 17 00:00:00 2001 From: Rodrigo Obregon Date: Fri, 5 Nov 2010 12:15:26 -0500 Subject: [PATCH 75/93] Bionic: Aliasing problems with frexpf This patch fixes a known bug in bionic libm due to aliasing issues in gcc 4.2 and 4.4; more specifically in frexpf. The function frexpf is used to extract the mantissa and exponent from a double precision number. The bug has already been reported here: https://code.google.com/p/android/issues/detail?id=6697 Change-Id: I2e1f2e0a45906642d2225b9d150ed391d2bf331c Signed-off-by: Rodrigo Obregon --- libm/src/s_frexpf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libm/src/s_frexpf.c b/libm/src/s_frexpf.c index 89d464b4d..c18cd54c6 100644 --- a/libm/src/s_frexpf.c +++ b/libm/src/s_frexpf.c @@ -39,6 +39,6 @@ frexpf(float x, int *eptr) } *eptr += (ix>>23)-126; hx = (hx&0x807fffff)|0x3f000000; - *(int*)&x = hx; + SET_FLOAT_WORD(x,hx); return x; } From c343d3fcd3fc60df6bae876ddedfc4159e0a0959 Mon Sep 17 00:00:00 2001 From: Dima Zavin Date: Mon, 4 Oct 2010 14:13:46 -0700 Subject: [PATCH 76/93] kernel/linux: add tegra avp/rpc/sema headers Change-Id: I7b8ee1e3e6a5db6a090f106d3d70f2122e12124c Signed-off-by: Dima Zavin --- libc/kernel/common/linux/tegra_avp.h | 38 +++++++++++++++++++++++++++ libc/kernel/common/linux/tegra_rpc.h | 35 ++++++++++++++++++++++++ libc/kernel/common/linux/tegra_sema.h | 24 +++++++++++++++++ 3 files changed, 97 insertions(+) create mode 100644 libc/kernel/common/linux/tegra_avp.h create mode 100644 libc/kernel/common/linux/tegra_rpc.h create mode 100644 libc/kernel/common/linux/tegra_sema.h diff --git a/libc/kernel/common/linux/tegra_avp.h b/libc/kernel/common/linux/tegra_avp.h new file mode 100644 index 000000000..c4a0cbd13 --- /dev/null +++ b/libc/kernel/common/linux/tegra_avp.h @@ -0,0 +1,38 @@ +/**************************************************************************** + **************************************************************************** + *** + *** This header was automatically generated from a Linux kernel header + *** of the same name, to make information necessary for userspace to + *** call into the kernel available to libc. It contains only constants, + *** structures, and macros generated from the original header, and thus, + *** contains no copyrightable information. + *** + **************************************************************************** + ****************************************************************************/ +#ifndef __LINUX_TEGRA_AVP_H +#define __LINUX_TEGRA_AVP_H + +#include +#include + +#define TEGRA_AVP_LIB_MAX_NAME 32 +#define TEGRA_AVP_LIB_MAX_ARGS 220 + +struct tegra_avp_lib { + char name[TEGRA_AVP_LIB_MAX_NAME]; + void __user *args; + size_t args_len; + int greedy; + unsigned long handle; +}; + +#define TEGRA_AVP_IOCTL_MAGIC 'r' + +#define TEGRA_AVP_IOCTL_LOAD_LIB _IOWR(TEGRA_AVP_IOCTL_MAGIC, 0x40, struct tegra_avp_lib) +#define TEGRA_AVP_IOCTL_UNLOAD_LIB _IOW(TEGRA_AVP_IOCTL_MAGIC, 0x41, unsigned long) + +#define TEGRA_AVP_IOCTL_MIN_NR _IOC_NR(TEGRA_AVP_IOCTL_LOAD_LIB) +#define TEGRA_AVP_IOCTL_MAX_NR _IOC_NR(TEGRA_AVP_IOCTL_UNLOAD_LIB) + +#endif + diff --git a/libc/kernel/common/linux/tegra_rpc.h b/libc/kernel/common/linux/tegra_rpc.h new file mode 100644 index 000000000..e3c8bf2e2 --- /dev/null +++ b/libc/kernel/common/linux/tegra_rpc.h @@ -0,0 +1,35 @@ +/**************************************************************************** + **************************************************************************** + *** + *** This header was automatically generated from a Linux kernel header + *** of the same name, to make information necessary for userspace to + *** call into the kernel available to libc. It contains only constants, + *** structures, and macros generated from the original header, and thus, + *** contains no copyrightable information. + *** + **************************************************************************** + ****************************************************************************/ +#ifndef __LINUX_TEGRA_RPC_H +#define __LINUX_TEGRA_RPC_H + +#define TEGRA_RPC_MAX_MSG_LEN 256 + +#define TEGRA_RPC_MAX_NAME_LEN 17 + +struct tegra_rpc_port_desc { + char name[TEGRA_RPC_MAX_NAME_LEN]; + int notify_fd; +}; + +#define TEGRA_RPC_IOCTL_MAGIC 'r' + +#define TEGRA_RPC_IOCTL_PORT_CREATE _IOW(TEGRA_RPC_IOCTL_MAGIC, 0x20, struct tegra_rpc_port_desc) +#define TEGRA_RPC_IOCTL_PORT_GET_NAME _IOR(TEGRA_RPC_IOCTL_MAGIC, 0x21, char *) +#define TEGRA_RPC_IOCTL_PORT_CONNECT _IOR(TEGRA_RPC_IOCTL_MAGIC, 0x22, long) +#define TEGRA_RPC_IOCTL_PORT_LISTEN _IOR(TEGRA_RPC_IOCTL_MAGIC, 0x23, long) + +#define TEGRA_RPC_IOCTL_MIN_NR _IOC_NR(TEGRA_RPC_IOCTL_PORT_CREATE) +#define TEGRA_RPC_IOCTL_MAX_NR _IOC_NR(TEGRA_RPC_IOCTL_PORT_LISTEN) + +#endif + diff --git a/libc/kernel/common/linux/tegra_sema.h b/libc/kernel/common/linux/tegra_sema.h new file mode 100644 index 000000000..bb112989c --- /dev/null +++ b/libc/kernel/common/linux/tegra_sema.h @@ -0,0 +1,24 @@ +/**************************************************************************** + **************************************************************************** + *** + *** This header was automatically generated from a Linux kernel header + *** of the same name, to make information necessary for userspace to + *** call into the kernel available to libc. It contains only constants, + *** structures, and macros generated from the original header, and thus, + *** contains no copyrightable information. + *** + **************************************************************************** + ****************************************************************************/ +#ifndef __LINUX_TEGRA_SEMA_H +#define __LINUX_TEGRA_SEMA_H + +#define TEGRA_SEMA_IOCTL_MAGIC 'r' + +#define TEGRA_SEMA_IOCTL_WAIT _IOW(TEGRA_SEMA_IOCTL_MAGIC, 0x30, long *) +#define TEGRA_SEMA_IOCTL_SIGNAL _IO(TEGRA_SEMA_IOCTL_MAGIC, 0x31) + +#define TEGRA_SEMA_IOCTL_MIN_NR _IOC_NR(TEGRA_SEMA_IOCTL_WAIT) +#define TEGRA_SEMA_IOCTL_MAX_NR _IOC_NR(TEGRA_SEMA_IOCTL_SIGNAL) + +#endif + From 88fb10f838e40110a4902ee723442fc33b439a44 Mon Sep 17 00:00:00 2001 From: Mike Lockwood Date: Tue, 16 Nov 2010 17:33:50 -0500 Subject: [PATCH 77/93] Update f_mtp.h kernel header Driver has changed to support transferring > 4 gigabyte files Change-Id: I9ddca13e8e906a403fe84c9af27ec1fab565be77 Signed-off-by: Mike Lockwood --- libc/kernel/common/linux/usb/f_mtp.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libc/kernel/common/linux/usb/f_mtp.h b/libc/kernel/common/linux/usb/f_mtp.h index e155e7e0a..a9e37c249 100644 --- a/libc/kernel/common/linux/usb/f_mtp.h +++ b/libc/kernel/common/linux/usb/f_mtp.h @@ -21,7 +21,7 @@ struct mtp_file_range { loff_t offset; - size_t length; + int64_t length; }; struct mtp_event { From 6c57fbf7a7d36c51fc308cfd2be0eb0cf37cec77 Mon Sep 17 00:00:00 2001 From: Erik Gilling Date: Thu, 18 Nov 2010 16:10:50 -0800 Subject: [PATCH 78/93] update linux/tegrafb.h Change-Id: Ib09e70b51b900447d17e9f992b0f81fd5f638677 --- libc/kernel/common/linux/tegrafb.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libc/kernel/common/linux/tegrafb.h b/libc/kernel/common/linux/tegrafb.h index e01e4d648..b8e79aeab 100644 --- a/libc/kernel/common/linux/tegrafb.h +++ b/libc/kernel/common/linux/tegrafb.h @@ -48,7 +48,10 @@ struct tegra_fb_windowattr { __u32 buff_id; __u32 blend; __u32 offset; + __u32 offset_u; + __u32 offset_v; __u32 stride; + __u32 stride_uv; __u32 pixformat; __u32 x; __u32 y; From 73c04b32691cb344cb60289a646ded8fc551d09e Mon Sep 17 00:00:00 2001 From: Jim Huang Date: Tue, 10 Aug 2010 17:23:39 +0800 Subject: [PATCH 79/93] bionic: Add ARM optimized strcpy() Reference results of the experiments on Qualcomm MSM7x25 (524MHz): [original C code] prc thr usecs/call samples errors cnt/samp size strcpy_1k 1 1 14.56159 99 0 1000 1024 [ARM optimized code] prc thr usecs/call samples errors cnt/samp size strcpy_1k 1 1 3.46653 99 0 1000 1024 The work was derived from ARM Ltd. Change-Id: I906ac53bb7a7285e14693c77d3ce8d4ed6f98bfd --- libc/Android.mk | 4 +- libc/arch-arm/bionic/strcpy.S | 138 ++++++++++++++++++++++++++++++++++ 2 files changed, 141 insertions(+), 1 deletion(-) create mode 100644 libc/arch-arm/bionic/strcpy.S diff --git a/libc/Android.mk b/libc/Android.mk index 39c63a21b..71a894135 100644 --- a/libc/Android.mk +++ b/libc/Android.mk @@ -186,7 +186,6 @@ libc_common_src_files := \ string/strcat.c \ string/strchr.c \ string/strcoll.c \ - string/strcpy.c \ string/strcspn.c \ string/strdup.c \ string/strerror.c \ @@ -309,6 +308,7 @@ libc_common_src_files += \ arch-arm/bionic/setjmp.S \ arch-arm/bionic/sigsetjmp.S \ arch-arm/bionic/strlen.c.arm \ + arch-arm/bionic/strcpy.S \ arch-arm/bionic/syscall.S \ arch-arm/bionic/sigaction.c \ arch-arm/bionic/__sig_restorer.S \ @@ -357,6 +357,7 @@ libc_common_src_files += \ arch-x86/string/strcmp_wrapper.S \ arch-x86/string/strncmp_wrapper.S \ arch-x86/string/strlen_wrapper.S \ + string/strcpy.c \ bionic/pthread.c \ bionic/pthread-atfork.c \ bionic/pthread-timers.c \ @@ -394,6 +395,7 @@ libc_common_src_files += \ string/strncmp.c \ string/memcmp.c \ string/strlen.c \ + string/strcpy.c \ bionic/pthread.c \ bionic/pthread-atfork.c \ bionic/pthread-timers.c \ diff --git a/libc/arch-arm/bionic/strcpy.S b/libc/arch-arm/bionic/strcpy.S new file mode 100644 index 000000000..70c353f79 --- /dev/null +++ b/libc/arch-arm/bionic/strcpy.S @@ -0,0 +1,138 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * Copyright (c) 2008 ARM Ltd + * 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. + * 3. The name of the company may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY ARM LTD ``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 ARM LTD 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. + * + * Android adaptation and tweak by Jim Huang . + */ + +#include + + .text + + .global strcpy + .type strcpy, %function + .align 4 + +strcpy: + .fnstart + PLD(r1, #0) + eor r2, r0, r1 + mov ip, r0 + tst r2, #3 + bne 4f + tst r1, #3 + bne 3f +5: + str r5, [sp, #-4]! + mov r5, #0x01 + orr r5, r5, r5, lsl #8 + orr r5, r5, r5, lsl #16 + + str r4, [sp, #-4]! + tst r1, #4 + ldr r3, [r1], #4 + beq 2f + sub r2, r3, r5 + bics r2, r2, r3 + tst r2, r5, lsl #7 + itt eq + streq r3, [ip], #4 + ldreq r3, [r1], #4 + bne 1f + /* Inner loop. We now know that r1 is 64-bit aligned, so we + can safely fetch up to two words. This allows us to avoid + load stalls. */ + .p2align 2 +2: + PLD(r1, #8) + ldr r4, [r1], #4 + sub r2, r3, r5 + bics r2, r2, r3 + tst r2, r5, lsl #7 + sub r2, r4, r5 + bne 1f + str r3, [ip], #4 + bics r2, r2, r4 + tst r2, r5, lsl #7 + itt eq + ldreq r3, [r1], #4 + streq r4, [ip], #4 + beq 2b + mov r3, r4 +1: +#ifdef __ARMEB__ + rors r3, r3, #24 +#endif + strb r3, [ip], #1 + tst r3, #0xff +#ifdef __ARMEL__ + ror r3, r3, #8 +#endif + bne 1b + ldr r4, [sp], #4 + ldr r5, [sp], #4 + bx lr + + /* Strings have the same offset from word alignment, but it's + not zero. */ +3: + tst r1, #1 + beq 1f + ldrb r2, [r1], #1 + strb r2, [ip], #1 + cmp r2, #0 + it eq + bxeq lr +1: + tst r1, #2 + beq 5b + ldrh r2, [r1], #2 +#ifdef __ARMEB__ + tst r2, #0xff00 + iteet ne + strneh r2, [ip], #2 + lsreq r2, r2, #8 + streqb r2, [ip] + tstne r2, #0xff +#else + tst r2, #0xff + itet ne + strneh r2, [ip], #2 + streqb r2, [ip] + tstne r2, #0xff00 +#endif + bne 5b + bx lr + + /* src and dst do not have a common word-alignement. Fall back to + byte copying. */ +4: + ldrb r2, [r1], #1 + strb r2, [ip], #1 + cmp r2, #0 + bne 4b + bx lr From c1974ee144156233c9257aed4bd84a482ec5ffcb Mon Sep 17 00:00:00 2001 From: Iliyan Malchev Date: Mon, 22 Nov 2010 16:52:22 -0800 Subject: [PATCH 80/93] bionic: update processed kernel header tegra_audio.h Change-Id: Idefc8cae9315f1f4f340330ee1b38a7c0acb5fd8 Signed-off-by: Iliyan Malchev --- libc/kernel/common/linux/tegra_audio.h | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/libc/kernel/common/linux/tegra_audio.h b/libc/kernel/common/linux/tegra_audio.h index 45e558aa1..e18ce11d6 100644 --- a/libc/kernel/common/linux/tegra_audio.h +++ b/libc/kernel/common/linux/tegra_audio.h @@ -27,32 +27,16 @@ struct tegra_audio_in_config { #define TEGRA_AUDIO_IN_SET_CONFIG _IOW(TEGRA_AUDIO_MAGIC, 2, const struct tegra_audio_in_config *) #define TEGRA_AUDIO_IN_GET_CONFIG _IOR(TEGRA_AUDIO_MAGIC, 3, struct tegra_audio_in_config *) -struct tegra_audio_buf_config { - unsigned size; - unsigned threshold; - unsigned chunk; -}; - -#define TEGRA_AUDIO_IN_SET_BUF_CONFIG _IOW(TEGRA_AUDIO_MAGIC, 4, const struct tegra_audio_buf_config *) -#define TEGRA_AUDIO_IN_GET_BUF_CONFIG _IOR(TEGRA_AUDIO_MAGIC, 5, struct tegra_audio_buf_config *) - -#define TEGRA_AUDIO_OUT_SET_BUF_CONFIG _IOW(TEGRA_AUDIO_MAGIC, 6, const struct tegra_audio_buf_config *) -#define TEGRA_AUDIO_OUT_GET_BUF_CONFIG _IOR(TEGRA_AUDIO_MAGIC, 7, struct tegra_audio_buf_config *) - -struct tegra_audio_error_counts { - unsigned late_dma; - unsigned full_empty; -}; - -#define TEGRA_AUDIO_IN_GET_ERROR_COUNT _IOR(TEGRA_AUDIO_MAGIC, 8, struct tegra_audio_error_counts *) - -#define TEGRA_AUDIO_OUT_GET_ERROR_COUNT _IOR(TEGRA_AUDIO_MAGIC, 9, struct tegra_audio_error_counts *) +#define TEGRA_AUDIO_IN_SET_NUM_BUFS _IOW(TEGRA_AUDIO_MAGIC, 4, const unsigned int *) +#define TEGRA_AUDIO_IN_GET_NUM_BUFS _IOW(TEGRA_AUDIO_MAGIC, 5, unsigned int *) +#define TEGRA_AUDIO_OUT_SET_NUM_BUFS _IOW(TEGRA_AUDIO_MAGIC, 6, const unsigned int *) +#define TEGRA_AUDIO_OUT_GET_NUM_BUFS _IOW(TEGRA_AUDIO_MAGIC, 7, unsigned int *) #define TEGRA_AUDIO_OUT_FLUSH _IO(TEGRA_AUDIO_MAGIC, 10) #define TEGRA_AUDIO_BIT_FORMAT_DEFAULT 0 #define TEGRA_AUDIO_BIT_FORMAT_DSP 1 -#define TEGRA_AUDIO_SET_BIT_FORMAT _IOW(TEGRA_AUDIO_MAGIC, 11, unsigned int *) +#define TEGRA_AUDIO_SET_BIT_FORMAT _IOW(TEGRA_AUDIO_MAGIC, 11, const unsigned int *) #define TEGRA_AUDIO_GET_BIT_FORMAT _IOR(TEGRA_AUDIO_MAGIC, 12, unsigned int *) #endif From 72e64e08697cc2b3d66397c8b6d34965dd2a7338 Mon Sep 17 00:00:00 2001 From: Kenny Root Date: Wed, 24 Nov 2010 13:10:49 -0800 Subject: [PATCH 81/93] Add support for pread64/pwrite64 64-bit pread() and pwrite() is needed for ZipFileRO to be able to read ludicrously large ZIP files just in case someone is crazy enough to do it. Also fix a license header that was apparently mangled. Change-Id: I6819ef8b36e46b63b40749c95717b1ecf9307033 --- libc/Android.mk | 2 ++ libc/include/unistd.h | 2 ++ libc/unistd/pread.c | 23 +++++++++++++---------- libc/unistd/pread64.c | 37 +++++++++++++++++++++++++++++++++++++ libc/unistd/pwrite64.c | 37 +++++++++++++++++++++++++++++++++++++ 5 files changed, 91 insertions(+), 10 deletions(-) create mode 100644 libc/unistd/pread64.c create mode 100644 libc/unistd/pwrite64.c diff --git a/libc/Android.mk b/libc/Android.mk index f919e316c..59e8e325d 100644 --- a/libc/Android.mk +++ b/libc/Android.mk @@ -39,10 +39,12 @@ libc_common_src_files := \ unistd/perror.c \ unistd/popen.c \ unistd/pread.c \ + unistd/pread64.c \ unistd/pselect.c \ unistd/ptsname.c \ unistd/ptsname_r.c \ unistd/pwrite.c \ + unistd/pwrite64.c \ unistd/raise.c \ unistd/reboot.c \ unistd/recv.c \ diff --git a/libc/include/unistd.h b/libc/include/unistd.h index 38e2825d6..aa236bd80 100644 --- a/libc/include/unistd.h +++ b/libc/include/unistd.h @@ -133,7 +133,9 @@ extern off64_t lseek64(int, off64_t, int); extern ssize_t read(int, void *, size_t); extern ssize_t write(int, const void *, size_t); extern ssize_t pread(int, void *, size_t, off_t); +extern ssize_t pread64(int, void *, size_t, off64_t); extern ssize_t pwrite(int, const void *, size_t, off_t); +extern ssize_t pwrite64(int, const void *, size_t, off64_t); extern int dup(int); extern int dup2(int, int); diff --git a/libc/unistd/pread.c b/libc/unistd/pread.c index b55623ed3..ec4691a92 100644 --- a/libc/unistd/pread.c +++ b/libc/unistd/pread.c @@ -11,17 +11,20 @@ * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. - * 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. - * * Neither the name of Google Inc. 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 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 #include diff --git a/libc/unistd/pread64.c b/libc/unistd/pread64.c new file mode 100644 index 000000000..2a4e08cad --- /dev/null +++ b/libc/unistd/pread64.c @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2010 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 +#include + +extern int __pread64(int fd, void *buf, size_t nbytes, loff_t offset); + +ssize_t pread64(int fd, void *buf, size_t nbytes, off64_t offset) +{ + return __pread64(fd, buf, nbytes, offset); +} + diff --git a/libc/unistd/pwrite64.c b/libc/unistd/pwrite64.c new file mode 100644 index 000000000..b0846503d --- /dev/null +++ b/libc/unistd/pwrite64.c @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2010 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 +#include + +extern int __pwrite64(int fd, const void *buf, size_t nbytes, loff_t offset); + +ssize_t pwrite64(int fd, const void *buf, size_t nbytes, off64_t offset) +{ + return __pwrite64(fd, buf, nbytes, offset); +} + From 16e02c2e3b005c2f801bf27fd4c27fbb235fb5be Mon Sep 17 00:00:00 2001 From: tedbo Date: Mon, 29 Nov 2010 13:15:07 -0800 Subject: [PATCH 82/93] Add wcscasecmp() and wcsncasecmp() prototypes to wchar.h. The above prototypes are missing from libc/include/wchar.h but the functions are present (although with a limited implementation) in libc. Change-Id: I1b7c6accfc59ff0f56f3f41a9d3c075e935ac54a --- libc/include/wchar.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libc/include/wchar.h b/libc/include/wchar.h index 9b744a50c..1361ff530 100644 --- a/libc/include/wchar.h +++ b/libc/include/wchar.h @@ -112,6 +112,7 @@ extern int vfwprintf(FILE *, const wchar_t *, va_list); extern int vwprintf(const wchar_t *, va_list); extern int vswprintf(wchar_t *, size_t, const wchar_t *, va_list); extern size_t wcrtomb(char *, wchar_t, mbstate_t *); +extern int wcscasecmp(const wchar_t *, const wchar_t *); extern wchar_t *wcscat(wchar_t *, const wchar_t *); extern wchar_t *wcschr(const wchar_t *, wchar_t); extern int wcscmp(const wchar_t *, const wchar_t *); @@ -120,6 +121,7 @@ extern wchar_t *wcscpy(wchar_t *, const wchar_t *); extern size_t wcscspn(const wchar_t *, const wchar_t *); extern size_t wcsftime(wchar_t *, size_t, const wchar_t *, const struct tm *); extern size_t wcslen(const wchar_t *); +extern int wcsncasecmp(const wchar_t *, const wchar_t *, size_t); extern wchar_t *wcsncat(wchar_t *, const wchar_t *, size_t); extern int wcsncmp(const wchar_t *, const wchar_t *, size_t); extern wchar_t *wcsncpy(wchar_t *, const wchar_t *, size_t); From ad1ff2fb268034074488f0b4b30b5311008b8617 Mon Sep 17 00:00:00 2001 From: tedbo Date: Tue, 30 Nov 2010 12:45:02 -0800 Subject: [PATCH 83/93] Add mkdtemp() prototype to stdlib.h. The mkdtemp() function is implemented in libc/stdio/mktemp.c but not exposed in stdlib.h. This change adds the prototype to stdlib.h. Change-Id: I5a98650c665d2e45b2cf6ed3382742f7bdc7c88a --- libc/include/stdlib.h | 1 + 1 file changed, 1 insertion(+) diff --git a/libc/include/stdlib.h b/libc/include/stdlib.h index 97d8e4650..5dc8a87b2 100644 --- a/libc/include/stdlib.h +++ b/libc/include/stdlib.h @@ -57,6 +57,7 @@ extern int setenv(const char *, const char *, int); extern int unsetenv(const char *); extern int clearenv(void); +extern char *mkdtemp(char *); extern char *mktemp (char *); extern int mkstemp (char *); From 2bf3ec03c3971a2aaad61a96d78c3a541fc2caf0 Mon Sep 17 00:00:00 2001 From: Bruce Beare Date: Fri, 3 Dec 2010 16:14:59 -0800 Subject: [PATCH 84/93] Add defines for CAIF support Change-Id: I32d2e02814f1965ebdcecb804e947ff303dbe230 Author: Mark Gross Signed-off-by: Bruce Beare --- libc/kernel/common/linux/if_ether.h | 1 + libc/kernel/common/linux/socket.h | 4 +++- libc/kernel/common/linux/tty.h | 2 ++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/libc/kernel/common/linux/if_ether.h b/libc/kernel/common/linux/if_ether.h index 1ba7a9928..7e235a54d 100644 --- a/libc/kernel/common/linux/if_ether.h +++ b/libc/kernel/common/linux/if_ether.h @@ -84,6 +84,7 @@ #define ETH_P_TRAILER 0x001C #define ETH_P_PHONET 0x00F5 #define ETH_P_IEEE802154 0x00F6 +#define ETH_P_CAIF 0x00F7 struct ethhdr { unsigned char h_dest[ETH_ALEN]; diff --git a/libc/kernel/common/linux/socket.h b/libc/kernel/common/linux/socket.h index b578df943..c30dae0d4 100644 --- a/libc/kernel/common/linux/socket.h +++ b/libc/kernel/common/linux/socket.h @@ -138,7 +138,8 @@ struct ucred { #define AF_LLC 26 #define AF_TIPC 30 #define AF_BLUETOOTH 31 -#define AF_MAX 32 +#define AF_CAIF 38 +#define AF_MAX 39 #define PF_UNSPEC AF_UNSPEC #define PF_UNIX AF_UNIX @@ -170,6 +171,7 @@ struct ucred { #define PF_LLC AF_LLC #define PF_TIPC AF_TIPC #define PF_BLUETOOTH AF_BLUETOOTH +#define PF_CAIF AF_CAIF #define PF_MAX AF_MAX #define SOMAXCONN 128 diff --git a/libc/kernel/common/linux/tty.h b/libc/kernel/common/linux/tty.h index b28791c76..b1f2eab83 100644 --- a/libc/kernel/common/linux/tty.h +++ b/libc/kernel/common/linux/tty.h @@ -12,4 +12,6 @@ #ifndef _LINUX_TTY_H #define _LINUX_TTY_H +#define N_CAIF 20 + #endif From 9a9c1619b8124f07fc772c0b700e4d411cd78525 Mon Sep 17 00:00:00 2001 From: Bruce Beare Date: Fri, 3 Dec 2010 16:48:47 -0800 Subject: [PATCH 85/93] sigsetmask.c was not processing the "mask" argument. Change-Id: I79b898ea5b882e8c0564e25466e827a9bedda6e8 Author: yhe19 Signed-off-by: Bruce Beare --- libc/unistd/sigsetmask.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libc/unistd/sigsetmask.c b/libc/unistd/sigsetmask.c index b98759577..4f4645865 100644 --- a/libc/unistd/sigsetmask.c +++ b/libc/unistd/sigsetmask.c @@ -38,6 +38,8 @@ sigsetmask(int mask) sigset_t the_sigset; } in, out; + in.the_mask = mask; + n = sigprocmask(SIG_SETMASK, &in.the_sigset, &out.the_sigset); if (n) return n; From 23d24394e72715ddf580726655c8ba3fbcf11bfe Mon Sep 17 00:00:00 2001 From: David 'Digit' Turner Date: Mon, 6 Dec 2010 12:05:11 +0100 Subject: [PATCH 86/93] libc: Add Add a new header that defines __ANDROID_API__ as a constant integer corresponding to the current native API level. This header is included by Change-Id: Ib4774e247b395991266245815a24292afc919848 NOTE: This header is already provided by the NDK's platform headers. for levels 3 to 9. --- libc/docs/CHANGES.TXT | 11 ++++++++++- libc/include/android/api-level.h | 33 ++++++++++++++++++++++++++++++++ libc/include/sys/cdefs.h | 1 + 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 libc/include/android/api-level.h diff --git a/libc/docs/CHANGES.TXT b/libc/docs/CHANGES.TXT index 0eab8791c..bc641f46b 100644 --- a/libc/docs/CHANGES.TXT +++ b/libc/docs/CHANGES.TXT @@ -1,7 +1,16 @@ Bionic ChangeLog: ----------------- -Differences between current and Android 2.2: +Differences between current and Android 2.3: + +- : Added new header to define __ANDROID_API__ to + a constant integer corresponding to the native API level. This header + also exists in the NDK's platform headers. + +- : Include + +------------------------------------------------------------------------------- +Differences between Android 2.3 and Android 2.2: - : Add reader/writer locks implementation. Add sanity checking to pthread_mutex_destroy() (e.g. a locked mutex will return diff --git a/libc/include/android/api-level.h b/libc/include/android/api-level.h new file mode 100644 index 000000000..611fdfbcd --- /dev/null +++ b/libc/include/android/api-level.h @@ -0,0 +1,33 @@ +/* + * 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. + */ +#ifndef ANDROID_API_LEVEL_H +#define ANDROID_API_LEVEL_H + +#define __ANDROID_API__ 10 + +#endif /* ANDROID_API_LEVEL_H */ diff --git a/libc/include/sys/cdefs.h b/libc/include/sys/cdefs.h index 849e2b8c6..9b6da3175 100644 --- a/libc/include/sys/cdefs.h +++ b/libc/include/sys/cdefs.h @@ -497,5 +497,6 @@ #endif #define __BIONIC__ 1 +#include #endif /* !_SYS_CDEFS_H_ */ From 6481b91520150e9664a3c4abc5d2aebdce422f93 Mon Sep 17 00:00:00 2001 From: David 'Digit' Turner Date: Mon, 6 Dec 2010 12:23:16 +0100 Subject: [PATCH 87/93] : Add timegm(), timelocal() and others. Add timegm(), timelocal(), time2posix() and posix2time() to the C library. Change-Id: I34d5771ed83dd994870a5ca58a511d01898b1ffb --- libc/bionic/time64_config.h | 2 +- libc/docs/CHANGES.TXT | 2 ++ libc/include/time.h | 5 +++++ libc/tzcode/localtime.c | 14 ++++++++++++-- 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/libc/bionic/time64_config.h b/libc/bionic/time64_config.h index 53bcecf6b..13850451c 100644 --- a/libc/bionic/time64_config.h +++ b/libc/bionic/time64_config.h @@ -33,7 +33,7 @@ */ #define HAS_GMTIME_R #define HAS_LOCALTIME_R -/*#define HAS_TIMEGM */ +#define HAS_TIMEGM /* Details of non-standard tm struct elements. diff --git a/libc/docs/CHANGES.TXT b/libc/docs/CHANGES.TXT index bc641f46b..67b9e76da 100644 --- a/libc/docs/CHANGES.TXT +++ b/libc/docs/CHANGES.TXT @@ -9,6 +9,8 @@ Differences between current and Android 2.3: - : Include +- : Add timegm(), timelocal(), time2posix() and posix2time() + ------------------------------------------------------------------------------- Differences between Android 2.3 and Android 2.2: diff --git a/libc/include/time.h b/libc/include/time.h index 5d1a0e268..4ad4f7bd7 100644 --- a/libc/include/time.h +++ b/libc/include/time.h @@ -128,6 +128,11 @@ extern int timer_settime(timer_t timerid, int flags, const struct itimerspec *v extern int timer_gettime(timer_t timerid, struct itimerspec *value); extern int timer_getoverrun(timer_t timerid); +extern time_t timelocal(struct tm *tm); +extern time_t timegm(struct tm* tm); +extern time_t time2posix(time_t ti); +extern time_t posix2time(time_t ti); + __END_DECLS #endif /* _TIME_H_ */ diff --git a/libc/tzcode/localtime.c b/libc/tzcode/localtime.c index 85a913ea6..e442a03a5 100644 --- a/libc/tzcode/localtime.c +++ b/libc/tzcode/localtime.c @@ -60,6 +60,14 @@ static char elsieid[] = "@(#)localtime.c 8.3"; # define XLOG(x) do{}while (0) #endif +/* Add the following function implementations: + * timelocal() + * timegm() + * time2posix() + * posix2time() + */ +#define STD_INSPIRED 1 + /* THREAD-SAFETY SUPPORT GOES HERE */ static pthread_mutex_t _tzMutex = PTHREAD_MUTEX_INITIALIZER; @@ -1509,7 +1517,7 @@ struct tm * tmp; } #ifdef STD_INSPIRED - +#if 0 /* disabled because there is no good documentation for this function */ struct tm * offtime(timep, offset) const time_t * const timep; @@ -1517,7 +1525,7 @@ const long offset; { return gmtsub(timep, offset, &tmGlobal); } - +#endif /* 0 */ #endif /* defined STD_INSPIRED */ /* @@ -2106,6 +2114,7 @@ struct tm * const tmp; return result; } +#if 0 /* disable due to lack of clear documentation on this function */ time_t timeoff(tmp, offset) struct tm * const tmp; @@ -2120,6 +2129,7 @@ const long offset; return result; } +#endif /* 0 */ #endif /* defined STD_INSPIRED */ From 72e6fd42421dca80fb2776a9185c186d4a04e5f7 Mon Sep 17 00:00:00 2001 From: David 'Digit' Turner Date: Fri, 3 Dec 2010 18:04:01 +0100 Subject: [PATCH 88/93] : Add sched_getcpu() and cpu_set_t This adds the cpu_set_t type definition and related functions and macros used to handle CPU thread affinity. sched_getcpu() sched_setaffinity() sched_getaffinity() Change-Id: If382ecafde8926341a88478062b275553645065b --- libc/Android.mk | 4 + libc/SYSCALLS.TXT | 3 + libc/arch-arm/syscalls.mk | 3 + libc/arch-arm/syscalls/__getcpu.S | 19 +++ libc/arch-arm/syscalls/__sched_getaffinity.S | 19 +++ libc/arch-arm/syscalls/sched_setaffinity.S | 19 +++ libc/arch-sh/syscalls.mk | 3 + libc/arch-sh/syscalls/__getcpu.S | 32 ++++ libc/arch-sh/syscalls/__sched_getaffinity.S | 32 ++++ libc/arch-sh/syscalls/sched_setaffinity.S | 32 ++++ libc/arch-x86/syscalls.mk | 3 + libc/arch-x86/syscalls/__getcpu.S | 29 ++++ libc/arch-x86/syscalls/__sched_getaffinity.S | 29 ++++ libc/arch-x86/syscalls/sched_setaffinity.S | 29 ++++ libc/bionic/sched_cpualloc.c | 40 +++++ libc/bionic/sched_cpucount.c | 40 +++++ libc/bionic/sched_getaffinity.c | 41 +++++ libc/bionic/sched_getcpu.c | 40 +++++ libc/docs/CHANGES.TXT | 3 + libc/include/sched.h | 156 +++++++++++++++++++ libc/include/sys/linux-syscalls.h | 5 + libc/include/sys/linux-unistd.h | 6 +- 22 files changed, 585 insertions(+), 2 deletions(-) create mode 100644 libc/arch-arm/syscalls/__getcpu.S create mode 100644 libc/arch-arm/syscalls/__sched_getaffinity.S create mode 100644 libc/arch-arm/syscalls/sched_setaffinity.S create mode 100644 libc/arch-sh/syscalls/__getcpu.S create mode 100644 libc/arch-sh/syscalls/__sched_getaffinity.S create mode 100644 libc/arch-sh/syscalls/sched_setaffinity.S create mode 100644 libc/arch-x86/syscalls/__getcpu.S create mode 100644 libc/arch-x86/syscalls/__sched_getaffinity.S create mode 100644 libc/arch-x86/syscalls/sched_setaffinity.S create mode 100644 libc/bionic/sched_cpualloc.c create mode 100644 libc/bionic/sched_cpucount.c create mode 100644 libc/bionic/sched_getaffinity.c create mode 100644 libc/bionic/sched_getcpu.c diff --git a/libc/Android.mk b/libc/Android.mk index 59e8e325d..8a22918f7 100644 --- a/libc/Android.mk +++ b/libc/Android.mk @@ -273,6 +273,10 @@ libc_common_src_files := \ bionic/md5.c \ bionic/pututline.c \ bionic/realpath.c \ + bionic/sched_getaffinity.c \ + bionic/sched_getcpu.c \ + bionic/sched_cpualloc.c \ + bionic/sched_cpucount.c \ bionic/semaphore.c \ bionic/sha1.c \ bionic/ssp.c \ diff --git a/libc/SYSCALLS.TXT b/libc/SYSCALLS.TXT index 0a08e1243..2bb8a42a9 100644 --- a/libc/SYSCALLS.TXT +++ b/libc/SYSCALLS.TXT @@ -229,6 +229,9 @@ int sched_getparam(pid_t pid, struct sched_param *param) 155 int sched_get_priority_max(int policy) 159 int sched_get_priority_min(int policy) 160 int sched_rr_get_interval(pid_t pid, struct timespec *interval) 161 +int sched_setaffinity(pid_t pid, size_t setsize, const cpu_set_t* set) 241 +int __sched_getaffinity:sched_getaffinity(pid_t pid, size_t setsize, cpu_set_t* set) 242 +int __getcpu:getcpu(unsigned *cpu, unsigned *node, void *unused) 345,318,318 # io priorities int ioprio_set(int which, int who, int ioprio) 314,289,288 diff --git a/libc/arch-arm/syscalls.mk b/libc/arch-arm/syscalls.mk index ba78c1846..e25bb3131 100644 --- a/libc/arch-arm/syscalls.mk +++ b/libc/arch-arm/syscalls.mk @@ -153,6 +153,9 @@ syscall_src += arch-arm/syscalls/sched_getparam.S syscall_src += arch-arm/syscalls/sched_get_priority_max.S syscall_src += arch-arm/syscalls/sched_get_priority_min.S syscall_src += arch-arm/syscalls/sched_rr_get_interval.S +syscall_src += arch-arm/syscalls/sched_setaffinity.S +syscall_src += arch-arm/syscalls/__sched_getaffinity.S +syscall_src += arch-arm/syscalls/__getcpu.S syscall_src += arch-arm/syscalls/ioprio_set.S syscall_src += arch-arm/syscalls/ioprio_get.S syscall_src += arch-arm/syscalls/uname.S diff --git a/libc/arch-arm/syscalls/__getcpu.S b/libc/arch-arm/syscalls/__getcpu.S new file mode 100644 index 000000000..ed6927a4f --- /dev/null +++ b/libc/arch-arm/syscalls/__getcpu.S @@ -0,0 +1,19 @@ +/* autogenerated by gensyscalls.py */ +#include + + .text + .type __getcpu, #function + .globl __getcpu + .align 4 + .fnstart + +__getcpu: + .save {r4, r7} + stmfd sp!, {r4, r7} + ldr r7, =__NR_getcpu + swi #0 + ldmfd sp!, {r4, r7} + movs r0, r0 + bxpl lr + b __set_syscall_errno + .fnend diff --git a/libc/arch-arm/syscalls/__sched_getaffinity.S b/libc/arch-arm/syscalls/__sched_getaffinity.S new file mode 100644 index 000000000..71f2b1d72 --- /dev/null +++ b/libc/arch-arm/syscalls/__sched_getaffinity.S @@ -0,0 +1,19 @@ +/* autogenerated by gensyscalls.py */ +#include + + .text + .type __sched_getaffinity, #function + .globl __sched_getaffinity + .align 4 + .fnstart + +__sched_getaffinity: + .save {r4, r7} + stmfd sp!, {r4, r7} + ldr r7, =__NR_sched_getaffinity + swi #0 + ldmfd sp!, {r4, r7} + movs r0, r0 + bxpl lr + b __set_syscall_errno + .fnend diff --git a/libc/arch-arm/syscalls/sched_setaffinity.S b/libc/arch-arm/syscalls/sched_setaffinity.S new file mode 100644 index 000000000..aedf8f3f7 --- /dev/null +++ b/libc/arch-arm/syscalls/sched_setaffinity.S @@ -0,0 +1,19 @@ +/* autogenerated by gensyscalls.py */ +#include + + .text + .type sched_setaffinity, #function + .globl sched_setaffinity + .align 4 + .fnstart + +sched_setaffinity: + .save {r4, r7} + stmfd sp!, {r4, r7} + ldr r7, =__NR_sched_setaffinity + swi #0 + ldmfd sp!, {r4, r7} + movs r0, r0 + bxpl lr + b __set_syscall_errno + .fnend diff --git a/libc/arch-sh/syscalls.mk b/libc/arch-sh/syscalls.mk index a87419d96..493f437ff 100644 --- a/libc/arch-sh/syscalls.mk +++ b/libc/arch-sh/syscalls.mk @@ -142,6 +142,9 @@ syscall_src += arch-sh/syscalls/sched_getparam.S syscall_src += arch-sh/syscalls/sched_get_priority_max.S syscall_src += arch-sh/syscalls/sched_get_priority_min.S syscall_src += arch-sh/syscalls/sched_rr_get_interval.S +syscall_src += arch-sh/syscalls/sched_setaffinity.S +syscall_src += arch-sh/syscalls/__sched_getaffinity.S +syscall_src += arch-sh/syscalls/__getcpu.S syscall_src += arch-sh/syscalls/ioprio_set.S syscall_src += arch-sh/syscalls/ioprio_get.S syscall_src += arch-sh/syscalls/uname.S diff --git a/libc/arch-sh/syscalls/__getcpu.S b/libc/arch-sh/syscalls/__getcpu.S new file mode 100644 index 000000000..125387baf --- /dev/null +++ b/libc/arch-sh/syscalls/__getcpu.S @@ -0,0 +1,32 @@ +/* autogenerated by gensyscalls.py */ +#include + + .text + .type __getcpu, @function + .globl __getcpu + .align 4 + +__getcpu: + + /* invoke trap */ + mov.l 0f, r3 /* trap num */ + trapa #(3 + 0x10) + + /* check return value */ + cmp/pz r0 + bt __NR_getcpu_end + + /* keep error number */ + sts.l pr, @-r15 + mov.l 1f, r1 + jsr @r1 + mov r0, r4 + lds.l @r15+, pr + +__NR_getcpu_end: + rts + nop + + .align 2 +0: .long __NR_getcpu +1: .long __set_syscall_errno diff --git a/libc/arch-sh/syscalls/__sched_getaffinity.S b/libc/arch-sh/syscalls/__sched_getaffinity.S new file mode 100644 index 000000000..7e8be6a61 --- /dev/null +++ b/libc/arch-sh/syscalls/__sched_getaffinity.S @@ -0,0 +1,32 @@ +/* autogenerated by gensyscalls.py */ +#include + + .text + .type __sched_getaffinity, @function + .globl __sched_getaffinity + .align 4 + +__sched_getaffinity: + + /* invoke trap */ + mov.l 0f, r3 /* trap num */ + trapa #(3 + 0x10) + + /* check return value */ + cmp/pz r0 + bt __NR_sched_getaffinity_end + + /* keep error number */ + sts.l pr, @-r15 + mov.l 1f, r1 + jsr @r1 + mov r0, r4 + lds.l @r15+, pr + +__NR_sched_getaffinity_end: + rts + nop + + .align 2 +0: .long __NR_sched_getaffinity +1: .long __set_syscall_errno diff --git a/libc/arch-sh/syscalls/sched_setaffinity.S b/libc/arch-sh/syscalls/sched_setaffinity.S new file mode 100644 index 000000000..9dda3b48b --- /dev/null +++ b/libc/arch-sh/syscalls/sched_setaffinity.S @@ -0,0 +1,32 @@ +/* autogenerated by gensyscalls.py */ +#include + + .text + .type sched_setaffinity, @function + .globl sched_setaffinity + .align 4 + +sched_setaffinity: + + /* invoke trap */ + mov.l 0f, r3 /* trap num */ + trapa #(3 + 0x10) + + /* check return value */ + cmp/pz r0 + bt __NR_sched_setaffinity_end + + /* keep error number */ + sts.l pr, @-r15 + mov.l 1f, r1 + jsr @r1 + mov r0, r4 + lds.l @r15+, pr + +__NR_sched_setaffinity_end: + rts + nop + + .align 2 +0: .long __NR_sched_setaffinity +1: .long __set_syscall_errno diff --git a/libc/arch-x86/syscalls.mk b/libc/arch-x86/syscalls.mk index 420a91eb0..c210b2190 100644 --- a/libc/arch-x86/syscalls.mk +++ b/libc/arch-x86/syscalls.mk @@ -156,6 +156,9 @@ syscall_src += arch-x86/syscalls/sched_getparam.S syscall_src += arch-x86/syscalls/sched_get_priority_max.S syscall_src += arch-x86/syscalls/sched_get_priority_min.S syscall_src += arch-x86/syscalls/sched_rr_get_interval.S +syscall_src += arch-x86/syscalls/sched_setaffinity.S +syscall_src += arch-x86/syscalls/__sched_getaffinity.S +syscall_src += arch-x86/syscalls/__getcpu.S syscall_src += arch-x86/syscalls/ioprio_set.S syscall_src += arch-x86/syscalls/ioprio_get.S syscall_src += arch-x86/syscalls/uname.S diff --git a/libc/arch-x86/syscalls/__getcpu.S b/libc/arch-x86/syscalls/__getcpu.S new file mode 100644 index 000000000..03817997e --- /dev/null +++ b/libc/arch-x86/syscalls/__getcpu.S @@ -0,0 +1,29 @@ +/* autogenerated by gensyscalls.py */ +#include + + .text + .type __getcpu, @function + .globl __getcpu + .align 4 + +__getcpu: + pushl %ebx + pushl %ecx + pushl %edx + mov 16(%esp), %ebx + mov 20(%esp), %ecx + mov 24(%esp), %edx + movl $__NR_getcpu, %eax + int $0x80 + cmpl $-129, %eax + jb 1f + negl %eax + pushl %eax + call __set_errno + addl $4, %esp + orl $-1, %eax +1: + popl %edx + popl %ecx + popl %ebx + ret diff --git a/libc/arch-x86/syscalls/__sched_getaffinity.S b/libc/arch-x86/syscalls/__sched_getaffinity.S new file mode 100644 index 000000000..43bfa508b --- /dev/null +++ b/libc/arch-x86/syscalls/__sched_getaffinity.S @@ -0,0 +1,29 @@ +/* autogenerated by gensyscalls.py */ +#include + + .text + .type __sched_getaffinity, @function + .globl __sched_getaffinity + .align 4 + +__sched_getaffinity: + pushl %ebx + pushl %ecx + pushl %edx + mov 16(%esp), %ebx + mov 20(%esp), %ecx + mov 24(%esp), %edx + movl $__NR_sched_getaffinity, %eax + int $0x80 + cmpl $-129, %eax + jb 1f + negl %eax + pushl %eax + call __set_errno + addl $4, %esp + orl $-1, %eax +1: + popl %edx + popl %ecx + popl %ebx + ret diff --git a/libc/arch-x86/syscalls/sched_setaffinity.S b/libc/arch-x86/syscalls/sched_setaffinity.S new file mode 100644 index 000000000..5fa51ef34 --- /dev/null +++ b/libc/arch-x86/syscalls/sched_setaffinity.S @@ -0,0 +1,29 @@ +/* autogenerated by gensyscalls.py */ +#include + + .text + .type sched_setaffinity, @function + .globl sched_setaffinity + .align 4 + +sched_setaffinity: + pushl %ebx + pushl %ecx + pushl %edx + mov 16(%esp), %ebx + mov 20(%esp), %ecx + mov 24(%esp), %edx + movl $__NR_sched_setaffinity, %eax + int $0x80 + cmpl $-129, %eax + jb 1f + negl %eax + pushl %eax + call __set_errno + addl $4, %esp + orl $-1, %eax +1: + popl %edx + popl %ecx + popl %ebx + ret diff --git a/libc/bionic/sched_cpualloc.c b/libc/bionic/sched_cpualloc.c new file mode 100644 index 000000000..30964bca7 --- /dev/null +++ b/libc/bionic/sched_cpualloc.c @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2010 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. + */ +#define _GNU_SOURCE 1 +#include +#include + +cpu_set_t* __sched_cpualloc(size_t count) +{ + return (cpu_set_t*) malloc(CPU_ALLOC_SIZE(count)); +} + +void __sched_cpufree(cpu_set_t* set) +{ + free(set); +} diff --git a/libc/bionic/sched_cpucount.c b/libc/bionic/sched_cpucount.c new file mode 100644 index 000000000..9458dc8f4 --- /dev/null +++ b/libc/bionic/sched_cpucount.c @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2010 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. + */ +#define _GNU_SOURCE 1 +#include + +int __sched_cpucount(size_t setsize, cpu_set_t* set) +{ + int nn = 0, nn_max = setsize / sizeof(__CPU_BITTYPE); + int count = 0; + + for ( ; nn < nn_max; nn++ ) + count += __builtin_popcount(set->__bits[nn]); + + return count; +} diff --git a/libc/bionic/sched_getaffinity.c b/libc/bionic/sched_getaffinity.c new file mode 100644 index 000000000..7313822a2 --- /dev/null +++ b/libc/bionic/sched_getaffinity.c @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2010 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. + */ +#define _GNU_SOURCE 1 +#include + +int sched_getaffinity(pid_t pid, size_t setsize, cpu_set_t* set) +{ + int ret = __sched_getaffinity(pid, setsize, set); + if (ret >= 0) { + if ((size_t)ret < setsize) { + memset((char*)set + ret, '\0', setsize - (size_t)ret); + } + ret = 0; + } + return ret; +} diff --git a/libc/bionic/sched_getcpu.c b/libc/bionic/sched_getcpu.c new file mode 100644 index 000000000..954df3727 --- /dev/null +++ b/libc/bionic/sched_getcpu.c @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2010 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. + */ +#define _GNU_SOURCE 1 +#include + +extern int __getcpu(unsigned *cpu, unsigned *node, void* unused); + +int sched_getcpu(void) +{ + unsigned cpu; + if (__getcpu(&cpu, NULL, NULL) < 0) + return 0; + + return (int)cpu; +} diff --git a/libc/docs/CHANGES.TXT b/libc/docs/CHANGES.TXT index 67b9e76da..8e23c0ef5 100644 --- a/libc/docs/CHANGES.TXT +++ b/libc/docs/CHANGES.TXT @@ -11,6 +11,9 @@ Differences between current and Android 2.3: - : Add timegm(), timelocal(), time2posix() and posix2time() +- : Add sched_getcpu(), sched_getaffinity(), sched_setaffinity(), + cpu_set_t and related macros (e.g. CPU_SETSIZE, CPU_ZERO, CPU_SET, ...) + ------------------------------------------------------------------------------- Differences between Android 2.3 and Android 2.2: diff --git a/libc/include/sched.h b/libc/include/sched.h index e70247005..ca72da7a7 100644 --- a/libc/include/sched.h +++ b/libc/include/sched.h @@ -73,6 +73,162 @@ extern int sched_rr_get_interval(pid_t pid, struct timespec *tp); extern int clone(int (*fn)(void *), void *child_stack, int flags, void* arg, ...); #endif +/* Support for cpu thread affinity */ +#ifdef _GNU_SOURCE + +extern int sched_getcpu(void); + + +/* Our implementation supports up to 32 independent CPUs, which is also + * the maximum supported by the kernel at the moment. GLibc uses 1024 by + * default. + * + * If you want to use more than that, you should use CPU_ALLOC() / CPU_FREE() + * and the CPU_XXX_S() macro variants. + */ +#define CPU_SETSIZE 32 + +#define __CPU_BITTYPE unsigned long int /* mandated by the kernel */ +#define __CPU_BITSHIFT 5 /* should be log2(BITTYPE) */ +#define __CPU_BITS (1 << __CPU_BITSHIFT) +#define __CPU_ELT(x) ((x) >> __CPU_BITSHIFT) +#define __CPU_MASK(x) ((__CPU_BITTYPE)1 << ((x) & (__CPU_BITS-1))) + +typedef struct { + __CPU_BITTYPE __bits[ CPU_SETSIZE / __CPU_BITS ]; +} cpu_set_t; + +extern int sched_setaffinity(pid_t pid, size_t setsize, const cpu_set_t* set); + +extern int sched_getaffinity(pid_t pid, size_t setsize, cpu_set_t* set); + +/* Provide optimized implementation for 32-bit cpu_set_t */ +#if CPU_SETSIZE == __CPU_BITS + +# define CPU_ZERO(set_) \ + do{ \ + (set_)->__bits[0] = 0; \ + }while(0) + +# define CPU_SET(cpu_,set_) \ + do {\ + size_t __cpu = (cpu_); \ + if (__cpu < CPU_SETSIZE) \ + (set_)->__bits[0] |= __CPU_MASK(__cpu); \ + }while (0) + +# define CPU_CLR(cpu_,set_) \ + do {\ + size_t __cpu = (cpu_); \ + if (__cpu < CPU_SETSIZE) \ + (set_)->__bits[0] &= ~__CPU_MASK(__cpu); \ + }while (0) + +# define CPU_ISSET(cpu_, set_) \ + (__extension__({\ + size_t __cpu = (cpu_); \ + (cpu_ < CPU_SETSIZE) \ + ? ((set_)->__bits[0] & __CPU_MASK(__cpu)) != 0 \ + : 0; \ + })) + +# define CPU_EQUAL(set1_, set2_) \ + ((set1_)->__bits[0] == (set2_)->__bits[0]) + +# define __CPU_OP(dst_, set1_, set2_, op_) \ + do { \ + (dst_)->__bits[0] = (set1_)->__bits[0] op_ (set2_)->__bits[0]; \ + } while (0) + +# define CPU_COUNT(set_) __builtin_popcountl((set_)->__bits[0]) + +#else /* CPU_SETSIZE != __CPU_BITS */ + +# define CPU_ZERO(set_) CPU_ZERO_S(sizeof(cpu_set_t), set_) +# define CPU_SET(cpu_,set_) CPU_SET_S(cpu_,sizeof(cpu_set_t),set_) +# define CPU_CLR(cpu_,set_) CPU_CLR_S(cpu_,sizeof(cpu_set_t),set_) +# define CPU_ISSET(cpu_,set_) CPU_ISSET_S(cpu_,sizeof(cpu_set_t),set_) +# define CPU_COUNT(set_) CPU_COUNT_S(sizeof(cpu_set_t),set_) +# define CPU_EQUAL(set1_,set2_) CPU_EQUAL_S(sizeof(cpu_set_t),set1_,set2_) + +# define __CPU_OP(dst_,set1_,set2_,op_) __CPU_OP_S(sizeof(cpu_set_t),dst_,set1_,set2_,op_) + +#endif /* CPU_SETSIZE != __CPU_BITS */ + +#define CPU_AND(set1_,set2_) __CPU_OP(set1_,set2_,&) +#define CPU_OR(set1_,set2_) __CPU_OP(set1_,set2_,|) +#define CPU_XOR(set1_,set2_) __CPU_OP(set1_,set2_,^) + +/* Support for dynamically-allocated cpu_set_t */ + +#define CPU_ALLOC_SIZE(count) \ + __CPU_ELT((count) + (__CPU_BITS-1))*sizeof(__CPU_BITTYPE) + +#define CPU_ALLOC(count) __sched_cpualloc((count)); +#define CPU_FREE(set) __sched_cpufree((set)) + +extern cpu_set_t* __sched_cpualloc(size_t count); +extern void __sched_cpufree(cpu_set_t* set); + +#define CPU_ZERO_S(setsize_,set_) \ + do { \ + size_t __nn = 0; \ + size_t __nn_max = (setsize_)/sizeof(__CPU_BITTYPE); \ + for (; __nn < __nn_max; __nn++) \ + (set_)->__bits[__nn] = 0; \ + } while (0) + +#define CPU_SET_S(cpu_,setsize_,set_) \ + do { \ + size_t __cpu = (cpu_); \ + if (__cpu < 8*(setsize_)) \ + (set_)->__bits[__CPU_ELT(__cpu)] |= __CPU_MASK(__cpu); \ + } while (0) + +#define CPU_CLR_S(cpu_,setsize_,set_) \ + do { \ + size_t __cpu = (cpu_); \ + if (__cpu < 8*(setsize_)) \ + (set_)->__bits[__CPU_ELT(__cpu)] &= ~__CPU_MASK(__cpu); \ + } while (0) + +#define CPU_ISSET_S(cpu_, setsize_, set_) \ + (__extension__ ({ \ + size_t __cpu = (cpu_); \ + (__cpu < 8*(setsize_)) \ + ? ((set_)->__bits[__CPU_ELT(__cpu)] & __CPU_MASK(__cpu)) != 0 \ + : 0; \ + })) + +#define CPU_EQUAL_S(setsize_, set1_, set2_) \ + (__extension__ ({ \ + __const __CPU_BITTYPE* __src1 = (set1_)->__bits; \ + __const __CPU_BITTYPE* __src2 = (set2_)->__bits; \ + size_t __nn = 0, __nn_max = (setsize_)/sizeof(__CPU_BITTYPE); \ + for (; __nn < __nn_max; __nn++) { \ + if (__src1[__nn] != __src2[__nn]) \ + break; \ + } \ + __nn == __nn_max; \ + })) + +#define __CPU_OP_S(setsize_, dstset_, srcset1_, srcset2_, op) \ + do { \ + cpu_set_t* __dst = (dstset); \ + const __CPU_BITTYPE* __src1 = (srcset1)->__bits; \ + const __CPU_BITTYPE* __src2 = (srcset2)->__bits; \ + size_t __nn = 0, __nn_max = (setsize_)/sizeof(__CPU_BITTYPE); \ + for (; __nn < __nn_max; __nn++) \ + (__dst)->__bits[__nn] = __src1[__nn] op __src2[__nn]; \ + } while (0) + +#define CPU_COUNT_S(setsize_, set_) \ + __sched_cpucount((setsize_), (set_)) + +extern int __sched_cpucount(size_t setsize, cpu_set_t* set); + +#endif /* _GNU_SOURCE */ + __END_DECLS #endif /* _SCHED_H_ */ diff --git a/libc/include/sys/linux-syscalls.h b/libc/include/sys/linux-syscalls.h index 9702a7a73..35729ae30 100644 --- a/libc/include/sys/linux-syscalls.h +++ b/libc/include/sys/linux-syscalls.h @@ -120,6 +120,8 @@ #define __NR_sched_get_priority_max (__NR_SYSCALL_BASE + 159) #define __NR_sched_get_priority_min (__NR_SYSCALL_BASE + 160) #define __NR_sched_rr_get_interval (__NR_SYSCALL_BASE + 161) +#define __NR_sched_setaffinity (__NR_SYSCALL_BASE + 241) +#define __NR_sched_getaffinity (__NR_SYSCALL_BASE + 242) #define __NR_uname (__NR_SYSCALL_BASE + 122) #define __NR_wait4 (__NR_SYSCALL_BASE + 114) #define __NR_umask (__NR_SYSCALL_BASE + 60) @@ -174,6 +176,7 @@ #define __NR_getsockopt (__NR_SYSCALL_BASE + 295) #define __NR_sendmsg (__NR_SYSCALL_BASE + 296) #define __NR_recvmsg (__NR_SYSCALL_BASE + 297) +#define __NR_getcpu (__NR_SYSCALL_BASE + 345) #define __NR_ioprio_set (__NR_SYSCALL_BASE + 314) #define __NR_ioprio_get (__NR_SYSCALL_BASE + 315) #define __NR_epoll_create (__NR_SYSCALL_BASE + 250) @@ -218,6 +221,7 @@ #define __NR_timer_delete (__NR_SYSCALL_BASE + 263) #define __NR_utimes (__NR_SYSCALL_BASE + 271) #define __NR_socketcall (__NR_SYSCALL_BASE + 102) +#define __NR_getcpu (__NR_SYSCALL_BASE + 318) #define __NR_ioprio_set (__NR_SYSCALL_BASE + 289) #define __NR_ioprio_get (__NR_SYSCALL_BASE + 290) #define __NR_epoll_create (__NR_SYSCALL_BASE + 254) @@ -276,6 +280,7 @@ #define __NR_socketcall (__NR_SYSCALL_BASE + 102) #define __NR_socketcall (__NR_SYSCALL_BASE + 102) #define __NR___socketcall (__NR_SYSCALL_BASE + 102) +#define __NR_getcpu (__NR_SYSCALL_BASE + 318) #define __NR_ioprio_set (__NR_SYSCALL_BASE + 288) #define __NR_ioprio_get (__NR_SYSCALL_BASE + 289) #define __NR_epoll_create (__NR_SYSCALL_BASE + 254) diff --git a/libc/include/sys/linux-unistd.h b/libc/include/sys/linux-unistd.h index 48c5c77cd..4a6172460 100644 --- a/libc/include/sys/linux-unistd.h +++ b/libc/include/sys/linux-unistd.h @@ -53,7 +53,7 @@ int acct (const char* filepath); ssize_t read (int, void*, size_t); ssize_t write (int, const void*, size_t); ssize_t __pread64 (int, void *, size_t, off_t, off_t); -ssize_t __pwrite64 (int, const void *, size_t, off_t, off_t); +ssize_t __pwrite64 (int, void *, size_t, off_t, off_t); int __open (const char*, int, mode_t); int __openat (int, const char*, int, mode_t); int close (int); @@ -183,6 +183,9 @@ int sched_getparam (pid_t pid, struct sched_param *param); int sched_get_priority_max (int policy); int sched_get_priority_min (int policy); int sched_rr_get_interval (pid_t pid, struct timespec *interval); +int sched_setaffinity (pid_t pid, size_t setsize, const cpu_set_t* set); +int __sched_getaffinity (pid_t pid, size_t setsize, cpu_set_t* set); +int __getcpu (unsigned *cpu, unsigned *node, void *unused); int ioprio_set (int which, int who, int ioprio); int ioprio_get (int which, int who); int uname (struct utsname *); @@ -205,7 +208,6 @@ int poll (struct pollfd *, unsigned int, long); int eventfd (unsigned int, int); int __set_tls (void*); int cacheflush (long start, long end, long flags); -int eventfd (int count, int flags); #ifdef __cplusplus } #endif From abdffc4e23f05d07004eeb46e7c0122204c22a55 Mon Sep 17 00:00:00 2001 From: Yu Shan Emily Lau Date: Thu, 9 Dec 2010 11:57:42 -0800 Subject: [PATCH 89/93] Revert "sigsetmask.c was not processing the "mask" argument." This reverts commit 9a9c1619b8124f07fc772c0b700e4d411cd78525. --- libc/unistd/sigsetmask.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/libc/unistd/sigsetmask.c b/libc/unistd/sigsetmask.c index 4f4645865..b98759577 100644 --- a/libc/unistd/sigsetmask.c +++ b/libc/unistd/sigsetmask.c @@ -38,8 +38,6 @@ sigsetmask(int mask) sigset_t the_sigset; } in, out; - in.the_mask = mask; - n = sigprocmask(SIG_SETMASK, &in.the_sigset, &out.the_sigset); if (n) return n; From ff3129b0fe52fabec273077871cb35515465d44b Mon Sep 17 00:00:00 2001 From: Bruce Beare Date: Fri, 3 Dec 2010 16:48:47 -0800 Subject: [PATCH 90/93] sigsetmask.c was not processing the "mask" argument. Change-Id: I79b898ea5b882e8c0564e25466e827a9bedda6e8 Author: yhe19 Signed-off-by: Bruce Beare --- libc/unistd/sigsetmask.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libc/unistd/sigsetmask.c b/libc/unistd/sigsetmask.c index b98759577..4f4645865 100644 --- a/libc/unistd/sigsetmask.c +++ b/libc/unistd/sigsetmask.c @@ -38,6 +38,8 @@ sigsetmask(int mask) sigset_t the_sigset; } in, out; + in.the_mask = mask; + n = sigprocmask(SIG_SETMASK, &in.the_sigset, &out.the_sigset); if (n) return n; From 4a7f31fad74417696ce740b1f5c14e4de0740e33 Mon Sep 17 00:00:00 2001 From: David 'Digit' Turner Date: Thu, 16 Dec 2010 14:57:31 +0100 Subject: [PATCH 91/93] libc: Remove duplicate eventfd declaration from SYSCALLS.TXT The second declaration came from an incorrect change in AOSP. The eventfd stubs are not affected by this, they are already correct. Change-Id: Icfc7612a68fc37a48dde2687137960a5d1dbc534 --- libc/SYSCALLS.TXT | 2 -- 1 file changed, 2 deletions(-) diff --git a/libc/SYSCALLS.TXT b/libc/SYSCALLS.TXT index 2bb8a42a9..3023b133c 100644 --- a/libc/SYSCALLS.TXT +++ b/libc/SYSCALLS.TXT @@ -267,5 +267,3 @@ int eventfd:eventfd2(unsigned int, int) 356,328 # ARM-specific ARM_NR_BASE == 0x0f0000 == 983040 int __set_tls:ARM_set_tls(void*) 983045,-1 int cacheflush:ARM_cacheflush(long start, long end, long flags) 983042,-1 - -int eventfd(int count, int flags) 351,323 From 95d751feacdb58d3fbc36f3f21a895a3ec2f065b Mon Sep 17 00:00:00 2001 From: David 'Digit' Turner Date: Thu, 16 Dec 2010 16:47:14 +0100 Subject: [PATCH 92/93] libc: Add ftruncate64 and improve 64-bit parameter syscall handling. This patch improves the handling of 64-bit parameters in syscalls on ARM. The ARM EABI mandates that 64-bit quantities be passed in even/odd register pairs, which requires special treatment. This allows us to simplify our implementations of pread() and pwrite() and remove the C stubs for pread64() and pwrite64(). Also add ftruncate64() to Change-Id: I407e2fd223ba0093dd2d0b04c6152fadfc9ce3ef Bug 3107933 --- libc/Android.mk | 2 - libc/SYSCALLS.TXT | 5 +- libc/arch-arm/syscalls.mk | 5 +- libc/arch-arm/syscalls/ftruncate64.S | 19 ++++++ .../syscalls/{__pread64.S => pread64.S} | 6 +- .../syscalls/{__pwrite64.S => pwrite64.S} | 6 +- libc/arch-sh/syscalls.mk | 5 +- libc/arch-sh/syscalls/ftruncate64.S | 32 +++++++++ .../syscalls/{__pread64.S => pread64.S} | 6 +- .../syscalls/{__pwrite64.S => pwrite64.S} | 6 +- libc/arch-x86/syscalls.mk | 5 +- libc/arch-x86/syscalls/ftruncate64.S | 29 ++++++++ .../syscalls/{__pread64.S => pread64.S} | 6 +- .../syscalls/{__pwrite64.S => pwrite64.S} | 6 +- libc/docs/CHANGES.TXT | 2 + libc/include/sys/linux-syscalls.h | 1 + libc/include/sys/linux-unistd.h | 5 +- libc/include/unistd.h | 1 + libc/tools/gensyscalls.py | 68 +++++++++++++++++-- libc/unistd/pread.c | 4 +- libc/unistd/pread64.c | 37 ---------- libc/unistd/pwrite.c | 4 +- libc/unistd/pwrite64.c | 37 ---------- 23 files changed, 181 insertions(+), 116 deletions(-) create mode 100644 libc/arch-arm/syscalls/ftruncate64.S rename libc/arch-arm/syscalls/{__pread64.S => pread64.S} (85%) rename libc/arch-arm/syscalls/{__pwrite64.S => pwrite64.S} (85%) create mode 100644 libc/arch-sh/syscalls/ftruncate64.S rename libc/arch-sh/syscalls/{__pread64.S => pread64.S} (89%) rename libc/arch-sh/syscalls/{__pwrite64.S => pwrite64.S} (89%) create mode 100644 libc/arch-x86/syscalls/ftruncate64.S rename libc/arch-x86/syscalls/{__pread64.S => pread64.S} (90%) rename libc/arch-x86/syscalls/{__pwrite64.S => pwrite64.S} (90%) delete mode 100644 libc/unistd/pread64.c delete mode 100644 libc/unistd/pwrite64.c diff --git a/libc/Android.mk b/libc/Android.mk index 8a22918f7..6361ad990 100644 --- a/libc/Android.mk +++ b/libc/Android.mk @@ -39,12 +39,10 @@ libc_common_src_files := \ unistd/perror.c \ unistd/popen.c \ unistd/pread.c \ - unistd/pread64.c \ unistd/pselect.c \ unistd/ptsname.c \ unistd/ptsname_r.c \ unistd/pwrite.c \ - unistd/pwrite64.c \ unistd/raise.c \ unistd/reboot.c \ unistd/recv.c \ diff --git a/libc/SYSCALLS.TXT b/libc/SYSCALLS.TXT index 3023b133c..5653c3cad 100644 --- a/libc/SYSCALLS.TXT +++ b/libc/SYSCALLS.TXT @@ -85,8 +85,8 @@ int acct(const char* filepath) 51 # file descriptors ssize_t read (int, void*, size_t) 3 ssize_t write (int, const void*, size_t) 4 -ssize_t __pread64:pread64 (int, void *, size_t, off_t, off_t) 180 -ssize_t __pwrite64:pwrite64 (int, void *, size_t, off_t, off_t) 181 +ssize_t pread64 (int, void *, size_t, off64_t) 180 +ssize_t pwrite64 (int, void *, size_t, off64_t) 181 int __open:open (const char*, int, mode_t) 5 int __openat:openat (int, const char*, int, mode_t) 322,295 int close (int) 6 @@ -116,6 +116,7 @@ int pipe2(int *, int) 359,331 int dup2(int, int) 63 int select:_newselect(int, struct fd_set *, struct fd_set *, struct fd_set *, struct timeval *) 142 int ftruncate(int, off_t) 93 +int ftruncate64(int, off64_t) 194 int getdents:getdents64(unsigned int, struct dirent *, unsigned int) 217,220 int fsync(int) 118 int fdatasync(int) 148 diff --git a/libc/arch-arm/syscalls.mk b/libc/arch-arm/syscalls.mk index e25bb3131..5210d6c39 100644 --- a/libc/arch-arm/syscalls.mk +++ b/libc/arch-arm/syscalls.mk @@ -41,8 +41,8 @@ syscall_src += arch-arm/syscalls/sigaltstack.S syscall_src += arch-arm/syscalls/acct.S syscall_src += arch-arm/syscalls/read.S syscall_src += arch-arm/syscalls/write.S -syscall_src += arch-arm/syscalls/__pread64.S -syscall_src += arch-arm/syscalls/__pwrite64.S +syscall_src += arch-arm/syscalls/pread64.S +syscall_src += arch-arm/syscalls/pwrite64.S syscall_src += arch-arm/syscalls/__open.S syscall_src += arch-arm/syscalls/__openat.S syscall_src += arch-arm/syscalls/close.S @@ -70,6 +70,7 @@ syscall_src += arch-arm/syscalls/pipe2.S syscall_src += arch-arm/syscalls/dup2.S syscall_src += arch-arm/syscalls/select.S syscall_src += arch-arm/syscalls/ftruncate.S +syscall_src += arch-arm/syscalls/ftruncate64.S syscall_src += arch-arm/syscalls/getdents.S syscall_src += arch-arm/syscalls/fsync.S syscall_src += arch-arm/syscalls/fdatasync.S diff --git a/libc/arch-arm/syscalls/ftruncate64.S b/libc/arch-arm/syscalls/ftruncate64.S new file mode 100644 index 000000000..37b47441e --- /dev/null +++ b/libc/arch-arm/syscalls/ftruncate64.S @@ -0,0 +1,19 @@ +/* autogenerated by gensyscalls.py */ +#include + + .text + .type ftruncate64, #function + .globl ftruncate64 + .align 4 + .fnstart + +ftruncate64: + .save {r4, r7} + stmfd sp!, {r4, r7} + ldr r7, =__NR_ftruncate64 + swi #0 + ldmfd sp!, {r4, r7} + movs r0, r0 + bxpl lr + b __set_syscall_errno + .fnend diff --git a/libc/arch-arm/syscalls/__pread64.S b/libc/arch-arm/syscalls/pread64.S similarity index 85% rename from libc/arch-arm/syscalls/__pread64.S rename to libc/arch-arm/syscalls/pread64.S index ea645e113..a54084ce6 100644 --- a/libc/arch-arm/syscalls/__pread64.S +++ b/libc/arch-arm/syscalls/pread64.S @@ -2,12 +2,12 @@ #include .text - .type __pread64, #function - .globl __pread64 + .type pread64, #function + .globl pread64 .align 4 .fnstart -__pread64: +pread64: mov ip, sp .save {r4, r5, r6, r7} stmfd sp!, {r4, r5, r6, r7} diff --git a/libc/arch-arm/syscalls/__pwrite64.S b/libc/arch-arm/syscalls/pwrite64.S similarity index 85% rename from libc/arch-arm/syscalls/__pwrite64.S rename to libc/arch-arm/syscalls/pwrite64.S index d1263be94..f9d56b2f6 100644 --- a/libc/arch-arm/syscalls/__pwrite64.S +++ b/libc/arch-arm/syscalls/pwrite64.S @@ -2,12 +2,12 @@ #include .text - .type __pwrite64, #function - .globl __pwrite64 + .type pwrite64, #function + .globl pwrite64 .align 4 .fnstart -__pwrite64: +pwrite64: mov ip, sp .save {r4, r5, r6, r7} stmfd sp!, {r4, r5, r6, r7} diff --git a/libc/arch-sh/syscalls.mk b/libc/arch-sh/syscalls.mk index 493f437ff..9575905f9 100644 --- a/libc/arch-sh/syscalls.mk +++ b/libc/arch-sh/syscalls.mk @@ -45,8 +45,8 @@ syscall_src += arch-sh/syscalls/sigaltstack.S syscall_src += arch-sh/syscalls/acct.S syscall_src += arch-sh/syscalls/read.S syscall_src += arch-sh/syscalls/write.S -syscall_src += arch-sh/syscalls/__pread64.S -syscall_src += arch-sh/syscalls/__pwrite64.S +syscall_src += arch-sh/syscalls/pread64.S +syscall_src += arch-sh/syscalls/pwrite64.S syscall_src += arch-sh/syscalls/__open.S syscall_src += arch-sh/syscalls/__openat.S syscall_src += arch-sh/syscalls/close.S @@ -73,6 +73,7 @@ syscall_src += arch-sh/syscalls/pipe2.S syscall_src += arch-sh/syscalls/dup2.S syscall_src += arch-sh/syscalls/select.S syscall_src += arch-sh/syscalls/ftruncate.S +syscall_src += arch-sh/syscalls/ftruncate64.S syscall_src += arch-sh/syscalls/getdents.S syscall_src += arch-sh/syscalls/fsync.S syscall_src += arch-sh/syscalls/fdatasync.S diff --git a/libc/arch-sh/syscalls/ftruncate64.S b/libc/arch-sh/syscalls/ftruncate64.S new file mode 100644 index 000000000..f4c7c1e13 --- /dev/null +++ b/libc/arch-sh/syscalls/ftruncate64.S @@ -0,0 +1,32 @@ +/* autogenerated by gensyscalls.py */ +#include + + .text + .type ftruncate64, @function + .globl ftruncate64 + .align 4 + +ftruncate64: + + /* invoke trap */ + mov.l 0f, r3 /* trap num */ + trapa #(3 + 0x10) + + /* check return value */ + cmp/pz r0 + bt __NR_ftruncate64_end + + /* keep error number */ + sts.l pr, @-r15 + mov.l 1f, r1 + jsr @r1 + mov r0, r4 + lds.l @r15+, pr + +__NR_ftruncate64_end: + rts + nop + + .align 2 +0: .long __NR_ftruncate64 +1: .long __set_syscall_errno diff --git a/libc/arch-sh/syscalls/__pread64.S b/libc/arch-sh/syscalls/pread64.S similarity index 89% rename from libc/arch-sh/syscalls/__pread64.S rename to libc/arch-sh/syscalls/pread64.S index 474add338..702a40227 100644 --- a/libc/arch-sh/syscalls/__pread64.S +++ b/libc/arch-sh/syscalls/pread64.S @@ -2,11 +2,11 @@ #include .text - .type __pread64, @function - .globl __pread64 + .type pread64, @function + .globl pread64 .align 4 -__pread64: +pread64: /* get ready for additonal arg */ mov.l @r15, r0 diff --git a/libc/arch-sh/syscalls/__pwrite64.S b/libc/arch-sh/syscalls/pwrite64.S similarity index 89% rename from libc/arch-sh/syscalls/__pwrite64.S rename to libc/arch-sh/syscalls/pwrite64.S index a72224200..3f6c1929e 100644 --- a/libc/arch-sh/syscalls/__pwrite64.S +++ b/libc/arch-sh/syscalls/pwrite64.S @@ -2,11 +2,11 @@ #include .text - .type __pwrite64, @function - .globl __pwrite64 + .type pwrite64, @function + .globl pwrite64 .align 4 -__pwrite64: +pwrite64: /* get ready for additonal arg */ mov.l @r15, r0 diff --git a/libc/arch-x86/syscalls.mk b/libc/arch-x86/syscalls.mk index c210b2190..e8c6a77d2 100644 --- a/libc/arch-x86/syscalls.mk +++ b/libc/arch-x86/syscalls.mk @@ -44,8 +44,8 @@ syscall_src += arch-x86/syscalls/sigaltstack.S syscall_src += arch-x86/syscalls/acct.S syscall_src += arch-x86/syscalls/read.S syscall_src += arch-x86/syscalls/write.S -syscall_src += arch-x86/syscalls/__pread64.S -syscall_src += arch-x86/syscalls/__pwrite64.S +syscall_src += arch-x86/syscalls/pread64.S +syscall_src += arch-x86/syscalls/pwrite64.S syscall_src += arch-x86/syscalls/__open.S syscall_src += arch-x86/syscalls/__openat.S syscall_src += arch-x86/syscalls/close.S @@ -73,6 +73,7 @@ syscall_src += arch-x86/syscalls/pipe2.S syscall_src += arch-x86/syscalls/dup2.S syscall_src += arch-x86/syscalls/select.S syscall_src += arch-x86/syscalls/ftruncate.S +syscall_src += arch-x86/syscalls/ftruncate64.S syscall_src += arch-x86/syscalls/getdents.S syscall_src += arch-x86/syscalls/fsync.S syscall_src += arch-x86/syscalls/fdatasync.S diff --git a/libc/arch-x86/syscalls/ftruncate64.S b/libc/arch-x86/syscalls/ftruncate64.S new file mode 100644 index 000000000..66835ab38 --- /dev/null +++ b/libc/arch-x86/syscalls/ftruncate64.S @@ -0,0 +1,29 @@ +/* autogenerated by gensyscalls.py */ +#include + + .text + .type ftruncate64, @function + .globl ftruncate64 + .align 4 + +ftruncate64: + pushl %ebx + pushl %ecx + pushl %edx + mov 16(%esp), %ebx + mov 20(%esp), %ecx + mov 24(%esp), %edx + movl $__NR_ftruncate64, %eax + int $0x80 + cmpl $-129, %eax + jb 1f + negl %eax + pushl %eax + call __set_errno + addl $4, %esp + orl $-1, %eax +1: + popl %edx + popl %ecx + popl %ebx + ret diff --git a/libc/arch-x86/syscalls/__pread64.S b/libc/arch-x86/syscalls/pread64.S similarity index 90% rename from libc/arch-x86/syscalls/__pread64.S rename to libc/arch-x86/syscalls/pread64.S index 3114673cd..eb004a99f 100644 --- a/libc/arch-x86/syscalls/__pread64.S +++ b/libc/arch-x86/syscalls/pread64.S @@ -2,11 +2,11 @@ #include .text - .type __pread64, @function - .globl __pread64 + .type pread64, @function + .globl pread64 .align 4 -__pread64: +pread64: pushl %ebx pushl %ecx pushl %edx diff --git a/libc/arch-x86/syscalls/__pwrite64.S b/libc/arch-x86/syscalls/pwrite64.S similarity index 90% rename from libc/arch-x86/syscalls/__pwrite64.S rename to libc/arch-x86/syscalls/pwrite64.S index 28f65360a..01389f8cb 100644 --- a/libc/arch-x86/syscalls/__pwrite64.S +++ b/libc/arch-x86/syscalls/pwrite64.S @@ -2,11 +2,11 @@ #include .text - .type __pwrite64, @function - .globl __pwrite64 + .type pwrite64, @function + .globl pwrite64 .align 4 -__pwrite64: +pwrite64: pushl %ebx pushl %ecx pushl %edx diff --git a/libc/docs/CHANGES.TXT b/libc/docs/CHANGES.TXT index 8e23c0ef5..3fbbee082 100644 --- a/libc/docs/CHANGES.TXT +++ b/libc/docs/CHANGES.TXT @@ -14,6 +14,8 @@ Differences between current and Android 2.3: - : Add sched_getcpu(), sched_getaffinity(), sched_setaffinity(), cpu_set_t and related macros (e.g. CPU_SETSIZE, CPU_ZERO, CPU_SET, ...) +- : Add ftruncate64(). + ------------------------------------------------------------------------------- Differences between Android 2.3 and Android 2.2: diff --git a/libc/include/sys/linux-syscalls.h b/libc/include/sys/linux-syscalls.h index 35729ae30..cb4d5e59e 100644 --- a/libc/include/sys/linux-syscalls.h +++ b/libc/include/sys/linux-syscalls.h @@ -71,6 +71,7 @@ #define __NR_dup2 (__NR_SYSCALL_BASE + 63) #define __NR__newselect (__NR_SYSCALL_BASE + 142) #define __NR_ftruncate (__NR_SYSCALL_BASE + 93) +#define __NR_ftruncate64 (__NR_SYSCALL_BASE + 194) #define __NR_fsync (__NR_SYSCALL_BASE + 118) #define __NR_fdatasync (__NR_SYSCALL_BASE + 148) #define __NR_fchown32 (__NR_SYSCALL_BASE + 207) diff --git a/libc/include/sys/linux-unistd.h b/libc/include/sys/linux-unistd.h index 4a6172460..f706d00cd 100644 --- a/libc/include/sys/linux-unistd.h +++ b/libc/include/sys/linux-unistd.h @@ -52,8 +52,8 @@ int sigaltstack (const stack_t*, stack_t*); int acct (const char* filepath); ssize_t read (int, void*, size_t); ssize_t write (int, const void*, size_t); -ssize_t __pread64 (int, void *, size_t, off_t, off_t); -ssize_t __pwrite64 (int, void *, size_t, off_t, off_t); +ssize_t pread64 (int, void *, size_t, off64_t); +ssize_t pwrite64 (int, void *, size_t, off64_t); int __open (const char*, int, mode_t); int __openat (int, const char*, int, mode_t); int close (int); @@ -83,6 +83,7 @@ int pipe2 (int *, int); int dup2 (int, int); int select (int, struct fd_set *, struct fd_set *, struct fd_set *, struct timeval *); int ftruncate (int, off_t); +int ftruncate64 (int, off64_t); int getdents (unsigned int, struct dirent *, unsigned int); int fsync (int); int fdatasync (int); diff --git a/libc/include/unistd.h b/libc/include/unistd.h index aa236bd80..4534fb9c1 100644 --- a/libc/include/unistd.h +++ b/libc/include/unistd.h @@ -145,6 +145,7 @@ extern int flock(int, int); extern int fsync(int); extern int fdatasync(int); extern int ftruncate(int, off_t); +extern int ftruncate64(int, off64_t); extern int pause(void); extern unsigned int alarm(unsigned int); diff --git a/libc/tools/gensyscalls.py b/libc/tools/gensyscalls.py index 41c9500b0..0535e5623 100755 --- a/libc/tools/gensyscalls.py +++ b/libc/tools/gensyscalls.py @@ -245,6 +245,59 @@ superh_7args_header = """ """ +def param_uses_64bits(param): + """Returns True iff a syscall parameter description corresponds + to a 64-bit type.""" + param = param.strip() + # First, check that the param type begins with one of the known + # 64-bit types. + if not ( \ + param.startswith("int64_t") or param.startswith("uint64_t") or \ + param.startswith("loff_t") or param.startswith("off64_t") or \ + param.startswith("long long") or param.startswith("unsigned long long") or + param.startswith("signed long long") ): + return False + + # Second, check that there is no pointer type here + if param.find("*") >= 0: + return False + + # Ok + return True + +def count_arm_param_registers(params): + """This function is used to count the number of register used + to pass parameters when invoking a thumb or ARM system call. + This is because the ARM EABI mandates that 64-bit quantities + must be passed in an even+odd register pair. So, for example, + something like: + + foo(int fd, off64_t pos) + + would actually need 4 registers: + r0 -> int + r1 -> unused + r2-r3 -> pos + """ + count = 0 + for param in params: + if param_uses_64bits(param): + if (count & 1) != 0: + count += 1 + count += 2 + else: + count += 1 + return count + +def count_generic_param_registers(params): + count = 0 + for param in params: + if param_uses_64bits(param): + count += 2 + else: + count += 1 + return count + class State: def __init__(self): self.old_stubs = [] @@ -370,25 +423,28 @@ class State: syscall_name = t["name"] if t["id"] >= 0: + num_regs = count_arm_param_registers(syscall_params) if gen_thumb_stubs: - t["asm-thumb"] = self.thumb_genstub(syscall_func,len(syscall_params),"__NR_"+syscall_name) + t["asm-thumb"] = self.thumb_genstub(syscall_func,num_regs,"__NR_"+syscall_name) else: if gen_eabi_stubs: - t["asm-arm"] = self.arm_eabi_genstub(syscall_func,len(syscall_params),"__NR_"+syscall_name) + t["asm-arm"] = self.arm_eabi_genstub(syscall_func,num_regs,"__NR_"+syscall_name) else: - t["asm-arm"] = self.arm_genstub(syscall_func,len(syscall_params),"__NR_"+syscall_name) + t["asm-arm"] = self.arm_genstub(syscall_func,num_regs,"__NR_"+syscall_name) if t["id2"] >= 0: + num_regs = count_generic_param_registers(syscall_params) if t["cid"] >= 0: - t["asm-x86"] = self.x86_genstub_cid(syscall_func, len(syscall_params), "__NR_"+syscall_name, t["cid"]) + t["asm-x86"] = self.x86_genstub_cid(syscall_func, num_regs, "__NR_"+syscall_name, t["cid"]) else: - t["asm-x86"] = self.x86_genstub(syscall_func,len(syscall_params),"__NR_"+syscall_name) + t["asm-x86"] = self.x86_genstub(syscall_func, num_regs, "__NR_"+syscall_name) elif t["cid"] >= 0: E("cid for dispatch syscalls is only supported for x86 in " "'%s'" % syscall_name) return if t["id3"] >= 0: - t["asm-sh"] = self.superh_genstub(syscall_func,len(syscall_params),"__NR_"+syscall_name) + num_regs = count_generic_param_registers(syscall_params) + t["asm-sh"] = self.superh_genstub(syscall_func,num_regs,"__NR_"+syscall_name) diff --git a/libc/unistd/pread.c b/libc/unistd/pread.c index ec4691a92..42fc3bc20 100644 --- a/libc/unistd/pread.c +++ b/libc/unistd/pread.c @@ -28,10 +28,8 @@ #include #include -extern int __pread64(int fd, void *buf, size_t nbytes, loff_t offset); - ssize_t pread(int fd, void *buf, size_t nbytes, off_t offset) { - return __pread64(fd, buf, nbytes, offset); + return pread64(fd, buf, nbytes, (off64_t)offset); } diff --git a/libc/unistd/pread64.c b/libc/unistd/pread64.c deleted file mode 100644 index 2a4e08cad..000000000 --- a/libc/unistd/pread64.c +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) 2010 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 -#include - -extern int __pread64(int fd, void *buf, size_t nbytes, loff_t offset); - -ssize_t pread64(int fd, void *buf, size_t nbytes, off64_t offset) -{ - return __pread64(fd, buf, nbytes, offset); -} - diff --git a/libc/unistd/pwrite.c b/libc/unistd/pwrite.c index 223e1b37f..f106cb31d 100644 --- a/libc/unistd/pwrite.c +++ b/libc/unistd/pwrite.c @@ -28,10 +28,8 @@ #include #include -extern int __pwrite64(int fd, const void *buf, size_t nbytes, loff_t offset); - ssize_t pwrite(int fd, const void *buf, size_t nbytes, off_t offset) { - return __pwrite64(fd, buf, nbytes, offset); + return pwrite64(fd, buf, nbytes, (off64_t)offset); } diff --git a/libc/unistd/pwrite64.c b/libc/unistd/pwrite64.c deleted file mode 100644 index b0846503d..000000000 --- a/libc/unistd/pwrite64.c +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) 2010 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 -#include - -extern int __pwrite64(int fd, const void *buf, size_t nbytes, loff_t offset); - -ssize_t pwrite64(int fd, const void *buf, size_t nbytes, off64_t offset) -{ - return __pwrite64(fd, buf, nbytes, offset); -} - From d4a65d28d4dd7dab4ad66d2d65903296d183d47c Mon Sep 17 00:00:00 2001 From: David 'Digit' Turner Date: Thu, 16 Dec 2010 14:35:53 +0100 Subject: [PATCH 93/93] libc: Add missing declarations in Add missing declarations: INET_ADDRSTRLEN IN6_IS_ADDR_MC_NODELOCAL IN6_IS_ADDR_MC_GLOBAL It has been reported that these prevent compilation of the Boost libraries with the NDK. The corresponding patch has already been performed under development/ndk/platforms/android-3/include. Change-Id: I4ac514973daf3c06a8ef5538d7df79142a98e562 --- libc/include/netinet/in.h | 2 ++ libc/include/netinet/in6.h | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/libc/include/netinet/in.h b/libc/include/netinet/in.h index 0ebd926fe..7a4b6c7b7 100644 --- a/libc/include/netinet/in.h +++ b/libc/include/netinet/in.h @@ -38,6 +38,8 @@ __BEGIN_DECLS #define IPPORT_RESERVED 1024 +#define INET_ADDRSTRLEN 16 + extern int bindresvport (int sd, struct sockaddr_in *sin); static const struct in6_addr in6addr_any = IN6ADDR_ANY_INIT; diff --git a/libc/include/netinet/in6.h b/libc/include/netinet/in6.h index 2f5fee116..c7a6374cc 100644 --- a/libc/include/netinet/in6.h +++ b/libc/include/netinet/in6.h @@ -74,6 +74,9 @@ #define IPV6_ADDR_MC_SCOPE(a) \ ((a)->s6_addr[1] & 0x0f) +#define IN6_IS_ADDR_MC_NODELOCAL(a) \ + (IN6_IS_ADDR_MULTICAST(a) && \ + (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_NODELOCAL)) #define IN6_IS_ADDR_MC_LINKLOCAL(a) \ (IN6_IS_ADDR_MULTICAST(a) && \ (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_LINKLOCAL)) @@ -83,7 +86,9 @@ #define IN6_IS_ADDR_MC_ORGLOCAL(a) \ (IN6_IS_ADDR_MULTICAST(a) && \ (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_ORGLOCAL)) - +#define IN6_IS_ADDR_MC_GLOBAL(a) \ + (IN6_IS_ADDR_MULTICAST(a) && \ + (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_GLOBAL)) #define IN6_ARE_ADDR_EQUAL(a, b) \ (memcmp(&(a)->s6_addr[0], &(b)->s6_addr[0], sizeof(struct in6_addr)) == 0)