Move zipos into runtime package

This way complex runtime features (e.g. ftrace, symbol tables) can
always yoink zipos support. This is important now that apelink.com
automates embedding symbol tables for multiple cpus.
This commit is contained in:
Justine Tunney 2023-08-11 23:14:02 -07:00
parent d53c335a45
commit e11fa30791
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
90 changed files with 133 additions and 289 deletions

View file

@ -145,7 +145,6 @@ include libc/mem/mem.mk #─┐
include third_party/gdtoa/gdtoa.mk # ├──DYNAMIC RUNTIME
include third_party/nsync/mem/mem.mk # │ You can now use stdio
include libc/thread/thread.mk # │ You can finally call malloc()
include libc/zipos/zipos.mk # │
include tool/hello/hello.mk # │
include libc/stdio/stdio.mk # │
include libc/time/time.mk # │
@ -243,7 +242,6 @@ include test/libc/fmt/test.mk
include test/libc/dns/test.mk
include test/libc/time/test.mk
include test/libc/stdio/test.mk
include test/libc/zipos/test.mk
include test/libc/release/test.mk
include test/libc/test.mk
include test/net/http/test.mk
@ -325,7 +323,6 @@ COSMOPOLITAN_OBJECTS = \
THIRD_PARTY_GETOPT \
LIBC_LOG \
LIBC_TIME \
LIBC_ZIPOS \
THIRD_PARTY_MUSL \
LIBC_STDIO \
THIRD_PARTY_GDTOA \
@ -383,7 +380,6 @@ COSMOPOLITAN_HEADERS = \
LIBC_TIME \
LIBC_TINYMATH \
LIBC_X \
LIBC_ZIPOS \
LIBC_VGA \
NET_HTTP \
TOOL_ARGS \

View file

@ -67,7 +67,6 @@ EXAMPLES_DIRECTDEPS = \
LIBC_TINYMATH \
LIBC_VGA \
LIBC_X \
LIBC_ZIPOS \
NET_HTTP \
NET_HTTPS \
THIRD_PARTY_AWK \

View file

@ -43,7 +43,7 @@
#include "libc/x/xasprintf.h"
#include "libc/x/xsigaction.h"
#include "libc/zip.internal.h"
#include "libc/zipos/zipos.internal.h"
#include "libc/runtime/zipos.internal.h"
#include "third_party/getopt/getopt.internal.h"
#include "third_party/libcxx/vector"
#include "tool/viz/lib/knobs.h"

View file

