Commit graph

58 commits

Author SHA1 Message Date
Elliott Hughes
f6d2ca2696 Expose __srefill for LP64 until we can fix the NDK.
The LP64 has a duplicate copy of part of stdio, and relies
on bionic supplying this part. We should remove the hack from
the NDK, at least for LP64, and then revert this.

Bug: 15291317
Change-Id: I75e06e130188ca0aeb9d50dfe3a3e48a1d3968b7
2014-05-27 21:23:36 -07:00
Elliott Hughes
aa50585d96 Restore __srefill for LP32.
The NDK apparently includes an android_support.a library that
refers to __srefill in its copy of the vsnprintf implementation.

Bug: 15249361
Change-Id: Ic2cf6f21290b3146c42fbe0624f5e4d54f6194b4
2014-05-27 11:22:39 -07:00
Elliott Hughes
35d90bb6ec Restore __srget and __swbuf for LP32.
Anthony King <anthonydking@slimroms.net> reports that for Grouper the
Nvidia GL blobs need access to __swbuf. This is because the old <stdio.h>
had inline getc and putc implementations that directly referred to these
symbols.

Change-Id: I11a7b5550018ecc93d8f195c99857759669b2906
2014-05-25 10:38:25 -07:00
Elliott Hughes
2899de9b05 Hide various stdio implementation details.
I've left __sF exposed since that's how the OpenBSD stdin, stdout, stderr
are implemented. Other BSDs and glibc use a separate global for each instead
of an array.

Bug: 11156955
Change-Id: I9f3d2d4314a8d4a78c3197b9acd9258820c5f150
2014-05-22 20:06:23 -07:00
Elliott Hughes
4c2da039ba Fix the newly-introduced warning and turn on -Werror.
I cleaned up most of our warnings last week but forgot to turn on -Werror,
so of course we're getting new warnings already. I've left -Werror commented
out in those places where we still have warnings to deal with before we can
turn on -Werror.

Change-Id: Ia58ff8b8c1ada4bf81eec6f19ec1d34e133cf4b1
2014-05-16 16:50:34 -07:00
Dmitriy Ivanov
623b0d05bd Register _cleanup function with atexit
* Register cleanup function with atexit
   instead of calling it explicitly on
   exit()
 * abort() no longer calls _cleanup:
   Flushing stdio buffers on abort is no
   longer required by POSIX.
 * dlmalloc no longer need to reset cleanup
   (see above)
 * Upstream findfp.c makebuf.c setvbuf.cexit.c
   to openbsd versions.

Bug: 14415367
Change-Id: I277058852485a9d3dbb13e5c232db5f9948d78ac
2014-05-15 13:05:21 -07:00
Calin Juravle
7b1a95bc76 Merge "Add include guard to fileext.h" 2014-05-06 13:47:19 +00:00
Elliott Hughes
ad534985ec Merge "Disable %n in printf and vfwprintf." 2014-05-05 21:49:22 +00:00
Elliott Hughes
e2341d08fa Disable %n in printf and vfwprintf.
Bug: 14492135
Change-Id: If190bede29e5f68a65043ddbe8e878c660933d03
2014-05-05 14:43:17 -07:00
Elliott Hughes
792ae72e41 Switch to current upstream OpenBSD fwrite.c.
Change-Id: Ife527aafc1e5438f477d711902efe6e6f59f3f8e
2014-05-02 18:22:23 -07:00
Calin Juravle
9287223674 Add include guard to fileext.h
Change-Id: I89b0e3bf0b15989727b5903b40bec92d49e122d9
2014-05-02 17:34:58 +01:00
Elliott Hughes
01ae00f317 Switch to the OpenBSD implementations of the wide scanf functions.
This also gets us the C99 wcstoimax and wcstoumax, and a working fgetwc and
ungetwc, all of which are needed in the implementation.

This also brings several other files closer to upstream.

Change-Id: I23b025a8237a6dbb9aa50d2a96765ea729a85579
2014-04-29 16:28:56 -07:00
Elliott Hughes
9d3c2dd11f Switch to upstream OpenBSD fread/fvwrite.
Change-Id: I3dc11083693bc8d99edc0cbcc6f70dc9e5dc6565
2014-04-18 13:13:04 -07:00
Elliott Hughes
0549371bd7 Upgrade to current vfprintf.
This gets us various bug fixes and missing C99 functionality.

Bug: https://code.google.com/p/android/issues/detail?id=64886
Change-Id: Ie9f8ac569e9b5eec1e4a1faacfe2c21662eaf895
2014-04-17 17:30:03 -07:00
Elliott Hughes
4bd97cee28 Switch to gdtoa.
This gives us a real strtold for LP64 and fixes various LP64
bugs.

