From e90b72ec3082588b296956730bd2930cf8d5d671 Mon Sep 17 00:00:00 2001 From: Richard Qin Date: Fri, 10 Jul 2026 11:31:46 +0800 Subject: refactor: promote new architecture to repository root Archive the deprecated implementation under lume-legacy, make the new kernel the default root-level build, and update repository entry points without changing kernel behavior. --- include/libc-shim/bits/alltypes.h | 15 ++++++ include/libc-shim/endian.h | 9 ++++ include/libc-shim/features.h | 12 +++++ include/libc-shim/limits.h | 17 ++++++ include/libc-shim/stdint.h | 21 ++++++++ include/libc-shim/string.h | 110 ++++++++++++++++++++++++++++++++++++++ include/libc-shim/strings.h | 40 ++++++++++++++ 7 files changed, 224 insertions(+) create mode 100644 include/libc-shim/bits/alltypes.h create mode 100644 include/libc-shim/endian.h create mode 100644 include/libc-shim/features.h create mode 100644 include/libc-shim/limits.h create mode 100644 include/libc-shim/stdint.h create mode 100644 include/libc-shim/string.h create mode 100644 include/libc-shim/strings.h (limited to 'include/libc-shim') diff --git a/include/libc-shim/bits/alltypes.h b/include/libc-shim/bits/alltypes.h new file mode 100644 index 0000000..cf21a5e --- /dev/null +++ b/include/libc-shim/bits/alltypes.h @@ -0,0 +1,15 @@ +/* Shim: provide types musl string functions need */ +#ifndef _BITS_ALLTYPES_H +#define _BITS_ALLTYPES_H + +#ifndef __cplusplus +typedef unsigned long size_t; +#endif + +typedef long ssize_t; +typedef unsigned long uintptr_t; + +/* locale_t stub — unused in kernel, but declared by some headers */ +typedef void *locale_t; + +#endif diff --git a/include/libc-shim/endian.h b/include/libc-shim/endian.h new file mode 100644 index 0000000..8346386 --- /dev/null +++ b/include/libc-shim/endian.h @@ -0,0 +1,9 @@ +/* Shim: endianness for musl string functions */ +#ifndef _ENDIAN_H +#define _ENDIAN_H + +#define __LITTLE_ENDIAN 1234 +#define __BIG_ENDIAN 4321 +#define __BYTE_ORDER __LITTLE_ENDIAN /* RISC-V is LE */ + +#endif diff --git a/include/libc-shim/features.h b/include/libc-shim/features.h new file mode 100644 index 0000000..a3466c8 --- /dev/null +++ b/include/libc-shim/features.h @@ -0,0 +1,12 @@ +/* Shim: musl expects this header */ +#ifndef _FEATURES_H +#define _FEATURES_H + +/* weak_alias: musl uses this for symbol aliasing (e.g. __memrchr -> memrchr) */ +#define weak_alias(old, new) \ + extern __typeof(old) new __attribute__((__weak__, __alias__(#old))) + +/* hidden attribute used by some musl sources */ +#define hidden __attribute__((__visibility__("hidden"))) + +#endif diff --git a/include/libc-shim/limits.h b/include/libc-shim/limits.h new file mode 100644 index 0000000..a1d546e --- /dev/null +++ b/include/libc-shim/limits.h @@ -0,0 +1,17 @@ +/* Shim: limits for musl string functions (memmem uses SIZE_MAX) */ +#ifndef _LIMITS_H +#define _LIMITS_H + +#define CHAR_BIT 8 +#define UCHAR_MAX 255 +#define SCHAR_MAX 127 +#define SCHAR_MIN (-128) +#define INT_MAX 2147483647 +#define INT_MIN (-INT_MAX - 1) +#define UINT_MAX 4294967295U +#define LONG_MAX 9223372036854775807L +#define LONG_MIN (-LONG_MAX - 1L) +#define ULONG_MAX 18446744073709551615UL +#define SIZE_MAX ULONG_MAX + +#endif diff --git a/include/libc-shim/stdint.h b/include/libc-shim/stdint.h new file mode 100644 index 0000000..650bdcf --- /dev/null +++ b/include/libc-shim/stdint.h @@ -0,0 +1,21 @@ +/* Shim: stdint types for musl string functions */ +#ifndef _STDINT_H +#define _STDINT_H + +typedef unsigned char uint8_t; +typedef unsigned short uint16_t; +typedef unsigned int uint32_t; +typedef unsigned long uint64_t; +typedef signed char int8_t; +typedef signed short int16_t; +typedef signed int int32_t; +typedef signed long int64_t; +typedef unsigned long uintptr_t; +typedef long intptr_t; + +#define UINT8_MAX 0xFF +#define UINT16_MAX 0xFFFF +#define UINT32_MAX 0xFFFFFFFFU +#define UINT64_MAX 0xFFFFFFFFFFFFFFFFUL + +#endif diff --git a/include/libc-shim/string.h b/include/libc-shim/string.h new file mode 100644 index 0000000..8a86304 --- /dev/null +++ b/include/libc-shim/string.h @@ -0,0 +1,110 @@ +#ifndef _STRING_H +#define _STRING_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#if __cplusplus >= 201103L +#define NULL nullptr +#elif defined(__cplusplus) +#define NULL 0L +#else +#define NULL ((void*)0) +#endif + +#define __NEED_size_t +#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ + || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ + || defined(_BSD_SOURCE) +#define __NEED_locale_t +#endif + +#include + +void *memcpy (void *__restrict, const void *__restrict, size_t); +void *memmove (void *, const void *, size_t); +void *memset (void *, int, size_t); +int memcmp (const void *, const void *, size_t); +void *memchr (const void *, int, size_t); + +char *strcpy (char *__restrict, const char *__restrict); +char *strncpy (char *__restrict, const char *__restrict, size_t); + +char *strcat (char *__restrict, const char *__restrict); +char *strncat (char *__restrict, const char *__restrict, size_t); + +int strcmp (const char *, const char *); +int strncmp (const char *, const char *, size_t); + +int strcoll (const char *, const char *); +size_t strxfrm (char *__restrict, const char *__restrict, size_t); + +char *strchr (const char *, int); +char *strrchr (const char *, int); + +size_t strcspn (const char *, const char *); +size_t strspn (const char *, const char *); +char *strpbrk (const char *, const char *); +char *strstr (const char *, const char *); +char *strtok (char *__restrict, const char *__restrict); + +size_t strlen (const char *); + +char *strerror (int); + +#if defined(_BSD_SOURCE) || defined(_GNU_SOURCE) +#include +#endif + +#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ + || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ + || defined(_BSD_SOURCE) +char *strtok_r (char *__restrict, const char *__restrict, char **__restrict); +int strerror_r (int, char *, size_t); +char *stpcpy(char *__restrict, const char *__restrict); +char *stpncpy(char *__restrict, const char *__restrict, size_t); +size_t strnlen (const char *, size_t); +char *strdup (const char *); +char *strndup (const char *, size_t); +char *strsignal(int); +char *strerror_l (int, locale_t); +int strcoll_l (const char *, const char *, locale_t); +size_t strxfrm_l (char *__restrict, const char *__restrict, size_t, locale_t); +void *memmem(const void *, size_t, const void *, size_t); +#endif + +#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ + || defined(_BSD_SOURCE) +void *memccpy (void *__restrict, const void *__restrict, int, size_t); +#endif + +#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) +char *strsep(char **, const char *); +size_t strlcat (char *, const char *, size_t); +size_t strlcpy (char *, const char *, size_t); +void explicit_bzero (void *, size_t); +#endif + +#ifdef _GNU_SOURCE +#define strdupa(x) strcpy(alloca(strlen(x)+1),x) +int strverscmp (const char *, const char *); +char *strchrnul(const char *, int); +char *strcasestr(const char *, const char *); +void *memrchr(const void *, int, size_t); +void *mempcpy(void *, const void *, size_t); +#endif + +/* musl internal symbols used across translation units */ +char *__strchrnul(const char *, int); +void *__memrchr(const void *, int, size_t); +char *__stpcpy(char *__restrict, const char *__restrict); +char *__stpncpy(char *__restrict, const char *__restrict, size_t); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/libc-shim/strings.h b/include/libc-shim/strings.h new file mode 100644 index 0000000..b7a5ea0 --- /dev/null +++ b/include/libc-shim/strings.h @@ -0,0 +1,40 @@ +#ifndef _STRINGS_H +#define _STRINGS_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#define __NEED_size_t +#define __NEED_locale_t +#include + +#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || defined(_POSIX_SOURCE) \ + || (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE+0 < 200809L) \ + || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE+0 < 700) +int bcmp (const void *, const void *, size_t); +void bcopy (const void *, void *, size_t); +void bzero (void *, size_t); +char *index (const char *, int); +char *rindex (const char *, int); +#endif + +#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) +int ffs (int); +int ffsl (long); +int ffsll (long long); +#endif + +int strcasecmp (const char *, const char *); +int strncasecmp (const char *, const char *, size_t); + +int strcasecmp_l (const char *, const char *, locale_t); +int strncasecmp_l (const char *, const char *, size_t, locale_t); + +#ifdef __cplusplus +} +#endif + +#endif -- cgit v1.2.3