syscall() call in libc/network/if_nameindex.c

1 view
Skip to first unread message

Waldek Kozaczuk

unread,
Aug 10, 2020, 10:17:36 AM8/10/20
to OSv Development
Any reason why we use __syscall(SYS_close, ...) vs close()?

struct if_nameindex *if_nameindex()
{
size_t n;
void *p = 0;
int s = socket(AF_INET, SOCK_DGRAM|SOCK_CLOEXEC, 0);
if (s>=0) {
for (n=0; (p=do_nameindex(s, n)) == (void *)-1; n++);
__syscall(SYS_close, s);
}
errno = ENOBUFS;
return p;
}

Nadav,

It looks like you imported this file from musl with this commit - c4df1043285b7597709f5199d619658909a22794?

Waldek

Nadav Har'El

unread,
Aug 11, 2020, 3:24:58 AM8/11/20
to Waldek Kozaczuk, OSv Development
Yes, I guess I copied it, and it worked, so I didn't even notice it, and didn't bother to change it.

In retrospect, the __syscall() thing does work and maybe we shouldn't have tried so hard to avoid it and remove it from every place.

Yes, calling syscall() wastes a small amount of time (function call, switch, saving FPU - which isn't necessary for a
function call and could have been eliminated) - but it's completely negligible for most if not all cases in musl.
It's not even a syscall instruction - it's a function call.



Waldek

--
You received this message because you are subscribed to the Google Groups "OSv Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to osv-dev+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/osv-dev/f7f26e7f-9b5b-4a53-83ee-543d4b726112n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages