Make improvements

- This change fixes a bug that allowed unbuffered printf() output (to
  streams like stderr) to be truncated. This regression was introduced
  some time between now and the last release.

- POSIX specifies all functions as thread safe by default. This change
  works towards cleaning up our use of the @threadsafe / @threadunsafe
  documentation annotations to reflect that. The goal is (1) to use
  @threadunsafe to document functions which POSIX say needn't be thread
  safe, and (2) use @threadsafe to document functions that we chose to
  implement as thread safe even though POSIX didn't mandate it.

- Tidy up the clock_gettime() implementation. We're now trying out a
  cleaner approach to system call support that aims to maintain the
  Linux errno convention as long as possible. This also fixes bugs that
  existed previously, where the vDSO errno wasn't being translated
  properly. The gettimeofday() system call is now a wrapper for
  clock_gettime(), which reduces bloat in apps that use both.

- The recently-introduced improvements to the execute bit on Windows has
  had bugs fixed. access(X_OK) on a directory on Windows now succeeds.
  fstat() will now perform the MZ/#! ReadFile() operation correctly.

- Windows.h is no longer included in libc/isystem/, because it confused
  PCRE's build system into thinking Cosmopolitan is a WIN32 platform.
  Cosmo's Windows.h polyfill was never even really that good, since it
  only defines a subset of the subset of WIN32 APIs that Cosmo defines.

- The setlongerjmp() / longerjmp() APIs are removed. While they're nice
  APIs that are superior to the standardized setjmp / longjmp functions,
  they weren't superior enough to not be dead code in the monorepo. If
  you use these APIs, please file an issue and they'll be restored.

- The .com appending magic has now been removed from APE Loader.
This commit is contained in:
Justine Tunney 2023-10-02 19:25:19 -07:00
parent b99512ac58
commit ff77f2a6af
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
226 changed files with 708 additions and 2657 deletions

View file

@ -16,8 +16,8 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/calls/calls.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "third_party/chibicc/chibicc.h"
long alloc_node_count;
@ -26,7 +26,7 @@ long alloc_obj_count;
long alloc_type_count;
wontreturn void __oom_hook(size_t request) {
fprintf(stderr, "error: chibicc ran out of memory\n");
tinyprint(2, "error: chibicc ran out of memory\n", NULL);
exit(1);
}

View file

@ -18,6 +18,7 @@
#include "third_party/libcxx/cstdlib"
#include "libc/calls/struct/stat.h"
#include "libc/sysv/consts/at.h"
#include "libc/calls/struct/timeval.h"
#include "third_party/libcxx/climits"
#define _LIBCPP_USE_UTIMENSAT

View file

@ -29,7 +29,7 @@
#include "libc/calls/calls.h"
#include "libc/calls/struct/rlimit.h"
#include "libc/calls/struct/rusage.h"
#include "libc/calls/sysparam.h"
#include "libc/stdio/sysparam.h"
#include "libc/calls/weirdtypes.h"
#include "libc/limits.h"
#include "libc/sysv/consts/endian.h"

View file

@ -215,14 +215,27 @@ static struct GetgrentState {
struct group gr;
} g_getgrent[1];
/**
* Closes group database.
* @threadunsafe
*/
void endgrent() {
setgrent();
}
/**
* Rewinds to beginning of group database.
* @threadunsafe
*/
void setgrent() {
if (g_getgrent->f) fclose(g_getgrent->f);
g_getgrent->f = 0;
}
/**
* Returns successive entries in /etc/group database.
* @threadunsafe
*/
struct group *getgrent() {
struct group *res;
size_t size = 0, nmem = 0;

View file

@ -240,6 +240,7 @@ static struct GetpwentState {
* Closes global handle to password database.
*
* @see getpwent()
* @threadunsafe
*/
void
endpwent(void)
@ -251,6 +252,7 @@ endpwent(void)
* Rewinds global handle to password database.
*
* @see getpwent()
* @threadunsafe
*/
void
setpwent(void)
@ -264,7 +266,8 @@ setpwent(void)
* Returns next entry in password database.
*
* @return pointer to entry static memory, or NULL on EOF
* @see getpwent()
* @see setpwent()
* @threadunsafe
*/
struct passwd *
getpwent()
@ -287,6 +290,7 @@ getpwent()
* if `/etc/passwd` doesn't exist, or is fake (e.g. MacOS).
*
* @return pointer to passwd entry static memory, or NULL if not found
* @threadunsafe
*/
struct passwd *
getpwuid(uid_t uid)
@ -305,6 +309,7 @@ getpwuid(uid_t uid)
* if `/etc/passwd` doesn't exist, or is fake (e.g. MacOS).
*
* @return pointer to passwd entry static memory, or NULL if not found
* @threadunsafe
*/
struct passwd *
getpwnam(const char *name)

View file

@ -290,9 +290,7 @@ int nsync_futex_wait_ (atomic_int *w, int expect, char pshare, const struct time
}
} else {
Polyfill:
tib->tib_flags |= TIB_FLAG_TIME_CRITICAL;
rc = nsync_futex_polyfill_ (w, expect, timeout);
tib->tib_flags &= ~TIB_FLAG_TIME_CRITICAL;
}
Finished:

View file

@ -20,7 +20,7 @@
#include "libc/calls/struct/utsname.h"
#include "libc/calls/struct/winsize.h"
#include "libc/calls/syscall-sysv.internal.h"
#include "libc/calls/sysparam.h"
#include "libc/stdio/sysparam.h"
#include "libc/calls/termios.h"
#include "libc/calls/weirdtypes.h"
#include "libc/dce.h"

View file

@ -22,7 +22,7 @@
#include "libc/calls/struct/utsname.h"
#include "libc/calls/struct/winsize.h"
#include "libc/calls/syscall-sysv.internal.h"
#include "libc/calls/sysparam.h"
#include "libc/stdio/sysparam.h"
#include "libc/calls/termios.h"
#include "libc/calls/weirdtypes.h"
#include "libc/dce.h"

View file

@ -10,7 +10,7 @@
#include "libc/calls/struct/tms.h"
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/fmt/conv.h"
#include "libc/fmt/wintime.internal.h"
#include "libc/nt/accounting.h"
#include "libc/nt/runtime.h"
#include "libc/runtime/clktck.h"

View file

@ -4,18 +4,44 @@
Python 3
https://docs.python.org/3/license.html │
*/
#include "libc/isystem/windows.h"
#include "libc/nt/registry.h"
#include "third_party/python/Include/abstract.h"
#include "third_party/python/Include/ceval.h"
#include "third_party/python/Include/listobject.h"
#include "third_party/python/Include/longobject.h"
#include "third_party/python/Include/modsupport.h"
#include "third_party/python/Include/object.h"
#include "third_party/python/Include/objimpl.h"
#include "third_party/python/Include/pyerrors.h"
#include "third_party/python/Include/pyhash.h"
#include "third_party/python/Include/pymacro.h"
#include "third_party/python/Include/structmember.h"
#undef NULL
#define NULL 0
#define BOOL bool32
#define DWORD32 uint32_t
#define HKEY int64_t
#define ULONG uint32_t
#define ACCESS_MASK ULONG
#define REGSAM ACCESS_MASK
#define HKEY_CLASSES_ROOT kNtHkeyClassesRoot
#define HKEY_CURRENT_USER kNtHkeyCurrentUser
#define HKEY_LOCAL_MACHINE kNtHkeyLocalMachine
#define HKEY_USERS kNtHkeyUsers
#define HKEY_PERFORMANCE_DATA kNtHkeyPerformanceData
#define HKEY_PERFORMANCE_TEXT kNtHkeyPerformanceText
#define HKEY_PERFORMANCE_NLSTEXT kNtHkeyPerformanceNlstext
#define HKEY_CURRENT_CONFIG kNtHkeyCurrentConfig
#define HKEY_DYN_DATA kNtHkeyDynData
#define HKEY_CURRENT_USER_LOCAL_SETTINGS kNtHkeyCurrentUserLocalSettings
#define KEY_READ kNtKeyRead
#define KEY_WRITE kNtKeyWrite
#define KEY_EXECUTE kNtKeyExecute
#define KEY_ALL_ACCESS kNtKeyAllAccess
/* clang-format off */
/*

View file

@ -126,7 +126,7 @@
#include "libc/sysv/consts/ok.h"
#include "libc/calls/struct/rlimit.h"
#include "libc/calls/struct/rusage.h"
#include "libc/calls/sysparam.h"
#include "libc/stdio/sysparam.h"
#include "libc/limits.h"
#endif /* SQLITE_ENABLE_LOCKING_STYLE */

View file

@ -705,7 +705,7 @@ char *d; /* directory to delete */
#include "libc/calls/calls.h"
#include "libc/calls/struct/rlimit.h"
#include "libc/calls/struct/rusage.h"
#include "libc/calls/sysparam.h"
#include "libc/stdio/sysparam.h"
#include "libc/calls/weirdtypes.h"
#include "libc/limits.h"
#include "libc/sysv/consts/endian.h"

View file

@ -1631,7 +1631,7 @@ failed:
#include "libc/calls/calls.h"
#include "libc/calls/struct/rlimit.h"
#include "libc/calls/struct/rusage.h"
#include "libc/calls/sysparam.h"
#include "libc/stdio/sysparam.h"
#include "libc/calls/weirdtypes.h"
#include "libc/limits.h"
#include "libc/sysv/consts/endian.h"