Skip to content

Commit 42ee008

Browse files
committed
Patch musl for Hyperlight
Signed-off-by: Ludvig Liljenberg <[email protected]>
1 parent c604b99 commit 42ee008

File tree

27 files changed

+77
-50
lines changed

27 files changed

+77
-50
lines changed

src/hyperlight_guest/third_party/musl/arch/x86_64/bits/float.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,22 @@
44
#define FLT_EVAL_METHOD 0
55
#endif
66

7+
#ifdef _MSC_VER
8+
#define LDBL_TRUE_MIN 4.9406564584124654e-324
9+
#define LDBL_MIN 2.2250738585072014e-308
10+
#define LDBL_MAX 1.7976931348623158e+308
11+
#define LDBL_EPSILON 2.2204460492503131e-016
12+
13+
#define LDBL_MANT_DIG 53
14+
#define LDBL_MIN_EXP (-1021)
15+
#define LDBL_MAX_EXP 1024
16+
17+
#define LDBL_DIG 15
18+
#define LDBL_MIN_10_EXP (-307)
19+
#define LDBL_MAX_10_EXP308
20+
21+
#define DECIMAL_DIG 17
22+
#else
723
#define LDBL_TRUE_MIN 3.6451995318824746025e-4951L
824
#define LDBL_MIN 3.3621031431120935063e-4932L
925
#define LDBL_MAX 1.1897314953572317650e+4932L
@@ -18,3 +34,4 @@
1834
#define LDBL_MAX_10_EXP 4932
1935

2036
#define DECIMAL_DIG 21
37+
#endif

src/hyperlight_guest/third_party/musl/include/math.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ extern "C" {
1111
#define __NEED_double_t
1212
#include <bits/alltypes.h>
1313

14-
#if 100*__GNUC__+__GNUC_MINOR__ >= 303
14+
#if 100*__GNUC__+__GNUC_MINOR__ >= 303 || defined (__clang__) && defined(_MSC_VER)
1515
#define NAN __builtin_nanf("")
1616
#define INFINITY __builtin_inff()
1717
#else

src/hyperlight_guest/third_party/musl/include/stdio.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ typedef union _G_fpos64_t {
5959
double __align;
6060
} fpos_t;
6161

62+
#ifndef HYPERLIGHT
63+
6264
extern FILE *const stdin;
6365
extern FILE *const stdout;
6466
extern FILE *const stderr;
@@ -221,4 +223,6 @@ FILE *fopencookie(void *, const char *, cookie_io_functions_t);
221223
}
222224
#endif
223225

226+
#endif //HYPERLIGHT
227+
224228
#endif

src/hyperlight_guest/third_party/musl/include/stdlib.h

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,19 @@ unsigned long strtoul (const char *__restrict, char **__restrict, int);
3434
long long strtoll (const char *__restrict, char **__restrict, int);
3535
unsigned long long strtoull (const char *__restrict, char **__restrict, int);
3636

37-
int rand (void);
38-
void srand (unsigned);
39-
37+
// These 5 functions are implemented in rust in hyperlight_guest
38+
_Noreturn void abort (void);
4039
void *malloc (size_t);
4140
void *calloc (size_t, size_t);
4241
void *realloc (void *, size_t);
4342
void free (void *);
43+
44+
#ifndef HYPERLIGHT
45+
int rand (void);
46+
void srand (unsigned);
47+
4448
void *aligned_alloc(size_t, size_t);
4549

46-
_Noreturn void abort (void);
4750
int atexit (void (*) (void));
4851
_Noreturn void exit (int);
4952
_Noreturn void _Exit (int);
@@ -53,6 +56,7 @@ _Noreturn void quick_exit (int);
5356
char *getenv (const char *);
5457

5558
int system (const char *);
59+
#endif // HYPERLIGHT
5660

5761
void *bsearch (const void *, const void *, size_t, size_t, int (*)(const void *, const void *));
5862
void qsort (void *, size_t, size_t, int (*)(const void *, const void *));
@@ -84,9 +88,9 @@ size_t __ctype_get_mb_cur_max(void);
8488
#define RAND_MAX (0x7fffffff)
8589

