Commit Graph

13 Commits

Author SHA1 Message Date
Xiang Xiao 2c9511e655 libc/stdio: Remove bforce from lib_fflush[_unlocked]
since all callers set bforce to true

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-10-29 17:09:18 +02:00
Michal Lenc 0a107ca6d9 libc: add support for custom streams with fopencookie()
This commit adds support for custom stream via fopencookie function.
The function allows the programmer the create his own custom stream
for IO operations and hook his custom functions to it.

This is a non POSIX interface defined in Standard C library and implemented
according to it. The only difference is in usage of off_t instead of
off64_t. Programmer can use 64 bits offset if CONFIG_FS_LARGEFILE is
enabled. In that case off_t is defined as int64_t (int32_t otherwise).

Field fs_fd is removed from file_struct and fs_cookie is used instead
as a shared variable for file descriptor or user defined cookie.

The interface will be useful for future fmemopen implementation.

Signed-off-by: Michal Lenc <michallenc@seznam.cz>
2023-10-18 21:13:01 +08:00
hujun5 90387a5b41 libc/misc: add fdsan module
FD (file descriptor) is widely used in system software development,
and almost all implementations of posix os (including nuttx) use FD as an index.
the value of fd needs to be allocated starting from the minimum available value of 3, and each process has a copy,
so the same fd value is very easy to reuse in the program.

In multi threaded or multi process environments without address isolation,
If the ownership, global variables, and competition relationships of fd are not properly handled,
there may be issues with fd duplication or accidental closure.
Further leading to the following issues, which are difficult to troubleshoot.

1. Security vulnerability: the fd we wrote is not the expected fd and will be accessed by hackers to obtain data
2. Program exceptions or crashes: write or read fd failures, and program logic errors
3. The structured file XML or database is damaged: the data format written to the database is not the expected format.

The implementation principle of fdsan is based on the implementation of Android
https://android.googlesource.com/platform/bionic/+/master/docs/fdsan.md

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2023-05-17 10:24:42 +08:00
Ville Juven 2ed51d026c fs/streams: Move the file streams from the group structure into TLS
This is preparation for flushing streams from user space, like it should
be done.

- Move tg_streamlist (group, kernel space) ->
       ta_streamlist (TLS, user space)
- Access stream list via tg_info in kernel
- Access stream list via TLS in user space
- Remove / rename nxsched_get_streams -> lib_getstreams
- Remove system call for nxsched_get_streams
2022-12-22 20:16:11 +08:00
Xiang Xiao 898093a822 libc/stdio: Remove the one line mutex wrapper
and call nxmutex api directly

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-11-09 21:38:10 +01:00
anjiahao d1d46335df Replace nxsem API when used as a lock with nxmutex API
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-10-17 15:59:46 +09:00
anjiahao b88a8cf39f use rmutex inside of all repeated implementation
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2022-05-30 19:43:48 +08:00
Xiang Xiao ad2f82898a libc/misc: Add lib_ prefix to stream_semtake and tream_semgive
and merge lib_streamsem.c to lib_stream.c

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2021-11-02 09:00:11 +01:00
Alin Jerpelea b5d4a01821 libs: Author Gregory Nutt: update licenses to Apache
Gregory Nutt has submitted the SGA and we can migrate the licenses
 to Apache.

Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>
2021-03-03 18:52:53 -08:00
Xiang Xiao 2b9282d5ee libc: Skip close stdin/stdout/stderr in fclose
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2020-10-26 22:16:53 -07:00
Xiang Xiao b0797263ca libc/stdio: Allocate file_struct dynamically
1.Reduce the default size of task_group_s(~512B each task)
2.Scale better between simple and complex application

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: Ia872137504fddcf64d89c48d6f0593d76d582710
2020-09-11 17:58:17 +08:00
Xiang Xiao a7a81b5126 libc: Replace all [nx]sem_xxx with _SEM_XXX
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: I34f407ccd52391588ac1b720fce59d24458fe218
2020-08-18 07:59:21 -07:00
Gregory Nutt cf99fb40c9 This commit moves all of the libraries under a common directory called libs/. This most certainly break libcxx and uClibc++ for now.
Squashed commit of the following:

    libs/libxx:  Fix some confusing in naming.  If the directory is called libxx, then the library must be libxx.a (unless perhaps LIBCXX is selected).
    libs/:  Fix paths in moved library directories.
    libs:  Brute force move of libc, libnx, and libxx to libs.  Cannot yet build it in that configuration.
2018-05-29 13:21:26 -06:00