3 Commits 38ced47171 ... e74fa89f68

Author SHA1 Message Date
  coderain e74fa89f68 Merge branch 'master' into mm_rewrite 5 years ago
  coderain dbbcc22291 Fix qsort 5 years ago
  coderain 7be3309df6 Use macros to allow prefixing C runtime library symbols 5 years ago

+ 9 - 7
libraries/mlcrt/include/ctype.h

@@ -1,7 +1,7 @@
 /*
  * ctype.h
  *
- * Copyright (C) 2017 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
+ * Copyright (C) 2019 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as
@@ -20,11 +20,13 @@
 #ifndef _CTYPE_H_
 #define _CTYPE_H_
 
-int isprint(int c);
-int isdigit(int c);
-int isxdigit(int c);
-int isspace(int c);
-char tolower(char c);
-char toupper(char c);
+#include <mlcrt.h>
+
+int __CRT_PUBLIC(isprint)(int c);
+int __CRT_PUBLIC(isdigit)(int c);
+int __CRT_PUBLIC(isxdigit)(int c);
+int __CRT_PUBLIC(isspace)(int c);
+char __CRT_PUBLIC(tolower)(char c);
+char __CRT_PUBLIC(toupper)(char c);
 
 #endif

+ 4 - 3
libraries/mlcrt/include/errno.h

@@ -1,7 +1,7 @@
 /*
  * errno.h
  *
- * Copyright (C) 2017 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
+ * Copyright (C) 2019 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as
@@ -20,6 +20,7 @@
 #ifndef _ERRNO_H_
 #define _ERRNO_H_
 
+#include <mlcrt.h>
 #include <stdint.h>
 
 #define EPERM        1
@@ -66,9 +67,9 @@
 #define ETOOSMALL    45
 #define EOVERFLOW    46
 
-extern int errno;
+extern int __CRT_PUBLIC(errno);
 
-int __crt_translate_error(uint32_t status_code);
+int __CRT_PRIVATE(translate_error)(uint32_t status_code);
 
 #endif
 

+ 8 - 6
libraries/mlcrt/include/malloc.h

@@ -1,7 +1,7 @@
 /*
  * malloc.h
  *
- * Copyright (C) 2017 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
+ * Copyright (C) 2019 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as
@@ -17,6 +17,8 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include "mlcrt.h"
+
 #ifndef _MALLOC_H_
 #define _MALLOC_H_
 
@@ -43,11 +45,11 @@ typedef struct
     void (*lock_mutex_proc)(void*);
     void (*unlock_mutex_proc)(void*);
     void (*problem)(int);
-} __crt_heap_t;
+} __CRT_PRIVATE(heap_t);
 
-void *malloc(size_t size);
-void free(void *ptr);
-void *calloc(size_t nmemb, size_t size);
-void *realloc(void *ptr, size_t size);
+void *__CRT_PUBLIC(malloc)(size_t size);
+void __CRT_PUBLIC(free)(void *ptr);
+void *__CRT_PUBLIC(calloc)(size_t nmemb, size_t size);
+void *__CRT_PUBLIC(realloc)(void *ptr, size_t size);
 
 #endif

+ 37 - 0
libraries/mlcrt/include/mlcrt.h

@@ -0,0 +1,37 @@
+/*
+ * mlcrt.h
+ *
+ * Copyright (C) 2019 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _MLCRT_H_
+#define _MLCRT_H_
+
+#ifndef __CRT_PUBLIC_PREFIX
+#define __CRT_PUBLIC_PREFIX
+#endif
+
+#ifndef __CRT_PRIVATE_PREFIX
+#define __CRT_PRIVATE_PREFIX __crt_
+#endif
+
+#define ___CRT_PASTE(a, b) a ## b
+#define __CRT_PASTE(a, b) ___CRT_PASTE(a, b)
+
+#define __CRT_PUBLIC(x)  __CRT_PASTE(__CRT_PUBLIC_PREFIX, x)
+#define __CRT_PRIVATE(x) __CRT_PASTE(__CRT_PRIVATE_PREFIX, x)
+
+#endif

+ 4 - 3
libraries/mlcrt/include/setjmp.h

@@ -22,14 +22,15 @@
 
 #include <stddef.h>
 #include <monolithium.h>
+#include <mlcrt.h>
 
 typedef struct
 {
     int val;
     thread_state_t state;
-} jmp_buf[1];
+} __CRT_PUBLIC(jmp_buf)[1];
 
-int setjmp(jmp_buf env);
-int longjmp(jmp_buf env, int val);
+int __CRT_PUBLIC(setjmp)(__CRT_PUBLIC(jmp_buf) env);
+int __CRT_PUBLIC(longjmp)(__CRT_PUBLIC(jmp_buf) env, int val);
 
 #endif

+ 79 - 49
libraries/mlcrt/include/stdio.h

@@ -20,66 +20,96 @@
 #ifndef _STDIO_H_
 #define _STDIO_H_
 
+#include <mlcrt.h>
 #include <stdlib.h>
 #include <stdarg.h>
 
 #define EOF -1
 
-#define getc(s) fgetc(s)
-#define getchar() fgetc(stdin)
-#define putc(c, s) fputc(c, s)
-#define putchar(c) fputc(c, stdout)
-
-#define getc_unlocked(s) fgetc_unlocked(s)
-#define getchar_unlocked() fgetc_unlocked(stdin)
-#define putc_unlocked(c, s) fputc_unlocked(c, s)
-#define putchar_unlocked(c) fputc(c, stdout)
-
-struct __crt_file;
-typedef struct __crt_file FILE;
-
-extern FILE *stdin;
-extern FILE *stdout;
-extern FILE *stderr;
-
-int fgetc(FILE *stream);
-int fputc(int c, FILE *stream);
-char *fgets(char *s, int size, FILE *stream);
-int fputs(const char *s, FILE *stream);
-int ungetc(int c, FILE *stream);
-char *gets(char *s);
-int puts(const char *s);
-
-int fgetc_unlocked(FILE *stream);
-int fputc_unlocked(int c, FILE *stream);
-char *fgets_unlocked(char *s, int size, FILE *stream);
-int fputs_unlocked(const char *s, FILE *stream);
-
-FILE *fopen(const char *pathname, const char *mode);
-FILE *fdopen(int fd, const char *mode);
-FILE *fmemopen(void *buf, size_t size, const char *mode);
-int fclose(FILE *stream);
+struct __CRT_PRIVATE(file);
+typedef struct __CRT_PRIVATE(file) FILE;
+
+extern FILE *__CRT_PUBLIC(stdin);
+extern FILE *__CRT_PUBLIC(stdout);
+extern FILE *__CRT_PUBLIC(stderr);
+
+int __CRT_PUBLIC(fgetc)(FILE *stream);
+int __CRT_PUBLIC(fputc)(int c, FILE *stream);
+char *__CRT_PUBLIC(fgets)(char *s, int size, FILE *stream);
+int __CRT_PUBLIC(fputs)(const char *s, FILE *stream);
+int __CRT_PUBLIC(ungetc)(int c, FILE *stream);
+char *__CRT_PUBLIC(gets)(char *s);
+int __CRT_PUBLIC(puts)(const char *s);
+
+static inline int __CRT_PUBLIC(getc)(FILE *stream)
+{
+    return __CRT_PUBLIC(fgetc)(stream);
+}
+
+static inline int __CRT_PUBLIC(getchar)(void)
+{
+    return __CRT_PUBLIC(fgetc)(__CRT_PUBLIC(stdin));
+}
+
+static inline int __CRT_PUBLIC(putc)(int c, FILE *stream)
+{
+    return __CRT_PUBLIC(fputc)(c, stream);
+}
+
+static inline int __CRT_PUBLIC(putchar)(int c)
+{
+    return __CRT_PUBLIC(fputc)(c, __CRT_PUBLIC(stdout));
+}
+
+int __CRT_PUBLIC(fgetc_unlocked)(FILE *stream);
+int __CRT_PUBLIC(fputc_unlocked)(int c, FILE *stream);
+char *__CRT_PUBLIC(fgets_unlocked)(char *s, int size, FILE *stream);
+int __CRT_PUBLIC(fputs_unlocked)(const char *s, FILE *stream);
+
+static inline int __CRT_PUBLIC(getc_unlocked)(FILE *stream)
+{
+    return __CRT_PUBLIC(fgetc_unlocked)(stream);
+}
+
+static inline int __CRT_PUBLIC(getchar_unlocked)(void)
+{
+    return __CRT_PUBLIC(fgetc_unlocked)(__CRT_PUBLIC(stdin));
+}
+
+static inline int __CRT_PUBLIC(putc_unlocked)(int c, FILE *stream)
+{
+    return __CRT_PUBLIC(fputc_unlocked)(c, stream);
+}
+
+static inline int __CRT_PUBLIC(putchar_unlocked)(int c)
+{
+    return __CRT_PUBLIC(fputc)(c, __CRT_PUBLIC(stdout));
+}
+
+FILE *__CRT_PUBLIC(fopen)(const char *pathname, const char *mode);
+FILE *__CRT_PUBLIC(fdopen)(int fd, const char *mode);
+FILE *__CRT_PUBLIC(fmemopen)(void *buf, size_t size, const char *mode);
+int __CRT_PUBLIC(fclose)(FILE *stream);
 
 #define BUFSIZ 4096
 #define _IOFBF 0
 #define _IOLBF 1
 #define _IONBF 2
 
-int setvbuf(FILE *stream, char *buf, int mode, size_t size);
-void setbuf(FILE *stream, char *buf);
-void setbuffer(FILE *stream, char *buf, size_t size);
-void setlinebuf(FILE *stream);
-
-int printf(const char *format, ...);
-int fprintf(FILE *stream, const char *format, ...);
-int dprintf(int fd, const char *format, ...);
-int sprintf(char *str, const char *format, ...);
-int snprintf(char *str, size_t size, const char *format, ...);
-int vprintf(const char *format, va_list ap);
-int vfprintf(FILE *stream, const char *format, va_list ap);
-int vdprintf(int fd, const char *format, va_list ap);
-int vsprintf(char *str, const char *format, va_list ap);
-int vsnprintf(char *str, size_t size, const char *format, va_list ap);
+int __CRT_PUBLIC(setvbuf)(FILE *stream, char *buf, int mode, size_t size);
+void __CRT_PUBLIC(setbuf)(FILE *stream, char *buf);
+void __CRT_PUBLIC(setbuffer)(FILE *stream, char *buf, size_t size);
+void __CRT_PUBLIC(setlinebuf)(FILE *stream);
 
+int __CRT_PUBLIC(printf)(const char *format, ...);
+int __CRT_PUBLIC(fprintf)(FILE *stream, const char *format, ...);
+int __CRT_PUBLIC(dprintf)(int fd, const char *format, ...);
+int __CRT_PUBLIC(sprintf)(char *str, const char *format, ...);
+int __CRT_PUBLIC(snprintf)(char *str, size_t size, const char *format, ...);
+int __CRT_PUBLIC(vprintf)(const char *format, va_list ap);
+int __CRT_PUBLIC(vfprintf)(FILE *stream, const char *format, va_list ap);
+int __CRT_PUBLIC(vdprintf)(int fd, const char *format, va_list ap);
+int __CRT_PUBLIC(vsprintf)(char *str, const char *format, va_list ap);
+int __CRT_PUBLIC(vsnprintf)(char *str, size_t size, const char *format, va_list ap);
 
 #endif

+ 22 - 21
libraries/mlcrt/include/stdlib.h

@@ -20,37 +20,38 @@
 #ifndef _STDLIB_H_
 #define _STDLIB_H_
 
+#include <mlcrt.h>
 #include <stddef.h>
 #include <stdint.h>
 #include <malloc.h>
 #include <errno.h>
 
-char *itoa(int value, char *str, int base);
-char *ltoa(long value, char *str, int base);
-char *lltoa(long long value, char *str, int base);
-char *uitoa(unsigned int value, char *str, int base);
-char *ultoa(unsigned long value, char *str, int base);
-char *ulltoa(unsigned long long value, char *str, int base);
-int atoi(const char *str);
-long atol(const char *str);
-long long atoll(const char *str);
-long strtol(const char *str, char **endptr, int base);
-long long strtoll(const char *str, char **endptr, int base);
-unsigned long strtoul(const char *str, char **endptr, int base);
-unsigned long long strtoull(const char *str, char **endptr, int base);
-
-void qsort(void *base, size_t nmemb, size_t size, int (*compare)(const void*, const void*));
-void *bsearch(const void *key, const void *base, size_t nmemb, size_t size, int (*compare)(const void*, const void*));
+char *__CRT_PUBLIC(itoa)(int value, char *str, int base);
+char *__CRT_PUBLIC(ltoa)(long value, char *str, int base);
+char *__CRT_PUBLIC(lltoa)(long long value, char *str, int base);
+char *__CRT_PUBLIC(uitoa)(unsigned int value, char *str, int base);
+char *__CRT_PUBLIC(ultoa)(unsigned long value, char *str, int base);
+char *__CRT_PUBLIC(ulltoa)(unsigned long long value, char *str, int base);
+int __CRT_PUBLIC(atoi)(const char *str);
+long __CRT_PUBLIC(atol)(const char *str);
+long long __CRT_PUBLIC(atoll)(const char *str);
+long __CRT_PUBLIC(strtol)(const char *str, char **endptr, int base);
+long long __CRT_PUBLIC(strtoll)(const char *str, char **endptr, int base);
+unsigned long __CRT_PUBLIC(strtoul)(const char *str, char **endptr, int base);
+unsigned long long __CRT_PUBLIC(strtoull)(const char *str, char **endptr, int base);
+
+void __CRT_PUBLIC(qsort)(void *base, size_t nmemb, size_t size, int (*compare)(const void*, const void*));
+void *__CRT_PUBLIC(bsearch)(const void *key, const void *base, size_t nmemb, size_t size, int (*compare)(const void*, const void*));
 
 #define ATEXIT_MAX 32
 
-int atexit(void (*function)(void));
-void __attribute__((__noreturn__)) exit(int status);
+int __CRT_PUBLIC(atexit)(void (*function)(void));
+void __attribute__((__noreturn__)) __CRT_PUBLIC(exit)(int status);
 
 typedef uint32_t pid_t;
 
-pid_t getpid(void);
-pid_t getppid(void);
-pid_t fork(void);
+pid_t __CRT_PUBLIC(getpid)(void);
+pid_t __CRT_PUBLIC(getppid)(void);
+pid_t __CRT_PUBLIC(fork)(void);
 
 #endif

+ 20 - 19
libraries/mlcrt/include/string.h

@@ -20,29 +20,30 @@
 #ifndef _STRING_H_
 #define _STRING_H_
 
+#include <mlcrt.h>
 #include <stddef.h>
 #include <stdint.h>
 #include <limits.h>
 #include <ctype.h>
 
-char *strcpy(char *destination, const char *source);
-char *strncpy(char *destination, const char *source, size_t n);
-int strcmp(const char *str1, const char *str2);
-int stricmp(const char *str1, const char *str2);
-int strncmp(const char *str1, const char *str2, size_t n);
-char *strstr(const char *haystack, const char *needle);
-char *strchr(const char *str, char c);
-char *strrchr(const char *str, char c);
-char *strcat(char *destination, const char *source);
-char *strncat(char *destination, const char *source, size_t n);
-char *strdup(const char *source);
-char *strtok(char *str, const char *delimiters);
-char *strtok_r(char *str, const char *delimiters, char **endptr);
-size_t strlen(const char *str);
-void strrev(char *str);
-void memset(void *ptr, int value, size_t n);
-void memcpy(void *destination, const void *source, size_t n);
-void memmove(void *destination, const void *source, size_t n);
-int memcmp(const void *mem1, const void *mem2, size_t n);
+char *__CRT_PUBLIC(strcpy)(char *destination, const char *source);
+char *__CRT_PUBLIC(strncpy)(char *destination, const char *source, size_t n);
+int __CRT_PUBLIC(strcmp)(const char *str1, const char *str2);
+int __CRT_PUBLIC(stricmp)(const char *str1, const char *str2);
+int __CRT_PUBLIC(strncmp)(const char *str1, const char *str2, size_t n);
+char *__CRT_PUBLIC(strstr)(const char *haystack, const char *needle);
+char *__CRT_PUBLIC(strchr)(const char *str, char c);
+char *__CRT_PUBLIC(strrchr)(const char *str, char c);
+char *__CRT_PUBLIC(strcat)(char *destination, const char *source);
+char *__CRT_PUBLIC(strncat)(char *destination, const char *source, size_t n);
+char *__CRT_PUBLIC(strdup)(const char *source);
+char *__CRT_PUBLIC(strtok)(char *str, const char *delimiters);
+char *__CRT_PUBLIC(strtok_r)(char *str, const char *delimiters, char **endptr);
+size_t __CRT_PUBLIC(strlen)(const char *str);
+void __CRT_PUBLIC(strrev)(char *str);
+void __CRT_PUBLIC(memset)(void *ptr, int value, size_t n);
+void __CRT_PUBLIC(memcpy)(void *destination, const void *source, size_t n);
+void __CRT_PUBLIC(memmove)(void *destination, const void *source, size_t n);
+int __CRT_PUBLIC(memcmp)(const void *mem1, const void *mem2, size_t n);
 
 #endif

+ 12 - 11
libraries/mlcrt/include/unistd.h

@@ -20,6 +20,7 @@
 #ifndef _UNISTD_H_
 #define _UNISTD_H_
 
+#include <mlcrt.h>
 #include <stddef.h>
 #include <stdint.h>
 
@@ -47,20 +48,20 @@ typedef uint16_t mode_t;
 typedef ptrdiff_t off_t;
 typedef ptrdiff_t ssize_t;
 
-char *getcwd(char *buf, size_t size);
-char *getwd(char *buf);
-char *get_current_dir_name(void);
-int fchdir(int fd);
-int chdir(const char *path);
+char *__CRT_PUBLIC(getcwd)(char *buf, size_t size);
+char *__CRT_PUBLIC(getwd)(char *buf);
+char *__CRT_PUBLIC(get_current_dir_name)(void);
+int __CRT_PUBLIC(fchdir)(int fd);
+int __CRT_PUBLIC(chdir)(const char *path);
 
 #ifndef __DONT_DEFINE_OPEN__
-int open(const char *pathname, int flags, ...);
+int __CRT_PUBLIC(open)(const char *pathname, int flags, ...);
 #endif
 
-int creat(const char *pathname, mode_t mode);
-int close(int fd);
-ssize_t read(int fd, void *buf, size_t count);
-ssize_t write(int fd, const void *buf, size_t count);
-off_t lseek(int fd, off_t offset, int whence);
+int __CRT_PUBLIC(creat)(const char *pathname, mode_t mode);
+int __CRT_PUBLIC(close)(int fd);
+ssize_t __CRT_PUBLIC(read)(int fd, void *buf, size_t count);
+ssize_t __CRT_PUBLIC(write)(int fd, const void *buf, size_t count);
+off_t __CRT_PUBLIC(lseek)(int fd, off_t offset, int whence);
 
 #endif

+ 0 - 0
libraries/mlcrt/src/algorithm.c


Some files were not shown because too many files changed in this diff