8690

87-
#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
91+
#if (defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
8892
|| defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
89-
|| defined(_BSD_SOURCE)
93+
|| defined(_BSD_SOURCE)) && !defined(HYPERLIGHT)
9094

9195
#define WNOHANG 1
9296
#define WUNTRACED 2
@@ -110,8 +114,8 @@ int rand_r (unsigned *);
110114
#endif
111115

112116

113-
#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
114-
|| defined(_BSD_SOURCE)
117+
#if (defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
118+
|| defined(_BSD_SOURCE)) && !defined(HYPERLIGHT)
115119
char *realpath (const char *__restrict, char *__restrict);
116120
long int random (void);
117121
void srandom (unsigned int);
@@ -136,8 +140,8 @@ unsigned short *seed48 (unsigned short [3]);
136140
void lcong48 (unsigned short [7]);
137141
#endif
138142

139-
#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
140143
#include <alloca.h>
144+
#if (defined(_GNU_SOURCE) || defined(_BSD_SOURCE)) && !defined(HYPERLIGHT)
141145
char *mktemp (char *);
142146
int mkstemps (char *, int);
143147
int mkostemps (char *, int, int);

src/hyperlight_guest/third_party/musl/include/sys/time.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,24 @@ struct itimerval {
1919
struct timeval it_value;
2020
};
2121

22-
int getitimer (int, struct itimerval *);
23-
int setitimer (int, const struct itimerval *__restrict, struct itimerval *__restrict);
24-
int utimes (const char *, const struct timeval [2]);
25-
2622
#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
2723
struct timezone {
2824
int tz_minuteswest;
2925
int tz_dsttime;
3026
};
27+
28+
#ifndef HYPERLIGHT
29+
int getitimer (int, struct itimerval *);
30+
int setitimer (int, const struct itimerval *__restrict, struct itimerval *__restrict);
31+
int utimes (const char *, const struct timeval [2]);
32+
3133
int futimes(int, const struct timeval [2]);
3234
int futimesat(int, const char *, const struct timeval [2]);
3335
int lutimes(const char *, const struct timeval [2]);
3436
int settimeofday(const struct timeval *, const struct timezone *);
3537
int adjtime (const struct timeval *, struct timeval *);
38+
#endif // HYPERLIGHT
39+
3640
#define timerisset(t) ((t)->tv_sec || (t)->tv_usec)
3741
#define timerclear(t) ((t)->tv_sec = (t)->tv_usec = 0)
3842
#define timercmp(s,t,op) ((s)->tv_sec == (t)->tv_sec ? \

src/hyperlight_guest/third_party/musl/include/time.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ struct tm {
5151
const char *__tm_zone;
5252
};
5353

54+
#ifndef HYPERLIGHT
5455
clock_t clock (void);
5556
time_t time (time_t *);
5657
double difftime (time_t, time_t);
@@ -61,14 +62,15 @@ struct tm *localtime (const time_t *);
6162
char *asctime (const struct tm *);
6263
char *ctime (const time_t *);
6364
int timespec_get(struct timespec *, int);
65+
#endif // HYPERLIGHT
6466

6567
#define CLOCKS_PER_SEC 1000000L
6668

6769
#define TIME_UTC 1
6870

69-
#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
71+
#if (defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
7072
|| defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
71-
|| defined(_BSD_SOURCE)
73+
|| defined(_BSD_SOURCE)) && !defined(HYPERLIGHT)
7274

7375
size_t strftime_l (char * __restrict, size_t, const char * __restrict, const struct tm * __restrict, locale_t);
7476

@@ -118,7 +120,7 @@ extern char *tzname[2];
118120
#endif
119121

120122

121-
#if defined(_XOPEN_SOURCE) || defined(_BSD_SOURCE) || defined(_GNU_SOURCE)
123+
#if (defined(_XOPEN_SOURCE) || defined(_BSD_SOURCE) || defined(_GNU_SOURCE)) && !defined(HYPERLIGHT)
122124
char *strptime (const char *__restrict, const char *__restrict, struct tm *__restrict);
123125
extern int daylight;
124126
extern long timezone;
@@ -127,7 +129,7 @@ struct tm *getdate (const char *);
127129
#endif
128130

