-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Shim'ing out GetNameInfo, get/free addrinfo, and GetHostName #3471
Conversation
Note - will run the formatting script for the unmanaged code before committing |
This should fix #2988 :) |
Thank you! @sokket :) This was supposed to be the last major stopper to build CoreFX on FreeBSD! Now BSD support should be completed. One minor note for those who would want to try to build on FreeBSD 10.2 (latest version, released Aug 2015); if you are using latest Mono from portsnap / After that I tried BatchRestorePackages:
Restoring all packages...
EXEC : error : SendFailure (Error writing headers) [/root/projects/corefx/build.proj]
EXEC : error : SendFailure (Error writing headers) [/root/projects/corefx/build.proj]
EXEC : error : SendFailure (The object was used after being disposed.) [/root/projects/corefx/build.proj]
...
... (note that i have done this exercise 4 times with FreeBSD v10.1 and v10.2 since yesterday via Windows 10 Hyper-V, but running into the same issue) maybe someone can assist how to get around this issue.. /cc @akoeplinger. |
@@ -27,11 +25,10 @@ internal static unsafe string gethostname() | |||
// which should only happen if the buffer we supply isn't big | |||
// enough, and we're using a buffer size that the man page | |||
// says is the max for POSIX (and larger than the max for Linux). | |||
Debug.Fail("gethostname failed"); | |||
System.Diagnostics.Debug.Fail("gethostname failed"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Why remove the using and then fully qualify this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah sorry this was a new file and I copy+paste the header and using's from a template. Will add the using back to keep it a simpler change to track
This one is failing with some segfaulting tests:
http://dotnet-ci.cloudapp.net/job/dotnet_corefx_linux_debug_tst_prtest/2749/console |
I believe its the System.Net.Primitives tests due to a native static assert. Looks like our assumption of max IP address string lengths is different in managed than the define in system headers |
static_assert(PAL_NO_DATA == NO_DATA, ""); | ||
static_assert(PAL_NO_ADDRESS == NO_ADDRESS, ""); | ||
|
||
static void IpStringToAddressHelper(const char* address, const char* port, bool isIpV6, int32_t* err, std::function<void(const addrinfo& info)> lambda) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK std::function
uses type erasure which may/should result in additional allocation via operator new
so I think this parameter should be const&
to avoid additional allocations during the copying.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to know, thanks! I added that fix
There are a number of places in this change that manually pad record types (incl. automatically-generated closures) out to avoid a compiler warning on 64-bit platforms. IIUC the warning is "the compiler is padding this structure out for alignment". Have we considered disabling this warning (esp. given that different platforms are going to require different alignments, so the decisions we make now may not be universally applicable)? |
// walk since we would (most likely) need to realloc the array, which is more | ||
// expensive than just incrementing the limited number of IPs twice. | ||
he->Count++; | ||
infos.push_back(ai); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer that we avoid the vector here and just repeat the check for AF_INET
and AF_INET6
in the loop below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure
@dotnet-bot test this please. |
Looks like more of the new socket tests are failing. I'm investigating now, the previous failures were fixed with trivial changes so hopefully these will be the same |
@pgavlin Have you seen these failures before? |
@dotnet-bot test this please |
Yes, I have. |
} | ||
sockaddr = new SocketAddress(AddressFamily.InterNetworkV6); | ||
factory = IPEndPointStatics.IPv6Any; | ||
bufferLength = SocketAddressPal.IPv6AddressSize; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a comment or file an issue to track updating this once sockaddr
et. al. are shimmed out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opened issue #3570
This is looking good aside from some comments re: |
@dotnet-bot test this please |
The calls to getaddrinfo are not 1-to-1 with the native calls due to complexities around the native structs. Calls using sockaddr and addrinfo have nested structs pointing to different data depending on if the IP is IPv4 or IPv6. To mitigate the complexities around this code and around the underlying struct differences on the currently supported platforms, I kept the same calling pattern (as in Get* and Free*) but converted them to use an intermediate data structure that is defined in the PAL. We can then take in the required data from the Managed World and determine which native types are required, handle all the native structs and casts, and give back only the information that the managed code needs in a much simpler format.
Looks like the test failure is unrelated and the assertions are a known issue that @pgavlin is investigating now. Once this build completes and I verify the same issues, this will be good to merge |
Same, expected, failures. Any further comments? |
@dotnet-bot test this please (I disabled the failing AssemblyLoadContext test) |
@dotnet-bot test this please (looks like a Windows timer test failed...?) |
Did you open an issue for it? 😉 |
Yup :) #3583 |
✅ 👍 |
Green run - any more comments or can this be merged? |
LGTM. We can address any other feedback during follow-up changes. |
Cool, merging. Thanks everyone! |
Shim'ing out GetNameInfo, get/free addrinfo, and GetHostName
Shim'ing out GetNameInfo, get/free addrinfo, and GetHostName Commit migrated from dotnet/corefx@5da58c0
Shim'ing out GetNameInfo, get/free addrinfo, and GetHostName. The calls to getaddrinfo are not 1-to-1 with the native calls due to
complexities around the native structs. Calls using sockaddr and
addrinfo have nested structs pointing to different data depending
on if the IP is IPv4 or IPv6. To mitigate the complexities around
this code and around the underlying struct differences on the
currently supported platforms, I kept the same calling pattern (as
in Get* and Free*) but converted them to use an intermediate data
structure that is defined in the PAL. We can then take in the
required data from the Managed World and determine which native
types are required, handle all the native structs and casts, and
give back only the information that the managed code needs in a
much simpler format.
/cc @nguerrera @stephentoub @jasonwilliams200OK @pgavlin