]> git.proxmox.com Git - wasi-libc.git/commitdiff
Disable unused fields in FILE and __libc.
authorDan Gohman <sunfish@mozilla.com>
Thu, 25 Apr 2019 22:30:07 +0000 (15:30 -0700)
committerDan Gohman <sunfish@mozilla.com>
Mon, 29 Apr 2019 14:33:59 +0000 (07:33 -0700)
Some of these fields are only needed for threads, some are not needed at
all. Removing them helps prevent code from accidentally using them, such
as when we merge in new musl versions.

17 files changed:
libc-top-half/musl/src/internal/libc.h
libc-top-half/musl/src/internal/stdio_impl.h
libc-top-half/musl/src/stdio/__fdopen.c
libc-top-half/musl/src/stdio/__fopen_rb_ca.c
libc-top-half/musl/src/stdio/fmemopen.c
libc-top-half/musl/src/stdio/open_memstream.c
libc-top-half/musl/src/stdio/open_wmemstream.c
libc-top-half/musl/src/stdio/stderr.c
libc-top-half/musl/src/stdio/stdin.c
libc-top-half/musl/src/stdio/stdout.c
libc-top-half/musl/src/stdio/vdprintf.c
libc-top-half/musl/src/stdio/vsnprintf.c
libc-top-half/musl/src/stdio/vsscanf.c
libc-top-half/musl/src/stdio/vswprintf.c
libc-top-half/musl/src/stdio/vswscanf.c
libc-top-half/musl/src/stdlib/wcstod.c
libc-top-half/musl/src/stdlib/wcstol.c

index 9ea374a88077ee1ac0dc9a33057d5b4f444a0e19..0e95d0f4ec6bfe39ba8b47dd75e25bde4aded4c1 100644 (file)
@@ -18,14 +18,26 @@ struct tls_module {
 };
 
 struct __libc {
+#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
        int can_do_threads;
        int threaded;
+#endif
+#ifdef __wasilibc_unmodified_upstream // WASI doesn't currently use any code that needs "secure" mode
        int secure;
+#endif
+#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
        volatile int threads_minus_1;
+#endif
+#ifdef __wasilibc_unmodified_upstream // WASI has no auxv
        size_t *auxv;
+#endif
+#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
        struct tls_module *tls_head;
        size_t tls_size, tls_align, tls_cnt;
+#endif
+#ifdef __wasilibc_unmodified_upstream // WASI doesn't get the page size from auxv
        size_t page_size;
+#endif
        struct __locale_struct global_locale;
 #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
 #else
index 81636700cd295920cb8246dd1c249b9021260e6c..3eb420b4c842acaae7feb023179a5525acea237f 100644 (file)
@@ -30,7 +30,9 @@ struct _IO_FILE {
        unsigned char *rpos, *rend;
        int (*close)(FILE *);
        unsigned char *wend, *wpos;
+#ifdef __wasilibc_unmodified_upstream // WASI doesn't need backwards-compatibility fields.
        unsigned char *mustbezero_1;
+#endif
        unsigned char *wbase;
        size_t (*read)(FILE *, unsigned char *, size_t);
        size_t (*write)(FILE *, const unsigned char *, size_t);
@@ -39,18 +41,28 @@ struct _IO_FILE {
        size_t buf_size;
        FILE *prev, *next;
        int fd;
+#ifdef __wasilibc_unmodified_upstream // WASI has no popen
        int pipe_pid;
+#endif
+#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
        long lockcount;
+#endif
        int mode;
+#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
        volatile int lock;
+#endif
        int lbf;
        void *cookie;
        off_t off;
        char *getln_buf;
+#ifdef __wasilibc_unmodified_upstream // WASI doesn't need backwards-compatibility fields.
        void *mustbezero_2;
+#endif
        unsigned char *shend;
        off_t shlim, shcnt;
+#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
        FILE *prev_locked, *next_locked;
+#endif
        struct __locale_struct *locale;
 };
 
index a76f46c173de03e55a49e4c97d7ecad230e142bc..5c8df495e3db5be3f2d14fa27eb22be823aea8e6 100644 (file)
@@ -74,7 +74,9 @@ FILE *__fdopen(int fd, const char *mode)
        f->seek = __stdio_seek;
        f->close = __stdio_close;
 
+#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
        if (!libc.threaded) f->lock = -1;
+#endif
 
        /* Add new FILE to open file list */
        return __ofl_add(f);
index b2b69c9226251bc2aac63a050a335331f30afb8e..192050b00606031afa188c76f99918ae09237625 100644 (file)
@@ -24,7 +24,9 @@ FILE *__fopen_rb_ca(const char *filename, FILE *f, unsigned char *buf, size_t le
        f->read = __stdio_read;
        f->seek = __stdio_seek;
        f->close = __stdio_close;
+#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
        f->lock = -1;
+#endif
 
        return f;
 }
index 82413b2d8d8386ab17b46fc49c68820551dd5deb..aab13f0fff612985b7f1d3f69c99ff33c395ec30 100644 (file)
@@ -121,7 +121,9 @@ FILE *fmemopen(void *restrict buf, size_t size, const char *restrict mode)
        f->f.seek = mseek;
        f->f.close = mclose;
 
+#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
        if (!libc.threaded) f->f.lock = -1;
+#endif
 
        return __ofl_add(&f->f);
 }
index 600d27705bf526e696c437845fd4844a8716c30e..a54537314f6426076bfed0ff6e46a629c5e9192b 100644 (file)
@@ -93,7 +93,9 @@ FILE *open_memstream(char **bufp, size_t *sizep)
        f->f.close = ms_close;
        f->f.mode = -1;
 
+#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
        if (!libc.threaded) f->f.lock = -1;
+#endif
 
        return __ofl_add(&f->f);
 }
