flesh out sysconf(3) and the _POSIX_* constants

Bug: 17571891
Change-Id: I81036615486bde65969ae5662587fcc88348474e
diff --git a/libc/include/machine/posix_limits.h b/libc/include/machine/posix_limits.h
index f092731..e5a299b 100644
--- a/libc/include/machine/posix_limits.h
+++ b/libc/include/machine/posix_limits.h
@@ -29,46 +29,129 @@
 #ifndef _POSIX_LIMITS_H_
 #define _POSIX_LIMITS_H_
 
-/* TODO: complete and check these. */
-#define _POSIX2_LINE_MAX            2048
-#define _POSIX2_RE_DUP_MAX          _POSIX_RE_DUP_MAX
+
+/* Any constant values here other than -1 or 200809L are explicitly specified by POSIX.1-2008. */
+/* Keep it sorted. */
+#define _POSIX_ADVISORY_INFO        -1  /* posix_madvise() not implemented */
+#define _POSIX_AIO_LISTIO_MAX       2
+#define _POSIX_AIO_MAX              1
 #define _POSIX_ARG_MAX              4096
+#define _POSIX_ASYNCHRONOUS_IO      -1  /* not implemented */
+#define _POSIX_BARRIERS             -1  /* not implemented */
 #define _POSIX_CHILD_MAX            25
 #define _POSIX_CHOWN_RESTRICTED     1  /* yes, chown requires appropriate privileges */
-#define _POSIX_FSYNC                1  /* fdatasync() supported */
-#define _POSIX_JOB_CONTROL          1  /* job control is a Linux feature */
+#define _POSIX_CLOCK_SELECTION      200809L
+#define _POSIX_CPUTIME              -1  /* clock_getcpuclockid() not implemented */
+#define _POSIX_DELAYTIMER_MAX       32
+#define _POSIX_FSYNC                200809L  /* fdatasync() supported */
 #define _POSIX_HOST_NAME_MAX        255
+#define _POSIX_IPV6                 200809L
+#define _POSIX_JOB_CONTROL          1  /* job control is a Linux feature */
 #define _POSIX_LINK_MAX             8
 #define _POSIX_LOGIN_NAME_MAX       9  /* includes trailing NUL */
-#define _POSIX_MAPPED_FILES         1  /* mmap-ed files supported */
+#define _POSIX_MAPPED_FILES         200809L  /* mmap-ed files supported */
 #define _POSIX_MAX_CANON            255
 #define _POSIX_MAX_INPUT            255
+#define _POSIX_MEMLOCK              200809L
+#define _POSIX_MEMLOCK_RANGE        200809L
+#define _POSIX_MEMORY_PROTECTION    200809L
+#define _POSIX_MESSAGE_PASSING      -1  /* not implemented */
 #define _POSIX_MONOTONIC_CLOCK      0  /* the monotonic clock may be available; ask sysconf */
+#define _POSIX_MQ_OPEN_MAX          8
+#define _POSIX_MQ_PRIO_MAX          32
 #define _POSIX_NAME_MAX             14
-#define _POSIX_NGROUPS_MAX          0
+#define _POSIX_NGROUPS_MAX          8
 #define _POSIX_NO_TRUNC             1  /* very long pathnames generate an error */
-#define _POSIX_OPEN_MAX             16
+#define _POSIX_OPEN_MAX             20
 #define _POSIX_PATH_MAX             256
 #define _POSIX_PIPE_BUF             512
-#define _POSIX_PRIORITY_SCHEDULING  1  /* priority scheduling is a Linux feature */
+#define _POSIX_PRIORITY_SCHEDULING  200809L  /* priority scheduling is a Linux feature */
+#define _POSIX_PRIORITIZED_IO       -1  /* not implemented */
+#define _POSIX_RAW_SOCKETS          200809L
+#define _POSIX_READER_WRITER_LOCKS  200809L
 #define _POSIX_REALTIME_SIGNALS     -1 /* for now, this is not supported */
+#define _POSIX_REGEXP               1
 #define _POSIX_RE_DUP_MAX           255
 #define _POSIX_SAVED_IDS            1  /* saved user ids is a Linux feature */
 #define _POSIX_SEMAPHORES           200809L
+#define _POSIX_SEM_NSEMS_MAX        256
 #define _POSIX_SEM_VALUE_MAX        32767
