diff --git a/Makefile b/Makefile index 4f831034b..3604d1da0 100644 --- a/Makefile +++ b/Makefile @@ -121,6 +121,7 @@ include libc/tinymath/tinymath.mk # │ You can issue raw system calls include third_party/compiler_rt/compiler_rt.mk # │ include libc/str/str.mk # │ include third_party/xed/xed.mk # │ +include third_party/puff/puff.mk # │ include third_party/zlib/zlib.mk # │ include third_party/double-conversion/dc.mk # │ include libc/elf/elf.mk # │ @@ -309,7 +310,6 @@ COSMOPOLITAN_OBJECTS = \ LIBC_LOG \ LIBC_TIME \ LIBC_ZIPOS \ - THIRD_PARTY_ZLIB \ THIRD_PARTY_MUSL \ LIBC_STDIO \ THIRD_PARTY_GDTOA \ @@ -335,6 +335,7 @@ COSMOPOLITAN_OBJECTS = \ LIBC_NT_ADVAPI32 \ LIBC_NT_SYNCHRONIZATION \ LIBC_FMT \ + THIRD_PARTY_PUFF \ THIRD_PARTY_COMPILER_RT \ LIBC_TINYMATH \ THIRD_PARTY_XED \ diff --git a/examples/getdomainname.c b/examples/getdomainname.c new file mode 100644 index 000000000..b387d0236 --- /dev/null +++ b/examples/getdomainname.c @@ -0,0 +1,21 @@ +#if 0 +/*─────────────────────────────────────────────────────────────────╗ +│ To the extent possible under law, Justine Tunney has waived │ +│ all copyright and related or neighboring rights to this file, │ +│ as it is written in the following disclaimers: │ +│ • http://unlicense.org/ │ +│ • http://creativecommons.org/publicdomain/zero/1.0/ │ +╚─────────────────────────────────────────────────────────────────*/ +#endif +#include "libc/calls/calls.h" +#include "libc/stdio/stdio.h" + +int main(int argc, char *argv[]) { + char buf[256]; + if (!getdomainname(buf, sizeof(buf))) { + printf("%s\n", buf); + return 0; + } else { + return 1; + } +} diff --git a/libc/isystem/sys/vfs.h b/libc/isystem/sys/vfs.h new file mode 100644 index 000000000..9d8ac9412 --- /dev/null +++ b/libc/isystem/sys/vfs.h @@ -0,0 +1,4 @@ +#ifndef COSMOPOLITAN_LIBC_ISYSTEM_SYS_VFS_H_ +#define COSMOPOLITAN_LIBC_ISYSTEM_SYS_VFS_H_ +#include "libc/calls/struct/statfs.h" +#endif /* COSMOPOLITAN_LIBC_ISYSTEM_SYS_VFS_H_ */ diff --git a/libc/isystem/zlib.h b/libc/isystem/zlib.h deleted file mode 100644 index 705f3db8c..000000000 --- a/libc/isystem/zlib.h +++ /dev/null @@ -1,4 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_ISYSTEM_ZLIB_H_ -#define COSMOPOLITAN_LIBC_ISYSTEM_ZLIB_H_ -#include "third_party/zlib/zlib.h" -#endif /* COSMOPOLITAN_LIBC_ISYSTEM_ZLIB_H_ */ diff --git a/libc/runtime/getmaxfd.c b/libc/runtime/getmaxfd.c index 59704886e..14f63eee4 100644 --- a/libc/runtime/getmaxfd.c +++ b/libc/runtime/getmaxfd.c @@ -26,12 +26,12 @@ /** * Returns maximum number of open files. */ -long GetMaxFd(void) { +long _GetMaxFd(void) { int rc; if (IsNetbsd()) { if ((rc = __sys_fcntl(0, F_MAXFD, 0)) != -1) { return rc; } } - return GetResourceLimit(RLIMIT_NOFILE); + return _GetResourceLimit(RLIMIT_NOFILE); } diff --git a/libc/runtime/getresourcelimit.c b/libc/runtime/getresourcelimit.c index a10160ac5..e678149f0 100644 --- a/libc/runtime/getresourcelimit.c +++ b/libc/runtime/getresourcelimit.c @@ -21,7 +21,7 @@ #include "libc/macros.internal.h" #include "libc/sysv/consts/rlim.h" -long GetResourceLimit(int resource) { +long _GetResourceLimit(int resource) { struct rlimit rl; getrlimit(resource, &rl); if (rl.rlim_cur == RLIM_INFINITY) return -1; diff --git a/libc/runtime/getsymboltable.c b/libc/runtime/getsymboltable.c index 3862d45ac..df491f9e8 100644 --- a/libc/runtime/getsymboltable.c +++ b/libc/runtime/getsymboltable.c @@ -30,7 +30,7 @@ #include "libc/x/x.h" #include "libc/zip.h" #include "libc/zipos/zipos.internal.h" -#include "third_party/zlib/puff.h" +#include "third_party/puff/puff.h" static pthread_spinlock_t g_lock; _Hide struct SymbolTable *__symtab; // for kprintf diff --git a/libc/runtime/inflate.c b/libc/runtime/inflate.c index 09679dbdf..5f33a0f2d 100644 --- a/libc/runtime/inflate.c +++ b/libc/runtime/inflate.c @@ -20,7 +20,7 @@ #include "libc/intrin/weaken.h" #include "libc/macros.internal.h" #include "libc/runtime/runtime.h" -#include "third_party/zlib/puff.h" +#include "third_party/puff/puff.h" #include "third_party/zlib/zlib.h" /** @@ -54,7 +54,7 @@ int __inflate(void *out, size_t outsize, const void *in, size_t insize) { rc = rc; } } else { - rc = puff(out, &outsize, in, &insize); + rc = _puff(out, &outsize, in, &insize); } STRACE("inflate([%#.*hhs%s], %'zu, %#.*hhs%s, %'zu) → %d", MIN(40, outsize), out, outsize > 40 ? "..." : "", outsize, MIN(40, insize), in, diff --git a/libc/runtime/internal.h b/libc/runtime/internal.h index ba5fa93fe..85cb1575c 100644 --- a/libc/runtime/internal.h +++ b/libc/runtime/internal.h @@ -44,9 +44,9 @@ int GetDosEnviron(const char16_t *, char *, size_t, char **, size_t); bool __intercept_flag(int *, char *[], const char *); int sys_mprotect_nt(void *, size_t, int) _Hide; int __inflate(void *, size_t, const void *, size_t); -noasan void *Mmap(void *addr, size_t size, int prot, int flags, int fd, - int64_t off) _Hide; -noasan int Munmap(char *, size_t) _Hide; +noasan void *_Mmap(void *addr, size_t size, int prot, int flags, int fd, + int64_t off) _Hide; +noasan int _Munmap(char *, size_t) _Hide; COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ diff --git a/libc/runtime/isdynamicexecutable.c b/libc/runtime/isdynamicexecutable.c index 06e14823e..588da0009 100644 --- a/libc/runtime/isdynamicexecutable.c +++ b/libc/runtime/isdynamicexecutable.c @@ -33,7 +33,7 @@ /** * Returns true if ELF executable uses dynamic loading magic. */ -bool IsDynamicExecutable(const char *prog) { +bool _IsDynamicExecutable(const char *prog) { bool res; Elf64_Ehdr *e; Elf64_Phdr *p; diff --git a/libc/runtime/mmap.c b/libc/runtime/mmap.c index e9c274f1e..b887410ba 100644 --- a/libc/runtime/mmap.c +++ b/libc/runtime/mmap.c @@ -238,8 +238,8 @@ static textwindows dontinline noasan void *MapMemories(char *addr, size_t size, return addr; } -noasan inline void *Mmap(void *addr, size_t size, int prot, int flags, int fd, - int64_t off) { +noasan inline void *_Mmap(void *addr, size_t size, int prot, int flags, int fd, + int64_t off) { char *p = addr; struct DirectMap dm; int a, b, i, f, m, n, x; @@ -494,7 +494,7 @@ void *mmap(void *addr, size_t size, int prot, int flags, int fd, int64_t off) { #endif __mmi_lock(); if (!__isfdkind(fd, kFdZip)) { - res = Mmap(addr, size, prot, flags, fd, off); + res = _Mmap(addr, size, prot, flags, fd, off); } else { res = _weaken(__zipos_Mmap)( addr, size, prot, flags, diff --git a/libc/runtime/munmap.c b/libc/runtime/munmap.c index b1baac6b2..e4781bdbb 100644 --- a/libc/runtime/munmap.c +++ b/libc/runtime/munmap.c @@ -53,7 +53,7 @@ static noasan void MunmapShadow(char *p, size_t n) { // to be >1mb since we can only unmap it if it's aligned, and // as such we poison the edges if there are any. __repstosb((void *)a, kAsanUnmapped, x - a); - Munmap((void *)x, y - x); + _Munmap((void *)x, y - x); __repstosb((void *)y, kAsanUnmapped, b - y); } else { // otherwise just poison and assume reuse @@ -113,7 +113,7 @@ static noasan void MunmapImpl(char *p, size_t n) { } } -noasan int Munmap(char *p, size_t n) { +noasan int _Munmap(char *p, size_t n) { unsigned i; char poison; intptr_t a, b, x, y; @@ -157,7 +157,7 @@ int munmap(void *p, size_t n) { int rc; size_t toto; __mmi_lock(); - rc = Munmap(p, n); + rc = _Munmap(p, n); #if SYSDEBUG toto = __strace > 0 ? GetMemtrackSize(&_mmi) : 0; #endif diff --git a/libc/runtime/openexecutable.S b/libc/runtime/openexecutable.S index 8ed1ae5f5..cc15a70ae 100644 --- a/libc/runtime/openexecutable.S +++ b/libc/runtime/openexecutable.S @@ -30,7 +30,7 @@ // @return file descriptor // @note only works on .com binary (not .com.dbg) // @note only supports linux, freebsd, openbsd, and netbsd -OpenExecutable: +_OpenExecutable: push %rbp mov %rsp,%rbp pushq __NR_open(%rip) # -0x08(%rbp) @@ -198,7 +198,7 @@ OpenExecutable: pop %rbx leave ret -9: .endfn OpenExecutable,globl +9: .endfn _OpenExecutable,globl .weak ape_rom_vaddr .weak ape_rom_filesz diff --git a/libc/runtime/runtime.h b/libc/runtime/runtime.h index d8aa565e6..4f415c4c1 100644 --- a/libc/runtime/runtime.h +++ b/libc/runtime/runtime.h @@ -94,12 +94,12 @@ void _peekall(void); void _savexmm(void *); void _weakfree(void *); void free_s(void *) paramsnonnull() libcesque; -int OpenExecutable(void); +int _OpenExecutable(void); int ftrace_install(void); int ftrace_enabled(int); int strace_enabled(int); -long GetResourceLimit(int); -long GetMaxFd(void); +long _GetResourceLimit(int); +long _GetMaxFd(void); char *GetProgramExecutableName(void); char *GetInterpreterExecutableName(char *, size_t); void __printargs(const char *); @@ -108,7 +108,7 @@ int __arg_max(void); void __print_maps(void); void __warn_if_powersave(void); const char *__describe_os(void); -bool IsDynamicExecutable(const char *); +bool _IsDynamicExecutable(const char *); void _restorewintty(void); const char *GetCpuidOs(void); const char *GetCpuidEmulator(void); diff --git a/libc/runtime/runtime.mk b/libc/runtime/runtime.mk index 7454c8be5..6a37e86a4 100644 --- a/libc/runtime/runtime.mk +++ b/libc/runtime/runtime.mk @@ -45,7 +45,7 @@ LIBC_RUNTIME_A_DIRECTDEPS = \ LIBC_STUBS \ LIBC_SYSV \ LIBC_SYSV_CALLS \ - THIRD_PARTY_ZLIB \ + THIRD_PARTY_PUFF \ THIRD_PARTY_XED LIBC_RUNTIME_A_DEPS := \ diff --git a/libc/runtime/sysconf.c b/libc/runtime/sysconf.c index a3f835d9b..51d1f7977 100644 --- a/libc/runtime/sysconf.c +++ b/libc/runtime/sysconf.c @@ -41,11 +41,11 @@ long sysconf(int name) { case _SC_ARG_MAX: return _ARG_MAX; case _SC_CHILD_MAX: - return GetResourceLimit(RLIMIT_NPROC); + return _GetResourceLimit(RLIMIT_NPROC); case _SC_CLK_TCK: return CLK_TCK; case _SC_OPEN_MAX: - return GetMaxFd(); + return _GetMaxFd(); case _SC_PAGESIZE: return FRAMESIZE; case _SC_NPROCESSORS_ONLN: diff --git a/libc/zipos/mmap.c b/libc/zipos/mmap.c index bddd1b743..898c55bb9 100644 --- a/libc/zipos/mmap.c +++ b/libc/zipos/mmap.c @@ -64,7 +64,7 @@ noasan void *__zipos_Mmap(void *addr, size_t size, int prot, int flags, const int tempProt = !IsXnu() ? prot | PROT_WRITE : PROT_WRITE; void *outAddr = - Mmap(addr, size, tempProt, (flags & (~MAP_FILE)) | MAP_ANONYMOUS, -1, 0); + _Mmap(addr, size, tempProt, (flags & (~MAP_FILE)) | MAP_ANONYMOUS, -1, 0); if (outAddr == MAP_FAILED) { return MAP_FAILED; } @@ -82,7 +82,7 @@ noasan void *__zipos_Mmap(void *addr, size_t size, int prot, int flags, return outAddr; } while (0); const int e = errno; - Munmap(outAddr, size); + _Munmap(outAddr, size); errno = e; strace_enabled(+1); return MAP_FAILED; diff --git a/libc/zipos/zipos.mk b/libc/zipos/zipos.mk index 66ae43e7c..89b60e0b5 100644 --- a/libc/zipos/zipos.mk +++ b/libc/zipos/zipos.mk @@ -40,7 +40,7 @@ LIBC_ZIPOS_A_DIRECTDEPS = \ LIBC_STUBS \ LIBC_SYSV_CALLS \ LIBC_NT_KERNEL32 \ - THIRD_PARTY_ZLIB + THIRD_PARTY_PUFF LIBC_ZIPOS_A_DEPS := \ $(call uniq,$(foreach zipos,$(LIBC_ZIPOS_A_DIRECTDEPS),$($(zipos)))) diff --git a/third_party/puff/README.cosmo b/third_party/puff/README.cosmo new file mode 100644 index 000000000..3cde08560 --- /dev/null +++ b/third_party/puff/README.cosmo @@ -0,0 +1,18 @@ +DESCRIPTION + + puff is a tiny implementation of deflate decompression + +LICENSE + + zlib license + +ORIGIN + + Origin: git@github.com:madler/zlib.git + Commit: 03614c56ad299f9b238c75aa1e66f0c08fc4fc8b + Author: Mark Adler + Date: Sun Oct 30 08:36:13 2016 -0700 + +LOCAL CHANGES + + None. diff --git a/third_party/zlib/puff.c b/third_party/puff/puff.c similarity index 99% rename from third_party/zlib/puff.c rename to third_party/puff/puff.c index 8ee5576af..d79a48086 100644 --- a/third_party/zlib/puff.c +++ b/third_party/puff/puff.c @@ -23,7 +23,7 @@ │ Mark Adler madler@alumni.caltech.edu │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/runtime/runtime.h" -#include "third_party/zlib/puff.h" +#include "third_party/puff/puff.h" // clang-format off asm(".ident\t\"\\n\\n\ @@ -825,10 +825,10 @@ local int dynamic(struct state *s) * block (if it was a fixed or dynamic block) are undefined and have no * expected values to check. */ -int puff(unsigned char *dest, /* pointer to destination pointer */ - unsigned long *destlen, /* amount of output space */ - const unsigned char *source, /* pointer to source data pointer */ - unsigned long *sourcelen) /* amount of input available */ +int _puff(unsigned char *dest, /* pointer to destination pointer */ + unsigned long *destlen, /* amount of output space */ + const unsigned char *source, /* pointer to source data pointer */ + unsigned long *sourcelen) /* amount of input available */ { struct state s; /* input/output state */ int last, type; /* block information */ diff --git a/third_party/zlib/puff.h b/third_party/puff/puff.h similarity index 74% rename from third_party/zlib/puff.h rename to third_party/puff/puff.h index 7900fd9f4..fd00f6f4b 100644 --- a/third_party/zlib/puff.h +++ b/third_party/puff/puff.h @@ -7,8 +7,8 @@ COSMOPOLITAN_C_START_ #define NIL ((unsigned char *)0) /* for no output option */ #endif -int puff(unsigned char *dest, unsigned long *destlen, - const unsigned char *source, unsigned long *sourcelen); +int _puff(unsigned char *dest, unsigned long *destlen, + const unsigned char *source, unsigned long *sourcelen); COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ diff --git a/third_party/puff/puff.mk b/third_party/puff/puff.mk new file mode 100644 index 000000000..e5f660cdf --- /dev/null +++ b/third_party/puff/puff.mk @@ -0,0 +1,45 @@ +#-*-mode:makefile-gmake;indent-tabs-mode:t;tab-width:8;coding:utf-8-*-┐ +#───vi: set et ft=make ts=8 tw=8 fenc=utf-8 :vi───────────────────────┘ + +PKGS += THIRD_PARTY_PUFF + +THIRD_PARTY_PUFF_ARTIFACTS += THIRD_PARTY_PUFF_A +THIRD_PARTY_PUFF = $(THIRD_PARTY_PUFF_A_DEPS) $(THIRD_PARTY_PUFF_A) +THIRD_PARTY_PUFF_A = o/$(MODE)/third_party/puff/puff.a +THIRD_PARTY_PUFF_A_FILES := $(wildcard third_party/puff/*) +THIRD_PARTY_PUFF_A_HDRS = $(filter %.h,$(THIRD_PARTY_PUFF_A_FILES)) +THIRD_PARTY_PUFF_A_SRCS = $(filter %.c,$(THIRD_PARTY_PUFF_A_FILES)) + +THIRD_PARTY_PUFF_A_OBJS = \ + $(THIRD_PARTY_PUFF_A_SRCS:%.c=o/$(MODE)/%.o) + +THIRD_PARTY_PUFF_A_CHECKS = \ + $(THIRD_PARTY_PUFF_A).pkg \ + $(THIRD_PARTY_PUFF_A_HDRS:%=o/$(MODE)/%.ok) + +THIRD_PARTY_PUFF_A_DIRECTDEPS = \ + LIBC_INTRIN \ + LIBC_NEXGEN32E \ + LIBC_STUBS + +THIRD_PARTY_PUFF_A_DEPS := \ + $(call uniq,$(foreach x,$(THIRD_PARTY_PUFF_A_DIRECTDEPS),$($(x)))) + +$(THIRD_PARTY_PUFF_A): \ + third_party/puff/ \ + $(THIRD_PARTY_PUFF_A).pkg \ + $(THIRD_PARTY_PUFF_A_OBJS) + +$(THIRD_PARTY_PUFF_A).pkg: \ + $(THIRD_PARTY_PUFF_A_OBJS) \ + $(foreach x,$(THIRD_PARTY_PUFF_A_DIRECTDEPS),$($(x)_A).pkg) + +THIRD_PARTY_PUFF_LIBS = $(foreach x,$(THIRD_PARTY_PUFF_ARTIFACTS),$($(x))) +THIRD_PARTY_PUFF_SRCS = $(foreach x,$(THIRD_PARTY_PUFF_ARTIFACTS),$($(x)_SRCS)) +THIRD_PARTY_PUFF_HDRS = $(foreach x,$(THIRD_PARTY_PUFF_ARTIFACTS),$($(x)_HDRS)) +THIRD_PARTY_PUFF_CHECKS = $(foreach x,$(THIRD_PARTY_PUFF_ARTIFACTS),$($(x)_CHECKS)) +THIRD_PARTY_PUFF_OBJS = $(foreach x,$(THIRD_PARTY_PUFF_ARTIFACTS),$($(x)_OBJS)) + +.PHONY: o/$(MODE)/third_party/puff +o/$(MODE)/third_party/puff: \ + $(THIRD_PARTY_PUFF_CHECKS) diff --git a/third_party/third_party.mk b/third_party/third_party.mk index 6788db814..570d1715f 100644 --- a/third_party/third_party.mk +++ b/third_party/third_party.mk @@ -23,6 +23,7 @@ o/$(MODE)/third_party: \ o/$(MODE)/third_party/mbedtls \ o/$(MODE)/third_party/musl \ o/$(MODE)/third_party/nsync \ + o/$(MODE)/third_party/puff \ o/$(MODE)/third_party/python \ o/$(MODE)/third_party/quickjs \ o/$(MODE)/third_party/regex \ diff --git a/tool/build/pledge.c b/tool/build/pledge.c index a54f426f6..a15cbcb07 100644 --- a/tool/build/pledge.c +++ b/tool/build/pledge.c @@ -673,7 +673,7 @@ int main(int argc, char *argv[]) { } // figure out where we want the dso - if (IsDynamicExecutable(prog)) { + if (_IsDynamicExecutable(prog)) { isdynamic = true; if ((s = getenv("TMPDIR")) || // (s = getenv("HOME")) || // diff --git a/tool/net/redbean.c b/tool/net/redbean.c index 4fd65a576..405575624 100644 --- a/tool/net/redbean.c +++ b/tool/net/redbean.c @@ -6893,7 +6893,7 @@ static void MakeExecutableModifiable(void) { if (_endswith(zpath, ".com.dbg")) return; close(zfd); ft = ftrace_enabled(0); - if ((zfd = OpenExecutable()) == -1) { + if ((zfd = _OpenExecutable()) == -1) { WARNF("(srvr) can't open executable for modification: %m"); } if (ft > 0) {