-
Notifications
You must be signed in to change notification settings - Fork 1
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
42 Subject change #2
Comments
Is the As for your implementation, I think you have to return Personally I'm using a dirty trick where I'm calling the Do you think the tests should check if Your test output would be much appreciated. |
I've made a new commit (86ee1c1) on the errno branch to show how we could test Unfortunatly I'm on Linux and I can't link the test with |
Hey there, thanks for your reply. Documentation on ___error is really difficult to find. Especially because on Linux, if a syscall fails, errno is set automatically and the returned value from the syscall will be a negative number. No need to set errno yourself using ___error. On FreeBSD (MacOS at 42 Network) syscall errors will not set errno. Instead the syscall returns errno itself (positive number) and set the 'carry flag'. As you will have to return -1 from ft_write or ft_read when an error is encountered, you will need to access the external variable errno (within the errno.h library) and set it accordingly. See the following links for more explanation. This one helped me a lot: https://stackoverflow.com/questions/15304829/how-to-return-errno-in-assembly The FreeBSD errno.h library that is mentioned in the Stack Overflow link: https://github.com/freebsd/freebsd/blob/master/sys/sys/errno.h From the FreeBSD errno.h library in the link above:
So for your questions
I think so, when I access Linux man page for errno.h it says:
The address to errno is returned from ___error. But you have to actually set what's in that address to the right errno (which you get from syscall that goes wrong). See my code and comments for an example.
If buffer == NULL, when I syscall the same applies as I wrote above. The problem with checking RDI, RSI and RDX before doing the syscall and returning -1 is that you will not set the errno accordingly. Only the return value is correct (-1). The way I check it is like this (not automatic, just reading standard output):
I manually set errno = 100 between calls of write and ft_write because if you don't reset errno and your ft_write does not touch errno at all, you will just print the errno from the original write function. --- I just looked at your new branch, I see you did a test that's similar including the reset. Will come back to you with the results. Thanks for your time again. |
Thanks for the detailed answer. For the I need to do the same As for the pipe related thing, the
Since I set the read end of the pipe to non-blocking. (The test doesn't work with empty string if I don't). |
I have no idea why you would segfault, file descriptor are unique for each process so the created pipe should be duplicated when forking. (I had no problem with it and I don't see why your implementation should have any either)
I may have fucked up and declared my variable to check errno as an unsigned. fixed in dfdb617 |
prettier compatible with python < 3.6 removed unaccurate test for ft_read
I saw couple of implementations for ft_write and I think yours is the best. I think the segfault comes from misalignment of the stack due to the call, this fixed it for me: |
@yorgsone Never heard of stack alignment in the calling convensions (tbh I think I just copy pasted the solution from https://stackoverflow.com/c/42network/questions/1494) If you have a better explaination for people who encounter this issue, feel free to put it in the Common Issues section of the README. |
That's sorcelery right there, you need to sub rsp, 8 to call ___error ?? what the actual fck ??? |
Commenting since nobody seems to have mentioned this.
In the C standard, errno is guaranteed to be thread local. Paraphrasing the draft of the C11 standard (https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1548.pdf), chapter 7.5:
Here's an example implementation of
Here's information from the Linux manual: https://www.man7.org/linux/man-pages/man3/errno.3.html
|
The subject has changed on this project: https://cdn.intra.42.fr/pdf/pdf/10535/en.subject.pdf
We have to set the right errno after syscall errors.
For this we have to use extern ___error.
I have implemented this in the following way for ft_write (same error handling in ft_read):
This works and sets the right errno.
But your test now return segfaults on ft_write.s and ft_read.s
I think it has to do with the pipe and accessing the external variable errno.
I tried the input from your tests without the pipe and there is no segfault.
While my old code with a simple error return passes all your tests (but does not set the right errno):
For evaluations on 42 campuses your test is very useful so I wanted to address this change in subject and the false (I'm not sure if this is the case?) segfaults it may show (on ft_read and ft_write).
Any thoughts on implementation of the errno checking and/or the segfault error?
Thank you for your time.
The text was updated successfully, but these errors were encountered: