Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix libc errno return for multiple system calls #317

Open
rennergade opened this issue Aug 7, 2023 · 2 comments
Open

Fix libc errno return for multiple system calls #317

rennergade opened this issue Aug 7, 2023 · 2 comments
Assignees
Labels
dependencies Pull requests that update a dependency file good first issue Good for newcomers

Comments

@rennergade
Copy link
Contributor

I've found a bug with errnos that may be prevalent for multiple system calls. I found this while testing the poll() call in a situation where we should return an errno. In this case it was EINTR which should return -1 and set the errno appropriately to 4.

Here we appropriately return -4 from lind_poll and NaClSysPoll .

But [here](static int nacl_irt_poll_lind (struct pollfd *fds, nfds_t nfds, int timeout)
{
int rv = NACL_SYSCALL (poll) (fds, nfds, timeout);
if (rv < 0)
return -rv;
return rv;
}) when we return to the IRT we negate the return value if its negative.

Then here in [poll.c](https://github.com/Lind-Project/Lind-GlibC/blob/5f73bc6e9b451a2bcef24f6967ece7fbedc41da2/sysdeps/nacl/poll.c#L10 it negates the errno again.

This ends up incorrectly setting the errno and the return value. poll() thinks were returning a non-error value of 4.

I think most of this code is a remnant of changes even before my time, and may be happening for a number of syscalls. We should comb through this code and do some tests to see what syscalls are affected when returning errors and fix those.

@yizhuoliang @Yaxuan-w can you address this as a project while I'm away?

If you have any questions about how the libc functions work @RusherRG and @kuzeyardabulut should be able to answer most questions.

@rennergade
Copy link
Contributor Author

@Yaxuan-w fixed most of these but theres a few other ones left. This possibly could be an issue for @abunav6 to finish up.

@Yaxuan-w
Copy link
Member

Here're list of syscalls need to be checked:

__nacl_irt_exit
__nacl_irt_gettod
__nacl_irt_clock
__nacl_irt_nanosleep
__nacl_irt_sched_yield
__nacl_irt_sysconf
__nacl_irt_chdir
__nacl_irt_chmod
__nacl_irt_getuid
__nacl_irt_geteuid
__nacl_irt_getgid
__nacl_irt_getegid
__nacl_irt_getcwd
__nacl_irt_fcntl_get
__nacl_irt_fcntl_set
__nacl_irt_ioctl
__nacl_irt_poll
__nacl_irt_ppoll
__nacl_irt_recvfrom
__nacl_irt_select
__nacl_irt_pselect
__nacl_irt_getdents
__nacl_irt_sysbrk
__nacl_irt_dyncode_create
__nacl_irt_dyncode_modify
__nacl_irt_dyncode_delete
__nacl_irt_thread_create
__nacl_irt_thread_exit
__nacl_irt_thread_nice
__nacl_irt_mutex_create
__nacl_irt_mutex_destroy
__nacl_irt_mutex_lock
__nacl_irt_mutex_unlock
__nacl_irt_mutex_trylock
__nacl_irt_cond_create
__nacl_irt_cond_destroy
__nacl_irt_cond_signal
__nacl_irt_cond_broadcast
__nacl_irt_cond_wait
__nacl_irt_cond_timed_wait_abs
__nacl_irt_tls_init
__nacl_irt_tls_get
__nacl_irt_open_resource
__nacl_irt_clock_getres
__nacl_irt_clock_gettime
__nacl_irt_gethostname
__nacl_irt_getpid
__nacl_irt_getppid
__nacl_irt_fork
__nacl_irt_dup
__nacl_irt_dup2
__nacl_irt_dup3
__nacl_irt_waitpid
__nacl_irt_wait
__nacl_irt_wait4
__nacl_irt_pipe
__nacl_irt_pipe2
__nacl_irt_execve
__nacl_irt_execv
__nacl_irt_sigprocmask
__nacl_irt_flock

@rennergade rennergade added the good first issue Good for newcomers label Jan 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

5 participants