129131

130-
#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
132+
#if (defined(_GNU_SOURCE) || defined(_BSD_SOURCE)) && !defined(HYPERLIGHT)
131133
int stime(const time_t *);
132134
time_t timegm(struct tm *);
133135
#endif

src/hyperlight_guest/third_party/musl/include/wchar.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,10 @@ wchar_t *wcsncat (wchar_t *__restrict, const wchar_t *__restrict, size_t);
5858
int wcscmp (const wchar_t *, const wchar_t *);
5959
int wcsncmp (const wchar_t *, const wchar_t *, size_t);
6060

61+
#ifndef HYPERLIGHT
6162
int wcscoll(const wchar_t *, const wchar_t *);
6263
size_t wcsxfrm (wchar_t *__restrict, const wchar_t *__restrict, size_t);
64+
#endif
6365

6466
wchar_t *wcschr (const wchar_t *, wchar_t);
6567
wchar_t *wcsrchr (const wchar_t *, wchar_t);
@@ -104,7 +106,7 @@ long long wcstoll (const wchar_t *__restrict, wchar_t **__restrict, int);
104106
unsigned long long wcstoull (const wchar_t *__restrict, wchar_t **__restrict, int);
105107

106108

107-
109+
#ifndef HYPERLIGHT
108110
int fwide (FILE *, int);
109111

110112

@@ -136,9 +138,10 @@ wchar_t *fgetws (wchar_t *__restrict, int, FILE *__restrict);
136138
int fputws (const wchar_t *__restrict, FILE *__restrict);
137139

138140
wint_t ungetwc (wint_t, FILE *);
141+
size_t wcsftime (wchar_t *__restrict, size_t, const wchar_t *__restrict, const struct tm *__restrict);
139142

143+
#endif // HYPERLIGHT
140144
struct tm;
141-
size_t wcsftime (wchar_t *__restrict, size_t, const wchar_t *__restrict, const struct tm *__restrict);
142145

143146
#undef iswdigit
144147

@@ -157,6 +160,7 @@ int fputws_unlocked (const wchar_t *__restrict, FILE *__restrict);
157160
size_t wcsftime_l (wchar_t *__restrict, size_t, const wchar_t *__restrict, const struct tm *__restrict, locale_t);
158161
#endif
159162

163+
160164
#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
161165
|| defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
162166
FILE *open_wmemstream(wchar_t **, size_t *);
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
#include <errno.h>
2-
#include "pthread_impl.h"
2+
3+
int errno_val;
34

45
int *__errno_location(void)
56
{
6-
return &__pthread_self()->errno_val;
7+
return &errno_val;
78
}
89

9-
weak_alias(__errno_location, ___errno_location);
10+
weak_alias(__errno_location, ___errno_location);
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#include <stdio.h>
22
#include <stdlib.h>
3+
#include "printf.h"
34

45
_Noreturn void __assert_fail(const char *expr, const char *file, int line, const char *func)
56
{
6-
fprintf(stderr, "Assertion failed: %s (%s: %s: %d)\n", expr, file, func, line);
7+
printf("Assertion failed: %s (%s: %s: %d)\n", expr, file, func, line);
78
abort();
89
}

src/hyperlight_guest/third_party/musl/src/fenv/x86_64/fenv.s

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
.global feclearexcept
2-
.type feclearexcept,@function
32
feclearexcept:
43
# maintain exceptions in the sse mxcsr, clear x87 exceptions
54
mov %edi,%ecx
@@ -20,7 +19,6 @@ feclearexcept:
2019
ret
2120

2221
.global feraiseexcept
23-
.type feraiseexcept,@function
2422
feraiseexcept:
2523
and $0x3f,%edi
2624
stmxcsr -8(%rsp)
@@ -30,8 +28,6 @@ feraiseexcept:
3028
ret
3129

3230
.global __fesetround
33-
.hidden __fesetround
34-
.type __fesetround,@function
3531
__fesetround:
3632
push %rax
3733
xor %eax,%eax
@@ -49,7 +45,6 @@ __fesetround:
4945
ret
5046

