Parcourir la source

integrate weak definitions and standardize the behavior of reentrant locks

2310863495@qq.com il y a 1 an
Parent
commit
04ff248f5c

+ 110 - 99
ARCH.md

@@ -1,63 +1,74 @@
 [TOC]
 
-## 模块架构图
+## File structure
 
 ```mermaid
 flowchart LR
 mlibc-->src
+
 mlibc-->include
+
 mlibc-->arch
+
 mlibc-->crt
+
+mlibc-->helloworld
+helloworld-->qemu
+qemu-->qemu-device
+
 src-->internal
 src-->stdio
 src-->stdlib
 src-->misc
+
 include-->sys
 ```
 
-## 模块介绍
 
-### 1. src
 
-src目录中有三种类型的文件
+## Module Overview
+
+### 1. src
 
-- internal:存放内部一些内部实现相关的头文件,该部分头文件不对外开放
-- 存放其它标准函数的实现的源文件
+- **src/internal:** Contains header files related to internal implementations. These header files are not exposed externally.
+- **src/module:** Contains source files implementing various standard functions.
 
 ### 2. include
 
-include目录中有三种类型的文件
+- **include/sys:** Contains header files related to the system and system call interfaces.
+- **include (current directory):** Contains public-facing interface headers, such as `stdio.h`.
 
-- sys:存放系统相关及系统调用接口相关的头文件
-- include(当前目录):存放对外开放的接口,如stdio.h
+### 3. arch
 
-> 注:generic存放各个硬件架构通用的一些文件
+Contains implementations of hardware/system-related interfaces or optimizations for different architectures.
 
-### 3. arch
+### 4. crt
+
+Startup code for various architectures.
 
-存放不同架构对于一些硬件/系统相关接口的实现或者是对于一些函数的优化
+### 5. helloworld
 
-## mlibc支持的功能
+## Features Supported by mlibc
 
-### 格式化输入输出
+### Formatted Input and Output
 
-| 函数                                                    | 功能描述                                              |
-| ------------------------------------------------------- | ----------------------------------------------------- |
-| `int printf(const char *, ...);`                        | 格式化输出到标准输出                                  |
-| `void perror(const char *);`                            | 打印错误信息(未实现)                                |
-| `int scanf(const char *, ...);`                         | 从标准输入读取格式化输入**(未实现)**                |
-| `int snprintf(char *, size_t, const char *, ...);`      | 格式化输出到字符串,带大小限制                        |
-| `int sprintf(char *, const char *, ...);`               | 格式化输出到字符串                                    |
-| `int sscanf(const char *, const char *, ...);`          | 从字符串读取格式化输入**(未实现)**                  |
-| `int vfprintf(FILE *, const char *, va_list);`          | 格式化输出到文件流,使用`va_list`                     |
-| `int vfscanf(FILE *, const char *, va_list);`           | 从文件流读取格式化输入,使用`va_list`**(未实现)**   |
-| `int vprintf(const char *, va_list);`                   | 格式化输出到标准输出,使用`va_list`                   |
-| `int vscanf(const char *, va_list);`                    | 从标准输入读取格式化输入,使用`va_list`**(未实现)** |
-| `int vsnprintf(char *, size_t, const char *, va_list);` | 格式化输出到字符串,使用`va_list`并带大小限制         |
-| `int vsprintf(char *, const char *, va_list);`          | 格式化输出到字符串,使用`va_list`                     |
-| `int vsscanf(const char *, const char *, va_list);`     | 从字符串读取格式化输入,使用`va_list`**(未实现)**   |
+| Function                                                | Description                                                  |
+| ------------------------------------------------------- | ------------------------------------------------------------ |
+| `int printf(const char *, ...);`                        | Formats and prints output to the standard output.            |
+| `void perror(const char *);`                            | Prints error messages (**Not Implemented**)                  |
+| `int scanf(const char *, ...);`                         | Reads formatted input from standard input (**Not Implemented**) |
+| `int snprintf(char *, size_t, const char *, ...);`      | Formats and prints output to a string with size limit.       |
+| `int sprintf(char *, const char *, ...);`               | Formats and prints output to a string.                       |
+| `int sscanf(const char *, const char *, ...);`          | Reads formatted input from a string (**Not Implemented**)    |
+| `int vfprintf(FILE *, const char *, va_list);`          | Formats and prints output to a file stream using `va_list`.  |
+| `int vfscanf(FILE *, const char *, va_list);`           | Reads formatted input from a file stream using `va_list` (**Not Implemented**) |
+| `int vprintf(const char *, va_list);`                   | Formats and prints output to the standard output using `va_list`. |
+| `int vscanf(const char *, va_list);`                    | Reads formatted input from standard input using `va_list` (**Not Implemented**) |
+| `int vsnprintf(char *, size_t, const char *, va_list);` | Formats and prints output to a string using `va_list` with size limit. |
+| `int vsprintf(char *, const char *, va_list);`          | Formats and prints output to a string using `va_list`.       |
+| `int vsscanf(const char *, const char *, va_list);`     | Reads formatted input from a string using `va_list` (**Not Implemented**) |
 
-#### printf家族关系表
+#### Relationship Diagram for `printf` Family
 
 ```mermaid
 flowchart TB
@@ -69,78 +80,78 @@ sprintf --> vsnprintf
 snprintf --> vsnprintf
 ```
 
-### 文件读写操作
-
-| 函数                                                   | 功能描述                                             |
-| ------------------------------------------------------ | ---------------------------------------------------- |
-| `int feof(FILE *);`                                    | 检查文件结束符**(未实现)**                         |
-| `int ferror(FILE *);`                                  | 检查文件错误标志**(未实现)**                       |
-| `int fflush(FILE *);`                                  | 刷新文件流                                           |
-| `int fgetc(FILE *);`                                   | 从文件流读取一个字符                                 |
-| `char *fgets(char *, int, FILE *);`                    | 从文件流读取一行**(未实现)**                       |
-| `int fileno(FILE *);`                                  | 获取文件流的文件描述符**(未实现)**                 |
-| `void flockfile(FILE *);`                              | 锁定文件流**(未实现)**                             |
-| `int fprintf(FILE *, const char *, ...);`              | 格式化输出到文件流                                   |
-| `int fputc(int, FILE *);`                              | 向文件流写入一个字符                                 |
-| `int fputs(const char *, FILE *);`                     | 向文件流写入一个字符串                               |
-| `size_t fread(void *, size_t, size_t, FILE *);`        | 从文件流读取数据块                                   |
-| `size_t fwrite(const void *, size_t, size_t, FILE *);` | 向文件流写入数据块                                   |
-| `int ftrylockfile(FILE *);`                            | 尝试锁定文件流**(未实现)**                         |
-| `void funlockfile(FILE *);`                            | 解锁文件流**(未实现)**                             |
-| `int getc(FILE *);`                                    | 从文件流读取一个字符                                 |
-| `int getc_unlocked(FILE *);`                           | 从文件流读取一个字符(非锁定)                       |
-| `int getchar(void);`                                   | 从标准输入读取一个字符                               |
-| `int getchar_unlocked(void);`                          | 从标准输入读取一个字符(非锁定)                     |
-| `char *gets(char *);`                                  | 从标准输入读取一行(不推荐使用,存在缓冲区溢出风险) |
-| `int putc(int, FILE *);`                               | 向文件流写入一个字符                                 |
-| `int putc_unlocked(int, FILE *);`                      | 向文件流写入一个字符(非锁定)                       |
-| `int putchar(int);`                                    | 向标准输出写入一个字符                               |
-| `int putchar_unlocked(int);`                           | 向标准输出写入一个字符(非锁定)                     |
-| `int puts(const char *);`                              | 向标准输出写入一个字符串并换行                       |
-| `int ungetc(int, FILE *);`                             | 将字符放回到文件流**(未实现)**                     |
-
-### 动态内存分配
-
-| 函数                                     | 功能描述                                                     |
+### File I/O Operations
+
+| Function                                               | Description                                                  |
+| ------------------------------------------------------ | ------------------------------------------------------------ |
+| `int feof(FILE *);`                                    | Checks for the end-of-file indicator (**Not Implemented**)   |
+| `int ferror(FILE *);`                                  | Checks for a file error indicator (**Not Implemented**)      |
+| `int fflush(FILE *);`                                  | Flushes a file stream.                                       |
+| `int fgetc(FILE *);`                                   | Reads a character from a file stream.                        |
+| `char *fgets(char *, int, FILE *);`                    | Reads a line from a file stream (**Not Implemented**)        |
+| `int fileno(FILE *);`                                  | Gets the file descriptor of a file stream (**Not Implemented**) |
+| `void flockfile(FILE *);`                              | Locks a file stream (**Not Implemented**)                    |
+| `int fprintf(FILE *, const char *, ...);`              | Formats and writes output to a file stream.                  |
+| `int fputc(int, FILE *);`                              | Writes a character to a file stream.                         |
+| `int fputs(const char *, FILE *);`                     | Writes a string to a file stream.                            |
+| `size_t fread(void *, size_t, size_t, FILE *);`        | Reads blocks of data from a file stream.                     |
+| `size_t fwrite(const void *, size_t, size_t, FILE *);` | Writes blocks of data to a file stream.                      |
+| `int ftrylockfile(FILE *);`                            | Attempts to lock a file stream (**Not Implemented**)         |
+| `void funlockfile(FILE *);`                            | Unlocks a file stream (**Not Implemented**)                  |
+| `int getc(FILE *);`                                    | Reads a character from a file stream.                        |
+| `int getc_unlocked(FILE *);`                           | Reads a character from a file stream (unlocked).             |
+| `int getchar(void);`                                   | Reads a character from standard input.                       |
+| `int getchar_unlocked(void);`                          | Reads a character from standard input (unlocked).            |
+| `char *gets(char *);`                                  | Reads a line from standard input (not recommended due to buffer overflow risk). |
+| `int putc(int, FILE *);`                               | Writes a character to a file stream.                         |
+| `int putc_unlocked(int, FILE *);`                      | Writes a character to a file stream (unlocked).              |
+| `int putchar(int);`                                    | Writes a character to standard output.                       |
+| `int putchar_unlocked(int);`                           | Writes a character to standard output (unlocked).            |
+| `int puts(const char *);`                              | Writes a string to standard output and appends a newline.    |
+| `int ungetc(int, FILE *);`                             | Pushes a character back to a file stream (**Not Implemented**) |
+
+### Dynamic Memory Allocation
+
+| Function                                 | Description                                                  |
 | ---------------------------------------- | ------------------------------------------------------------ |
