Commit eab7ae92 authored by Stephanos Ioannidis's avatar Stephanos Ioannidis Committed by Christopher Friedt
Browse files

lib: libc: newlib: Fix userspace write() and read() mishap



The commit 4344e27c changed the syscall
function invocation in the `write()` and `read()` functions to the
direct syscall implementation function invocation by mistake.

The newlib `write()` and `read()` functions must call the
`z_zephyr_write_stdout()` and `z_zephyr_read_stdin()` syscall functions
in order to function properly in a user mode context.

Signed-off-by: default avatarStephanos Ioannidis <root@stephanos.io>
parent 30db452a
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -178,7 +178,7 @@ void __stdin_hook_install(unsigned char (*hook)(void))
	_stdin_hook = hook;
}

int z_impl_zephyr_read_stdin(char *buf, int nbytes)
int z_impl_z_zephyr_read_stdin(char *buf, int nbytes)
{
	int i = 0;

@@ -196,12 +196,12 @@ int z_impl_zephyr_read_stdin(char *buf, int nbytes)
static inline int z_vrfy_z_zephyr_read_stdin(char *buf, int nbytes)
{
	Z_OOPS(Z_SYSCALL_MEMORY_WRITE(buf, nbytes));
	return z_impl_zephyr_read_stdin((char *)buf, nbytes);
	return z_impl_z_zephyr_read_stdin((char *)buf, nbytes);
}
#include <syscalls/z_zephyr_read_stdin_mrsh.c>
#endif

int z_impl_zephyr_write_stdout(const void *buffer, int nbytes)
int z_impl_z_zephyr_write_stdout(const void *buffer, int nbytes)
{
	const char *buf = buffer;
	int i;
@@ -219,7 +219,7 @@ int z_impl_zephyr_write_stdout(const void *buffer, int nbytes)
static inline int z_vrfy_z_zephyr_write_stdout(const void *buf, int nbytes)
{
	Z_OOPS(Z_SYSCALL_MEMORY_READ(buf, nbytes));
	return z_impl_zephyr_write_stdout((const void *)buf, nbytes);
	return z_impl_z_zephyr_write_stdout((const void *)buf, nbytes);
}
#include <syscalls/z_zephyr_write_stdout_mrsh.c>
#endif
@@ -229,7 +229,7 @@ int _read(int fd, char *buf, int nbytes)
{
	ARG_UNUSED(fd);

	return z_impl_zephyr_read_stdin(buf, nbytes);
	return z_zephyr_read_stdin(buf, nbytes);
}
__weak FUNC_ALIAS(_read, read, int);

@@ -237,7 +237,7 @@ int _write(int fd, const void *buf, int nbytes)
{
	ARG_UNUSED(fd);

	return z_impl_zephyr_write_stdout(buf, nbytes);
	return z_zephyr_write_stdout(buf, nbytes);
}
__weak FUNC_ALIAS(_write, write, int);