Page MenuHomeFreeBSD

Implement linux_sendfile for the linuxulator
Needs ReviewPublic

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



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

Test Plan

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.


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 Skipped
Unit Tests Skipped

Event Timeline

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

This generally looks good to me.


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


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). marked 2 inline comments as done.Apr 22 2019, 9:38 PM added inline comments.

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.


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. 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 )


int error prefered


missied fp, you need fdrop()