-| `void *malloc(size_t size);`             | 分配指定大小的内存块                                         |
-| `void *calloc(size_t num, size_t size);` | 分配指定数量的元素,每个元素大小为`size`的内存块,并初始化为零 |
-| `void *realloc(void *ptr, size_t size);` | 调整之前分配的内存块的大小                                   |
-| `void free(void *ptr);`                  | 释放之前分配的内存块                                         |
+| `void *malloc(size_t size);`             | Allocates a block of memory of the specified size.           |
+| `void *calloc(size_t num, size_t size);` | Allocates memory for an array of `num` elements of `size` each and initializes them to zero. |
+| `void *realloc(void *ptr, size_t size);` | Resizes a previously allocated memory block.                 |
+| `void free(void *ptr);`                  | Frees a previously allocated memory block.                   |
 
-### 内存操作函数
+### Memory Manipulation Functions
 
-| 函数                                                        | 功能描述                                              |
-| ----------------------------------------------------------- | ----------------------------------------------------- |
-| `void *memset(void *s, int c, size_t count);`               | 将内存块的前`count`个字节设置为指定值`c`              |
-| `void *memcpy(void *dst, const void *src, size_t count);`   | 将`count`个字节从源地址`src`复制到目标地址`dst`       |
-| `int memcmp(const void *cs, const void *ct, size_t count);` | 比较两个内存块的前`count`个字节                       |
-| `void *memmove(void *d, const void *s, size_t n);`          | 将`n`个字节从源地址`s`移动到目标地址`d`,处理重叠情况 |
-| `void *memchr(const void *m, int c, size_t n);`             | 在前`n`个字节的内存块中搜索值`c`                      |
+| Function                                                    | Description                                                  |
+| ----------------------------------------------------------- | ------------------------------------------------------------ |
+| `void *memset(void *s, int c, size_t count);`               | Sets the first `count` bytes of the memory block to the specified value `c`. |
+| `void *memcpy(void *dst, const void *src, size_t count);`   | Copies `count` bytes from the source address `src` to the destination address `dst`. |
+| `int memcmp(const void *cs, const void *ct, size_t count);` | Compares the first `count` bytes of two memory blocks.       |
+| `void *memmove(void *d, const void *s, size_t n);`          | Moves `n` bytes from the source address `s` to the destination address `d`, handling overlapping regions. |
+| `void *memchr(const void *m, int c, size_t n);`             | Searches for the value `c` in the first `n` bytes of the memory block. |
 
-### 字符串操作函数
+### String Manipulation Functions
 
-| 函数                                                         | 功能描述                                                     |
+| Function                                                     | Description                                                  |
 | ------------------------------------------------------------ | ------------------------------------------------------------ |
