Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Shim'ing out GetNameInfo, get/free addrinfo, and GetHostName #3471

Merged
merged 1 commit into from
Oct 1, 2015
Merged

Shim'ing out GetNameInfo, get/free addrinfo, and GetHostName #3471

merged 1 commit into from
Oct 1, 2015

Conversation

jonmill
Copy link

@jonmill jonmill commented Sep 25, 2015

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

@jonmill
Copy link
Author

jonmill commented Sep 25, 2015

Note - will run the formatting script for the unmanaged code before committing

@jonmill
Copy link
Author

jonmill commented Sep 25, 2015

This should fix #2988 :)

@ghost
Copy link

ghost commented Sep 25, 2015

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 / pkg install mono, you should add TZ=UTC before ./build.sh#L132 like so: TZ=UTC Mono29679.. or using setenv TZ UTC before running ./build.sh; as pointed out by @saper here: https://github.com/dotnet/coreclr/issues/602#issuecomment-108672899. This is most probably fixed in Mono master (by mono/mono#1860 and mono/mono#1870, which is landed on master but the current mono master is still not building on FreeBSD as is, due to some linux specific GCC macro usage..), so until vNext of Mono is landed for FreeBSD, this patch is needed.

After that I tried cert-sync /usr/local/share/certs/ca-root-nss.crt as well as mozroots --import --sync and mozroots --import --sync --machine and certmgr -ssl <for all: nuget.org, myget.org, go.microsoft.com and nugetgallery.blob.core.windows.net>, but it fails on Restoring all packages... step:

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");
Copy link
Member

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?

Copy link
Author

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

@bartonjs
Copy link
Member

This one is failing with some segfaulting tests:

22:13:21 ./run-test.sh: line 172: 58393 Aborted                 (core dumped) ./corerun xunit.console.netcore.exe $testDllName -xml testResults.xml -notrait category=failing -notrait category=OuterLoop -notrait category=$xunitOSCategory
22:13:21    System.Diagnostics.FileVersionInfo.Tests  Total: 3, Errors: 0, Failed: 0, Skipped: 0, Time: 0.873s
22:13:21 ./run-test.sh: line 172: 58391 Aborted                 (core dumped) ./corerun xunit.console.netcore.exe $testDllName -xml testResults.xml -notrait category=failing -notrait category=OuterLoop -notrait category=$xunitOSCatego

http://dotnet-ci.cloudapp.net/job/dotnet_corefx_linux_debug_tst_prtest/2749/console

@jonmill
Copy link
Author

jonmill commented Sep 25, 2015

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)
Copy link
Contributor

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.

Copy link
Author

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

@pgavlin
Copy link
Contributor

pgavlin commented Sep 28, 2015

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);
Copy link
Contributor

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

@janhenke
Copy link
Member

@dotnet-bot test this please.

@jonmill
Copy link
Author

jonmill commented Sep 29, 2015

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

@jonmill
Copy link
Author

jonmill commented Sep 29, 2015

@pgavlin Have you seen these failures before?

@pgavlin
Copy link
Contributor

pgavlin commented Sep 29, 2015

@dotnet-bot test this please

@pgavlin
Copy link
Contributor

pgavlin commented Sep 29, 2015

Yes, I have.

}
sockaddr = new SocketAddress(AddressFamily.InterNetworkV6);
factory = IPEndPointStatics.IPv6Any;
bufferLength = SocketAddressPal.IPv6AddressSize;
Copy link
Contributor

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened issue #3570

@pgavlin
Copy link
Contributor

pgavlin commented Sep 29, 2015

This is looking good aside from some comments re: PalIpAddress.

@jonmill
Copy link
Author

jonmill commented Oct 1, 2015

@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.
@jonmill
Copy link
Author

jonmill commented Oct 1, 2015

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

@jonmill
Copy link
Author

jonmill commented Oct 1, 2015

Same, expected, failures. Any further comments?

@stephentoub
Copy link
Member

@dotnet-bot test this please (I disabled the failing AssemblyLoadContext test)

@jonmill
Copy link
Author

jonmill commented Oct 1, 2015

@dotnet-bot test this please (looks like a Windows timer test failed...?)

@stephentoub
Copy link
Member

looks like a Windows timer test failed...?

Did you open an issue for it? 😉

@jonmill
Copy link
Author

jonmill commented Oct 1, 2015

Yup :) #3583

@ghost
Copy link

ghost commented Oct 1, 2015

✅ 👍

@jonmill
Copy link
Author

jonmill commented Oct 1, 2015

Green run - any more comments or can this be merged?

@pgavlin
Copy link
Contributor

pgavlin commented Oct 1, 2015

LGTM. We can address any other feedback during follow-up changes.

@jonmill
Copy link
Author

jonmill commented Oct 1, 2015

Cool, merging. Thanks everyone!

jonmill pushed a commit that referenced this pull request Oct 1, 2015
Shim'ing out GetNameInfo, get/free addrinfo, and GetHostName
@jonmill jonmill merged commit 5da58c0 into dotnet:master Oct 1, 2015
@jonmill jonmill deleted the pal branch October 1, 2015 18:10
@karelz karelz modified the milestone: 1.0.0-rtm Dec 3, 2016
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
Shim'ing out GetNameInfo, get/free addrinfo, and GetHostName

Commit migrated from dotnet/corefx@5da58c0
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants