Commit Graph

137 Commits

Author SHA1 Message Date
Xiang Xiao b068e2357a circbuf: Move from mm/circbuf to libs/libc/misc
so that it can be used by userspace program.

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Signed-off-by: Neo Xu <neo.xu1990@gmail.com>
2024-10-09 08:41:49 +08:00
dongjiuzhu1 0fb1dc2b93 drivers/pipes: using rmutex to protect pipe and avoid deadlock
nxsem_wait
nuttx/sched/semaphore/sem_wait.c:176
nxmutex_lock
nuttx/libs/libc/misc/lib_mutex.c:204 (discriminator 2)
pipecommon_write
nuttx/drivers/pipes/pipe_common.c:538 (discriminator 2)
file_write
nuttx/fs/vfs/fs_write.c:91
write
nuttx/include/unistd.h:523 (discriminator 2)
nxsig_deliver
nuttx/sched/signal/sig_deliver.c:170 (discriminator 4)
arm_sigdeliver
nuttx/arch/arm/src/armv7-a/arm_sigdeliver.c:107
irq_waitlock
nuttx/sched/irq/irq_csection.c:204
nxsem_post
nuttx/sched/semaphore/sem_post.c:86 (discriminator 2)
nxmutex_unlock
nuttx/libs/libc/misc/lib_mutex.c:339 (discriminator 2)
pipecommon_poll
nuttx/drivers/pipes/pipe_common.c:769
file_poll
nuttx/fs/vfs/fs_poll.c:321
poll_fdsetup
nuttx/fs/vfs/fs_poll.c:194
poll
nuttx/include/sys/poll.h:164
uv_run
apps/system/libuv/libuv/src/unix/core.c:449
adb_hal_run
apps/system/adb/microADB/hal/hal_uv.c:76
adbd_main
apps/system/adb/adb_main.c:157
nxtask_startup
nuttx/libs/libc/sched/task_startup.c:70 (discriminator 2)
nxtask_start
nuttx/sched/task/task_start.c:134

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2024-09-28 13:50:21 +08:00
zhanghongyu 420648b0c6 drivers/pipes: add fcntl(F_SETPIPE_SZ/F_GETPIPE_SZ) support
allows user programs to modify pipe size, but not larger than
CONFIG_DEV_PIPE_MAXSIZE

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2024-09-10 11:35:15 +08:00
Petro Karashchenko d499ac9d58 nuttx: fix multiple 'FAR', 'CODE' and style issues
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2024-08-25 19:22:15 +08:00
wangchen 7050c312df pipes:fix the issue of the circbuf cannot be incorrectly initialized due to PIPE_POLICY_0
if dev->d_flags is POLICY_1, the circbuf cannot be initialized incorrectly.
We determine whether the circbuf should be initialized based on first reference on device and d_buffer is NULL

Signed-off-by: wangchen <wangchen41@xiaomi.com>
2024-08-23 16:14:39 -03:00
Zhe Weng a591adc6d5 drivers/pipes: Add offset support for PIPEIOC_PEEK
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2024-08-23 16:14:39 -03:00
wangchen 6a267fe019 drivers/pipes:add PIPEPOLICY_0 check in pipecommon_read & pipecommon_write.
From the current implementation,udp localsoket receiver's pipe is closed, the sender write failed in the pipe;
we change the implementation to check if buffer is free(PIPE_IS_POLICY_0),if not free,the sender could write in the pipe;

From the current implementation,udp localsoket sender's pipe is empty,the recevier directly return end of file;
we change the implementation to check if buffer is free(PIPE_IS_POLICY_0),if not free,the receiver wait for data

Signed-off-by: wangchen <wangchen41@xiaomi.com>
2024-08-23 16:14:39 -03:00
ligd 1a21445877 pipes: use priv refs instead of inode to resolve memleak
thread1                 thread2
open pipe               open pipe
close()
-> pipecommon_close()
  -> check inode refs
  -> do NOT free dev    close()
                        -> pipecommon_close()
                          -> check inode refs
                          -> do NOT free dev
-> inode_release
   inode refs--
                        -> inode_release
                           inode refs--

Then, you will see the pipe hasn't free its resource, memleak

Resolve:
replace the inode refs with priv refs

Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-08-23 16:14:39 -03:00
Xiang Xiao 1ba065db87 drivers/pipe: Change to the block mode by file_ioctl(FIONBIO)
it's simpler and safer than file_fcntl(F_SETFL)

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2024-03-07 10:09:35 -03:00
Xiang Xiao eddd90de78 poll: pollsetup should notify only one fd passd by caller
since it's redundant to iterate the whole fds array in setup

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-11-21 09:07:17 +01:00
chao an 664927c86e mm/alloc: remove all unnecessary cast for alloc
Fix the minor style issue and remove unnecessary cast

Signed-off-by: chao an <anchao@xiaomi.com>
2023-08-30 14:34:20 +08:00
chao an b60f01a55b inode/i_private: remove all unnecessary cast for i_private
Signed-off-by: chao an <anchao@xiaomi.com>
2023-08-29 08:58:07 +02:00
chao an 7aa45305b7 fs/inode: remove all unnecessary check for filep/inode
Since VFS layer already contains sanity checks, so remove unnecessary lower half checks

