Closed yingmingx closed 3 years ago
I thought calling these from userspace worked (at least on ARM). Maybe this failure is x86-specific.
Needs more investigation.
When directly call read() in userspace on platform mps2_an385.
START - test_newlib_stub_read E: MPU FAULT E: Data Access Violation E: MMFAR Address: 0x20003c48 E: r0/a1: 0x200006b8 r1/a2: 0x00000001 r2/a3: 0x00000001 E: r3/a4: 0x000009e1 r12/ip: 0x0000aa9f r14/lr: 0x000009ef E: xpsr: 0x81000000 E: Faulting instruction address (r15/pc): 0x00002c42 E: >>> ZEPHYR FATAL ERROR 0: CPU exception on CPU 0 E: Current thread: 0x20000180 (test_newlib_stub_read) E: Halting system
Yup, this is a bug -- the newlib _write
and _read
hooks should indeed be calling the syscall functions and not the impls themselves.
They used to do that, but that got changed (by mistake) during the process of renaming functions around.
In https://github.com/zephyrproject-rtos/zephyr/commit/4344e27c267e1139c26dbd9cafcca4b3069ea821:
diff --git a/lib/libc/newlib/libc-hooks.c b/lib/libc/newlib/libc-hooks.c
index 578271916b..d6bef58d2b 100644
--- a/lib/libc/newlib/libc-hooks.c
+++ b/lib/libc/newlib/libc-hooks.c
@@ -153,7 +153,7 @@ int _read(int fd, char *buf, int nbytes)
{
ARG_UNUSED(fd);
- return _zephyr_read_stdin(buf, nbytes);
+ return z_impl_zephyr_read_stdin(buf, nbytes);
}
FUNC_ALIAS(_read, read, int);
@@ -161,7 +161,7 @@ int _write(int fd, const void *buf, int nbytes)
{
ARG_UNUSED(fd);
- return _zephyr_write_stdout(buf, nbytes);
+ return z_impl_zephyr_write_stdout(buf, nbytes);
}
FUNC_ALIAS(_write, write, int);
The importance of having the tests for all these cannot be overstated.
p.s. How did we manage to not notice this for over 2 years?
Describe the bug
To Reproduce Steps to reproduce the behavior:
Expected behavior
Impact I met this problem when testing #38064
Logs and console output 2.1
2.2
Environment (please complete the following information):