Bug: 13563801
Change-Id: I277858d718ee746e136b6b6308a495ba50dfa488
2014-04-16 15:15:52 -07:00
Elliott Hughes
02c78a3867 Reimplement isinf/isnan/fpclassify.
Also move isinf and isnan into libc like everyone else.

Also move fpclassify to libc like the BSDs (but unlike glibc). We need
this to be able to upgrade our float/double/long double parsing to gdtoa.

Also add some missing aliases. We now have all of:

  isnan, __isnan, isnanf, __isnanf, isnanl, __isnanl,
  isinf, __isinf, isinff, __isinff, isinfl, __isinfl,
  __fpclassify, __fpclassifyd, __fpclassifyf, __fpclassifyl.

Bug: 13469877
Change-Id: I407ffbac06c765a6c5fffda8106c37d7db04f27d
2014-04-14 14:35:47 -07:00
Elliott Hughes
5eb670462a Replace the bionic hack for a vfprintf leak with (roughly) the upstream fix.
Currently in bionic free and freedtoa are equivalent, but that's not true
of gdtoa. This makes it easier to test gdtoa without having to replace
everything. (Yes, I found this bug the hard way.)

Change-Id: I290823a2a0a83329def5f2719b349215ad0dbbde
2014-04-11 18:00:37 -07:00
Alexander Ivchenko
edd7c2ec25 Fix the printf issue for 64 bits. The following case:
printf("%1$s %1$s\n", "test");

would print garbage instead of the second "test". The problem is __find_arguments
and the patch is a backport of two patches from OpenBSD that fix the issue:

Author: tedu <tedu@cvs.openbsd.org>
Date:   Sat Apr 29 23:00:24 2006 +0000

    check mmap for failure.  the helper functions using it return -1, but
    callers do not yet check since printf() for example is not documented
    to return an error.
    some formatting cleanups.
    mostly ok deraadt millert

Author: millert <millert@cvs.openbsd.org>
Date:   Fri May 16 14:28:54 2008 +0000

    C99 says that for each va_copy() there must be a matching va_end().
    Replace the non-portable hackery in __find_arguments() with a union.
    From FreeBSD.

Change-Id: I6ea392ce6fcf4a319ae6a67ec58cc52fe7cbe534
Signed-off-by: Alexander Ivchenko <alexander.ivchenko@intel.com>
2014-04-02 18:30:55 +04:00
Calin Juravle
c20de90287 Remove ALIGNBYTES and ALIGN from <sys/param.h>
There are only three users of bionic definition of ALIGN and keeping it
in sys/param.h polutes the namespace.

I inline the definition in the the three places that's used.

Bug: 13400663
Change-Id: I565008e8426c38ffb07422f42cd8e547d53044e9
2014-03-21 09:59:34 +00:00
Elliott Hughes
f2cea021ab Clean up <stdio.h> macros.
Also neuter __isthreaded.

We should come back to try to hide struct FILE's internals for LP64.

Bug: 3453512
Bug: 3453550
Change-Id: I7e115329fb4579246a72fea367b9fc8cb6055d18
2014-03-13 14:54:53 -07:00
Elliott Hughes
603332fc4c Upgrade to current upstream scanf implementation.
Also add a basic test.

Change-Id: Icc0e68a5716b9579244f6eb8bac1ab5a24eda85a
2014-03-12 17:10:41 -07:00
Elliott Hughes
ad41e9a4eb More stdio cleanup.
Change-Id: Idc909cd3dc7b072f1edd2ae4980932d6550e8568
2014-03-11 15:05:50 -07:00
Elliott Hughes
53e43292aa More OpenBSD cleanup (primarily string).
This patch removes the string/ and wchar/ directories.

Change-Id: Ia489904bc67047e4bc79acb1f3eec21aa3fe5f0d
2014-02-24 18:02:05 -08:00
Elliott Hughes
0133944b09 Clean up our OpenBSD usage.
Also undo some of the mess where we have OpenBSD <stdio.h> but a mix of
different BSD's implementations.

In this first pass, I've only moved easy OpenBSD stuff.

Change-Id: Iae67b02cde6dba9d8d06fedeb53efbfdac0a8cf6
2014-02-21 14:30:18 -08:00
Elliott Hughes
eb847bc866 Fix x86_64 build, clean up intermediate libraries.
The x86_64 build was failing because clone.S had a call to __thread_entry which
was being added to a different intermediate .a on the way to making libc.so,
and the linker couldn't guarantee statically that such a relocation would be
possible.

  ld: error: out/target/product/generic_x86_64/obj/STATIC_LIBRARIES/libc_common_intermediates/libc_common.a(clone.o): requires dynamic R_X86_64_PC32 reloc against '__thread_entry' which may overflow at runtime; recompile with -fPIC