+#define _POSIX_SHARED_MEMORY_OBJECTS  -1  /* shm_open()/shm_unlink() not implemented */
+#define _POSIX_SHELL                1   /* system() supported */
+#define _POSIX_SIGQUEUE_MAX         32
+#define _POSIX_SPAWN                -1  /* not implemented */
+#define _POSIX_SPIN_LOCKS           -1  /* not implemented */
+#define _POSIX_SPORADIC_SERVER      -1  /* not implemented */
 #define _POSIX_SSIZE_MAX            32767
 #define _POSIX_STREAM_MAX           8
 #define _POSIX_SYMLINK_MAX          255
 #define _POSIX_SYMLOOP_MAX          8
-#define _POSIX_SYNCHRONIZED_IO      1  /* synchronized i/o supported */
-#define _POSIX_THREAD_PRIO_INHERIT  200112L  /* linux feature */
-#define _POSIX_THREAD_PRIO_PROTECT  200112L  /* linux feature */
-#define _POSIX_THREADS              1  /* we support threads */
-#define _POSIX_THREAD_STACKADDR     1  /* we support thread stack address */
-#define _POSIX_THREAD_STACKSIZE     1  /* we support thread stack size */
-#define _POSIX_TIMERS               1  /* Posix timers are supported */
+#define _POSIX_SYNCHRONIZED_IO      200809L  /* synchronized i/o supported */
+#define _POSIX_THREADS              200809L  /* we support threads */
+#define _POSIX_THREAD_ATTR_STACKADDR  200809L
+#define _POSIX_THREAD_ATTR_STACKSIZE  200809L
+#define _POSIX_THREAD_CPUTIME       200809L
+#define _POSIX_THREAD_DESTRUCTOR_ITERATIONS 4
+#define _POSIX_THREAD_KEYS_MAX      128
+#define _POSIX_THREAD_PRIORITY_SCHEDULING 200809L
+#define _POSIX_THREAD_PRIO_INHERIT  200809L  /* linux feature */
+#define _POSIX_THREAD_PRIO_PROTECT  200809L  /* linux feature */
+#define _POSIX_THREAD_PROCESS_SHARED  -1  /* not implemented */
+#define _POSIX_THREAD_ROBUST_PRIO_INHERIT -1  /* not implemented */
+#define _POSIX_THREAD_ROBUST_PRIO_PROTECT -1  /* not implemented */
+#define _POSIX_THREAD_SAFE_FUNCTIONS 200809L
+#define _POSIX_THREAD_SPORADIC_SERVER -1  /* not implemented */
+#define _POSIX_THREAD_THREADS_MAX   64
+#define _POSIX_TIMEOUTS             200809L
+#define _POSIX_TIMERS               200809L  /* Posix timers are supported */
+#define _POSIX_TIMER_MAX            32
+#define _POSIX_TRACE                -1  /* not implemented */
+#define _POSIX_TRACE_EVENT_FILTER   -1  /* not implemented */
+#define _POSIX_TRACE_INHERIT        -1  /* not implemented */
+#define _POSIX_TRACE_LOG            -1  /* not implemented */
+#define _POSIX_TRACE_NAME_MAX       8
+#define _POSIX_TRACE_SYS_MAX        8
+#define _POSIX_TRACE_USER_EVENT_MAX 32
 #define _POSIX_TTY_NAME_MAX         9  /* includes trailing NUL */
-#define _POSIX_TZNAME_MAX           3
+#define _POSIX_TYPED_MEMORY_OBJECTS -1  /* not implemented */
+#define _POSIX_TZNAME_MAX           6
 #define _POSIX_VDISABLE             '\0'
 
+#if defined(__LP64__)
+#define _POSIX_V7_ILP32_OFF32       -1
+#define _POSIX_V7_ILP32_OFFBIG      -1
+#define _POSIX_V7_LP64_OFF64         1
+#define _POSIX_V7_LPBIG_OFFBIG       1
+#else
+#define _POSIX_V7_ILP32_OFF32        1
+#define _POSIX_V7_ILP32_OFFBIG      -1
+#define _POSIX_V7_LP64_OFF64        -1
+#define _POSIX_V7_LPBIG_OFFBIG      -1
+#endif
+
+#define _POSIX2_BC_BASE_MAX         99
+#define _POSIX2_BC_DIM_MAX          2048
+#define _POSIX2_BC_SCALE_MAX        99
+#define _POSIX2_BC_STRING_MAX       1000
+#define _POSIX2_CHARCLASS_NAME_MAX  14
+#define _POSIX2_CHAR_TERM           -1  /* not implemented */
+#define _POSIX2_COLL_WEIGHTS_MAX    2
+#define _POSIX2_C_BIND              _POSIX_VERSION
+#define _POSIX2_C_DEV               -1  /* c dev utilities not implemented */
+#define _POSIX2_EXPR_NEST_MAX       32
+#define _POSIX2_LINE_MAX            2048
+#define _POSIX2_LOCALEDEF           -1  /* localedef utilitiy not implemented */
+#define _POSIX2_RE_DUP_MAX          _POSIX_RE_DUP_MAX
+#define _POSIX2_SW_DEV              -1  /* software dev utilities not implemented */
+#define _POSIX2_UPE                 -1  /* user portability utilities not implemented */
+
+#define _XOPEN_ENH_I18N             -1  /* we don't support internationalization in the C library */
+#define _XOPEN_CRYPT                -1  /* don't support X/Open Encryption */
+#define _XOPEN_IOV_MAX              16
+#define _XOPEN_LEGACY               -1  /* not support all */
+#define _XOPEN_REALTIME             -1 /* we don't support all these functions */
+#define _XOPEN_REALTIME_THREADS     -1  /* same here */
+#define _XOPEN_SHM                  -1
+#define _XOPEN_UNIX                 1
+
 #endif /* _POSIX_LIMITS_H_ */