@ -27,7 +27,7 @@
#include "libc/intrin/weaken.h"
#include "libc/sock/syscall_fd.internal.h"
#include "libc/sysv/errfuns.h"
#include "libc/zipos/zipos.internal.h"
#include "libc/runtime/zipos.internal.h"
/**
* Closes file descriptor.

View file

@ -31,7 +31,7 @@
#include "libc/log/libfatal.internal.h"
#include "libc/sysv/consts/o.h"
#include "libc/sysv/errfuns.h"
#include "libc/zipos/zipos.internal.h"
#include "libc/runtime/zipos.internal.h"
/**
* Replaces current process with program.

View file

@ -28,7 +28,7 @@
#include "libc/intrin/weaken.h"
#include "libc/sysv/consts/at.h"
#include "libc/sysv/errfuns.h"
#include "libc/zipos/zipos.internal.h"
#include "libc/runtime/zipos.internal.h"
/**
* Checks if effective user can access path in particular ways.

View file

@ -25,7 +25,7 @@
#include "libc/intrin/strace.internal.h"
#include "libc/intrin/weaken.h"
#include "libc/sysv/errfuns.h"
#include "libc/zipos/zipos.internal.h"
#include "libc/runtime/zipos.internal.h"
int sys_fchmodat_linux(int, const char *, unsigned, int);

View file

@ -24,7 +24,7 @@
#include "libc/intrin/strace.internal.h"
#include "libc/intrin/weaken.h"
#include "libc/sysv/errfuns.h"
#include "libc/zipos/zipos.internal.h"
#include "libc/runtime/zipos.internal.h"
/**
* Changes owner and/or group of path.

View file

@ -29,7 +29,7 @@
#include "libc/intrin/weaken.h"
#include "libc/sysv/consts/f.h"
#include "libc/sysv/errfuns.h"
#include "libc/zipos/zipos.internal.h"
#include "libc/runtime/zipos.internal.h"
/**
* Does things with file descriptor, e.g.

View file

@ -30,7 +30,7 @@
#include "libc/str/str.h"
#include "libc/sysv/consts/at.h"
#include "libc/sysv/errfuns.h"
#include "libc/zipos/zipos.internal.h"
#include "libc/runtime/zipos.internal.h"
/**
* Returns true if file exists at path.

View file

@ -25,7 +25,7 @@
#include "libc/intrin/strace.internal.h"
#include "libc/intrin/weaken.h"
#include "libc/sysv/errfuns.h"
#include "libc/zipos/zipos.internal.h"
#include "libc/runtime/zipos.internal.h"
/**
* Returns information about file, via open()'d descriptor.

View file

@ -32,7 +32,7 @@
#include "libc/str/str.h"
#include "libc/sysv/consts/at.h"
#include "libc/sysv/errfuns.h"
#include "libc/zipos/zipos.internal.h"
#include "libc/runtime/zipos.internal.h"
static inline const char *__strace_fstatat_flags(char buf[12], int flags) {
if (flags == AT_SYMLINK_NOFOLLOW) return "AT_SYMLINK_NOFOLLOW";

View file

@ -30,7 +30,7 @@
#include "libc/sysv/consts/at.h"
#include "libc/sysv/consts/s.h"
#include "libc/sysv/errfuns.h"
#include "libc/zipos/zipos.internal.h"
#include "libc/runtime/zipos.internal.h"
/**
* Returns true if file exists and is a directory.

View file

@ -28,7 +28,7 @@
#include "libc/sysv/consts/at.h"
#include "libc/sysv/consts/s.h"
#include "libc/sysv/errfuns.h"
#include "libc/zipos/zipos.internal.h"
#include "libc/runtime/zipos.internal.h"
/**
* Returns true if file exists and is a regular file.

View file

@ -30,7 +30,7 @@
#include "libc/sysv/consts/at.h"
#include "libc/sysv/consts/s.h"
#include "libc/sysv/errfuns.h"
#include "libc/zipos/zipos.internal.h"
#include "libc/runtime/zipos.internal.h"
/**
* Returns true if file exists and is a symbolic link.

View file

@ -25,7 +25,7 @@
#include "libc/intrin/strace.internal.h"
#include "libc/intrin/weaken.h"
#include "libc/sysv/errfuns.h"
#include "libc/zipos/zipos.internal.h"
#include "libc/runtime/zipos.internal.h"
/**
* Creates hard filesystem link.

View file

@ -26,7 +26,7 @@
#include "libc/intrin/weaken.h"
#include "libc/log/backtrace.internal.h"
#include "libc/sysv/errfuns.h"
#include "libc/zipos/zipos.internal.h"
#include "libc/runtime/zipos.internal.h"
/**
* Changes current position of file descriptor, e.g.

View file

@ -26,7 +26,7 @@
#include "libc/intrin/weaken.h"
#include "libc/sysv/consts/at.h"
#include "libc/sysv/errfuns.h"
#include "libc/zipos/zipos.internal.h"
#include "libc/runtime/zipos.internal.h"
/**
* Creates directory a.k.a. folder.

View file

@ -33,7 +33,7 @@
#include "libc/sysv/consts/o.h"
#include "libc/sysv/consts/prot.h"
#include "libc/sysv/errfuns.h"
#include "libc/zipos/zipos.internal.h"
#include "libc/runtime/zipos.internal.h"
#ifdef __x86_64__

View file

@ -33,7 +33,7 @@
#include "libc/sysv/consts/at.h"
#include "libc/sysv/consts/o.h"
#include "libc/sysv/errfuns.h"
#include "libc/zipos/zipos.internal.h"
#include "libc/runtime/zipos.internal.h"
/**
* Opens file.

View file

@ -30,7 +30,7 @@
#include "libc/macros.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/sysv/errfuns.h"
#include "libc/zipos/zipos.internal.h"
#include "libc/runtime/zipos.internal.h"
/**
* Reads from file at offset.

View file

@ -30,7 +30,7 @@
#include "libc/intrin/strace.internal.h"
#include "libc/intrin/weaken.h"
#include "libc/sysv/errfuns.h"
#include "libc/zipos/zipos.internal.h"
#include "libc/runtime/zipos.internal.h"
static ssize_t Preadv(int fd, struct iovec *iov, int iovlen, int64_t off) {
int e, i;

View file

@ -30,7 +30,7 @@
#include "libc/intrin/strace.internal.h"
#include "libc/intrin/weaken.h"
#include "libc/sysv/errfuns.h"
#include "libc/zipos/zipos.internal.h"
#include "libc/runtime/zipos.internal.h"
static ssize_t Pwritev(int fd, const struct iovec *iov, int iovlen,
int64_t off) {

View file

@ -29,7 +29,7 @@
#include "libc/sock/internal.h"
#include "libc/sock/sock.h"
#include "libc/sysv/errfuns.h"
#include "libc/zipos/zipos.internal.h"
#include "libc/runtime/zipos.internal.h"
/**
* Reads data from file descriptor.

View file

@ -25,7 +25,7 @@
#include "libc/intrin/weaken.h"
#include "libc/runtime/runtime.h"
#include "libc/sysv/errfuns.h"
#include "libc/zipos/zipos.internal.h"
#include "libc/runtime/zipos.internal.h"
/**
* Reads symbolic link.

View file

@ -31,7 +31,7 @@
#include "libc/intrin/weaken.h"
#include "libc/sock/internal.h"
#include "libc/sysv/errfuns.h"
#include "libc/zipos/zipos.internal.h"
#include "libc/runtime/zipos.internal.h"
/**
* Reads data to multiple buffers.

View file

@ -26,7 +26,7 @@
#include "libc/intrin/weaken.h"
#include "libc/sysv/consts/at.h"
#include "libc/sysv/errfuns.h"
#include "libc/zipos/zipos.internal.h"
#include "libc/runtime/zipos.internal.h"
/**
* Renames files relative to directories.

View file

@ -26,7 +26,7 @@
#include "libc/intrin/strace.internal.h"
#include "libc/intrin/weaken.h"
#include "libc/sysv/errfuns.h"
#include "libc/zipos/zipos.internal.h"
#include "libc/runtime/zipos.internal.h"
/**
* Changes size of file.

View file

@ -28,7 +28,7 @@
#include "libc/intrin/weaken.h"
#include "libc/sysv/consts/s.h"
#include "libc/sysv/errfuns.h"
#include "libc/zipos/zipos.internal.h"
#include "libc/runtime/zipos.internal.h"
/**
* Deletes inode and maybe the file too.

View file

@ -30,7 +30,7 @@
#include "libc/intrin/weaken.h"
#include "libc/sysv/consts/at.h"
#include "libc/sysv/errfuns.h"
#include "libc/zipos/zipos.internal.h"
#include "libc/runtime/zipos.internal.h"
int __utimens(int fd, const char *path, const struct timespec ts[2],
int flags) {

View file

@ -23,7 +23,7 @@
#include "libc/fmt/conv.h"
#include "libc/sysv/consts/at.h"
#include "libc/time/time.h"
#include "libc/zipos/zipos.internal.h"
#include "libc/runtime/zipos.internal.h"
int sys_utimensat(int dirfd, const char *path, const struct timespec ts[2],
int flags) {

View file

@ -27,7 +27,7 @@
#include "libc/intrin/weaken.h"
#include "libc/sysv/consts/at.h"
#include "libc/sysv/errfuns.h"
#include "libc/zipos/zipos.internal.h"
#include "libc/runtime/zipos.internal.h"
/**
* Sets access/modified time on file, the modern way.

View file

@ -27,7 +27,7 @@
#include "libc/intrin/weaken.h"
#include "libc/sock/sock.h"
#include "libc/sysv/errfuns.h"
#include "libc/zipos/zipos.internal.h"
#include "libc/runtime/zipos.internal.h"
/**
* Writes data to file descriptor.

View file

@ -30,7 +30,7 @@
#include "libc/intrin/weaken.h"
#include "libc/sock/internal.h"
#include "libc/sysv/errfuns.h"
#include "libc/zipos/zipos.internal.h"
#include "libc/runtime/zipos.internal.h"
/**
* Writes data from multiple buffers.

View file

@ -39,7 +39,6 @@ LIBC_LOG_A_DIRECTDEPS = \
LIBC_SYSV_CALLS \
LIBC_TIME \
LIBC_TINYMATH \
LIBC_ZIPOS \
THIRD_PARTY_COMPILER_RT \
THIRD_PARTY_DLMALLOC \
THIRD_PARTY_GDTOA

View file

@ -21,6 +21,8 @@
#include "libc/str/str.h"
#include "libc/thread/tls.h"
__static_yoink("zipos");
/**
* Enables plaintext function tracing if `--ftrace` flag is passed.
*

View file

@ -29,7 +29,7 @@
#include "libc/thread/thread.h"
#include "libc/x/x.h"
#include "libc/zip.internal.h"
#include "libc/zipos/zipos.internal.h"
#include "libc/runtime/zipos.internal.h"
#include "third_party/puff/puff.h"
__static_yoink("__get_symbol");

View file

@ -43,6 +43,7 @@
#include "libc/runtime/internal.h"
#include "libc/runtime/memtrack.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/runtime/zipos.internal.h"
#include "libc/stdckdint.h"
#include "libc/stdio/rand.h"
#include "libc/str/str.h"

View file

@ -26,7 +26,8 @@ LIBC_RUNTIME_A_SRCS = \
LIBC_RUNTIME_A_OBJS = \
$(LIBC_RUNTIME_A_SRCS_S:%.S=o/$(MODE)/%.o) \
$(LIBC_RUNTIME_A_SRCS_C:%.c=o/$(MODE)/%.o)
$(LIBC_RUNTIME_A_SRCS_C:%.c=o/$(MODE)/%.o) \
o/$(MODE)/libc/runtime/.cosmo.zip.o
LIBC_RUNTIME_A_CHECKS = \
$(LIBC_RUNTIME_A).pkg \
@ -138,6 +139,10 @@ o/$(MODE)/libc/runtime/clone.o: private \
-fno-sanitize=all \
-fpatchable-function-entry=0,0
o/$(MODE)/libc/runtime/.cosmo.zip.o: private \
ZIPOBJ_FLAGS += \
-B
# these assembly files are safe to build on aarch64
o/$(MODE)/libc/runtime/init.o: libc/runtime/init.S
@$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) -c $<
@ -151,6 +156,8 @@ o/$(MODE)/libc/runtime/ftrace-hook.o: libc/runtime/ftrace-hook.S
@$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) -c $<
o/$(MODE)/libc/runtime/dsohandle.o: libc/runtime/dsohandle.S
@$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) -c $<
o/$(MODE)/libc/runtime/zipos.o: libc/runtime/zipos.S
@$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) -c $<
LIBC_RUNTIME_LIBS = $(foreach x,$(LIBC_RUNTIME_ARTIFACTS),$($(x)))
LIBC_RUNTIME_SRCS = $(foreach x,$(LIBC_RUNTIME_ARTIFACTS),$($(x)_SRCS))

View file

@ -21,7 +21,7 @@
#include "libc/sysv/consts/ok.h"
#include "libc/sysv/errfuns.h"
#include "libc/zip.internal.h"
#include "libc/zipos/zipos.internal.h"
#include "libc/runtime/zipos.internal.h"
// TODO: this should check parent directory components

View file

@ -21,7 +21,7 @@
#include "libc/calls/state.internal.h"
#include "libc/calls/syscall-sysv.internal.h"
#include "libc/dce.h"
#include "libc/zipos/zipos.internal.h"
#include "libc/runtime/zipos.internal.h"
/**
* Closes compressed object.

View file

@ -22,7 +22,7 @@
#include "libc/sysv/consts/o.h"
#include "libc/sysv/errfuns.h"
#include "libc/zip.internal.h"
#include "libc/zipos/zipos.internal.h"
#include "libc/runtime/zipos.internal.h"
#define ZIPOS __zipos_get()
#define HANDLE ((struct ZiposHandle *)(intptr_t)g_fds.p[fd].handle)

View file

@ -21,7 +21,7 @@
#include "libc/runtime/runtime.h"
#include "libc/str/str.h"
#include "libc/zip.internal.h"
#include "libc/zipos/zipos.internal.h"
#include "libc/runtime/zipos.internal.h"
// TODO(jart): improve time complexity here

View file

@ -22,7 +22,7 @@
#include "libc/intrin/cmpxchg.h"
#include "libc/str/str.h"
#include "libc/thread/thread.h"
#include "libc/zipos/zipos.internal.h"
#include "libc/runtime/zipos.internal.h"
void __zipos_free(struct Zipos *z, struct ZiposHandle *h) {
if (IsAsan()) {

View file

@ -19,7 +19,7 @@
#include "libc/assert.h"
#include "libc/sysv/errfuns.h"
#include "libc/zip.internal.h"
#include "libc/zipos/zipos.internal.h"
#include "libc/runtime/zipos.internal.h"
/**
* Reads file metadata from αcτµαlly pδrταblε εxεcµταblε object store.

View file

@ -29,7 +29,7 @@
#include "libc/sysv/consts/prot.h"
#include "libc/thread/thread.h"
#include "libc/zip.internal.h"
#include "libc/zipos/zipos.internal.h"
#include "libc/runtime/zipos.internal.h"
#ifdef __x86_64__
__static_yoink(APE_COM_NAME);

View file

@ -17,7 +17,7 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/thread/thread.h"
#include "libc/zipos/zipos.internal.h"
#include "libc/runtime/zipos.internal.h"
static pthread_mutex_t __zipos_lock_obj;

View file

@ -20,7 +20,7 @@
#include "libc/sysv/errfuns.h"
#include "libc/thread/thread.h"
#include "libc/zip.internal.h"
#include "libc/zipos/zipos.internal.h"
#include "libc/runtime/zipos.internal.h"
/**
* Changes current position of zip file handle.

View file

@ -23,10 +23,11 @@
#include "libc/intrin/likely.h"
#include "libc/intrin/strace.internal.h"
#include "libc/runtime/internal.h"
#include "libc/runtime/runtime.h"
#include "libc/runtime/zipos.internal.h"
#include "libc/sysv/consts/map.h"
#include "libc/sysv/consts/prot.h"
#include "libc/sysv/errfuns.h"
#include "libc/zipos/zipos.internal.h"
#define IP(X) (intptr_t)(X)
#define VIP(X) (void *)IP(X)

View file

@ -18,7 +18,7 @@
*/
#include "libc/calls/internal.h"
#include "libc/sysv/errfuns.h"
#include "libc/zipos/zipos.internal.h"
#include "libc/runtime/zipos.internal.h"
int __zipos_notat(int dirfd, const char *path) {
struct ZiposUri zipname;

View file

@ -42,7 +42,7 @@
#include "libc/sysv/errfuns.h"
#include "libc/thread/thread.h"
#include "libc/zip.internal.h"
#include "libc/zipos/zipos.internal.h"
#include "libc/runtime/zipos.internal.h"
static char *mapend;
static size_t maptotal;

View file

@ -17,7 +17,7 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/str/str.h"
#include "libc/zipos/zipos.internal.h"
#include "libc/runtime/zipos.internal.h"
/**
* Extracts information about ZIP URI if it is one.

View file

@ -22,7 +22,7 @@
#include "libc/str/str.h"
#include "libc/thread/thread.h"
#include "libc/zip.internal.h"
#include "libc/zipos/zipos.internal.h"
#include "libc/runtime/zipos.internal.h"
static size_t GetIovSize(const struct iovec *iov, size_t iovlen) {
size_t i, r;

View file

@ -22,7 +22,7 @@
#include "libc/sysv/consts/s.h"
#include "libc/sysv/errfuns.h"
#include "libc/zip.internal.h"
#include "libc/zipos/zipos.internal.h"
#include "libc/runtime/zipos.internal.h"
int __zipos_stat_impl(struct Zipos *zipos, size_t cf, struct stat *st) {
size_t lf;

View file

@ -18,7 +18,7 @@
*/
#include "libc/stdio/stdio.h"
#include "libc/sysv/errfuns.h"
#include "libc/zipos/zipos.internal.h"
#include "libc/runtime/zipos.internal.h"
/**
* Reads file metadata from αcτµαlly pδrταblε εxεcµταblε object store.

View file

@ -0,0 +1,66 @@
#ifndef COSMOPOLITAN_LIBC_ZIPOS_ZIPOS_H_
#define COSMOPOLITAN_LIBC_ZIPOS_ZIPOS_H_
#include "libc/intrin/nopl.internal.h"
#include "libc/thread/thread.h"
#include "libc/thread/tls.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
struct stat;
struct iovec;
struct ZiposUri {
const char *path;
size_t len;
};
struct ZiposHandle {
struct ZiposHandle *next;
pthread_mutex_t lock;
size_t size; /* byte length of `mem` */
size_t mapsize; /* total size of this struct */
size_t pos; /* read/write byte offset state */
uint32_t cfile; /* central directory entry rva */
uint8_t *mem; /* points to inflated data or uncompressed image */
uint8_t data[]; /* uncompressed file memory */
};
struct Zipos {
uint8_t *map;
uint8_t *cdir;
struct ZiposHandle *freelist;
};
void __zipos_lock(void);
void __zipos_unlock(void);
int __zipos_close(int);
struct Zipos *__zipos_get(void) pureconst;
void __zipos_free(struct Zipos *, struct ZiposHandle *);
ssize_t __zipos_parseuri(const char *, struct ZiposUri *);
ssize_t __zipos_find(struct Zipos *, const struct ZiposUri *);
int __zipos_open(const struct ZiposUri *, unsigned, int);
int __zipos_access(const struct ZiposUri *, int);
int __zipos_stat(const struct ZiposUri *, struct stat *);
int __zipos_fstat(const struct ZiposHandle *, struct stat *);
int __zipos_stat_impl(struct Zipos *, size_t, struct stat *);
ssize_t __zipos_read(struct ZiposHandle *, const struct iovec *, size_t,
ssize_t);
ssize_t __zipos_write(struct ZiposHandle *, const struct iovec *, size_t,
ssize_t);
int64_t __zipos_lseek(struct ZiposHandle *, int64_t, unsigned);
int __zipos_fcntl(int, int, uintptr_t);
int __zipos_notat(int, const char *);
void *__zipos_Mmap(void *, uint64_t, int32_t, int32_t, struct ZiposHandle *,
int64_t) dontasan;
#ifdef _NOPL0
#define __zipos_lock() _NOPL0("__threadcalls", __zipos_lock)
#define __zipos_unlock() _NOPL0("__threadcalls", __zipos_unlock)
#else
#define __zipos_lock() (__threaded ? __zipos_lock() : 0)
#define __zipos_unlock() (__threaded ? __zipos_unlock() : 0)
#endif
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_ZIPOS_ZIPOS_H_ */

