Page MenuHomeFreeBSD

Implement linux_sendfile for the linuxulator
Needs ReviewPublic

Authored by borako.ozarslan_gmail.com on Apr 15 2019, 6:01 PM.

Details

Summary

Implement linux_sendfile for the linuxulator using FreeBSD's sendfile. FreeBSD's sendfile only works if the target descriptor is a socket stream. So linux_sendfile is only implemented for this case and currently doesn't work with any descriptor so it returns not implemented in the other cases.

Submitted by: Bora Ozarslan borako.ozarslan@gmail.com

Test Plan

DONE
Test linux_sendfile using linuxulator with these linux binaries both as 32 and 64 bit versions:

  • TCP client/server program: One uses sendfile to send file
  • UDP client/server program: One uses sendfile to send file
  • Use sendfile to copy a file to another file.

In each case sendfile is tested multiple times using different parameters to check the correct error code is returned.

Tested it with linux binary of nginx which is the original use case.

TODO

Test linux_sendfile64. As far as I can understand this means have a 32-bit binary with Large File Support. I have a cross-compiled 32-bit linux binary with Large File Support which I'm not sure if that might be a correct way to test this functionality. Currently this leads to a panic and needs to be fixed.

Diff Detail

Lint
Lint Skipped
Unit
Unit Tests Skipped

Event Timeline

emaste added a subscriber: trasz.Apr 16 2019, 1:28 AM

This generally looks good to me.

sys/amd64/linux32/syscalls.master
416

I assume I'm missing something in the linux syscall implementation, but where is this version implemented?

sys/compat/linux/linux_socket.c
1804

It looks like there might be a whitespace consistency issue yet.

P.S. Not to be fixed in this commit, but this should really be using designated initializers (e.g. [LINUX_SENDFILE] = 4).

borako.ozarslan_gmail.com marked 2 inline comments as done.Apr 22 2019, 9:38 PM
borako.ozarslan_gmail.com added inline comments.
sys/amd64/linux32/syscalls.master
416

I left this out to be corrected. I tried this and another version where I tried referencing linux_sendfile for sendfile64 but I can't seem to get it to work. It always crashes. I am open to any direction on how to properly implement the 64 bit version for 32 bit linux. There also shouldn't be any difference between the implementations, hence I tried just referencing linux_sendfile.

sys/compat/linux/linux_socket.c
1804

There are tabs before the second column in all instances. It looks fine using diff tools and on vim. This might just be phabricator not showing it correctly, unless my editor is doing something weird.

borako.ozarslan_gmail.com edited the test plan for this revision. (Show Details)Apr 22 2019, 9:42 PM

@dchagin Bora is back at school now but I will handle committing this after review is complete

@emaste, np )

sys/compat/linux/linux_socket.c
1704

int error prefered

1775

missied fp, you need fdrop()