diff --git a/libc/include/sys/limits.h b/libc/include/sys/limits.h
index edb8c47..be79cf3 100644
--- a/libc/include/sys/limits.h
+++ b/libc/include/sys/limits.h
@@ -115,31 +115,13 @@
 
 /* Bionic-specific definitions */
 
-#define  _POSIX_VERSION             200112L   /* Posix C language bindings version */
+#define  _POSIX_VERSION             200809L   /* Posix C language bindings version */
 #define  _POSIX2_VERSION            -1        /* we don't support Posix command-line tools */
-#define  _POSIX2_C_VERSION          _POSIX_VERSION
-#define  _XOPEN_VERSION             500       /* by Posix definition */
-#define  _XOPEN_XCU_VERSION         -1        /* we don't support command-line utilities */
+#define  _XOPEN_VERSION             700       /* by Posix definition */
 
-/* tell what we implement legacy stuff when appropriate */
-#if _POSIX_VERSION > 0
-#define  _XOPEN_XPG2                1
-#define  _XOPEN_XPG3                1
-#define  _XOPEN_XPG4                1
-#define  _XOPEN_UNIX                1
-#endif
 
-#define  _XOPEN_ENH_I18N          -1  /* we don't support internationalization in the C library */
-#define  _XOPEN_CRYPT             -1  /* don't support X/Open Encryption */
-#define  _XOPEN_LEGACY            -1  /* don't claim we support these, we have some of them but not all */
-#define  _XOPEN_REALTIME          -1 /* we don't support all these functions */
-#define  _XOPEN_REALTIME_THREADS  -1  /* same here */
-
-#define _POSIX_THREAD_DESTRUCTOR_ITERATIONS 4 /* the minimum mandated by POSIX */
-#define PTHREAD_DESTRUCTOR_ITERATIONS _POSIX_THREAD_DESTRUCTOR_ITERATIONS
-#define _POSIX_THREAD_KEYS_MAX 128            /* the minimum mandated by POSIX */
-#define PTHREAD_KEYS_MAX _POSIX_THREAD_KEYS_MAX
-#define _POSIX_THREAD_THREADS_MAX 64          /* the minimum mandated by POSIX */
-#define PTHREAD_THREADS_MAX                   /* bionic has no specific limit */
+#define PTHREAD_DESTRUCTOR_ITERATIONS 4     // >= _POSIX_THREAD_DESTRUCTOR_ITERATIONS
+#define PTHREAD_KEYS_MAX              128   // >= _POSIX_THREAD_KEYS_MAX
+#define PTHREAD_THREADS_MAX           2048  // bionic has no specific limit
 
 #endif
diff --git a/libc/include/sys/sysconf.h b/libc/include/sys/sysconf.h
index 3d058d7..8aa506e 100644
--- a/libc/include/sys/sysconf.h
+++ b/libc/include/sys/sysconf.h
@@ -50,7 +50,7 @@
 #define _SC_PASS_MAX            0x000c
 #define _SC_2_C_BIND            0x000d
 #define _SC_2_C_DEV             0x000e
-#define _SC_2_C_VERSION         0x000f
+#define _SC_2_C_VERSION         0x000f  /* Obsolescent in POSIX.1-2008, TODO: remove it. */
 #define _SC_2_CHAR_TERM         0x0010
 #define _SC_2_FORT_DEV          0x0011
 #define _SC_2_FORT_RUN          0x0012