This patch addresses that by ensuring that the caller and callee end up in the
same intermediate .a. While I'm here, I've tried to clean up some of the mess
that led to this situation too. In particular, this removes libc/private/ from
the default include path (except for the DNS code), and splits out the DNS
code into its own library (since it's a weird special case of upstream NetBSD
code that's diverged so heavily it's unlikely ever to get back in sync).

There's more cleanup of the DNS situation possible, but this is definitely a
step in the right direction, and it's more than enough to get x86_64 building
cleanly.

Change-Id: I00425a7245b7a2573df16cc38798187d0729e7c4
2013-10-09 16:00:17 -07:00
Stephen Hines
35d937e4eb Remove _FORTIFY_SOURCE in implementation files.
This was causing conflicting declarations for the library definitions of
common functions like sprintf(), snprintf(), and strchr().

Change-Id: I5daaa8a58183aa0d4d0fae8a7cb799671810f576
2013-10-01 15:02:07 -07:00
Elliott Hughes
1d13c64d78 Fix %hhd formats in the printf family.
Found by adapting the simple unit tests for libc logging to test
snprintf too. Fix taken from upstream OpenBSD without updating
the rest of stdio.

Change-Id: Ie339a8e9393a36080147aae4d6665118e5d93647
2013-09-23 16:02:39 -07:00
Elliott Hughes
284f788032 Upgrade mktemp.c to the current upstream version.
Yet another archaic relic containing bugs that had been fixed years before the
Android project even started...

Bug: 9935113
Change-Id: I3c9d019a216efd609ee568cf8c70bc360f357403
2013-07-19 15:20:31 -07:00
Elliott Hughes
677ee56477 Switch to current upstream stdio makebuf.c and setvbuf.c.
Change-Id: I4761b5e94459815520f01062eef39abf62af621f
2013-06-12 15:24:15 -07:00
Elliott Hughes
61e699a133 Clean up abort.
* A dlmalloc usage error shouldn't call abort(3) because we want to
  cause a SIGSEGV by writing the address dlmalloc didn't like to an
  address the kernel won't like, so that debuggerd will dump the
  memory around the address that upset dlmalloc.

* Switch to the simpler FreeBSD/NetBSD style of registering stdio
  cleanup. Hopefully this will let us simplify more of the stdio
  implementation.

* Clear the stdio cleanup handler before we abort because of a dlmalloc
  corruption error. This fixes the reported bug, where we'd hang inside
  dlmalloc because the stdio cleanup reentered dlmalloc.

Bug: 9301265
Change-Id: Ief31b389455d6876e5a68f0f5429567d37277dbc
2013-06-12 14:14:53 -07:00
Elliott Hughes
6b05c8e280 Start moving to current FreeBSD stdio.
This only touches the easy stuff.

Change-Id: Iecee57f1681dba5c56bff59f0e9a89811a71f0ca
2013-04-11 13:55:01 -07:00
Hakan Kvist
f27b7fb056 Define DEFFILEMODE and friends
Define the macros ACCESSPERMS, ALLPERMS and DEFFILEMODE.
These macros originates from BSD but has been available in glibc
for quite some time.

Change-Id: I429cd30aa4e73f53b153ee7740070cebba166c57
2012-11-29 11:53:33 -08:00
Elliott Hughes
a89864a20b Move non-upstream code into the libc/bionic directory.
I'll need at least one more pass, because there's some upstream code
lurking in libc/bionic, but this is still a step in the right direction.

Change-Id: I55927315972da8327ae01c5240ed587db17e8462
2012-10-01 17:35:49 -07:00
Elliott Hughes
91875dcd6e Fix tmpfile(3).
This could be better, but at least now it works.

Change-Id: I88b7cf3f7ce8e5fa0b3fe678b7d1679a68ffffc9
2012-09-26 12:02:17 -07:00
Ian Rogers
a37ce7faa6 Merge "Add missing va_end() to prevent stack corruptions" 2012-08-24 15:10:07 -07:00
Nick Kralevich
9145ad3f0a vfprintf: fix spelling.
Change-Id: I6dc611143fb1f3e9ccf0a77b40ee48a3c1d72ca9
2012-07-25 16:01:38 -07:00
Yaroslav Miroshnychenko
c7dcd67d56 Add missing va_end() to prevent stack corruptions
Added va_end() for copied variable arguments lists
in __vfprintf() and __find_arguments().
This is by C standard.
Important for systems which pass arguments in registers.

