authorgravatar for lucas.chollet@free.frLucas Chollet <lucas.chollet@free.fr> 2026-08-26 21:03:30+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-08-31 23:15:50+02:00
log536e6625bf45762aec2dc216745253002573b575
treecaeeed2e30808f6c00dfb314749e6ad28ed74f84
parent5bff5eebb28a6faab8b85ba80da2a43e772b014a
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

libcxx: add serenity support


6 files changed, 288 insertions(+), 5 deletions(-)

lib/libcxx/include/__config+5-2
......@@ -236,8 +236,10 @@ typedef __char32_t char32_t;
236236 defined(__MVS__) || \
237237 defined(_AIX) || \
238238 defined(__EMSCRIPTEN__) || \
239 defined(__HAIKU__)
239 defined(__HAIKU__) || \
240 defined(__serenity__)
240241// zig patch: haiku support
242// zig patch: serenity support
241243// clang-format on
242244# undef _LIBCPP_HAS_THREAD_API_PTHREAD
243245# define _LIBCPP_HAS_THREAD_API_PTHREAD 1
......@@ -315,8 +317,9 @@ typedef __char32_t char32_t;
315317# define _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION 0
316318# endif
317319
320// zig patch: serenity support
318321# if defined(__BIONIC__) || defined(__NuttX__) || defined(__Fuchsia__) || defined(__wasi__) || \
319 _LIBCPP_HAS_MUSL_LIBC || defined(__OpenBSD__) || _LIBCPP_LIBC_LLVM_LIBC
322 _LIBCPP_HAS_MUSL_LIBC || defined(__OpenBSD__) || _LIBCPP_LIBC_LLVM_LIBC || defined(__serenity__)
320323# define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE
321324# endif
322325
lib/libcxx/include/__locale_dir/locale_base_api.h+3
......@@ -131,6 +131,9 @@
131131// zig patch: haiku support
132132# elif defined(__HAIKU__)
133133# include <__locale_dir/support/haiku.h>
134// zig patch: serenity support
135# elif defined(__serenity__)
136# include <__locale_dir/support/serenity.h>
134137# else
135138
136139// TODO: This is a temporary definition to bridge between the old way we defined the locale base API
lib/libcxx/include/__locale_dir/messages.h+2-1
......@@ -22,7 +22,8 @@
2222
2323# if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
2424// Most unix variants have catopen. These are the specific ones that don't.
25# if !defined(__BIONIC__) && !_LIBCPP_LIBC_NEWLIB && !defined(__EMSCRIPTEN__)
25// zig patch: serenity support
26# if !defined(__BIONIC__) && !_LIBCPP_LIBC_NEWLIB && !defined(__EMSCRIPTEN__) && !defined(__serenity__)
2627# define _LIBCPP_HAS_CATOPEN 1
2728# include <nl_types.h>
2829# else
lib/libcxx/include/__locale_dir/support/serenity.h created+274
......@@ -0,0 +1,274 @@
1// zig patch: serenity support
2// -*- C++ -*-
3//===-----------------------------------------------------------------------===//
4//
5// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
6// See https://llvm.org/LICENSE.txt for license information.
7// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_SERENITY_H
12#define _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_SERENITY_H
13
14#include <__config>
15#include <__cstddef/size_t.h>
16#include <__std_mbstate_t.h>
17#include <__utility/forward.h>
18#include <clocale> // std::lconv
19#include <ctype.h>
20#include <langinfo.h>
21#include <stdio.h>
22#include <stdlib.h>
23#include <string.h>
24#include <time.h>
25#if _LIBCPP_HAS_WIDE_CHARACTERS
26# include <wchar.h>
27# include <wctype.h>
28#endif
29
30#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
31# pragma GCC system_header
32#endif
33
34_LIBCPP_BEGIN_NAMESPACE_STD
35namespace __locale {
36
37struct __locale_guard {
38 __locale_guard(locale_t& __loc) : __old_loc_(::uselocale(__loc)) {}
39
40 ~__locale_guard() {
41 if (__old_loc_)
42 ::uselocale(__old_loc_);
43 }
44
45 locale_t __old_loc_;
46
47 __locale_guard(__locale_guard const&) = delete;
48 __locale_guard& operator=(__locale_guard const&) = delete;
49};
50
51//
52// Locale management
53//
54#define _LIBCPP_COLLATE_MASK LC_COLLATE_MASK
55#define _LIBCPP_CTYPE_MASK LC_CTYPE_MASK
56#define _LIBCPP_MONETARY_MASK LC_MONETARY_MASK
57#define _LIBCPP_NUMERIC_MASK LC_NUMERIC_MASK
58#define _LIBCPP_TIME_MASK LC_TIME_MASK
59#define _LIBCPP_MESSAGES_MASK LC_MESSAGES_MASK
60#define _LIBCPP_ALL_MASK LC_ALL_MASK
61#define _LIBCPP_LC_ALL LC_ALL
62
63using __locale_t _LIBCPP_NODEBUG = ::locale_t;
64#if defined(_LIBCPP_BUILDING_LIBRARY)
65using __lconv_t _LIBCPP_NODEBUG = std::lconv;
66
67inline __locale_t __newlocale(int __category_mask, const char* __locale, __locale_t __base) {
68 return ::newlocale(__category_mask, __locale, __base);
69}
70
71inline void __freelocale(__locale_t __loc) { ::freelocale(__loc); }
72
73inline char* __setlocale(int __category, char const* __locale) { return ::setlocale(__category, __locale); }
74
75inline __lconv_t* __localeconv(__locale_t& __loc) {
76 __locale_guard __current(__loc);
77 return ::localeconv();
78}
79#endif // _LIBCPP_BUILDING_LIBRARY
80
81//
82// Strtonum functions
83//
84inline float __strtof(const char* __nptr, char** __endptr, __locale_t) { return ::strtof(__nptr, __endptr); }
85
86inline double __strtod(const char* __nptr, char** __endptr, __locale_t) { return ::strtod(__nptr, __endptr); }
87
88inline long double __strtold(const char* __nptr, char** __endptr, __locale_t) { return ::strtold(__nptr, __endptr); }
89
90//
91// Character manipulation functions
92//
93#if defined(_LIBCPP_BUILDING_LIBRARY)
94inline int __toupper(int __c, __locale_t __loc) {
95 __locale_guard __current(__loc);
96 return ::toupper(__c);
97}
98
99inline int __tolower(int __c, __locale_t __loc) {
100 __locale_guard __current(__loc);
101 return ::tolower(__c);
102}
103
104inline int __strcoll(const char* __s1, const char* __s2, __locale_t __loc) {
105 __locale_guard __current(__loc);
106 return ::strcoll(__s1, __s2);
107}
108
109inline size_t __strxfrm(char* __dest, const char* __src, size_t __n, __locale_t __loc) {
110 __locale_guard __current(__loc);
111 return ::strxfrm(__dest, __src, __n);
112}
113
114# if _LIBCPP_HAS_WIDE_CHARACTERS
115inline int __iswctype(wint_t __c, wctype_t __type, __locale_t __loc) {
116 __locale_guard __current(__loc);
117 return ::iswctype(__c, __type); }
118
119inline int __iswspace(wint_t __c, __locale_t __loc) {
120 __locale_guard __current(__loc);
121 return ::iswspace(__c); }
122
123inline int __iswprint(wint_t __c, __locale_t __loc) {
124 __locale_guard __current(__loc);
125 return ::iswprint(__c); }
126
127inline int __iswcntrl(wint_t __c, __locale_t __loc) {
128 __locale_guard __current(__loc);
129 return ::iswcntrl(__c); }
130
131inline int __iswupper(wint_t __c, __locale_t __loc) {
132 __locale_guard __current(__loc);
133 return ::iswupper(__c); }
134
135inline int __iswlower(wint_t __c, __locale_t __loc) {
136 __locale_guard __current(__loc);
137 return ::iswlower(__c); }
138
139inline int __iswalpha(wint_t __c, __locale_t __loc) {
140 __locale_guard __current(__loc);
141 return ::iswalpha(__c); }
142
143inline int __iswblank(wint_t __c, __locale_t __loc) {
144 __locale_guard __current(__loc);
145 return ::iswblank(__c); }
146
147inline int __iswdigit(wint_t __c, __locale_t __loc) {
148 __locale_guard __current(__loc);
149 return ::iswdigit(__c); }
150
151inline int __iswpunct(wint_t __c, __locale_t __loc) {
152 __locale_guard __current(__loc);
153 return ::iswpunct(__c); }
154
155inline int __iswxdigit(wint_t __c, __locale_t __loc) {
156 __locale_guard __current(__loc);
157 return ::iswxdigit(__c); }
158
159inline wint_t __towupper(wint_t __c, __locale_t __loc) {
160 __locale_guard __current(__loc);
161 return ::towupper(__c); }
162
163inline wint_t __towlower(wint_t __c, __locale_t __loc) {
164 __locale_guard __current(__loc);
165 return ::towlower(__c); }
166
167inline int __wcscoll(const wchar_t* __ws1, const wchar_t* __ws2, __locale_t __loc) {
168 __locale_guard __current(__loc);
169 return ::wcscoll(__ws1, __ws2);
170}
171
172inline size_t __wcsxfrm(wchar_t* __dest, const wchar_t* __src, size_t __n, __locale_t __loc) {
173 __locale_guard __current(__loc);
174 return ::wcsxfrm(__dest, __src, __n);
175}
176# endif // _LIBCPP_HAS_WIDE_CHARACTERS
177
178inline _LIBCPP_HIDE_FROM_ABI const char* __get_locale_encoding(__locale_t __loc) {
179 return ::nl_langinfo_l(CODESET, __loc);
180}
181
182inline _LIBCPP_ATTRIBUTE_FORMAT(__strftime__, 3, 0) size_t
183 __strftime(char* __s, size_t __max, const char* __format, const struct tm* __tm, __locale_t __loc) {
184 __locale_guard __current(__loc);
185 return ::strftime(__s, __max, __format, __tm);
186}
187
188//
189// Other functions
190//
191inline decltype(MB_CUR_MAX) __mb_len_max(__locale_t __loc) {
192 __locale_guard __current(__loc);
193 return MB_CUR_MAX;
194}
195
196# if _LIBCPP_HAS_WIDE_CHARACTERS
197inline wint_t __btowc(int __c, __locale_t __loc) {
198 __locale_guard __current(__loc);
199 return btowc(__c);
200}
201
202inline int __wctob(wint_t __c, __locale_t __loc) {
203 __locale_guard __current(__loc);
204 return wctob(__c);
205}
206
207inline size_t
208__wcsnrtombs(char* __dest, const wchar_t** __src, size_t __nwc, size_t __len, mbstate_t* __ps, __locale_t __loc) {
209 __locale_guard __current(__loc);
210 return wcsnrtombs(__dest, __src, __nwc, __len, __ps); // wcsnrtombs is a POSIX extension
211}
212
213inline size_t __wcrtomb(char* __s, wchar_t __wc, mbstate_t* __ps, __locale_t __loc) {
214 __locale_guard __current(__loc);
215 return wcrtomb(__s, __wc, __ps);
216}
217
218inline size_t
219__mbsnrtowcs(wchar_t* __dest, const char** __src, size_t __nms, size_t __len, mbstate_t* __ps, __locale_t __loc) {
220 __locale_guard __current(__loc);
221 return mbsnrtowcs(__dest, __src, __nms, __len, __ps); // mbsnrtowcs is a POSIX extension
222}
223
224inline size_t __mbrtowc(wchar_t* __pwc, const char* __s, size_t __n, mbstate_t* __ps, __locale_t __loc) {
225 __locale_guard __current(__loc);
226 return mbrtowc(__pwc, __s, __n, __ps);
227}
228
229inline int __mbtowc(wchar_t* __pwc, const char* __pmb, size_t __max, __locale_t __loc) {
230 __locale_guard __current(__loc);
231 return mbtowc(__pwc, __pmb, __max);
232}
233
234inline size_t __mbrlen(const char* __s, size_t __n, mbstate_t* __ps, __locale_t __loc) {
235 __locale_guard __current(__loc);
236 return mbrlen(__s, __n, __ps);
237}
238
239inline size_t __mbsrtowcs(wchar_t* __dest, const char** __src, size_t __len, mbstate_t* __ps, __locale_t __loc) {
240 __locale_guard __current(__loc);
241 return mbsrtowcs(__dest, __src, __len, __ps);
242}
243# endif // _LIBCPP_HAS_WIDE_CHARACTERS
244#endif // _LIBCPP_BUILDING_LIBRARY
245
246_LIBCPP_DIAGNOSTIC_PUSH
247_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wgcc-compat")
248_LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wformat-nonliteral") // GCC doesn't support [[gnu::format]] on variadic templates
249#ifdef _LIBCPP_COMPILER_CLANG_BASED
250# define _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(...) _LIBCPP_ATTRIBUTE_FORMAT(__VA_ARGS__)
251#else
252# define _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(...) /* nothing */
253#endif
254
255template <class... _Args>
256_LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(__printf__, 4, 5)
257int __snprintf(char* __s, size_t __n, __locale_t __loc, const char* __format, _Args&&... __args) {
258 __locale_guard __current(__loc);
259 return ::snprintf(__s, __n, __format, std::forward<_Args>(__args)...);
260}
261
262template <class... _Args>
263_LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(__printf__, 3, 4)
264int __asprintf(char** __s, __locale_t __loc, const char* __format, _Args&&... __args) {
265 __locale_guard __current(__loc);
266 return ::asprintf(__s, __format, std::forward<_Args>(__args)...); // non-standard
267}
268_LIBCPP_DIAGNOSTIC_POP
269#undef _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT
270
271} // namespace __locale
272_LIBCPP_END_NAMESPACE_STD
273
274#endif // _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_SERENITY_H
lib/libcxxabi/include/cxxabi.h+2-1
......@@ -180,7 +180,8 @@ extern _LIBCXXABI_FUNC_VIS bool __cxa_uncaught_exception() _LIBCXXABI_NOEXCEPT;
180180extern _LIBCXXABI_FUNC_VIS unsigned int __cxa_uncaught_exceptions() _LIBCXXABI_NOEXCEPT;
181181
182182// zig patch: haiku support
183#if defined(__linux__) || defined(__Fuchsia__) || defined(__HAIKU__)
183// zig patch: serenity support
184#if defined(__linux__) || defined(__Fuchsia__) || defined(__HAIKU__) || defined(__serenity__)
184185// Linux and Fuchsia TLS support. Not yet an official part of the Itanium ABI.
185186// https://sourceware.org/glibc/wiki/Destructor%20support%20for%20thread_local%20variables
186187extern _LIBCXXABI_FUNC_VIS int __cxa_thread_atexit(void (*)(void *), void *,
lib/libcxxabi/src/cxa_thread_atexit.cpp+2-1
......@@ -107,7 +107,8 @@ namespace {
107107#endif // HAVE___CXA_THREAD_ATEXIT_IMPL
108108
109109// zig patch: haiku support
110#if defined(__linux__) || defined(__Fuchsia__) || defined(__HAIKU__)
110// zig patch: serenity support
111#if defined(__linux__) || defined(__Fuchsia__) || defined(__HAIKU__) || defined(__serenity__)
111112extern "C" {
112113
113114 _LIBCXXABI_FUNC_VIS int __cxa_thread_atexit(Dtor dtor, void* obj, void* dso_symbol) throw() {