@@ -68,7 +68,7 @@
 #define _SC_XOPEN_ENH_I18N      0x001e
 #define _SC_XOPEN_SHM           0x001f
 #define _SC_XOPEN_VERSION       0x0020
-#define _SC_XOPEN_XCU_VERSION   0x0021
+#define _SC_XOPEN_XCU_VERSION   0x0021  /* Obsolescent in POSIX.1-2008, TODO: remove it. */
 #define _SC_XOPEN_REALTIME      0x0022
 #define _SC_XOPEN_REALTIME_THREADS  0x0023
 #define _SC_XOPEN_LEGACY        0x0024
@@ -77,10 +77,10 @@
 #define _SC_PAGESIZE            0x0027
 #define _SC_PAGE_SIZE           0x0028
 #define _SC_XOPEN_UNIX          0x0029
-#define _SC_XBS5_ILP32_OFF32    0x002a
-#define _SC_XBS5_ILP32_OFFBIG   0x002b
-#define _SC_XBS5_LP64_OFF64     0x002c
-#define _SC_XBS5_LPBIG_OFFBIG   0x002d
+#define _SC_XBS5_ILP32_OFF32    0x002a  /* Obsolescent in POSIX.1-2008, TODO: remove it. */
+#define _SC_XBS5_ILP32_OFFBIG   0x002b  /* Obsolescent in POSIX.1-2008, TODO: remove it. */
+#define _SC_XBS5_LP64_OFF64     0x002c  /* Obsolescent in POSIX.1-2008, TODO: remove it. */
+#define _SC_XBS5_LPBIG_OFFBIG   0x002d  /* Obsolescent in POSIX.1-2008, TODO: remove it. */
 #define _SC_AIO_LISTIO_MAX      0x002e
 #define _SC_AIO_MAX             0x002f
 #define _SC_AIO_PRIO_DELTA_MAX  0x0030
@@ -129,6 +129,49 @@
 #define _SC_AVPHYS_PAGES                0x0063
 #define _SC_MONOTONIC_CLOCK             0x0064
 
+#define _SC_2_PBS               0x0065
+#define _SC_2_PBS_ACCOUNTING    0x0066
+#define _SC_2_PBS_CHECKPOINT    0x0067
+#define _SC_2_PBS_LOCATE        0x0068
+#define _SC_2_PBS_MESSAGE       0x0069
+#define _SC_2_PBS_TRACK         0x006a
+#define _SC_ADVISORY_INFO       0x006b
+#define _SC_BARRIERS            0x006c
+#define _SC_CLOCK_SELECTION     0x006d
+#define _SC_CPUTIME             0x006e
+#define _SC_HOST_NAME_MAX       0x006f
+#define _SC_IPV6                0x0070
+#define _SC_RAW_SOCKETS         0x0071
+#define _SC_READER_WRITER_LOCKS 0x0072
+#define _SC_REGEXP              0x0073
+#define _SC_SHELL               0x0074
+#define _SC_SPAWN               0x0075
+#define _SC_SPIN_LOCKS          0x0076
+#define _SC_SPORADIC_SERVER     0x0077
+#define _SC_SS_REPL_MAX         0x0078
+#define _SC_SYMLOOP_MAX         0x0079
+#define _SC_THREAD_CPUTIME      0x007a
+#define _SC_THREAD_PROCESS_SHARED       0x007b
+#define _SC_THREAD_ROBUST_PRIO_INHERIT  0x007c
+#define _SC_THREAD_ROBUST_PRIO_PROTECT  0x007d
+#define _SC_THREAD_SPORADIC_SERVER      0x007e
+#define _SC_TIMEOUTS            0x007f
+#define _SC_TRACE               0x0080
+#define _SC_TRACE_EVENT_FILTER  0x0081
+#define _SC_TRACE_EVENT_NAME_MAX  0x0082
+#define _SC_TRACE_INHERIT       0x0083
+#define _SC_TRACE_LOG           0x0084
+#define _SC_TRACE_NAME_MAX      0x0085
+#define _SC_TRACE_SYS_MAX       0x0086
+#define _SC_TRACE_USER_EVENT_MAX  0x0087
+#define _SC_TYPED_MEMORY_OBJECTS  0x0088
+#define _SC_V7_ILP32_OFF32      0x0089
+#define _SC_V7_ILP32_OFFBIG     0x008a
+#define _SC_V7_LP64_OFF64       0x008b
+#define _SC_V7_LPBIG_OFFBIG     0x008c
+#define _SC_XOPEN_STREAMS       0x008d
+#define _SC_XOPEN_UUCP          0x008e
+
 long sysconf(int);
 
 __END_DECLS