View file

@ -39,7 +39,7 @@
#include "libc/sysv/errfuns.h"
#include "libc/thread/thread.h"
#include "libc/zip.internal.h"
#include "libc/zipos/zipos.internal.h"
#include "libc/runtime/zipos.internal.h"
/**
* @fileoverview Directory Streams for Linux+Mac+Windows+FreeBSD+OpenBSD.

View file

@ -106,7 +106,6 @@ LIBC_TESTLIB_A_DIRECTDEPS = \
LIBC_TIME \
LIBC_TINYMATH \
LIBC_X \
LIBC_ZIPOS \
THIRD_PARTY_COMPILER_RT \
THIRD_PARTY_DLMALLOC \
THIRD_PARTY_GDTOA \

View file

@ -38,7 +38,6 @@ LIBC_TIME_A_DIRECTDEPS = \
LIBC_STDIO \
LIBC_STR \
LIBC_SYSV \
LIBC_ZIPOS \
THIRD_PARTY_COMPILER_RT
LIBC_TIME_A_DEPS := \

66
libc/zipos/zipos.internal.h Normal file → Executable file
View file

@ -1,66 +0,0 @@
#ifndef COSMOPOLITAN_LIBC_ZIPOS_ZIPOS_H_
#define COSMOPOLITAN_LIBC_ZIPOS_ZIPOS_H_
#include "libc/intrin/nopl.internal.h"
#include "libc/thread/thread.h"
#include "libc/thread/tls.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
struct stat;
struct iovec;
struct ZiposUri {
const char *path;
size_t len;
};
struct ZiposHandle {
struct ZiposHandle *next;
pthread_mutex_t lock;
size_t size; /* byte length of `mem` */
size_t mapsize; /* total size of this struct */
size_t pos; /* read/write byte offset state */
uint32_t cfile; /* central directory entry rva */
uint8_t *mem; /* points to inflated data or uncompressed image */
uint8_t data[]; /* uncompressed file memory */
};
struct Zipos {
uint8_t *map;
uint8_t *cdir;
struct ZiposHandle *freelist;
};
void __zipos_lock(void);
void __zipos_unlock(void);
int __zipos_close(int);
struct Zipos *__zipos_get(void) pureconst;
void __zipos_free(struct Zipos *, struct ZiposHandle *);
ssize_t __zipos_parseuri(const char *, struct ZiposUri *);
ssize_t __zipos_find(struct Zipos *, const struct ZiposUri *);
int __zipos_open(const struct ZiposUri *, unsigned, int);
int __zipos_access(const struct ZiposUri *, int);
int __zipos_stat(const struct ZiposUri *, struct stat *);
int __zipos_fstat(const struct ZiposHandle *, struct stat *);
int __zipos_stat_impl(struct Zipos *, size_t, struct stat *);
ssize_t __zipos_read(struct ZiposHandle *, const struct iovec *, size_t,
ssize_t);
ssize_t __zipos_write(struct ZiposHandle *, const struct iovec *, size_t,
ssize_t);
int64_t __zipos_lseek(struct ZiposHandle *, int64_t, unsigned);
int __zipos_fcntl(int, int, uintptr_t);
int __zipos_notat(int, const char *);
void *__zipos_Mmap(void *, uint64_t, int32_t, int32_t, struct ZiposHandle *,
int64_t) dontasan;
#ifdef _NOPL0
#define __zipos_lock() _NOPL0("__threadcalls", __zipos_lock)
#define __zipos_unlock() _NOPL0("__threadcalls", __zipos_unlock)
#else
#define __zipos_lock() (__threaded ? __zipos_lock() : 0)
#define __zipos_unlock() (__threaded ? __zipos_unlock() : 0)
#endif
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_ZIPOS_ZIPOS_H_ */

View file

@ -1,73 +0,0 @@
#-*-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 += LIBC_ZIPOS
LIBC_ZIPOS_ARTIFACTS += LIBC_ZIPOS_A
LIBC_ZIPOS_A = o/$(MODE)/libc/zipos/zipos.a
LIBC_ZIPOS_A_FILES := $(wildcard libc/zipos/*)
LIBC_ZIPOS_A_HDRS = $(filter %.h,$(LIBC_ZIPOS_A_FILES))
LIBC_ZIPOS_A_SRCS_S = $(filter %.S,$(LIBC_ZIPOS_A_FILES))
LIBC_ZIPOS_A_SRCS_C = $(filter %.c,$(LIBC_ZIPOS_A_FILES))
LIBC_ZIPOS = \
$(LIBC_ZIPOS_A_DEPS) \
$(LIBC_ZIPOS_A)
LIBC_ZIPOS_A_SRCS = \
$(LIBC_ZIPOS_A_SRCS_S) \
$(LIBC_ZIPOS_A_SRCS_C)
LIBC_ZIPOS_A_OBJS = \
$(LIBC_ZIPOS_A_SRCS_S:%.S=o/$(MODE)/%.o) \
$(LIBC_ZIPOS_A_SRCS_C:%.c=o/$(MODE)/%.o) \
o/$(MODE)/libc/zipos/.cosmo.zip.o
LIBC_ZIPOS_A_CHECKS = \
$(LIBC_ZIPOS_A).pkg \
$(LIBC_ZIPOS_A_HDRS:%=o/$(MODE)/%.ok)
LIBC_ZIPOS_A_DIRECTDEPS = \
LIBC_CALLS \
LIBC_FMT \
LIBC_INTRIN \
LIBC_MEM \
LIBC_NEXGEN32E \
LIBC_NT_KERNEL32 \
LIBC_RUNTIME \
LIBC_STR \
LIBC_SYSV \
LIBC_SYSV_CALLS \
LIBC_THREAD \
THIRD_PARTY_PUFF
LIBC_ZIPOS_A_DEPS := \
$(call uniq,$(foreach zipos,$(LIBC_ZIPOS_A_DIRECTDEPS),$($(zipos))))
$(LIBC_ZIPOS_A):libc/zipos/ \
$(LIBC_ZIPOS_A).pkg \
$(LIBC_ZIPOS_A_OBJS)
$(LIBC_ZIPOS_A).pkg: \
$(LIBC_ZIPOS_A_OBJS) \
$(foreach zipos,$(LIBC_ZIPOS_A_DIRECTDEPS),$($(zipos)_A).pkg)
o/$(MODE)/libc/zipos/.cosmo.zip.o: private \
ZIPOBJ_FLAGS += \
-B
# these assembly files are safe to build on aarch64
o/$(MODE)/libc/zipos/zipos.o: libc/zipos/zipos.S
@$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) -c $<
LIBC_ZIPOS_LIBS = $(foreach zipos,$(LIBC_ZIPOS_ARTIFACTS),$($(zipos)))
LIBC_ZIPOS_SRCS = $(foreach zipos,$(LIBC_ZIPOS_ARTIFACTS),$($(zipos)_SRCS))
LIBC_ZIPOS_HDRS = $(foreach zipos,$(LIBC_ZIPOS_ARTIFACTS),$($(zipos)_HDRS))
LIBC_ZIPOS_BINS = $(foreach zipos,$(LIBC_ZIPOS_ARTIFACTS),$($(zipos)_BINS))
LIBC_ZIPOS_CHECKS = $(foreach zipos,$(LIBC_ZIPOS_ARTIFACTS),$($(zipos)_CHECKS))
LIBC_ZIPOS_OBJS = $(foreach zipos,$(LIBC_ZIPOS_ARTIFACTS),$($(zipos)_OBJS))
LIBC_ZIPOS_TESTS = $(foreach zipos,$(LIBC_ZIPOS_ARTIFACTS),$($(zipos)_TESTS))
$(LIBC_ZIPOS_OBJS): $(BUILD_FILES) libc/zipos/zipos.mk
.PHONY: o/$(MODE)/libc/zipos
o/$(MODE)/libc/zipos: $(LIBC_ZIPOS_CHECKS)

View file

@ -33,7 +33,6 @@ NET_HTTPS_A_DIRECTDEPS = \
LIBC_SYSV \
LIBC_TIME \
LIBC_X \
LIBC_ZIPOS \
THIRD_PARTY_COMPILER_RT \
THIRD_PARTY_MBEDTLS

View file

@ -49,7 +49,6 @@ TEST_LIBC_CALLS_DIRECTDEPS = \
LIBC_TIME \
LIBC_TESTLIB \
LIBC_X \
LIBC_ZIPOS \
TOOL_DECODE_LIB \
THIRD_PARTY_COMPILER_RT \
THIRD_PARTY_XED

View file

@ -38,8 +38,7 @@ TEST_LIBC_LOG_DIRECTDEPS = \
LIBC_STR \
LIBC_TESTLIB \
LIBC_SYSV \
LIBC_LOG \
LIBC_ZIPOS
LIBC_LOG
TEST_LIBC_LOG_DEPS := \
$(call uniq,$(foreach x,$(TEST_LIBC_LOG_DIRECTDEPS),$($(x))))

View file

@ -44,7 +44,6 @@ TEST_LIBC_MEM_DIRECTDEPS = \
LIBC_TESTLIB \
LIBC_THREAD \
LIBC_X \
LIBC_ZIPOS \
THIRD_PARTY_DLMALLOC \
THIRD_PARTY_LIBCXX

View file

@ -37,9 +37,9 @@ TEST_LIBC_RUNTIME_DIRECTDEPS = \
LIBC_TESTLIB \
LIBC_TINYMATH \
LIBC_X \
LIBC_ZIPOS \
TOOL_BUILD_LIB \
THIRD_PARTY_XED
THIRD_PARTY_XED \
THIRD_PARTY_ZLIB
TEST_LIBC_RUNTIME_DEPS := \
$(call uniq,$(foreach x,$(TEST_LIBC_RUNTIME_DIRECTDEPS),$($(x))))

View file

@ -38,7 +38,6 @@ TEST_LIBC_STDIO_DIRECTDEPS = \
LIBC_TIME \
LIBC_LOG \
LIBC_X \
LIBC_ZIPOS \
THIRD_PARTY_GDTOA \
THIRD_PARTY_MBEDTLS \
THIRD_PARTY_MUSL \

View file

@ -45,7 +45,6 @@ TEST_LIBC_STR_DIRECTDEPS = \
LIBC_SYSV_CALLS \
LIBC_TESTLIB \
LIBC_X \
LIBC_ZIPOS \
THIRD_PARTY_COMPILER_RT \
THIRD_PARTY_MBEDTLS \
THIRD_PARTY_REGEX \

View file

@ -19,5 +19,4 @@ o/$(MODE)/test/libc: \
o/$(MODE)/test/libc/time \
o/$(MODE)/test/libc/tinymath \
o/$(MODE)/test/libc/x \
o/$(MODE)/test/libc/zipos \
o/$(MODE)/test/libc/xed

View file

@ -1,62 +0,0 @@
#-*-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 += TEST_LIBC_ZIPOS
TEST_LIBC_ZIPOS_SRCS := $(wildcard test/libc/zipos/*.c)
TEST_LIBC_ZIPOS_SRCS_TEST = $(filter %_test.c,$(TEST_LIBC_ZIPOS_SRCS))
TEST_LIBC_ZIPOS_OBJS = \
$(TEST_LIBC_ZIPOS_SRCS:%.c=o/$(MODE)/%.o)
TEST_LIBC_ZIPOS_COMS = \
$(TEST_LIBC_ZIPOS_SRCS:%.c=o/$(MODE)/%.com)
TEST_LIBC_ZIPOS_BINS = \
$(TEST_LIBC_ZIPOS_COMS) \
$(TEST_LIBC_ZIPOS_COMS:%=%.dbg)
TEST_LIBC_ZIPOS_TESTS = \
$(TEST_LIBC_ZIPOS_SRCS_TEST:%.c=o/$(MODE)/%.com.ok)
TEST_LIBC_ZIPOS_CHECKS = \
$(TEST_LIBC_ZIPOS_SRCS_TEST:%.c=o/$(MODE)/%.com.runs)
TEST_LIBC_ZIPOS_DIRECTDEPS = \
LIBC_CALLS \
LIBC_FMT \
LIBC_INTRIN \
LIBC_MEM \
LIBC_NEXGEN32E \
LIBC_RUNTIME \
LIBC_STR \
LIBC_THREAD \
LIBC_SYSV \
LIBC_ZIPOS \
LIBC_TIME \
LIBC_TESTLIB \
THIRD_PARTY_ZLIB
TEST_LIBC_ZIPOS_DEPS := \
$(call uniq,$(foreach x,$(TEST_LIBC_ZIPOS_DIRECTDEPS),$($(x))))
o/$(MODE)/test/libc/zipos/zipos.pkg: \
$(TEST_LIBC_ZIPOS_OBJS) \
$(foreach x,$(TEST_LIBC_ZIPOS_DIRECTDEPS),$($(x)_A).pkg)
#o/$(MODE)/libc/testlib/hyperion.txt.zip.o: private ZIPOBJ_FLAGS += -0
o/$(MODE)/test/libc/zipos/%.com.dbg: \
$(TEST_LIBC_ZIPOS_DEPS) \
o/$(MODE)/test/libc/zipos/%.o \
o/$(MODE)/test/libc/zipos/zipos.pkg \
o/$(MODE)/libc/testlib/hyperion.txt.zip.o \
$(LIBC_TESTMAIN) \
$(CRT) \
$(APE_NO_MODIFY_SELF)
@$(APELINK)
.PHONY: o/$(MODE)/test/libc/zipos
o/$(MODE)/test/libc/zipos: \
$(TEST_LIBC_ZIPOS_BINS) \
$(TEST_LIBC_ZIPOS_CHECKS)

View file

@ -40,7 +40,6 @@ TEST_TOOL_ARGS_DIRECTDEPS = \
LIBC_STR \
LIBC_SYSV \
LIBC_TESTLIB \
LIBC_ZIPOS \
LIBC_X \
THIRD_PARTY_COMPILER_RT \
TOOL_ARGS

View file

@ -43,7 +43,6 @@ TEST_TOOL_NET_DIRECTDEPS = \
LIBC_TESTLIB \
LIBC_THREAD \
LIBC_X \
LIBC_ZIPOS \
THIRD_PARTY_MBEDTLS \
THIRD_PARTY_REGEX \
THIRD_PARTY_SQLITE3

View file

@ -51,7 +51,6 @@ TEST_TOOL_PLINKO_DIRECTDEPS = \
LIBC_SYSV \
LIBC_TESTLIB \
LIBC_X \
LIBC_ZIPOS \
THIRD_PARTY_COMPILER_RT \
THIRD_PARTY_XED

View file

@ -136,7 +136,6 @@ THIRD_PARTY_GGML_LLAMA_DIRECTDEPS = \
LIBC_SYSV_CALLS \
LIBC_THREAD \
LIBC_TINYMATH \
LIBC_ZIPOS \
THIRD_PARTY_GGML \
THIRD_PARTY_LIBCXX

View file

@ -108,7 +108,6 @@ THIRD_PARTY_MBEDTLS_TEST_DIRECTDEPS = \
LIBC_TIME \
LIBC_TESTLIB \
LIBC_X \
LIBC_ZIPOS \
THIRD_PARTY_COMPILER_RT \
THIRD_PARTY_GDTOA \
THIRD_PARTY_MBEDTLS

View file

@ -1179,7 +1179,6 @@ THIRD_PARTY_PYTHON_STAGE2_A_DIRECTDEPS = \
LIBC_TIME \
LIBC_TINYMATH \
LIBC_X \
LIBC_ZIPOS \
NET_HTTP \
NET_HTTPS \
THIRD_PARTY_BZIP2 \
@ -2099,7 +2098,6 @@ THIRD_PARTY_PYTHON_PYTEST_PYMAINS_DIRECTDEPS = \
LIBC_NEXGEN32E \
LIBC_TESTLIB \
LIBC_LOG \
LIBC_ZIPOS \
LIBC_MEM \
LIBC_INTRIN \
LIBC_X \
@ -4003,7 +4001,6 @@ THIRD_PARTY_PYTHON_PYTHON_DIRECTDEPS = \
LIBC_LOG \
LIBC_SYSV \
LIBC_X \
LIBC_ZIPOS \
THIRD_PARTY_GETOPT \
THIRD_PARTY_LINENOISE \
THIRD_PARTY_PYTHON_STAGE1 \

View file

@ -56,7 +56,6 @@ THIRD_PARTY_SQLITE3_A_DIRECTDEPS = \
LIBC_THREAD \
LIBC_TIME \
LIBC_TINYMATH \
LIBC_ZIPOS \
THIRD_PARTY_COMPILER_RT \
THIRD_PARTY_GDTOA \
THIRD_PARTY_LINENOISE \

View file

@ -24,7 +24,6 @@ THIRD_PARTY_UNZIP_A_DIRECTDEPS = \
LIBC_STR \
LIBC_SYSV \
LIBC_TIME \
LIBC_ZIPOS \
THIRD_PARTY_BZIP2
THIRD_PARTY_UNZIP_A_DEPS := \

View file

@ -27,7 +27,6 @@ TOOL_APE_DIRECTDEPS = \
LIBC_SYSV \
LIBC_TIME \
LIBC_X \
LIBC_ZIPOS \
NET_HTTP \
NET_HTTPS \
THIRD_PARTY_GETOPT \

View file

@ -19,10 +19,10 @@ TOOL_ARGS_A_DIRECTDEPS = \
LIBC_INTRIN \
LIBC_MEM \
LIBC_NEXGEN32E \
LIBC_RUNTIME \
LIBC_STR \
LIBC_SYSV \
LIBC_X \
LIBC_ZIPOS
LIBC_X
TOOL_ARGS_A_DEPS := \
$(call uniq,$(foreach x,$(TOOL_ARGS_A_DIRECTDEPS),$($(x))))

View file

@ -46,7 +46,6 @@ TOOL_BUILD_DIRECTDEPS = \
LIBC_TIME \
LIBC_TINYMATH \
LIBC_X \
LIBC_ZIPOS \
NET_HTTPS \
THIRD_PARTY_COMPILER_RT \
THIRD_PARTY_GDTOA \

View file

@ -26,7 +26,6 @@ TOOL_CURL_DIRECTDEPS = \
LIBC_STR \
LIBC_SYSV \
LIBC_TIME \
LIBC_ZIPOS \
NET_HTTP \
NET_HTTPS \
THIRD_PARTY_GETOPT \

View file

@ -20,7 +20,6 @@ TOOL_HELLO_COMS = \
TOOL_HELLO_DIRECTDEPS = \
LIBC_CALLS \
LIBC_RUNTIME \
LIBC_ZIPOS
TOOL_HELLO_DEPS := \
$(call uniq,$(foreach x,$(TOOL_HELLO_DIRECTDEPS),$($(x))))

View file

@ -48,7 +48,6 @@ TOOL_NET_DIRECTDEPS = \
LIBC_THREAD \
LIBC_TINYMATH \
LIBC_X \
LIBC_ZIPOS \
NET_FINGER \
NET_HTTP \
NET_HTTPS \

View file

@ -27,7 +27,6 @@ TOOL_PLINKO_DIRECTDEPS = \
LIBC_STDIO \
LIBC_X \
LIBC_NEXGEN32E \
LIBC_ZIPOS \
TOOL_PLINKO_LIB
TOOL_PLINKO_DEPS := \

View file

@ -40,7 +40,6 @@ TOOL_VIZ_DIRECTDEPS = \
LIBC_TIME \
LIBC_TINYMATH \
LIBC_X \
LIBC_ZIPOS \
NET_HTTP \
THIRD_PARTY_COMPILER_RT \
THIRD_PARTY_DLMALLOC \