-| `size_t strlen(const char *s);`                              | 计算字符串的长度,不包括终止符                               |
-| `int strcmp(const char *cs, const char *ct);`                | 比较两个字符串                                               |
-| `int strncmp(const char *cs, const char *ct, size_t count);` | 比较字符串的前`count`个字符                                  |
-| `char *strcpy(char *d, const char *s);`                      | 将字符串`s`复制到目标`d`                                     |
-| `char *strncpy(char *dst, const char *src, size_t n);`       | 将源字符串`src`的前`n`个字符复制到目标`dst`                  |
-| `char *strcat(char *dest, const char *src);`                 | 将字符串`src`附加到`dest`的末尾                              |
-| `char *strncat(char *dest, const char *src, size_t count);`  | 将源字符串`src`的前`count`个字符附加到目标`dest`的末尾       |
-| `char *strrchr(const char *s, int c);`                       | 在字符串`s`中搜索最后一次出现的字符`c`                       |
-| `char *strchr(const char *str, int c);`                      | 在字符串`str`中搜索第一次出现的字符`c`                       |
-| `char *__strchrnul(const char *s, int c);`                   | 在字符串`s`中搜索第一次出现的字符`c`,如果未找到,返回指向终止符的位置 |
-| `char *strstr(const char *string, const char *substring);`   | 在字符串`string`中搜索第一次出现的子字符串`substring`        |
-| `char *strrev(char *str);`                                   | 反转字符串                                                   |
-| `size_t strcspn(const char *s, const char *c);`              | 计算字符串`s`中第一个包含在字符串`c`中的字符的索引           |
-| `char *strtok_r(char *s, const char *delim, char **last);`   | 分割字符串(线程安全)                                       |
-| `char *strtok(char *s, const char *delim);`                  | 分割字符串(非线程安全)                                     |
-| `char *strpbrk(const char *s1, const char *s2);`             | 在字符串`s1`中搜索第一个包含在字符串`s2`中的字符             |
-| `size_t strspn(const char *s, const char *group);`           | 计算字符串`s`中连续包含在字符串`group`中的字符的长度         |
-| `size_t strxfrm(char *dest, const char *src, size_t n);`     | 按照当前区域设置将`src`转换为一个可比较的形式,并复制到`dest`**(未实现)** |
-
-### 时间处理函数
-
-**TODO**
+| `size_t strlen(const char *s);`                              | Calculates the length of a string, excluding the null terminator. |
+| `int strcmp(const char *cs, const char *ct);`                | Compares two strings.                                        |
+| `int strncmp(const char *cs, const char *ct, size_t count);` | Compares the first `count` characters of two strings.        |
+| `char *strcpy(char *d, const char *s);`                      | Copies the string `s` to the destination `d`.                |
+| `char *strncpy(char *dst, const char *src, size_t n);`       | Copies the first `n` characters of the source string `src` to the destination `dst`. |
+| `char *strcat(char *dest, const char *src);`                 | Appends the string `src` to the end of `dest`.               |
+| `char *strncat(char *dest, const char *src, size_t count);`  | Appends the first `count` characters of the source string `src` to the end of `dest`. |
+| `char *strrchr(const char *s, int c);`                       | Searches for the last occurrence of the character `c` in the string `s`. |
+| `char *strchr(const char *str, int c);`                      | Searches for the first occurrence of the character `c` in the string `str`. |
+| `char *__strchrnul(const char *s, int c);`                   | Searches for the first occurrence of the character `c` in the string `s`; if not found, returns a pointer to the null terminator. |
+| `char *strstr(const char *string, const char *substring);`   | Searches for the first occurrence of the substring `substring` in the string `string`. |
+| `char *strrev(char *str);`                                   | Reverses a string.                                           |
+| `size_t strcspn(const char *s, const char *c);`              | Calculates the index of the first character in `s` that is contained in `c`. |
+| `char *strtok_r(char *s, const char *delim, char **last);`   | Splits a string into tokens (thread-safe).                   |
+| `char *strtok(char *s, const char *delim);`                  | Splits a string into tokens (not thread-safe).               |
+| `char *strpbrk(const char *s1, const char *s2);`             | Searches for the first character in `s1` that is also in `s2`. |
+| `size_t strspn(const char *s, const char *group);`           | Calculates the length of the initial segment of `s` that consists only of characters in `group`. |
+| `size_t strxfrm(char *dest, const char *src, size_t n);`     | Transforms the string `src` into a form that can be compared and copies it to `dest` based on the current locale (**Not Implemented**). |
+
+### Time Handling Functions
+
+**TODO**

+ 157 - 0
ARCH_zh.md

