mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-29 08:42:28 +00:00
Rewrite ZipOS
This reduces the virtual memory usage of Emacs for me by 30%. We now have a simpler implementation that uses read(), rather mmap()ing the whole executable.
This commit is contained in:
parent
ff77f2a6af
commit
b01282e23e
21 changed files with 408 additions and 421 deletions
|
@ -1,11 +1,12 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_ZIPOS_ZIPOS_H_
|
||||
#define COSMOPOLITAN_LIBC_ZIPOS_ZIPOS_H_
|
||||
#ifndef COSMOPOLITAN_ZIPOS_H_
|
||||
#define COSMOPOLITAN_ZIPOS_H_
|
||||
#include "libc/thread/thread.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
#define ZIPOS_PATH_MAX 1024
|
||||
|
||||
#define ZIPOS_SYNTHETIC_DIRECTORY 0
|
||||
#define ZIPOS_SYNTHETIC_DIRECTORY -2
|
||||
|
||||
struct stat;
|
||||
struct iovec;
|
||||
|
@ -19,37 +20,43 @@ struct ZiposUri {
|
|||
struct ZiposHandle {
|
||||
struct ZiposHandle *next;
|
||||
struct Zipos *zipos;
|
||||
size_t size;
|
||||
size_t mapsize;
|
||||
size_t pos;
|
||||
size_t cfile;
|
||||
uint8_t *mem;
|
||||
uint8_t data[];
|
||||
int64_t handle; /* original upstream open()'d handle */
|
||||
uint64_t size; /* accessible bytes stored at data[] */
|
||||
uint64_t mapsize; /* the full byte size of this struct */
|
||||
uint64_t pos; /* the file position, relative start */
|
||||
int cfile; /* byte offset into zipos->cdir ents */
|
||||
uint8_t data[]; /* original file content or dir name */
|
||||
};
|
||||
|
||||
struct Zipos {
|
||||
long pagesz;
|
||||
uint8_t *map;
|
||||
uint8_t *cdir;
|
||||
uint64_t dev;
|
||||
size_t *index;
|
||||
size_t records;
|
||||
_Atomic(unsigned) once;
|
||||
int cnt; /* element count, accessible via `index` */
|
||||
int cdirsize; /* number of bytes accessible via `cdir` */
|
||||
uint64_t dev; /* remembers st_dev, of zipos image file */
|
||||
int *index; /* points to cdirsize+cnt*4 mmap'd bytes */
|
||||
uint8_t *cdir; /* points after index, in the above mmap */
|
||||
const char *progpath;
|
||||
struct ZiposHandle *freelist;
|
||||
char *mapend;
|
||||
size_t maptotal;
|
||||
pthread_mutex_t lock;
|
||||
};
|
||||
|
||||
int __zipos_close(int);
|
||||
void __zipos_lock(void);
|
||||
void __zipos_unlock(void);
|
||||
void __zipos_free(struct ZiposHandle *);
|
||||
struct Zipos *__zipos_get(void) pureconst;
|
||||
size_t __zipos_normpath(char *, const char *, size_t);
|
||||
ssize_t __zipos_find(struct Zipos *, struct ZiposUri *);
|
||||
ssize_t __zipos_scan(struct Zipos *, struct ZiposUri *);
|
||||
int __zipos_find(struct Zipos *, struct ZiposUri *);
|
||||
int __zipos_scan(struct Zipos *, struct ZiposUri *);
|
||||
ssize_t __zipos_parseuri(const char *, struct ZiposUri *);
|
||||
uint64_t __zipos_inode(struct Zipos *, int64_t, const void *, size_t);
|
||||
int __zipos_open(struct ZiposUri *, int);
|
||||
int __zipos_access(struct ZiposUri *, int);
|
||||
int __zipos_stat(struct ZiposUri *, struct stat *);
|
||||
int __zipos_fstat(struct ZiposHandle *, struct stat *);
|
||||
int __zipos_stat_impl(struct Zipos *, size_t, struct stat *);
|
||||
int __zipos_stat_impl(struct Zipos *, int, struct stat *);
|
||||
ssize_t __zipos_read(struct ZiposHandle *, const struct iovec *, size_t,
|
||||
ssize_t);
|
||||
int64_t __zipos_seek(struct ZiposHandle *, int64_t, unsigned);
|
||||
|
@ -60,4 +67,4 @@ void *__zipos_mmap(void *, uint64_t, int32_t, int32_t, struct ZiposHandle *,
|
|||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_ZIPOS_ZIPOS_H_ */
|
||||
#endif /* COSMOPOLITAN_ZIPOS_H_ */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue