Skip to content

Commit

Permalink
Misc AIX/PASE tweaks (mono/mono#15651)
Browse files Browse the repository at this point in the history
* Partial enablement of alternate stack for AIX/i

It turns out much like macOS, AIX doesn't like to do mprotect/valloc
for the first thread's guard pages, so skip those. It seems mostly
fine except for one or two crashes causes it to grab the wrong IAR
and deadlock dumping memory. As such, leave the code and configure
script override to disable in place, just change the comment and
add support code.

* Use Qp2getifaddrs on PASE

Not sure if proper way to implement. Reuses getifaddrs code as much
as possible, since it's merely a name change based on the docs, due
to it being namespaced in case AIX gets it or something.

I'm not sure how many of these codepaths still work properly;
one had a questionable order of ifdef.

This will eventually prepare for CoreFX NetworkInterface, so test
it here.


Commit migrated from mono/mono@41469ee
  • Loading branch information
NattyNarwhal authored and vargaz committed Jul 11, 2019
1 parent 194c583 commit 68a52de
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/mono/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,9 @@ case "$host" in
with_gc=sgen
need_link_unlink=yes
use_sigposix=yes
dnl the valloc call to alloc the guard page bombs out, even with extending the data area
dnl Similar limitation to macOS about the first thread and the
dnl guard page, except sometimes the runtime hangs. Disable for
dnl now until cause can be determined or it seems OK enough.
with_sigaltstack=no
dnl use pthread TLS, __thread has issues with the compiler flags we use
with_tls=pthread
Expand Down Expand Up @@ -3338,6 +3340,7 @@ if test x$host_win32 = xno; then
AC_CHECK_DECL(F_DUPFD_CLOEXEC, [AC_DEFINE(HAVE_F_DUPFD_CLOEXEC, 1, [F_DUPFD_CLOEXEC])], [], [[#include <fcntl.h>]])

# AC_CHECK_FUNC(getifaddrs, [AC_DEFINE(HAVE_GETIFADDRS, 1, [getifaddrs])]) # already done above
AC_CHECK_FUNC(Qp2getifaddrs, [AC_DEFINE(HAVE_QP2GETIFADDRS, 1, [Qp2getifaddrs])])

AC_CHECK_FUNC(lseek64, [AC_DEFINE(HAVE_LSEEK64, 1, [lseek64])])
AC_CHECK_FUNC(mmap64, [AC_DEFINE(HAVE_MMAP64, 1, [mmap64])])
Expand Down
10 changes: 9 additions & 1 deletion src/mono/mono/metadata/w32socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@
#ifdef HAVE_GETIFADDRS
// <net/if.h> must be included before <ifaddrs.h>
#include <ifaddrs.h>
#elif defined(HAVE_QP2GETIFADDRS)
/* Bizarrely, IBM i implements this, but AIX doesn't, so on i, it has a different name... */
#include <as400_types.h>
#include <as400_protos.h>
/* Defines to just reuse ifaddrs code */
#define ifaddrs ifaddrs_pase
#define freeifaddrs Qp2freeifaddrs
#define getifaddrs Qp2getifaddrs
#endif

#if defined(_MSC_VER) && G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT | HAVE_UWP_WINAPI_SUPPORT)
Expand Down Expand Up @@ -1970,7 +1978,7 @@ ipaddress_handle_to_struct_in6_addr (MonoObjectHandle ipaddr)
static int
get_local_interface_id (int family)
{
#if !defined(HAVE_GETIFADDRS) || !defined(HAVE_IF_NAMETOINDEX)
#if !(defined(HAVE_GETIFADDRS) || defined(HAVE_QP2GETIFADDRS)) || !defined(HAVE_IF_NAMETOINDEX)
return 0;
#else
struct ifaddrs *ifap = NULL, *ptr;
Expand Down
6 changes: 5 additions & 1 deletion src/mono/mono/mini/mini-exceptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -3046,10 +3046,14 @@ mono_setup_altstack (MonoJitTlsData *tls)
size_t stsize = 0;
stack_t sa;
guint8 *staddr = NULL;
#ifdef TARGET_OSX
#if defined(TARGET_OSX) || defined(_AIX)
/*
* On macOS Mojave we are encountering a bug when changing mapping for main thread
* stack pages. Stack overflow on main thread will kill the app.
*
* AIX seems problematic as well; it gives ENOMEM for mprotect and valloc, if we
* do this for thread 1 with its stack at the top of memory. Other threads seem
* fine for the altstack guard page, though.
*/
gboolean disable_stack_guard = mono_threads_platform_is_main_thread ();
#else
Expand Down
7 changes: 7 additions & 0 deletions src/mono/mono/utils/mono-threads-aix.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,11 @@ mono_threads_platform_get_stack_bounds (guint8 **staddr, size_t *stsize)
*stsize = pi.__pi_stackend - pi.__pi_stackaddr;
}

gboolean
mono_threads_platform_is_main_thread (void)
{
/* returns 1 on main thread, even if the kernel tid is diff */
return pthread_self () == 1;
}

#endif
11 changes: 10 additions & 1 deletion src/mono/mono/utils/networking-posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@
#ifdef HAVE_GETIFADDRS
#include <ifaddrs.h>
#endif
#ifdef HAVE_QP2GETIFADDRS
/* Bizarrely, IBM i implements this, but AIX doesn't, so on i, it has a different name... */
#include <as400_types.h>
#include <as400_protos.h>
/* Defines to just reuse ifaddrs code */
#define ifaddrs ifaddrs_pase
#define freeifaddrs Qp2freeifaddrs
#define getifaddrs Qp2getifaddrs
#endif

#include <mono/utils/networking.h>
#include <mono/utils/mono-threads-coop.h>
Expand Down Expand Up @@ -280,7 +289,7 @@ mono_get_local_interfaces (int family, int *interface_count)
return result;
}

#elif defined(HAVE_GETIFADDRS)
#elif defined(HAVE_GETIFADDRS) || defined(HAVE_QP2GETIFADDRS)

void *
mono_get_local_interfaces (int family, int *interface_count)
Expand Down

0 comments on commit 68a52de

Please sign in to comment.