@@ -0,0 +1,157 @@
+[TOC]
+
+## 模块架构图
+
+```mermaid
+flowchart LR
+mlibc-->src
+
+mlibc-->include
+
+mlibc-->arch
+
+mlibc-->crt
+
+mlibc-->helloworld
+helloworld-->qemu
+qemu-->qemu-device
+
+src-->internal
+src-->stdio
+src-->stdlib
+src-->misc
+
+include-->sys
+```
+
+## 模块介绍
+
+### 1. src
+
+- src/internal: 存放内部一些内部实现相关的头文件,该部分头文件不对外开放
+- src/module: 存放其它标准函数的实现的源文件
+
+### 2. include
+
+- include/sys:存放系统相关及系统调用接口相关的头文件
+- include(当前目录):存放对外开放的接口,如stdio.h
+
+### 3. arch
+
+存放不同架构对于一些硬件/系统相关接口的实现或者是对于一些函数的优化
+
+### 4. crt
+
+各个架构的启动代码
+
+### 5. helloworld
+
+
+
+## mlibc支持的功能
+
+### 格式化输入输出
+
+| 函数                                                    | 功能描述                                              |
+| ------------------------------------------------------- | ----------------------------------------------------- |
+| `int printf(const char *, ...);`                        | 格式化输出到标准输出                                  |
+| `void perror(const char *);`                            | 打印错误信息(未实现)                                |
+| `int scanf(const char *, ...);`                         | 从标准输入读取格式化输入**(未实现)**                |
+| `int snprintf(char *, size_t, const char *, ...);`      | 格式化输出到字符串,带大小限制                        |
+| `int sprintf(char *, const char *, ...);`               | 格式化输出到字符串                                    |
+| `int sscanf(const char *, const char *, ...);`          | 从字符串读取格式化输入**(未实现)**                  |
+| `int vfprintf(FILE *, const char *, va_list);`          | 格式化输出到文件流,使用`va_list`                     |
+| `int vfscanf(FILE *, const char *, va_list);`           | 从文件流读取格式化输入,使用`va_list`**(未实现)**   |
+| `int vprintf(const char *, va_list);`                   | 格式化输出到标准输出,使用`va_list`                   |
+| `int vscanf(const char *, va_list);`                    | 从标准输入读取格式化输入,使用`va_list`**(未实现)** |
+| `int vsnprintf(char *, size_t, const char *, va_list);` | 格式化输出到字符串,使用`va_list`并带大小限制         |
+| `int vsprintf(char *, const char *, va_list);`          | 格式化输出到字符串,使用`va_list`                     |
+| `int vsscanf(const char *, const char *, va_list);`     | 从字符串读取格式化输入,使用`va_list`**(未实现)**   |
+
+#### printf家族关系表
+
+```mermaid
+flowchart TB
+printf --> vprintf
+vprintf --> vfprintf
+vfprintf --> vsnprintf
+fprintf --> vfprintf
+sprintf --> vsnprintf
+snprintf --> vsnprintf
+```
+
+### 文件读写操作
+
+| 函数                                                   | 功能描述                                             |
+| ------------------------------------------------------ | ---------------------------------------------------- |
+| `int feof(FILE *);`                                    | 检查文件结束符**(未实现)**                         |
+| `int ferror(FILE *);`                                  | 检查文件错误标志**(未实现)**                       |
+| `int fflush(FILE *);`                                  | 刷新文件流                                           |
+| `int fgetc(FILE *);`                                   | 从文件流读取一个字符                                 |
+| `char *fgets(char *, int, FILE *);`                    | 从文件流读取一行**(未实现)**                       |
+| `int fileno(FILE *);`                                  | 获取文件流的文件描述符**(未实现)**                 |
+| `void flockfile(FILE *);`                              | 锁定文件流**(未实现)**                             |
+| `int fprintf(FILE *, const char *, ...);`              | 格式化输出到文件流                                   |
+| `int fputc(int, FILE *);`                              | 向文件流写入一个字符                                 |
+| `int fputs(const char *, FILE *);`                     | 向文件流写入一个字符串                               |
+| `size_t fread(void *, size_t, size_t, FILE *);`        | 从文件流读取数据块                                   |
+| `size_t fwrite(const void *, size_t, size_t, FILE *);` | 向文件流写入数据块                                   |
+| `int ftrylockfile(FILE *);`                            | 尝试锁定文件流**(未实现)**                         |
+| `void funlockfile(FILE *);`                            | 解锁文件流**(未实现)**                             |
+| `int getc(FILE *);`                                    | 从文件流读取一个字符                                 |
+| `int getc_unlocked(FILE *);`                           | 从文件流读取一个字符(非锁定)                       |
+| `int getchar(void);`                                   | 从标准输入读取一个字符                               |
+| `int getchar_unlocked(void);`                          | 从标准输入读取一个字符(非锁定)                     |
+| `char *gets(char *);`                                  | 从标准输入读取一行(不推荐使用,存在缓冲区溢出风险) |
+| `int putc(int, FILE *);`                               | 向文件流写入一个字符                                 |
+| `int putc_unlocked(int, FILE *);`                      | 向文件流写入一个字符(非锁定)                       |
+| `int putchar(int);`                                    | 向标准输出写入一个字符                               |
+| `int putchar_unlocked(int);`                           | 向标准输出写入一个字符(非锁定)                     |
+| `int puts(const char *);`                              | 向标准输出写入一个字符串并换行                       |
+| `int ungetc(int, FILE *);`                             | 将字符放回到文件流**(未实现)**                     |
+
+### 动态内存分配
+
+| 函数                                     | 功能描述                                                     |
+| ---------------------------------------- | ------------------------------------------------------------ |
+| `void *malloc(size_t size);`             | 分配指定大小的内存块                                         |
+| `void *calloc(size_t num, size_t size);` | 分配指定数量的元素,每个元素大小为`size`的内存块,并初始化为零 |
+| `void *realloc(void *ptr, size_t size);` | 调整之前分配的内存块的大小                                   |
+| `void free(void *ptr);`                  | 释放之前分配的内存块                                         |
+
+### 内存操作函数
+
+| 函数                                                        | 功能描述                                              |
+| ----------------------------------------------------------- | ----------------------------------------------------- |
+| `void *memset(void *s, int c, size_t count);`               | 将内存块的前`count`个字节设置为指定值`c`              |
+| `void *memcpy(void *dst, const void *src, size_t count);`   | 将`count`个字节从源地址`src`复制到目标地址`dst`       |
+| `int memcmp(const void *cs, const void *ct, size_t count);` | 比较两个内存块的前`count`个字节                       |
+| `void *memmove(void *d, const void *s, size_t n);`          | 将`n`个字节从源地址`s`移动到目标地址`d`,处理重叠情况 |
+| `void *memchr(const void *m, int c, size_t n);`             | 在前`n`个字节的内存块中搜索值`c`                      |
+
+### 字符串操作函数
+
+| 函数                                                         | 功能描述                                                     |
+| ------------------------------------------------------------ | ------------------------------------------------------------ |
+| `size_t strlen(const char *s);`                              | 计算字符串的长度,不包括终止符                               |
+| `int strcmp(const char *cs, const char *ct);`                | 比较两个字符串                                               |
+| `int strncmp(const char *cs, const char *ct, size_t count);` | 比较字符串的前`count`个字符                                  |
+| `char *strcpy(char *d, const char *s);`                      | 将字符串`s`复制到目标`d`                                     |
+| `char *strncpy(char *dst, const char *src, size_t n);`       | 将源字符串`src`的前`n`个字符复制到目标`dst`                  |
+| `char *strcat(char *dest, const char *src);`                 | 将字符串`src`附加到`dest`的末尾                              |
+| `char *strncat(char *dest, const char *src, size_t count);`  | 将源字符串`src`的前`count`个字符附加到目标`dest`的末尾       |
+| `char *strrchr(const char *s, int c);`                       | 在字符串`s`中搜索最后一次出现的字符`c`                       |
+| `char *strchr(const char *str, int c);`                      | 在字符串`str`中搜索第一次出现的字符`c`                       |
+| `char *__strchrnul(const char *s, int c);`                   | 在字符串`s`中搜索第一次出现的字符`c`,如果未找到,返回指向终止符的位置 |
+| `char *strstr(const char *string, const char *substring);`   | 在字符串`string`中搜索第一次出现的子字符串`substring`        |
+| `char *strrev(char *str);`                                   | 反转字符串                                                   |
+| `size_t strcspn(const char *s, const char *c);`              | 计算字符串`s`中第一个包含在字符串`c`中的字符的索引           |
+| `char *strtok_r(char *s, const char *delim, char **last);`   | 分割字符串(线程安全)                                       |
+| `char *strtok(char *s, const char *delim);`                  | 分割字符串(非线程安全)                                     |
+| `char *strpbrk(const char *s1, const char *s2);`             | 在字符串`s1`中搜索第一个包含在字符串`s2`中的字符             |
+| `size_t strspn(const char *s, const char *group);`           | 计算字符串`s`中连续包含在字符串`group`中的字符的长度         |
+| `size_t strxfrm(char *dest, const char *src, size_t n);`     | 按照当前区域设置将`src`转换为一个可比较的形式,并复制到`dest`**(未实现)** |
+
+### 时间处理函数
+
+**TODO**

