aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBen Hutchings <ben@decadent.org.uk>2020-07-25 21:18:30 +0100
committerBen Hutchings <ben@decadent.org.uk>2020-07-25 21:44:14 +0100
commit8c056cab6c8cce0b5dbc2c3141060f89a6ffc905 (patch)
tree1045e01ca7ffa74e111418574a9d86338054657a
parent1aacafeba630135c2d8377887486f5e369b598f9 (diff)
downloadklibc-8c056cab6c8cce0b5dbc2c3141060f89a6ffc905.tar.gz
[klibc] stdio: Define all the _unlocked functions and macros
Clang 9.0 can optimise stdio function calls to use the _unlocked variants, presumably based on escape analysis. We don't define many of them, and adding a lot of -fno-builtin-* options to inhibit this seems like a losing battle. Since we don't support multi-threaded programs or locking in stdio, define the _unlocked function names as aliases. For completeness, also define corresponding _unlocked macros for the macro-only pseudo-functions, and for the inline functions in stdio.h. Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
-rw-r--r--usr/include/stdio.h20
-rw-r--r--usr/klibc/fgets.c1
-rw-r--r--usr/klibc/fputc.c1
-rw-r--r--usr/klibc/fputs.c1
-rw-r--r--usr/klibc/fread2.c1
-rw-r--r--usr/klibc/fwrite2.c2
-rw-r--r--usr/klibc/stdio/clearerr.c1
-rw-r--r--usr/klibc/stdio/feof.c1
-rw-r--r--usr/klibc/stdio/ferror.c1
-rw-r--r--usr/klibc/stdio/fflush.c2
-rw-r--r--usr/klibc/stdio/fgetc.c1
-rw-r--r--usr/klibc/stdio/fileno.c1
12 files changed, 32 insertions, 1 deletions
diff --git a/usr/include/stdio.h b/usr/include/stdio.h
index 1d45fe1aa4649b..521213df4e3729 100644
--- a/usr/include/stdio.h
+++ b/usr/include/stdio.h
@@ -48,17 +48,24 @@ __extern int fseek(FILE *, off_t, int);
#define fseeko fseek
__extern void rewind(FILE *);
__extern int fputs(const char *, FILE *);
+__extern int fputs_unlocked(const char *, FILE *);
__extern int puts(const char *);
__extern int fputc(int, FILE *);
+__extern int fputc_unlocked(int, FILE *);
#define putc(c,f) fputc((c),(f))
+#define putc_unlocked(c,f) putc((c),(f))
#define putchar(c) fputc((c),stdout)
+#define putchar_unlocked(c) putchar(c)
__extern int fgetc(FILE *);
+__extern int fgetc_unlocked(FILE *);
__extern char *fgets(char *, int, FILE *);
+__extern char *fgets_unlocked(char *, int, FILE *);
#define getc(f) fgetc(f)
__extern int getc_unlocked(FILE *);
#define getc_unlocked(f) fgetc(f)
#define getchar() fgetc(stdin)
+#define getchar_unlocked() getchar()
__extern int ungetc(int, FILE *);
__extern int printf(const char *, ...);
@@ -86,17 +93,24 @@ __extern int remove(const char *);
__extern size_t _fread(void *, size_t, FILE *);
__extern size_t _fwrite(const void *, size_t, FILE *);
__extern int fflush(FILE *);
+__extern int fflush_unlocked(FILE *);
__extern size_t fread(void *, size_t, size_t, FILE *);
+__extern size_t fread_unlocked(void *, size_t, size_t, FILE *);
__extern size_t fwrite(const void *, size_t, size_t, FILE *);
+__extern size_t fwrite_unlocked(const void *, size_t, size_t, FILE *);
__extern off_t ftell(FILE *__f);
#define ftello ftell
__extern int ferror(FILE * );
+__extern int ferror_unlocked(FILE * );
__extern int feof(FILE *);
+__extern int feof_unlocked(FILE *);
__extern int fileno(FILE *);
+__extern int fileno_unlocked(FILE *);
__extern void clearerr(FILE *);
+__extern void clearerr_unlocked(FILE *);
#ifndef __NO_STDIO_INLINES
__extern_inline size_t
@@ -104,33 +118,39 @@ fread(void *__p, size_t __s, size_t __n, FILE * __f)
{
return _fread(__p, __s * __n, __f) / __s;
}
+#define fread_unlocked(p, s, n, f) fread((p), (s), (n), (f))
__extern_inline size_t
fwrite(const void *__p, size_t __s, size_t __n, FILE * __f)
{
return _fwrite(__p, __s * __n, __f) / __s;
}
+#define fwrite_unlocked(p, s, n, f) fwrite((p), (s), (n), (f))
__extern_inline int fileno(FILE *__f)
{
return __f->_IO_fileno;
}
+#define fileno_unlocked(f) fileno(f)
__extern_inline int ferror(FILE *__f)
{
return __f->_IO_error;
}
+#define ferror_unlocked(f) ferror(f)
__extern_inline int feof(FILE *__f)
{
return __f->_IO_eof;
}
+#define feof_unlocked(f) feof(f)
__extern_inline void clearerr(FILE *__f)
{
__f->_IO_error = 0;
__f->_IO_eof = 0;
}
+#define clearerr_unlocked(f) clearerr(f)
#endif
#endif /* _STDIO_H */
diff --git a/usr/klibc/fgets.c b/usr/klibc/fgets.c
index dbf742c68779b6..b6e6f3ea5efd3c 100644
--- a/usr/klibc/fgets.c
+++ b/usr/klibc/fgets.c
@@ -25,3 +25,4 @@ char *fgets(char *s, int n, FILE *f)
return s;
}
+__ALIAS(char *, fgets_unlocked, (char *, int, FILE *), fgets)
diff --git a/usr/klibc/fputc.c b/usr/klibc/fputc.c
index 386d86cb0ae292..7385d6fcd9315b 100644
--- a/usr/klibc/fputc.c
+++ b/usr/klibc/fputc.c
@@ -12,3 +12,4 @@ int fputc(int c, FILE *f)
return _fwrite(&ch, 1, f) == 1 ? ch : EOF;
}
+__ALIAS(int, fputc_unlocked, (int, FILE *), fputc)
diff --git a/usr/klibc/fputs.c b/usr/klibc/fputs.c
index fb240d69b9e55f..cbc2056be53045 100644
--- a/usr/klibc/fputs.c
+++ b/usr/klibc/fputs.c
@@ -13,3 +13,4 @@ int fputs(const char *s, FILE *file)
{
return _fwrite(s, strlen(s), file);
}
+__ALIAS(int, fputs_unlocked, (const char *, FILE *), fputs)
diff --git a/usr/klibc/fread2.c b/usr/klibc/fread2.c
index 7dca56b163313d..f5b2acb4a16429 100644
--- a/usr/klibc/fread2.c
+++ b/usr/klibc/fread2.c
@@ -11,3 +11,4 @@ size_t fread(void *ptr, size_t size, size_t nmemb, FILE * f)
{
return _fread(ptr, size * nmemb, f) / size;
}
+__ALIAS(size_t, fread_unlocked, (void *, size_t, size_t, FILE *), fread)
diff --git a/usr/klibc/fwrite2.c b/usr/klibc/fwrite2.c
index cebc017c68b662..a8c14c98af6b0b 100644
--- a/usr/klibc/fwrite2.c
+++ b/usr/klibc/fwrite2.c
@@ -11,3 +11,5 @@ size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE * f)
{
return _fwrite(ptr, size * nmemb, f) / size;
}
+__ALIAS(size_t, fwrite_unlocked, (const void *, size_t, size_t, FILE *),
+ fwrite)
diff --git a/usr/klibc/stdio/clearerr.c b/usr/klibc/stdio/clearerr.c
index fb56514422365b..ebdd22def2170f 100644
--- a/usr/klibc/stdio/clearerr.c
+++ b/usr/klibc/stdio/clearerr.c
@@ -6,3 +6,4 @@ void clearerr(FILE *__f)
__f->_IO_error = 0;
__f->_IO_eof = 0;
}
+__ALIAS(void, clearerr_unlocked, (FILE *), clearerr)
diff --git a/usr/klibc/stdio/feof.c b/usr/klibc/stdio/feof.c
index 590b1c5912893d..4215c113dae7d3 100644
--- a/usr/klibc/stdio/feof.c
+++ b/usr/klibc/stdio/feof.c
@@ -5,3 +5,4 @@ int feof(FILE *__f)
{
return __f->_IO_eof;
}
+__ALIAS(int, feof_unlocked, (FILE *), feof)
diff --git a/usr/klibc/stdio/ferror.c b/usr/klibc/stdio/ferror.c
index 8b36e443cb595d..819743b9b715b1 100644
--- a/usr/klibc/stdio/ferror.c
+++ b/usr/klibc/stdio/ferror.c
@@ -5,3 +5,4 @@ int ferror(FILE *__f)
{
return __f->_IO_error;
}
+__ALIAS(int, ferror_unlocked, (FILE *), ferror)
diff --git a/usr/klibc/stdio/fflush.c b/usr/klibc/stdio/fflush.c
index dfccd24d4f8d1c..6ac5cf576d11a1 100644
--- a/usr/klibc/stdio/fflush.c
+++ b/usr/klibc/stdio/fflush.c
@@ -56,5 +56,5 @@ int fflush(FILE *file)
return err;
}
}
-
+__ALIAS(int, fflush_unlocked, (FILE *), fflush)
diff --git a/usr/klibc/stdio/fgetc.c b/usr/klibc/stdio/fgetc.c
index a0e8650fee56e0..5d1fc06ccc29f8 100644
--- a/usr/klibc/stdio/fgetc.c
+++ b/usr/klibc/stdio/fgetc.c
@@ -16,3 +16,4 @@ int fgetc(FILE *file)
return _fread(&ch, 1, file) == 1 ? ch : EOF;
}
}
+__ALIAS(int, fgetc_unlocked, (FILE *), fgetc)
diff --git a/usr/klibc/stdio/fileno.c b/usr/klibc/stdio/fileno.c
index b5a101618684e6..16c15dd8ebf3d3 100644
--- a/usr/klibc/stdio/fileno.c
+++ b/usr/klibc/stdio/fileno.c
@@ -5,3 +5,4 @@ int fileno(FILE *__f)
{
return __f->_IO_fileno;
}
+__ALIAS(int, fileno_unlocked, (FILE *), fileno)