Signed-off-by: chao an <anchao@xiaomi.com>
2023-08-29 09:47:11 +08:00
dongjiuzhu1 38c001a914 drivers/pipes: fix busyloop issue when circbuf is full
pipecommon_poll always reutrn POLLOUT when the circbuf is full.

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2023-08-22 01:30:17 +08:00
wangyingdong 8f6f601ec1 net/local:Add peek support for pipe and MSG_PEEK support for local socket
fifo peek example:
struct pipe_peek_s peek_buf;
peek_buf.len = len;
peek_buf.data = buf;
ret = file_ioctl(filep, PIPEIOC_PEEK,(unsigned long)((uintptr_t)&peek_buf));

Signed-off-by: wangyingdong <wangyingdong@xiaomi.com>
2023-08-15 23:58:45 +08:00
chao an d010744582 drivers/pipes: use circbuf to refine buffer model
Signed-off-by: chao an <anchao@xiaomi.com>
2023-08-10 03:33:56 +08:00
yinshengkai a6fcb0a5a9 fs: add pipe type support to inode
Both the device and the pipe used the FSNODEFLAG_TYPE_DRIVER type before,
and now add an independent pipe type

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2023-08-05 06:32:50 -07:00
fangxinyong 7e90855d76 drivers/pipe: implement pipe mmap just return ENODEV
The fd of pipe type is not supported by mmap, mmap() shall failed
with ENODEV. If pipe mmap is not implemented, mmap will forward to
rammap() and get unexpected error.

Implement pipe mmap just return ENODEV. That is to pass LTP posix
test case mmap/23-1.c

https://pubs.opengroup.org/onlinepubs/9699919799/functions/mmap.html

Signed-off-by: fangxinyong <fangxinyong@xiaomi.com>
2023-08-02 22:57:28 -07:00
chao an 6ee9ec7656 build: add initial cmake build system
1. Update all CMakeLists.txt to adapt to new layout
2. Fix cmake build break
3. Update all new file license
4. Fully compatible with current compilation environment(use configure.sh or cmake as you choose)

------------------

How to test

From within nuttx/. Configure:

cmake -B build -DBOARD_CONFIG=sim/nsh -GNinja
cmake -B build -DBOARD_CONFIG=sim:nsh -GNinja
cmake -B build -DBOARD_CONFIG=sabre-6quad/smp -GNinja
cmake -B build -DBOARD_CONFIG=lm3s6965-ek/qemu-flat -GNinja

(or full path in custom board) :
cmake -B build -DBOARD_CONFIG=$PWD/boards/sim/sim/sim/configs/nsh -GNinja

This uses ninja generator (install with sudo apt install ninja-build). To build:

$ cmake --build build

menuconfig:

$ cmake --build build -t menuconfig

--------------------------

2. cmake/build: reformat the cmake style by cmake-format

https://github.com/cheshirekow/cmake_format

$ pip install cmakelang

$ for i in `find -name CMakeLists.txt`;do cmake-format $i -o $i;done
$ for i in `find -name *\.cmake`;do cmake-format $i -o $i;done

Co-authored-by: Matias N <matias@protobits.dev>
Signed-off-by: chao an <anchao@xiaomi.com>
2023-07-08 13:50:48 +08:00
Tiago Medicci Serrano d4e7fe55c7 drivers/pipe: fix blocking file_pipe
Similar to the fix introduced by
4d6a8663fa, it's necessary to set
one end of the file_pipe as non-blocking temporarily while opening
the other end to avoid it blocking unexpectedily.
2023-04-28 09:42:17 +08:00
Tiago Medicci Serrano 4d6a8663fa drivers/pipe: make pipe and named pipe (mkfifo) POSIX-compliant
According to https://pubs.opengroup.org/onlinepubs/9699919799/functions/open.html

"
 When opening a FIFO with O_RDONLY or O_WRONLY set:
  * If O_NONBLOCK is set, an open() for reading-only shall return
    without delay. An open() for writing-only shall return an error
    if no process currently has the file open for reading.

  * If O_NONBLOCK is clear, an open() for reading-only shall block
    the calling thread until a thread opens the file for writing.
    An open() for writing-only shall block the calling thread until
    a thread opens the file for reading.
"

This commit has an equivalent on nuttx-apps: EXAMPLES_PIPE app
was updated to be able to check pipes and named pipes behavior.
2023-04-22 01:28:33 +08:00
dongjiuzhu1 74e032e924 drivers/pipes: fix write busy loop because POLLOUT always ready.
the size of pipes buffer +1 as compensate the full indicator

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2023-01-31 12:45:16 +08:00
crafcat7 2ec117b3ca fs/fs_fsync:Fix the expected error of socket,fifo and pipe returning error in fsync case 2023-01-17 01:56:40 +08:00
田昕 587305723e drivers/pipe:add PIPEIOC_POLLTHRES to set POLLIN/POLLOUT threshold
Signed-off-by: 田昕 <tianxin7@xiaomi.com>
2023-01-10 13:33:13 +08:00
Xiang Xiao b0a0ba3ad7 fs: Move mmap callback before truncate in [file|mountpt]_operations
since mmap may exist in block_operations, but truncate may not,
moving mmap beforee truncate could make three struct more compatible

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-01-04 17:43:59 +02:00
Jukka Laitinen f33dc4df3f Change FIOC_MMAP into file operation call
- Add mmap into file_operations and remove it from ioctl definitions.
- Add mm_map structure definitions to support future unmapping
- Modify all drivers to initialize the operations struct accordingly

Signed-off-by: Jukka Laitinen <jukkax@ssrc.tii.ae>
2023-01-02 11:23:20 -03:00
Jukka Laitinen 41e9df2f3e Add ftruncate into file operation calls
- Add truncate into file_operations
- Move truncate to be common for mountpt_operations and file_operations
- Modify all drivers to initialize the operations struct accordingly

Signed-off-by: Jukka Laitinen <jukkax@ssrc.tii.ae>
2023-01-02 11:23:20 -03:00
Xiang Xiao 19bded4738 fs: Remove the unused nx_pipe to prefer file_pipe for kernel
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-10-27 23:14:25 +02:00
anjiahao 5724c6b2e4 sem:remove sem default protocl
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2022-10-22 14:50:48 +08: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
wangbowen6 344c8be049 poll: add poll_notify() api and call it in all drivers
Signed-off-by: wangbowen6 <wangbowen6@xiaomi.com>
2022-09-26 12:06:32 +08:00
Xiang Xiao c29a3b7bd8 pipe: Increase buffer size by one byte to ompensate the full indicator
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-04-21 12:45:30 +03:00
Jiuzhu Dong d87cf8d4ca fs/poll: change format for type pollevent_t
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
2022-04-07 12:14:06 +08:00
Xiang Xiao e0ae2963d2 drivers/pipe: Don't use sched_[lock|unlock] to do protection
since the sched lock can't work in SMP context

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-02-17 22:08:43 +01:00
Xiang Xiao fe04eb535f drivers/pipe: Fix the format style issue
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-02-17 22:08:43 +01:00
Xiang Xiao 22f2269d6a drivers/pipe: Remove pipe from file system after open
to make the pipe as an anonymous object as soon as
possible and simplify the life cycle management

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-02-07 12:05:47 +08:00
Xiang Xiao 345d2ac227 drivers/pipe: Add g_ prefix to pipe_fops and fifo_fops
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-02-07 12:05:47 +08:00
Xiang Xiao 01a234bfb1 pipe: Add DEV_PIPE_VFS_PATH to specify the pipe location
and put into /var/pipe by default like other pseudo device

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-02-05 23:37:44 +01:00
Xiang Xiao 91c331f3fd pipe: Change the default of DEV_PIPE_MAXSIZE from 256/1024 to 65535
since both values have to typedef pipe_ndx_t to uint16_t,
it doesn't make sense to limit the size smaller than 65535

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-02-05 23:37:44 +01:00
Petro Karashchenko a743fed63d file_operations: get back C89 compatible initializer
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2022-01-11 02:14:00 +08:00
ligd dbaf8a92b4 pipe: pipe close should notify block writting, and write will return -EPIPE
Signed-off-by: ligd <liguiding1@xiaomi.com>
2021-11-01 23:21:30 -05:00
chao.an ee3980abd7 driver/pipe: add nonblock open support
Signed-off-by: chao.an <anchao@xiaomi.com>
2021-08-19 19:18:52 -07:00
Xiang Xiao 2e54df0f35 Don't include assert.h from public header file
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2021-06-03 08:36:03 -07:00
Gustavo Henrique Nihei 330eff36d7 sourcefiles: Fix relative path in file header 2021-03-09 23:18:28 +08:00
Alin Jerpelea ccff570e6f drivers: nxstyle fixes
nxstyle fixes to pass the CI.

Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>
2021-03-04 18:32:27 -08:00
Alin Jerpelea e5b6305f4a drivers: 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-04 18:32:27 -08:00
Gustavo Henrique Nihei 55d66f60a3 drivers: Fix typos reported by codespell 2021-02-25 18:57:18 -08:00
Xiang Xiao a24ff44ae6 fs: Add file_pipe function
so pty don't need call nx_pipe and then file_detach

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: Ibb8d108abd76bafe53897e5fca35babcf3e1bae9
2021-01-08 11:03:19 +08:00
Xiang Xiao 4d4cba41f6 Move the declaration of nx_mkfifo/nx_pipe to nuttx/fs/fs.h
the new location is better than nuttx/drivers/drivers.h
since they are part of the file system api.

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2021-01-08 11:03:19 +08:00
Xiang Xiao 40516a3df9 drivers/pipes: Fix a typo error
"event & POLLOUT"(not "event | POLLOUT") should be used to check POLLOUT is set

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: I09af7669a1c8ee46118b904d2c5946ecb99e6215
2021-01-02 02:01:52 +01:00