+ 3 - 0
README.md

@@ -27,6 +27,9 @@ Embedded libc, a libc library adapted for embedded systems and bare metal enviro
 │   ├───misc            -- Miscellaneous, contains modules that can be implemented in a single file
 │   ├───stdio           -- Standard IO module
 │   └───stdlib          -- Standard utility library module
+├───helloworld          -- Helloworld testcase
+│	└───qemu			-- QEMU bare-metal config
+│		└───qemu-device	-- Specific to the QEMU virtual machine device, related scripts and header files
 ├───xscript             -- Scripts related to xmake
 └───toolchains          -- xmake scripts related to toolchains
 ```

+ 4 - 1
README_zh.md

@@ -27,7 +27,10 @@ Embedded libc,一个为嵌入式系统和裸机适配的libc库
 │   ├───misc       		-- 杂项,存放单文件就能实现的模块
 |	├───stdio       	-- 标准IO模块
 │   └───stdlib    		-- 标准工具库模块
-├───xscript				-- xmake相关的脚本
+├───helloworld          -- helloworld测试样例
+|	└───qemu			-- qemu裸机测试代码
+|		└───qemu-device	-- 具体到qemu虚拟机设备的相关脚本及头文件
+├───xscript				-- 编译相关的xmake脚本
 └───toolchains		    -- 工具链相关的xmake脚本
 ```
 

+ 0 - 0
src/misc/__errno_location.c → src/dummy/dummy_errno.c


+ 55 - 0
src/dummy/dummy_lock.c

@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) mlibc & plct lab
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2024/9/3   0Bitbiscuits the first version
+ */
+#include <compiler.h>
+
+struct __lock
+{
+    void dummy_lock;
+}
+
+mlibc_weak int __retarget_lock_init(_LOCK_T *lock)
+{
+    return 0;
+}
+
+mlibc_weak int __retarget_lock_init_recursive(_LOCK_T *lock)
+{
+    return 0;
+}
+
+mlibc_weak int __retarget_lock_deinit(_LOCK_T lock)
+{
+    return 0;
+}
+
+mlibc_weak int __retarget_lock_deinit_recursive(_LOCK_T lock)
+{
+    return 0;
+}
+
+mlibc_weak int __retarget_lock_take(_LOCK_T lock)
+{
+    return 0;
+}
+
+mlibc_weak int __retarget_lock_take_recursive(_LOCK_T lock)
+{
+    return 0;
+}
+
+mlibc_weak int __retarget_lock_release(_LOCK_T lock)
+{
+    return 0;
+}
+
+mlibc_weak int __retarget_lock_release_recursive(_LOCK_T lock)
+{
+    return 0;
+}

+ 71 - 0
src/dummy/dummy_posix.c

@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) mlibc & plct lab
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2024/9/3   0Bitbiscuits the first version
+ */
+#include <unistd.h>
+#include <compiler.h>
+#include <errno.h>
+#include <fcntl.h>
+
+mlibc_weak int read(int fd, void *buf, size_t len)
+{
+    (void)fd;
+    (void)buf;
+    (void)len;
+
+    return -EPERM;
+}
+
+mlibc_weak off_t lseek(int fd, off_t offset, int whence)
+{
+    (void)fd;
+    (void)offset;
+    (void)whence;
+
+    return -EPERM;
+}
+
+mlibc_weak ssize_t write(int fd, const void *buf, size_t count)
+{
+    (void)fd;
+    (void)buf;
+    (void)count;
+
+    return -EPERM;
+}
+
+mlibc_weak int open(const char *file, int flags, ...)
+{
+    (void)file;
+    (void)flags;
+
+    return -EPERM;
+}
+
+mlibc_weak int close(int d)
+{
+    (void)d;
+
+    return -EPERM;
+}
+
+mlibc_weak int fcntl(int fd, int cmd, ... /* arg */ )
+{
+    (void)fd;
+    (void)cmd;
+
+    return -EPERM;
+}
+
+mlibc_weak int ioctl(int fildes, int cmd, ...)
+{
+    (void)fildes;
+    (void)cmd;
+
+    return -EPERM;
+}