5147
.global fegetround
52-
.type fegetround,@function
5348
fegetround:
5449
push %rax
5550
stmxcsr (%rsp)
@@ -59,15 +54,13 @@ fegetround:
5954
ret
6055

6156
.global fegetenv
62-
.type fegetenv,@function
6357
fegetenv:
6458
xor %eax,%eax
6559
fnstenv (%rdi)
6660
stmxcsr 28(%rdi)
6761
ret
6862

6963
.global fesetenv
70-
.type fesetenv,@function
7164
fesetenv:
7265
xor %eax,%eax
7366
inc %rdi
@@ -86,7 +79,6 @@ fesetenv:
8679
ret
8780

8881
.global fetestexcept
89-
.type fetestexcept,@function
9082
fetestexcept:
9183
and $0x3f,%edi
9284
push %rax

src/hyperlight_guest/third_party/musl/src/internal/stdio_impl.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
#define _STDIO_IMPL_H
33

44
#include <stdio.h>
5+
#ifndef HYPERLIGHT
56
#include "syscall.h"
67

78
#define UNGET 8
89

910
#define FFINALLOCK(f) ((f)->lock>=0 ? __lockfile((f)) : 0)
1011
#define FLOCK(f) int __need_unlock = ((f)->lock>=0 ? __lockfile((f)) : 0)
1112
#define FUNLOCK(f) do { if (__need_unlock) __unlockfile((f)); } while (0)
13+
#endif // HYPERLIGHT
1214

1315
#define F_PERM 1
1416
#define F_NORD 4
@@ -47,6 +49,11 @@ struct _IO_FILE {
4749
struct __locale_struct *locale;
4850
};
4951

52+
hidden int __toread(FILE *);
53+
hidden int __towrite(FILE *);
54+
int __uflow(FILE *);
55+
56+
#ifndef HYPERLIGHT
5057
extern hidden FILE *volatile __stdin_used;
5158
extern hidden FILE *volatile __stdout_used;
5259
extern hidden FILE *volatile __stderr_used;
@@ -60,16 +67,13 @@ hidden size_t __stdout_write(FILE *, const unsigned char *, size_t);
6067
hidden off_t __stdio_seek(FILE *, off_t, int);
6168
hidden int __stdio_close(FILE *);
6269

63-
hidden int __toread(FILE *);
64-
hidden int __towrite(FILE *);
65-
6670
hidden void __stdio_exit(void);
6771
hidden void __stdio_exit_needed(void);
6872

6973
#if defined(__PIC__) && (100*__GNUC__+__GNUC_MINOR__ >= 303)
7074
__attribute__((visibility("protected")))
7175
#endif
72-
int __overflow(FILE *, int), __uflow(FILE *);
76+
int __overflow(FILE *, int);
7377

7478
hidden int __fseeko(FILE *, off_t, int);
7579
hidden int __fseeko_unlocked(FILE *, off_t, int);
@@ -110,3 +114,4 @@ hidden FILE *__fopen_rb_ca(const char *, FILE *, unsigned char *, size_t);
110114
hidden int __fclose_ca(FILE *);
111115

112116
#endif
117+
#endif

src/hyperlight_guest/third_party/musl/src/math/x86_64/acosl.s

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# see ../i386/acos.s
22

33
.global acosl
4-
.type acosl,@function
54
acosl:
65
fldt 8(%rsp)
76
1: fld %st(0)

src/hyperlight_guest/third_party/musl/src/math/x86_64/asinl.s

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
.global asinl
2-
.type asinl,@function
32
asinl:
43
fldt 8(%rsp)
54
1: fld %st(0)

src/hyperlight_guest/third_party/musl/src/math/x86_64/atan2l.s

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
.global atan2l
2-
.type atan2l,@function
32
atan2l:
43
fldt 8(%rsp)
54
fldt 24(%rsp)

src/hyperlight_guest/third_party/musl/src/math/x86_64/atanl.s

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
.global atanl
2-
.type atanl,@function
32
atanl:
43
fldt 8(%rsp)
54
fld1

0 commit comments

Comments
 (0)