index ed1b561d9c92fa0ce787692dbd27d369292dd0a5..fffec57d1fc71b7039f06777f088a3742625de38 100644 (file)
@@ -94,7 +94,9 @@ FILE *open_wmemstream(wchar_t **bufp, size_t *sizep)
        f->f.seek = wms_seek;
        f->f.close = wms_close;
 
+#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
        if (!libc.threaded) f->f.lock = -1;
+#endif
 
        fwide(&f->f, 1);
 
index f2bc4648d6f0af2f0e8c2ced2531fcef940ad56f..5f24549f83b4379a3695feaf508d881fa0953541 100644 (file)
@@ -12,7 +12,9 @@ hidden FILE __stderr_FILE = {
        .write = __stdio_write,
        .seek = __stdio_seek,
        .close = __stdio_close,
+#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
        .lock = -1,
+#endif
 };
 FILE *const stderr = &__stderr_FILE;
 FILE *volatile __stderr_used = &__stderr_FILE;
index 5aa5262c2a5c8822f9006431898887789421c6e1..68e1c3f643437b43cc3c6ac91bbfd1744c798509 100644 (file)
@@ -11,7 +11,9 @@ hidden FILE __stdin_FILE = {
        .read = __stdio_read,
        .seek = __stdio_seek,
        .close = __stdio_close,
+#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
        .lock = -1,
+#endif
 };
 FILE *const stdin = &__stdin_FILE;
 FILE *volatile __stdin_used = &__stdin_FILE;
index 4985a417bdda733de44f88defcc849eeac9fb427..e0e2bced94103b24ed225b70feba3dde29c07b55 100644 (file)
@@ -12,7 +12,9 @@ hidden FILE __stdout_FILE = {
        .write = __stdout_write,
        .seek = __stdio_seek,
        .close = __stdio_close,
+#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
        .lock = -1,
+#endif
 };
 FILE *const stdout = &__stdout_FILE;
 FILE *volatile __stdout_used = &__stdout_FILE;
index c35d9b4fb0412fdefb2f4a07c198b8de8b451871..e366bfa0c6ff86034b0aad050c4dab0aa6706ba7 100644 (file)
@@ -10,7 +10,9 @@ int vdprintf(int fd, const char *restrict fmt, va_list ap)
        FILE f = {
                .fd = fd, .lbf = EOF, .write = wrap_write,
                .buf = (void *)fmt, .buf_size = 0,
+#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
                .lock = -1
+#endif
        };
        return vfprintf(&f, fmt, ap);
 }
index b3510a63408abe2d4d08e630aa1ddf5b7ba1480a..08989d68ce9c5ab721c32cb66af0d6ec33300a56 100644 (file)
@@ -40,7 +40,9 @@ int vsnprintf(char *restrict s, size_t n, const char *restrict fmt, va_list ap)
        FILE f = {
                .lbf = EOF,
                .write = sn_write,
+#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
                .lock = -1,
+#endif
                .buf = buf,
                .cookie = &c,
        };
index 985002256e32e9a13124c8f0a355f09a4bfa2984..4b0e9e326f3736e57754c2d3cb3c3e2c4c3e8eed 100644 (file)
@@ -9,7 +9,11 @@ int vsscanf(const char *restrict s, const char *restrict fmt, va_list ap)
 {
        FILE f = {
                .buf = (void *)s, .cookie = (void *)s,
+#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
                .read = do_read, .lock = -1
+#else
+               .read = do_read
+#endif
        };
        return vfscanf(&f, fmt, ap);
 }
index 7f98c5c9690e46c604674a9d6afa527cebca4d37..bf9bcaf3a2a162a3f1939834f9288a694a758be9 100644 (file)
@@ -42,7 +42,9 @@ int vswprintf(wchar_t *restrict s, size_t n, const wchar_t *restrict fmt, va_lis
        FILE f = {
                .lbf = EOF,
                .write = sw_write,
+#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
                .lock = -1,
+#endif
                .buf = buf,
                .buf_size = sizeof buf,
                .cookie = &c,
index 00b614bc2f5af24079ebd4f9a793e92090b26647..ea827102d56c690e5eee2f193a0d79acc89d853b 100644 (file)
@@ -30,7 +30,11 @@ int vswscanf(const wchar_t *restrict s, const wchar_t *restrict fmt, va_list ap)
        FILE f = {
                .buf = buf, .buf_size = sizeof buf,
                .cookie = (void *)s,
+#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
                .read = wstring_read, .lock = -1
+#else
+               .read = wstring_read
+#endif
        };
        return vfwscanf(&f, fmt, ap);
 }
index 7b1be70ea49bb3e436548a82dbd1f6b36282d830..bc33e5c9a925802f11a5b585ac00826d547a815d 100644 (file)
@@ -44,7 +44,9 @@ static long double wcstox(const wchar_t *s, wchar_t **p, int prec)
        f.rpos = f.rend = 0;
        f.buf = buf + 4;
        f.buf_size = sizeof buf - 4;
+#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
        f.lock = -1;
+#endif
        f.read = do_read;
        while (iswspace(*t)) t++;
        f.cookie = (void *)t;
index 4443f5772d90ee32d7aa29fda26b54a0520f938c..1aa971b60004a3e7d8c34024745bd0d1c5d3b65a 100644 (file)
@@ -38,7 +38,9 @@ static unsigned long long wcstox(const wchar_t *s, wchar_t **p, int base, unsign
        f.rpos = f.rend = 0;
        f.buf = buf + 4;
        f.buf_size = sizeof buf - 4;
+#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
        f.lock = -1;
+#endif
        f.read = do_read;
        while (iswspace(*t)) t++;
        f.cookie = (void *)t;