+ 34 - 38
src/internal/lock.h

@@ -10,25 +10,6 @@
 #ifndef MLIBC_LOCK_H__
 #define MLIBC_LOCK_H__
 
-#ifndef MLIBC_RETARGETABLE_LOCKING
-typedef int _LOCK_T;
-typedef int _LOCK_RECURSIVE_T;
-
-#define __LOCK_INIT(class,lock)             static int lock = 0;
-#define __LOCK_INIT_RECURSIVE(class,lock)   static int lock = 0;
-#define __lock_init(lock)                   ((void) 0)
-#define __lock_init_recursive(lock)         ((void) 0)
-#define __lock_deinit(lock)                  ((void) 0)
-#define __lock_deinit_recursive(lock)        ((void) 0)
-#define __lock_take(lock)                ((void) 0)
-#define __lock_take_recursive(lock)      ((void) 0)
-#define __lock_try_take(lock)            ((void) 0)
-#define __lock_try_take_recursive(lock)  ((void) 0)
-#define __lock_release(lock)                ((void) 0)
-#define __lock_release_recursive(lock)      ((void) 0)
-
-#else
-
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -37,36 +18,53 @@ struct __lock;
 typedef struct __lock * _LOCK_T;
 #define _LOCK_RECURSIVE_T _LOCK_T
 
-#define __LOCK_INIT(class,lock) extern struct __lock __lock_ ## lock; \
-    class _LOCK_T lock = &__lock_ ## lock
-#define __LOCK_INIT_RECURSIVE(class,lock) __LOCK_INIT(class,lock)
-
-/* Lock init */
+/**
+ * @brief Reentrant Lock Initialization Interface
+ * 
+ * @param lock Reentrant Lock pointer
+ * @return int 
+ * Return the operation status. ONLY When the return value is EOK, the operation is successful.
+ * If the return value is any other values, it means that the mutex take failed.
+ */
 extern int __retarget_lock_init(_LOCK_T *lock);
 #define __lock_init(lock) __retarget_lock_init(&lock)
 extern int __retarget_lock_init_recursive(_LOCK_T *lock);
 #define __lock_init_recursive(lock) __retarget_lock_init_recursive(&lock)
 
-/* Lock deinit */
+/**
+ * @brief Reentrant Lock Destroy Interface
+ * 
+ * @param lock Reentrant Lock pointer
+ * @return int 
+ * Return the operation status. ONLY When the return value is EOK, the operation is successful.
+ * If the return value is any other values, it means that the mutex take failed.
+ */
 extern int __retarget_lock_deinit(_LOCK_T lock);
 #define __lock_deinit(lock) __retarget_lock_deinit(lock)
 extern int __retarget_lock_deinit_recursive(_LOCK_T lock);
 #define __lock_deinit_recursive(lock) __retarget_lock_deinit_recursive(lock)
 
-/* Lock take */
-extern int __retarget_lock_take(_LOCK_T lock, int timeout);
-#define __lock_take(lock) __retarget_lock_take(lock, 0)
+/**
+ * @brief Reentrant Lock Take Interface
+ * 
+ * @param lock Reentrant Lock pointer
+ * @return int 
+ * Return the operation status. ONLY When the return value is EOK, the operation is successful.
+ * If the return value is any other values, it means that the mutex take failed.
+ */
+extern int __retarget_lock_take(_LOCK_T lock);
+#define __lock_take(lock) __retarget_lock_take(lock)
 extern int __retarget_lock_take_recursive(_LOCK_T lock);
 #define __lock_take_recursive(lock) __retarget_lock_take_recursive(lock)
 
-/* Lock try take */
-extern int __retarget_lock_try_take(_LOCK_T lock);
-#define __lock_try_take(lock) __retarget_lock_try_take(lock)
-extern int __retarget_lock_try_take_recursive(_LOCK_T lock);
-#define __lock_try_take_recursive(lock) \
-  __retarget_lock_try_take_recursive(lock)
-
-/* Lock release */
+/**
+ * @brief Reentrant Lock Release Interface
+ * 
+ * @param lock Reentrant Lock pointer
+ * @return int 
+ * Return the operation status. ONLY When the return value is EOK, the operation is successful.
+ * If the return value is any other values, it means that the mutex take failed.
+ */
 extern int __retarget_lock_release(_LOCK_T lock);
 #define __lock_release(lock) __retarget_lock_release(lock)
 extern int __retarget_lock_release_recursive(_LOCK_T lock);
@@ -76,6 +74,4 @@ extern int __retarget_lock_release_recursive(_LOCK_T lock);
 }
 #endif
 
-#endif /* MLIBC_RETARGETABLE_LOCKING */
-
 #endif /* MLIBC_LOCK_H__ */

+ 2 - 2
src/internal/mem_impl.h

@@ -21,9 +21,9 @@ extern _LOCK_T heap_lock;
 #define POOL_SIZE   1728                          /* size of pool head*/
 
 #ifdef MLIBC_RETARGETABLE_LOCKING