Change-Id: I7ac42beaa6645bfe856c18132253352dae29ea37
2012-07-13 09:37:57 +02:00
Nick Kralevich
965dbc6405 FORTIFY_SOURCE: add fgets support.
Change-Id: I8c3410a90c71a3336c4ac8581618fa9330edf5e3
2012-07-09 09:57:18 -07:00
Nick Kralevich
9b549c39c9 FORTIFY_SOURCE: add sprintf / vsprintf support
sprintf FORTIFY_SOURCE protections are not available
on clang.

Also add various __attribute__s to stdio functions.

Change-Id: I936d1f9e55fe53a68885c4524b7b59e68fed218d
2012-06-13 09:14:30 -07:00
Nick Kralevich
cffdf6693f FORTIFY_SOURCE: add snprintf, vsnprintf
Add _FORTIFY_SOURCE support for snprintf, vsnprintf

At this time, we opt out of these protections for clang, as clang
does not implement __builtin_va_arg_pack().

http://clang.llvm.org/docs/UsersManual.html#c_unimpl_gcc

Change-Id: I73ebe5ec8dad1dca8898a76d6afb693a25f75375
2012-06-11 16:46:16 -07:00
David 'Digit' Turner
9831ad3ce6 libc: speed-up flockfile()/funlockfile()
For Honeycomb, we added proper file thread-safety for
all FILE* operations. However, we did implement that by
using an out-of-band hash table to map FILE* pointers
to phtread_mutex_t mutexes, because we couldn't change
the size of 'struct _sFILE' without breaking the ABI.

It turns out that our BSD-derived code already has
some support code to extend FILE* objects, so use it
instead. See libc/stdio/fileext.h

This patch gets rid of the hash table, and put the
mutex directly into the sFILE extension.

Change-Id: If1c3fe0a0a89da49c568e9a7560b7827737ff4d0
2011-11-15 13:16:42 +01:00
David Turner
bc9d1fe7c4 am 4685acbd: am 9efda5b7: Merge "typo in libc/stdio/wcio.h"
* commit '4685acbdd45c44e2e21c74242953bee5198209f9':
  typo in libc/stdio/wcio.h
2011-08-03 08:16:37 -07:00
Nathan Forbes
7743f68204 typo in libc/stdio/wcio.h
whcar_io_data -> wchar_io_data
Signed-off-by: Nathan Forbes <me@nathanforbes.com>

Change-Id: I45c231efffac265eed51b7632d5a1b21c18bfa55
2011-07-02 20:29:25 -04:00
David Turner
3f7a3228cd am c5c84c86: Merge "vfscanf: Add support for L type modifier for long long"
* commit 'c5c84c8643250c71bde87541f2b28fc21a9c5cc7':
  vfscanf: Add support for L type modifier for long long
2011-05-17 04:47:06 -07:00
Chris Fries
712e4f81e0 vfscanf: Add support for L type modifier for long long
scanf()'s man page suggests support for %Ld, (and ioux).
Implement this so that 3rd party code will work correctly.

Change-Id: Idce9d266071cb688ca71429395a2d9edf6813595
2011-05-05 11:02:33 -05:00
Kenny Root
f582340a6a Fix the handle locking in stdio
Fix the handle locking in stdio to use flockfile/funlockfile
internally when and where required.  Macros in <stdio.h> are updated
to automatically call the underlying functions when the process is
threaded to obtain the necessary locking.  A private mutex is added
to protect __sglue, the internal list of FILE handles, and another
to protect the one-time initialization.  Some routines in libc that
use getc() change to use getc_unlocked() as they're either protected
by their own lock or aren't thread-safe routines anyway.

Based on OpenBSD change by guenther@openbsd.org
http://www.mail-archive.com/source-changes@cvs.openbsd.org/msg01015.html

Bug: 3446659
Change-Id: Ie82116e358c541718d6709ec45ca6796be5a007b
2011-02-14 09:32:56 -08:00
Glenn Kasten
f4e10b721e Merge "Bug 3330205 Put blanks and zeroes in const area" 2011-01-16 08:50:20 -08:00
Glenn Kasten
e9d0518394 Bug 3330205 Remove unnecessary static variable
Change-Id: I7e781d26d6565952712f8fb0274d336462b441fd
2011-01-09 11:47:42 -08:00
Glenn Kasten
0946b1f6e9 Bug 3330205 Put blanks and zeroes in const area
Change-Id: I8f25aebd1ded3617dc60951271767281f73b8684
2011-01-09 11:38:56 -08:00
Jim Huang
b4867734b0 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
2010-10-15 01:10:31 +08:00