-#define INIT_HEAP_LOCK __lock_init_recursive(heap_lock)     
+#define INIT_HEAP_LOCK __lock_init_recursive(heap_lock)
 #else
-#define INIT_HEAP_LOCK 1                                    /* support for bare-metal */
+#define INIT_HEAP_LOCK (void*)0                                    /* support for bare-metal */
 #endif /* MLIBC_RETARGETABLE_LOCKING */
 #define LOCK_HEAP   __lock_take_recursive(heap_lock)        /* lock heap */
 #define UNLOCK_HEAP __lock_release_recursive(heap_lock)     /* unlock heap */

+ 0 - 19
src/stdio/close.c

@@ -1,19 +0,0 @@
-/*
- * Copyright (c) mlibc & plct lab
- *
- * SPDX-License-Identifier: MIT
- *
- * Change Logs:
- * Date           Author       Notes
- * 2024/6/4   0Bitbiscuits  the first version
- */
-#include <unistd.h>
-#include <compiler.h>
-#include <errno.h>
-
-mlibc_weak int close(int d)
-{
-    (void)d;
-
-    return -EINVAL;
-}

+ 0 - 21
src/stdio/fcntl.c

@@ -1,21 +0,0 @@
-/*
- * Copyright (c) mlibc & plct lab
- *
- * SPDX-License-Identifier: MIT
- *
- * Change Logs:
- * Date           Author       Notes
- * 2024/6/4   0Bitbiscuits the first version
- */
-#include <unistd.h>
-#include <fcntl.h>
-#include <compiler.h>
-#include <errno.h>
-
-mlibc_weak int fcntl(int fd, int cmd, ... /* arg */ )
-{
-    (void)fd;
-    (void)cmd;
-
-    return -EINVAL;
-}

+ 0 - 21
src/stdio/ioctl.c

@@ -1,21 +0,0 @@
-/*
- * Copyright (c) mlibc & plct lab
- *
- * SPDX-License-Identifier: MIT
- *
- * Change Logs:
- * Date           Author       Notes
- * 2024/6/4   0Bitbiscuits the first version
- */
-#include <unistd.h>
-#include <fcntl.h>
-#include <compiler.h>
-#include <errno.h>
-
-mlibc_weak int ioctl(int fildes, int cmd, ...)
-{
-    (void)fildes;
-    (void)cmd;
-
-    return -EINVAL;
-}

+ 0 - 21
src/stdio/lseek.c

@@ -1,21 +0,0 @@
-/*
- * Copyright (c) mlibc & plct lab
- *
- * SPDX-License-Identifier: MIT
- *
- * Change Logs:
- * Date           Author       Notes
- * 2024/6/4   0Bitbiscuits  the first version
- */
-#include <unistd.h>
-#include <compiler.h>
-#include <errno.h>
-
-mlibc_weak off_t lseek(int fd, off_t offset, int whence)
-{
-    (void)fd;
-    (void)offset;
-    (void)whence;
-
-    return -EINVAL;
-}

+ 0 - 20
src/stdio/open.c

@@ -1,20 +0,0 @@
-/*
- * Copyright (c) mlibc & plct lab
- *
- * SPDX-License-Identifier: MIT
- *
- * Change Logs:
- * Date           Author       Notes
- * 2024/6/4   0Bitbiscuits  the first version
- */
-#include <fcntl.h>
-#include <compiler.h>
-#include <errno.h>
-
-mlibc_weak int open(const char *file, int flags, ...)
-{
-    (void)file;
-    (void)flags;
-
-    return -EINVAL;
-}

+ 0 - 21
src/stdio/read.c

@@ -1,21 +0,0 @@
-/*
- * Copyright (c) mlibc & plct lab
- *
- * SPDX-License-Identifier: MIT
- *
- * Change Logs:
- * Date           Author       Notes
- * 2024/6/4   0Bitbiscuits  the first version
- */
-#include <unistd.h>
-#include <compiler.h>
-#include <errno.h>
-
-mlibc_weak int read(int fd, void *buf, size_t len)
-{
-    (void)fd;
-    (void)buf;
-    (void)len;
-
-    return -EINVAL;
-}

+ 0 - 21
src/stdio/write.c

@@ -1,21 +0,0 @@
-/*
- * Copyright (c) mlibc & plct lab
- *
- * SPDX-License-Identifier: MIT
- *
- * Change Logs:
- * Date           Author       Notes
- * 2024/6/4   0Bitbiscuits  the first version
- */
-#include <unistd.h>
-#include <compiler.h>
-#include <errno.h>
-
-mlibc_weak ssize_t write(int fd, const void *buf, size_t count)
-{
-    (void)fd;
-    (void)buf;
-    (void)count;
-
-    return -1;
-}

+ 1 - 2
src/stdlib/mem_init.c

@@ -30,8 +30,7 @@ mlibc_weak void __mlibc_sys_heap_init(void)
 {   
     if(!tlsf)
     {
-        __lock_init(heap_lock);
-        assert(heap_lock != NULL && "Heap lock init failed\n");
+        assert((INIT_HEAP_LOCK == 0) && "Heap lock init failed\n");
         tlsf = __heap_init(libc_heap, POOL_SIZE);
         assert(tlsf != NULL && "Heap init failed\n");
     }