diff --git a/src/Mono.Android/Android.Runtime/AndroidEnvironment.cs b/src/Mono.Android/Android.Runtime/AndroidEnvironment.cs index ca7a16228b5..761a9cbde86 100644 --- a/src/Mono.Android/Android.Runtime/AndroidEnvironment.cs +++ b/src/Mono.Android/Android.Runtime/AndroidEnvironment.cs @@ -228,85 +228,6 @@ static void NotifyTimeZoneChanged () } } - // This is invoked by - // System.Drawing!System.Drawing.GraphicsAndroid.FromAndroidSurface () - // DO NOT REMOVE - // - // Exception audit: - // - // Verdict - // No need to wrap thrown exceptions in a BCL class - // - // Rationale - // No longer called by the indicated caller, however we keep it for backward compatibility. - [global::System.Runtime.Versioning.ObsoletedOSPlatform ("android31.0")] - static void GetDisplayDPI (out float x_dpi, out float y_dpi) - { - var wm = Application.Context.GetSystemService (Context.WindowService).JavaCast (); - var metrics = new DisplayMetrics (); -#if ANDROID_17 - wm?.DefaultDisplay?.GetRealMetrics (metrics); -#else - wm.DefaultDisplay.GetMetrics (metrics); -#endif - x_dpi = metrics.Xdpi; - y_dpi = metrics.Ydpi; - } - - // This is invoked by - // System.Core!System.AndroidPlatform.GetDefaultTimeZone () - // DO NOT REMOVE - // - // Exception audit: - // - // Verdict - // No need to wrap thrown exceptions in a BCL class - // - // Rationale - // Java code (invoked from our native runtime) will always return the default timezone and no - // exceptions are documented for the Java API. - // - static string GetDefaultTimeZone () - { - IntPtr id = RuntimeNativeMethods._monodroid_timezone_get_default_id (); - try { - return Marshal.PtrToStringAnsi (id)!; - } finally { - RuntimeNativeMethods.monodroid_free (id); - } - } - - // This is invoked by - // mscorlib.dll!System.AndroidPlatform.GetDefaultSyncContext() - // DO NOT REMOVE - static SynchronizationContext? GetDefaultSyncContext () - { - var looper = Android.OS.Looper.MainLooper; - try { - if (Android.OS.Looper.MyLooper() == looper) - return Android.App.Application.SynchronizationContext; - } catch (System.Exception ex) { - Logger.Log (LogLevel.Warn, "MonoAndroid", $"GetDefaultSyncContext caught a Java exception: {ex}"); - } - return null; - } - - // These are invoked by - // System.dll!System.AndroidPlatform.getifaddrs - // DO NOT REMOVE - static int GetInterfaceAddresses (out IntPtr ifap) - { - return RuntimeNativeMethods._monodroid_getifaddrs (out ifap); - } - - // These are invoked by - // System.dll!System.AndroidPlatform.freeifaddrs - // DO NOT REMOVE - static void FreeInterfaceAddresses (IntPtr ifap) - { - RuntimeNativeMethods._monodroid_freeifaddrs (ifap); - } - static void DetectCPUAndArchitecture (out ushort builtForCPU, out ushort runningOnCPU, out bool is64bit) { ushort built_for_cpu = 0; @@ -319,18 +240,6 @@ static void DetectCPUAndArchitecture (out ushort builtForCPU, out ushort running is64bit = _is64bit != 0; } - // This is invoked by - // System.dll!System.AndroidPlatform.GetDefaultProxy() - // DO NOT REMOVE - static IWebProxy GetDefaultProxy () - { -#if ANDROID_14 - return new _Proxy (); -#else - return null; -#endif - } - // This is invoked by // System.Net.Http.dll!System.Net.Http.HttpClient.cctor // DO NOT REMOVE @@ -395,61 +304,5 @@ static Type GetFallbackHttpMessageHandlerType () return handlerType; } - class _Proxy : IWebProxy { - readonly ProxySelector selector = ProxySelector.Default!; - - // Exception audit: - // - // Verdict - // Exception wrapping required - // - // Rationale - // Java code may throw URISyntaxException which we map to the managed UriFormatException - // - static URI CreateJavaUri (Uri destination) - { - try { - return new URI (destination.Scheme, destination.UserInfo, destination.Host, destination.Port, destination.AbsolutePath, destination.Query, destination.Fragment); - } catch (Java.Lang.Throwable ex) when (JNIEnv.ShouldWrapJavaException (ex)) { - throw new UriFormatException (ex.Message, ex); - } - } - - public Uri GetProxy (Uri destination) - { - IList list; - using (var uri = CreateJavaUri (destination)) - list = selector.Select (uri)!; - if (list.Count < 1) - return destination; - - var proxy = list [0]; - if (proxy.Equals (Proxy.NoProxy)) - return destination; - - var address = proxy.Address () as InetSocketAddress; - if (address == null) // FIXME - return destination; - - return new Uri (FormattableString.Invariant ($"http://{address.HostString}:{address.Port}/")); - } - - public bool IsBypassed (Uri host) - { - IList list; - using (var uri = CreateJavaUri (host)) - list = selector.Select (uri)!; - - if (list.Count < 1) - return true; - - return list [0].Equals (Proxy.NoProxy); - } - - public ICredentials? Credentials { - get; - set; - } - } } } diff --git a/src/Mono.Android/Android.Runtime/RuntimeNativeMethods.cs b/src/Mono.Android/Android.Runtime/RuntimeNativeMethods.cs index e4c68c98f7a..a976f4c1bb8 100644 --- a/src/Mono.Android/Android.Runtime/RuntimeNativeMethods.cs +++ b/src/Mono.Android/Android.Runtime/RuntimeNativeMethods.cs @@ -45,14 +45,6 @@ internal unsafe static class RuntimeNativeMethods [DllImport (RuntimeConstants.InternalDllName, CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr _monodroid_lookup_replacement_method_info (string jniSourceType, string jniMethodName, string jniMethodSignature); - [DllImport (RuntimeConstants.InternalDllName, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr _monodroid_timezone_get_default_id (); - - [DllImport (RuntimeConstants.InternalDllName, CallingConvention = CallingConvention.Cdecl)] - internal static extern int _monodroid_getifaddrs (out IntPtr ifap); - - [DllImport (RuntimeConstants.InternalDllName, CallingConvention = CallingConvention.Cdecl)] - internal static extern void _monodroid_freeifaddrs (IntPtr ifap); [DllImport (RuntimeConstants.InternalDllName, CallingConvention = CallingConvention.Cdecl)] internal static extern void _monodroid_detect_cpu_and_architecture (ref ushort built_for_cpu, ref ushort running_on_cpu, ref byte is64bit); diff --git a/src/native/clr/host/CMakeLists.txt b/src/native/clr/host/CMakeLists.txt index 017a66918cf..edfaef02ec2 100644 --- a/src/native/clr/host/CMakeLists.txt +++ b/src/native/clr/host/CMakeLists.txt @@ -36,7 +36,6 @@ set(XAMARIN_MONODROID_SOURCES os-bridge.cc runtime-util.cc typemap.cc - xamarin_getifaddrs.cc ) if(DEBUG_BUILD) diff --git a/src/native/clr/host/internal-pinvokes.cc b/src/native/clr/host/internal-pinvokes.cc index 5260a6bac6a..387829131d4 100644 --- a/src/native/clr/host/internal-pinvokes.cc +++ b/src/native/clr/host/internal-pinvokes.cc @@ -183,23 +183,3 @@ void _monodroid_detect_cpu_and_architecture (uint16_t *built_for_cpu, uint16_t * *is64bit = _64bit; } -void* _monodroid_timezone_get_default_id () -{ - JNIEnv *env = OSBridge::ensure_jnienv (); - jmethodID getDefault = env->GetStaticMethodID (Host::get_java_class_TimeZone (), "getDefault", "()Ljava/util/TimeZone;"); - jmethodID getID = env->GetMethodID (Host::get_java_class_TimeZone (), "getID", "()Ljava/lang/String;"); - jobject d = env->CallStaticObjectMethod (Host::get_java_class_TimeZone (), getDefault); - jstring id = reinterpret_cast (env->CallObjectMethod (d, getID)); - const char *mutf8 = env->GetStringUTFChars (id, nullptr); - if (mutf8 == nullptr) { - log_error (LOG_DEFAULT, "Failed to convert Java TimeZone ID to UTF8 (out of memory?)"sv); - env->DeleteLocalRef (id); - env->DeleteLocalRef (d); - return nullptr; - } - char *def_id = strdup (mutf8); - env->ReleaseStringUTFChars (id, mutf8); - env->DeleteLocalRef (id); - env->DeleteLocalRef (d); - return def_id; -} diff --git a/src/native/clr/host/xamarin_getifaddrs.cc b/src/native/clr/host/xamarin_getifaddrs.cc deleted file mode 100644 index 1d551ead702..00000000000 --- a/src/native/clr/host/xamarin_getifaddrs.cc +++ /dev/null @@ -1,993 +0,0 @@ -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include - -using namespace xamarin::android; - -/* Maximum interface address label size, should be more than enough */ -#define MAX_IFA_LABEL_SIZE 1024 - -#if defined (__linux__) || defined (__linux) - -/* This is the message we send to the kernel */ -typedef struct { - struct nlmsghdr header; - struct rtgenmsg message; -} netlink_request; - -typedef struct { - int sock_fd; - int seq; - struct sockaddr_nl them; /* kernel end */ - struct sockaddr_nl us; /* our end */ - struct msghdr message_header; /* for use with sendmsg */ - struct iovec payload_vector; /* Used to send netlink_request */ -} netlink_session; - -/* Turns out that quite a few link types have address length bigger than the 8 bytes allocated in - * this structure as defined by the OS. Examples are Infiniband or ipv6 tunnel devices - */ -struct sockaddr_ll_extended { - unsigned short int sll_family; - unsigned short int sll_protocol; - int sll_ifindex; - unsigned short int sll_hatype; - unsigned char sll_pkttype; - unsigned char sll_halen; - unsigned char sll_addr[24]; -}; - -static int parse_netlink_reply (netlink_session *session, struct ifaddrs **ifaddrs_head, struct ifaddrs **last_ifaddr); -static struct ifaddrs *get_link_info (const struct nlmsghdr *message); -static struct ifaddrs *get_link_address (const struct nlmsghdr *message, struct ifaddrs **ifaddrs_head); -static int open_netlink_session (netlink_session *session); -static int send_netlink_dump_request (netlink_session *session, int type); -static int append_ifaddr (struct ifaddrs *addr, struct ifaddrs **ifaddrs_head, struct ifaddrs **last_ifaddr); -static int fill_ll_address (struct sockaddr_ll_extended **sa, struct ifinfomsg *net_interface, void *rta_data, size_t rta_payload_length); -static int fill_sa_address (struct sockaddr **sa, struct ifaddrmsg *net_address, void *rta_data, size_t rta_payload_length); -static void free_single_xamarin_ifaddrs (struct ifaddrs **ifap); -static void get_ifaddrs_impl (int (**getifaddrs_impl) (struct ifaddrs **ifap), void (**freeifaddrs_impl) (struct ifaddrs *ifa)); -static struct ifaddrs *find_interface_by_index (int index, struct ifaddrs **ifaddrs_head); -static char *get_interface_name_by_index (int index, struct ifaddrs **ifaddrs_head); -static int get_interface_flags_by_index (int index, struct ifaddrs **ifaddrs_head); -static int calculate_address_netmask (struct ifaddrs *ifa, struct ifaddrmsg *net_address); -#if DEBUG -static void print_ifla_name (int id); -static void print_address_list (const char title[], struct ifaddrs *list); -#endif - -/* We don't use 'struct ifaddrs' since that doesn't exist in Android's bionic, but since our - * version of the structure is 100% compatible we can just use it instead - */ -typedef int (*getifaddrs_impl_fptr)(struct ifaddrs **); -typedef void (*freeifaddrs_impl_fptr)(struct ifaddrs *ifa); - -namespace { - getifaddrs_impl_fptr getifaddrs_impl = nullptr; - freeifaddrs_impl_fptr freeifaddrs_impl = nullptr; - bool initialized = false; - std::mutex init_lock{}; - - void _monodroid_getifaddrs_init () - { - get_ifaddrs_impl (&getifaddrs_impl, &freeifaddrs_impl); - } -} - -int -_monodroid_getifaddrs (struct ifaddrs **ifap) -{ - if (!initialized) { - std::lock_guard lock (init_lock); - if (!initialized) { - _monodroid_getifaddrs_init (); - initialized = true; - } - } - - int ret = -1; - - if (getifaddrs_impl) - return (*getifaddrs_impl)(ifap); - - if (!ifap) - return ret; - - *ifap = NULL; - struct ifaddrs *ifaddrs_head = 0; - struct ifaddrs *last_ifaddr = 0; - netlink_session session; - - if (open_netlink_session (&session) < 0) { - goto cleanup; - } - - /* Request information about the specified link. In our case it will be all of them since we - request the root of the link tree below - */ - if ((send_netlink_dump_request (&session, RTM_GETLINK) < 0) || - (parse_netlink_reply (&session, &ifaddrs_head, &last_ifaddr) < 0) || - (send_netlink_dump_request (&session, RTM_GETADDR) < 0) || - (parse_netlink_reply (&session, &ifaddrs_head, &last_ifaddr) < 0)) { - _monodroid_freeifaddrs (ifaddrs_head); - goto cleanup; - } - - ret = 0; - *ifap = ifaddrs_head; -#if DEBUG - print_address_list ("Initial interfaces list", *ifap); -#endif - - cleanup: - if (session.sock_fd >= 0) { - close (session.sock_fd); - session.sock_fd = -1; - } - - return ret; -} - -void -_monodroid_freeifaddrs (struct ifaddrs *ifa) -{ - struct ifaddrs *cur, *next; - - if (!ifa) - return; - - if (freeifaddrs_impl) { - (*freeifaddrs_impl)(ifa); - return; - } - -#if DEBUG - print_address_list ("List passed to freeifaddrs", ifa); -#endif - cur = ifa; - while (cur) { - next = cur->ifa_next; - free_single_xamarin_ifaddrs (&cur); - cur = next; - } -} - -static void -get_ifaddrs_impl (int (**getifaddrs_implementation) (struct ifaddrs **ifap), void (**freeifaddrs_implementation) (struct ifaddrs *ifa)) -{ - void *libc; - - abort_if_invalid_pointer_argument (getifaddrs_implementation, "getifaddrs_implementation"); - abort_if_invalid_pointer_argument (freeifaddrs_implementation, "freeifaddrs_implementation"); - - libc = dlopen ("libc.so", RTLD_NOW); - if (libc) { - *getifaddrs_implementation = reinterpret_cast (dlsym (libc, "getifaddrs")); - if (*getifaddrs_implementation) - *freeifaddrs_implementation = reinterpret_cast (dlsym (libc, "freeifaddrs")); - } - - if (!*getifaddrs_implementation) { - log_info (LOG_NET, "This libc does not have getifaddrs/freeifaddrs, using Xamarin's"sv); - } else { - log_info (LOG_NET, "This libc has getifaddrs/freeifaddrs"sv); - } -} - -static void -free_single_xamarin_ifaddrs (struct ifaddrs **ifap) -{ - struct ifaddrs *ifa = ifap ? *ifap : NULL; - if (!ifa) - return; - - if (ifa->ifa_name) - free (ifa->ifa_name); - - if (ifa->ifa_addr) - free (ifa->ifa_addr); - - if (ifa->ifa_netmask) - free (ifa->ifa_netmask); - - if (ifa->ifa_broadaddr) - free (ifa->ifa_broadaddr); - - if (ifa->ifa_data) - free (ifa->ifa_data); - - free (ifa); - *ifap = NULL; -} - -static int -open_netlink_session (netlink_session *session) -{ - abort_if_invalid_pointer_argument (session, "session"); - - memset (session, 0, sizeof (*session)); - session->sock_fd = socket (AF_NETLINK, SOCK_RAW, NETLINK_ROUTE); - if (session->sock_fd == -1) { - log_warn (LOG_NETLINK, "Failed to create a netlink socket. {}", strerror (errno)); - return -1; - } - - /* Fill out addresses */ - session->us.nl_family = AF_NETLINK; - - /* We have previously used `getpid()` here but it turns out that WebView/Chromium does the same - and there can only be one session with the same PID. Setting it to 0 will cause the kernel to - assign some PID that's unique and valid instead. - - See: https://bugzilla.xamarin.com/show_bug.cgi?id=41860 - */ - session->us.nl_pid = 0; - session->us.nl_groups = 0; - - session->them.nl_family = AF_NETLINK; - - if (bind (session->sock_fd, (struct sockaddr *)&session->us, sizeof (session->us)) < 0) { - log_warn (LOG_NETLINK, "Failed to bind to the netlink socket. {}", strerror (errno)); - return -1; - } - - return 0; -} - -static int -send_netlink_dump_request (netlink_session *session, int type) -{ - netlink_request request; - - memset (&request, 0, sizeof (request)); - request.header.nlmsg_len = NLMSG_LENGTH (sizeof (struct rtgenmsg)); - /* Flags (from netlink.h): - NLM_F_REQUEST - it's a request message - NLM_F_DUMP - gives us the root of the link tree and returns all links matching our requested - AF, which in our case means all of them (AF_PACKET) - */ - request.header.nlmsg_flags = NLM_F_REQUEST | NLM_F_ROOT | NLM_F_MATCH; - request.header.nlmsg_seq = static_cast<__u32>(++session->seq); - request.header.nlmsg_pid = session->us.nl_pid; - request.header.nlmsg_type = static_cast<__u16>(type); - - /* AF_PACKET means we want to see everything */ - request.message.rtgen_family = AF_PACKET; - - memset (&session->payload_vector, 0, sizeof (session->payload_vector)); - session->payload_vector.iov_len = request.header.nlmsg_len; - session->payload_vector.iov_base = &request; - - memset (&session->message_header, 0, sizeof (session->message_header)); - session->message_header.msg_namelen = sizeof (session->them); - session->message_header.msg_name = &session->them; - session->message_header.msg_iovlen = 1; - session->message_header.msg_iov = &session->payload_vector; - - if (sendmsg (session->sock_fd, (const struct msghdr*)&session->message_header, 0) < 0) { - log_warn (LOG_NETLINK, "Failed to send netlink message. {}", strerror (errno)); - return -1; - } - - return 0; -} - -static int -append_ifaddr (struct ifaddrs *addr, struct ifaddrs **ifaddrs_head, struct ifaddrs **last_ifaddr) -{ - abort_if_invalid_pointer_argument (addr, "addr"); - abort_if_invalid_pointer_argument (ifaddrs_head, "ifaddrs_head"); - abort_if_invalid_pointer_argument (last_ifaddr, "last_ifaddr"); - - if (!*ifaddrs_head) { - *ifaddrs_head = *last_ifaddr = addr; - if (!*ifaddrs_head) - return -1; - } else if (!*last_ifaddr) { - struct ifaddrs *last = *ifaddrs_head; - - while (last->ifa_next) - last = last->ifa_next; - *last_ifaddr = last; - } - - addr->ifa_next = NULL; - if (addr == *last_ifaddr) - return 0; - - (*last_ifaddr)->ifa_next = addr; - *last_ifaddr = addr; - - return 0; -} - -static int -parse_netlink_reply (netlink_session *session, struct ifaddrs **ifaddrs_head, struct ifaddrs **last_ifaddr) -{ - struct msghdr netlink_reply; - struct iovec reply_vector; - struct nlmsghdr *current_message; - struct ifaddrs *addr; - int ret = -1; - unsigned char *response = NULL; - - abort_if_invalid_pointer_argument (session, "session"); - abort_if_invalid_pointer_argument (ifaddrs_head, "ifaddrs_head"); - abort_if_invalid_pointer_argument (last_ifaddr, "last_ifaddr"); - - size_t buf_size = static_cast(getpagesize ()); - log_debug (LOG_NETLINK, "receive buffer size == {}", buf_size); - - size_t alloc_size = Helpers::multiply_with_overflow_check (sizeof(*response), buf_size); - response = (unsigned char*)malloc (alloc_size); - ssize_t length = 0z; - if (!response) { - goto cleanup; - } - - while (1) { - memset (response, 0, buf_size); - memset (&reply_vector, 0, sizeof (reply_vector)); - reply_vector.iov_len = buf_size; - reply_vector.iov_base = response; - - memset (&netlink_reply, 0, sizeof (netlink_reply)); - netlink_reply.msg_namelen = sizeof (&session->them); - netlink_reply.msg_name = &session->them; - netlink_reply.msg_iovlen = 1; - netlink_reply.msg_iov = &reply_vector; - - length = recvmsg (session->sock_fd, &netlink_reply, 0); - log_debug (LOG_NETLINK, " length == {}", (int)length); - - if (length < 0) { - log_debug (LOG_NETLINK, "Failed to receive reply from netlink. {}", strerror (errno)); - goto cleanup; - } - -#if DEBUG - if (Util::should_log (LOG_NETLINK)) { - log_debug_nocheck (LOG_NETLINK, "response flags:"sv); - if (netlink_reply.msg_flags == 0) - log_debug_nocheck (LOG_NETLINK, " [NONE]"sv); - else { - if (netlink_reply.msg_flags & MSG_EOR) - log_debug_nocheck (LOG_NETLINK, " MSG_EOR"sv); - if (netlink_reply.msg_flags & MSG_TRUNC) - log_debug_nocheck (LOG_NETLINK, " MSG_TRUNC"sv); - if (netlink_reply.msg_flags & MSG_CTRUNC) - log_debug_nocheck (LOG_NETLINK, " MSG_CTRUNC"sv); - if (netlink_reply.msg_flags & MSG_OOB) - log_debug_nocheck (LOG_NETLINK, " MSG_OOB"sv); - if (netlink_reply.msg_flags & MSG_ERRQUEUE) - log_debug_nocheck (LOG_NETLINK, " MSG_ERRQUEUE"sv); - } - } -#endif - - if (length == 0) - break; - - for (current_message = (struct nlmsghdr*)response; current_message && NLMSG_OK (current_message, static_cast(length)); current_message = NLMSG_NEXT (current_message, length)) { - log_debug (LOG_NETLINK, "next message... (type: {})", current_message->nlmsg_type); - switch (current_message->nlmsg_type) { - /* See rtnetlink.h */ - case RTM_NEWLINK: - log_debug (LOG_NETLINK, " dumping link..."sv); - addr = get_link_info (current_message); - if (!addr || append_ifaddr (addr, ifaddrs_head, last_ifaddr) < 0) { - ret = -1; - goto cleanup; - } - log_debug (LOG_NETLINK, " done"sv); - break; - - case RTM_NEWADDR: - log_debug (LOG_NETLINK, " got an address"sv); - addr = get_link_address (current_message, ifaddrs_head); - if (!addr || append_ifaddr (addr, ifaddrs_head, last_ifaddr) < 0) { - ret = -1; - goto cleanup; - } - break; - - case NLMSG_DONE: - log_debug (LOG_NETLINK, " message done"sv); - ret = 0; - goto cleanup; - break; - - default: - log_debug (LOG_NETLINK, " message type: {}", current_message->nlmsg_type); - break; - } - } - } - - cleanup: - if (response) - free (response); - return ret; -} - -static int -fill_sa_address (struct sockaddr **sa, struct ifaddrmsg *net_address, void *rta_data, size_t rta_payload_length) -{ - abort_if_invalid_pointer_argument (sa, "sa"); - abort_if_invalid_pointer_argument (net_address, "net_address"); - abort_if_invalid_pointer_argument (rta_data, "rta_data"); - - switch (net_address->ifa_family) { - case AF_INET: { - struct sockaddr_in *sa4; - if (rta_payload_length != 4) /* IPv4 address length */ { - log_warn (LOG_NETLINK, "Unexpected IPv4 address payload length {}", rta_payload_length); - return -1; - } - sa4 = (struct sockaddr_in*)calloc (1, sizeof (*sa4)); - if (sa4 == nullptr) - return -1; - - sa4->sin_family = AF_INET; - memcpy (&sa4->sin_addr, rta_data, rta_payload_length); - *sa = (struct sockaddr*)sa4; - break; - } - - case AF_INET6: { - struct sockaddr_in6 *sa6; - if (rta_payload_length != 16) /* IPv6 address length */ { - log_warn (LOG_NETLINK, "Unexpected IPv6 address payload length {}", rta_payload_length); - return -1; - } - sa6 = (struct sockaddr_in6*)calloc (1, sizeof (*sa6)); - if (sa6 == nullptr) - return -1; - - sa6->sin6_family = AF_INET6; - memcpy (&sa6->sin6_addr, rta_data, rta_payload_length); - if (IN6_IS_ADDR_LINKLOCAL (&sa6->sin6_addr) || IN6_IS_ADDR_MC_LINKLOCAL (&sa6->sin6_addr)) - sa6->sin6_scope_id = net_address->ifa_index; - *sa = (struct sockaddr*)sa6; - break; - } - - default: { - struct sockaddr *sagen; - if (rta_payload_length > sizeof (sagen->sa_data)) { - log_warn (LOG_NETLINK, "Unexpected RTA payload length {} (wanted at most {})", rta_payload_length, sizeof (sagen->sa_data)); - return -1; - } - - *sa = sagen = (struct sockaddr*)calloc (1, sizeof (*sagen)); - if (!sagen) - return -1; - - sagen->sa_family = net_address->ifa_family; - memcpy (&sagen->sa_data, rta_data, rta_payload_length); - break; - } - } - - return 0; -} - -static int -fill_ll_address (struct sockaddr_ll_extended **sa, struct ifinfomsg *net_interface, void *rta_data, size_t rta_payload_length) -{ - abort_if_invalid_pointer_argument (sa, "sa"); - abort_if_invalid_pointer_argument (net_interface, "net_interface"); - - /* Always allocate, do not free - caller may reuse the same variable */ - *sa = reinterpret_cast(calloc (1, sizeof (**sa))); - if (!*sa) - return -1; - - (*sa)->sll_family = AF_PACKET; /* Always for physical links */ - - /* The assert can only fail for Iniband links, which are quite unlikely to be found - * in any mobile devices - */ - log_debug (LOG_NETLINK, "rta_payload_length == {}; sizeof sll_addr == {}; hw type == {:x}", rta_payload_length, sizeof ((*sa)->sll_addr), net_interface->ifi_type); - if (static_cast(rta_payload_length) > sizeof ((*sa)->sll_addr)) { - log_info (LOG_NETLINK, "Address is too long to place in sockaddr_ll ({} > {})", rta_payload_length, sizeof ((*sa)->sll_addr)); - free (*sa); - *sa = NULL; - return -1; - } - - if (rta_payload_length > std::numeric_limits::max ()) { - log_info (LOG_NETLINK, "Payload length too big to fit in the address structure"sv); - free (*sa); - *sa = NULL; - return -1; - } - - (*sa)->sll_ifindex = net_interface->ifi_index; - (*sa)->sll_hatype = net_interface->ifi_type; - (*sa)->sll_halen = static_cast(rta_payload_length); - memcpy ((*sa)->sll_addr, rta_data, rta_payload_length); - - return 0; -} - -static struct ifaddrs * -find_interface_by_index (int index, struct ifaddrs **ifaddrs_head) -{ - struct ifaddrs *cur; - if (!ifaddrs_head || !*ifaddrs_head) - return NULL; - - /* Normally expensive, but with the small amount of links in the chain we'll deal with it's not - * worth the extra houskeeping and memory overhead - */ - cur = *ifaddrs_head; - while (cur) { - if (cur->ifa_addr && cur->ifa_addr->sa_family == AF_PACKET && ((struct sockaddr_ll_extended*)cur->ifa_addr)->sll_ifindex == index) - return cur; - if (cur == cur->ifa_next) - break; - cur = cur->ifa_next; - } - - return NULL; -} - -static char * -get_interface_name_by_index (int index, struct ifaddrs **ifaddrs_head) -{ - struct ifaddrs *iface = find_interface_by_index (index, ifaddrs_head); - if (!iface || !iface->ifa_name) - return NULL; - - return iface->ifa_name; -} - -static int -get_interface_flags_by_index (int index, struct ifaddrs **ifaddrs_head) -{ - struct ifaddrs *iface = find_interface_by_index (index, ifaddrs_head); - if (!iface) - return 0; - - return static_cast(iface->ifa_flags); -} - -static int -calculate_address_netmask (struct ifaddrs *ifa, struct ifaddrmsg *net_address) -{ - if (ifa->ifa_addr && ifa->ifa_addr->sa_family != AF_UNSPEC && ifa->ifa_addr->sa_family != AF_PACKET) { - uint32_t prefix_length = 0; - uint32_t data_length = 0; - unsigned char *netmask_data = NULL; - - switch (ifa->ifa_addr->sa_family) { - case AF_INET: { - struct sockaddr_in *sa = (struct sockaddr_in*)calloc (1, sizeof (struct sockaddr_in)); - if (!sa) - return -1; - - ifa->ifa_netmask = (struct sockaddr*)sa; - prefix_length = net_address->ifa_prefixlen; - if (prefix_length > 32) - prefix_length = 32; - data_length = sizeof (sa->sin_addr); - netmask_data = (unsigned char*)&sa->sin_addr; - break; - } - - case AF_INET6: { - struct sockaddr_in6 *sa = (struct sockaddr_in6*)calloc (1, sizeof (struct sockaddr_in6)); - if (!sa) - return -1; - - ifa->ifa_netmask = (struct sockaddr*)sa; - prefix_length = net_address->ifa_prefixlen; - if (prefix_length > 128) - prefix_length = 128; - data_length = sizeof (sa->sin6_addr); - netmask_data = (unsigned char*)&sa->sin6_addr; - break; - } - } - - if (ifa->ifa_netmask && netmask_data) { - /* Fill the first X bytes with 255 */ - uint32_t prefix_bytes = prefix_length / 8; - uint32_t postfix_bytes; - - if (prefix_bytes > data_length) { - errno = EINVAL; - return -1; - } - postfix_bytes = data_length - prefix_bytes; - memset (netmask_data, 0xFF, prefix_bytes); - if (postfix_bytes > 0) - memset (netmask_data + prefix_bytes + 1, 0x00, postfix_bytes); - log_debug (LOG_NETLINK, " calculating netmask, prefix length is {} bits ({} bytes), data length is {} bytes\n", prefix_length, prefix_bytes, data_length); - if (prefix_bytes + 2 < data_length) - /* Set the rest of the mask bits in the byte following the last 0xFF value */ - netmask_data [prefix_bytes + 1] = static_cast(0xff << (8 - (prefix_length % 8))); - if (Util::should_log (LOG_NETLINK)) { - log_debug_nocheck (LOG_NETLINK, " netmask is: "sv); - for (uint32_t i = 0; i < data_length; i++) { - log_debug_nocheck_fmt (LOG_NETLINK, "{}{}", i == 0 ? " "sv : "."sv, (unsigned char)ifa->ifa_netmask->sa_data [i]); - } - } - } - } - - return 0; -} - - -static struct ifaddrs * -get_link_address (const struct nlmsghdr *message, struct ifaddrs **ifaddrs_head) -{ - ssize_t length = 0z; - struct rtattr *attribute; - struct ifaddrmsg *net_address; - struct ifaddrs *ifa = NULL; - struct sockaddr **sa; - size_t payload_size; - - abort_if_invalid_pointer_argument (message, "message"); - net_address = reinterpret_cast (NLMSG_DATA (message)); - length = static_cast(IFA_PAYLOAD (message)); - log_debug (LOG_NETLINK, " address data length: {}", length); - if (length <= 0) { - goto error; - } - - ifa = reinterpret_cast (calloc (1, sizeof (*ifa))); - if (!ifa) { - goto error; - } - - // values < 0 are never returned, the cast is safe - ifa->ifa_flags = static_cast(get_interface_flags_by_index (static_cast(net_address->ifa_index), ifaddrs_head)); - - attribute = IFA_RTA (net_address); - log_debug (LOG_NETLINK, " reading attributes"sv); - while (RTA_OK (attribute, length)) { - payload_size = RTA_PAYLOAD (attribute); - log_debug (LOG_NETLINK, " attribute payload_size == {}", payload_size); - sa = NULL; - - switch (attribute->rta_type) { - case IFA_LABEL: { - size_t room_for_trailing_null = 0uz; - - log_debug (LOG_NETLINK, " attribute type: LABEL"sv); - if (payload_size > MAX_IFA_LABEL_SIZE) { - payload_size = MAX_IFA_LABEL_SIZE; - room_for_trailing_null = 1; - } - - if (payload_size > 0) { - size_t alloc_size = Helpers::add_with_overflow_check (payload_size, room_for_trailing_null); - ifa->ifa_name = (char*)malloc (alloc_size); - if (!ifa->ifa_name) { - goto error; - } - - memcpy (ifa->ifa_name, RTA_DATA (attribute), payload_size); - if (room_for_trailing_null) - ifa->ifa_name [payload_size] = '\0'; - } - break; - } - - case IFA_LOCAL: - log_debug (LOG_NETLINK, " attribute type: LOCAL"sv); - if (ifa->ifa_addr) { - /* P2P protocol, set the dst/broadcast address union from the original address. - * Since ifa_addr is set it means IFA_ADDRESS occured earlier and that address - * is indeed the P2P destination one. - */ - ifa->ifa_dstaddr = ifa->ifa_addr; - ifa->ifa_addr = 0; - } - sa = &ifa->ifa_addr; - break; - - case IFA_BROADCAST: - log_debug (LOG_NETLINK, " attribute type: BROADCAST"sv); - if (ifa->ifa_dstaddr) { - /* IFA_LOCAL happened earlier, undo its effect here */ - free (ifa->ifa_dstaddr); - ifa->ifa_dstaddr = NULL; - } - sa = &ifa->ifa_broadaddr; - break; - - case IFA_ADDRESS: - log_debug (LOG_NETLINK, " attribute type: ADDRESS"sv); - if (ifa->ifa_addr) { - /* Apparently IFA_LOCAL occured earlier and we have a P2P connection - * here. IFA_LOCAL carries the destination address, move it there - */ - ifa->ifa_dstaddr = ifa->ifa_addr; - ifa->ifa_addr = NULL; - } - sa = &ifa->ifa_addr; - break; - - case IFA_UNSPEC: - log_debug (LOG_NETLINK, " attribute type: UNSPEC"sv); - break; - - case IFA_ANYCAST: - log_debug (LOG_NETLINK, " attribute type: ANYCAST"sv); - break; - - case IFA_CACHEINFO: - log_debug (LOG_NETLINK, " attribute type: CACHEINFO"sv); - break; - - case IFA_MULTICAST: - log_debug (LOG_NETLINK, " attribute type: MULTICAST"sv); - break; - - default: - log_debug (LOG_NETLINK, " attribute type: {}", attribute->rta_type); - break; - } - - if (sa) { - if (fill_sa_address (sa, net_address, RTA_DATA (attribute), RTA_PAYLOAD (attribute)) < 0) { - goto error; - } - } - - attribute = RTA_NEXT (attribute, length); - } - - /* glibc stores the associated interface name in the address if IFA_LABEL never occured */ - if (!ifa->ifa_name) { - char *name = get_interface_name_by_index (static_cast(net_address->ifa_index), ifaddrs_head); - log_debug (LOG_NETLINK, " address has no name/label, getting one from interface"sv); - ifa->ifa_name = name ? strdup (name) : NULL; - } - log_debug (LOG_NETLINK, " address label: {}", optional_string (ifa->ifa_name)); - - if (calculate_address_netmask (ifa, net_address) < 0) { - goto error; - } - - return ifa; - - error: - { - /* errno may be modified by free, or any other call inside the free_single_xamarin_ifaddrs - * function. We don't care about errors in there since it is more important to know how we - * failed to obtain the link address and not that we went OOM. Save and restore the value - * after the resources are freed. - */ - int errno_save = errno; - free_single_xamarin_ifaddrs (&ifa); - errno = errno_save; - return NULL; - } - -} - -static struct ifaddrs * -get_link_info (const struct nlmsghdr *message) -{ - ssize_t length; - struct rtattr *attribute; - struct ifinfomsg *net_interface; - struct ifaddrs *ifa = NULL; - struct sockaddr_ll_extended *sa = NULL; - - abort_if_invalid_pointer_argument (message, "message"); - net_interface = reinterpret_cast (NLMSG_DATA (message)); - length = static_cast(message->nlmsg_len - NLMSG_LENGTH (sizeof (*net_interface))); - if (length <= 0) { - goto error; - } - - ifa = reinterpret_cast (calloc (1, sizeof (*ifa))); - if (!ifa) { - goto error; - } - - ifa->ifa_flags = net_interface->ifi_flags; - attribute = IFLA_RTA (net_interface); - while (RTA_OK (attribute, length)) { - switch (attribute->rta_type) { - case IFLA_IFNAME: - ifa->ifa_name = strdup (reinterpret_cast (RTA_DATA (attribute))); - if (!ifa->ifa_name) { - goto error; - } - if (Util::should_log (LOG_NETLINK)) { - log_debug_nocheck_fmt (LOG_NETLINK, " interface name (payload length: {}; string length: {})", RTA_PAYLOAD (attribute), strlen (ifa->ifa_name)); - log_debug_nocheck_fmt (LOG_NETLINK, " {}", optional_string (ifa->ifa_name)); - } - break; - - case IFLA_BROADCAST: - log_debug (LOG_NETLINK, " interface broadcast ({} bytes)", RTA_PAYLOAD (attribute)); - if (fill_ll_address (&sa, net_interface, RTA_DATA (attribute), RTA_PAYLOAD (attribute)) < 0) { - goto error; - } - ifa->ifa_broadaddr = (struct sockaddr*)sa; - break; - - case IFLA_ADDRESS: - log_debug (LOG_NETLINK, " interface address ({} bytes)", RTA_PAYLOAD (attribute)); - if (fill_ll_address (&sa, net_interface, RTA_DATA (attribute), RTA_PAYLOAD (attribute)) < 0) { - goto error; - } - ifa->ifa_addr = (struct sockaddr*)sa; - break; - - default: -#if DEBUG - log_debug (LOG_NETLINK, " rta_type: "sv); - print_ifla_name (attribute->rta_type); -#endif // DEBUG - break; - } - - attribute = RTA_NEXT (attribute, length); - } - log_debug (LOG_NETLINK, "link flags: {:X}", ifa->ifa_flags); - return ifa; - - error: - if (sa) - free (sa); - free_single_xamarin_ifaddrs (&ifa); - - return NULL; -} -#else -void -_monodroid_getifaddrs_init (void) -{ - -} - -int -_monodroid_getifaddrs (struct ifaddrs **ifap) -{ - *ifap = NULL; - return 0; -} - -void _monodroid_freeifaddrs (struct ifaddrs *ifa) -{ - -} -#endif - -#if DEBUG -#define ENUM_VALUE_ENTRY(enumvalue) { enumvalue, #enumvalue } -struct enumvalue -{ - int value; - const char *name; -}; - -struct enumvalue iflas[] = { - ENUM_VALUE_ENTRY (IFLA_UNSPEC), - ENUM_VALUE_ENTRY (IFLA_ADDRESS), - ENUM_VALUE_ENTRY (IFLA_BROADCAST), - ENUM_VALUE_ENTRY (IFLA_IFNAME), - ENUM_VALUE_ENTRY (IFLA_MTU), - ENUM_VALUE_ENTRY (IFLA_LINK), - ENUM_VALUE_ENTRY (IFLA_QDISC), - ENUM_VALUE_ENTRY (IFLA_STATS), - ENUM_VALUE_ENTRY (IFLA_COST), - ENUM_VALUE_ENTRY (IFLA_PRIORITY), - ENUM_VALUE_ENTRY (IFLA_MASTER), - ENUM_VALUE_ENTRY (IFLA_WIRELESS), - ENUM_VALUE_ENTRY (IFLA_PROTINFO), - ENUM_VALUE_ENTRY (IFLA_TXQLEN), - ENUM_VALUE_ENTRY (IFLA_MAP), - ENUM_VALUE_ENTRY (IFLA_WEIGHT), - ENUM_VALUE_ENTRY (IFLA_OPERSTATE), - ENUM_VALUE_ENTRY (IFLA_LINKMODE), - ENUM_VALUE_ENTRY (IFLA_LINKINFO), - ENUM_VALUE_ENTRY (IFLA_NET_NS_PID), - ENUM_VALUE_ENTRY (IFLA_IFALIAS), - ENUM_VALUE_ENTRY (IFLA_NUM_VF), - ENUM_VALUE_ENTRY (IFLA_VFINFO_LIST), - ENUM_VALUE_ENTRY (IFLA_STATS64), - ENUM_VALUE_ENTRY (IFLA_VF_PORTS), - ENUM_VALUE_ENTRY (IFLA_PORT_SELF), - ENUM_VALUE_ENTRY (IFLA_AF_SPEC), - ENUM_VALUE_ENTRY (IFLA_GROUP), - ENUM_VALUE_ENTRY (IFLA_NET_NS_FD), - ENUM_VALUE_ENTRY (IFLA_EXT_MASK), - ENUM_VALUE_ENTRY (IFLA_PROMISCUITY), - ENUM_VALUE_ENTRY (IFLA_NUM_TX_QUEUES), - ENUM_VALUE_ENTRY (IFLA_NUM_RX_QUEUES), - ENUM_VALUE_ENTRY (IFLA_CARRIER), - ENUM_VALUE_ENTRY (IFLA_PHYS_PORT_ID), - ENUM_VALUE_ENTRY (IFLA_CARRIER_CHANGES), - ENUM_VALUE_ENTRY (IFLA_PHYS_SWITCH_ID), - ENUM_VALUE_ENTRY (IFLA_LINK_NETNSID), - ENUM_VALUE_ENTRY (IFLA_PHYS_PORT_NAME), - ENUM_VALUE_ENTRY (IFLA_PROTO_DOWN), - ENUM_VALUE_ENTRY (IFLA_GSO_MAX_SEGS), - ENUM_VALUE_ENTRY (IFLA_GSO_MAX_SIZE), - ENUM_VALUE_ENTRY (IFLA_PAD), - ENUM_VALUE_ENTRY (IFLA_XDP), - { -1, 0 } -}; - -static void -print_ifla_name (int id) -{ - if (!Util::should_log (LOG_NETLINK)) - return; - - int i = 0; - while (1) { - if (iflas [i].value == -1 && iflas [i].name == 0) { - log_info_nocheck_fmt (LOG_NETLINK, "Unknown ifla->name: unknown id {}", id); - break; - } - - if (iflas [i].value != id) { - i++; - continue; - } - log_info_nocheck_fmt (LOG_NETLINK, "ifla->name: {} ({})", optional_string (iflas [i].name), iflas [i].value); - break; - } -} - -static void -print_address_list (const char title[], struct ifaddrs *list) -{ - if (!Util::should_log (LOG_NETLINK)) - return; - - struct ifaddrs *cur; - char *msg, *tmp; - - if (!list) { - log_info_nocheck_fmt (LOG_NETLINK, "No list to print in {}", __FUNCTION__); - return; - } - - cur = list; - msg = NULL; - while (cur) { - tmp = NULL; - asprintf (&tmp, "%s%s%p (%s; %p)", msg ? msg : "", msg ? " -> " : "", cur, cur->ifa_name, cur->ifa_name); - if (msg) - free (msg); - msg = tmp; - cur = cur->ifa_next; - } - - log_info_nocheck_fmt (LOG_NETLINK, "{}: {}", title, optional_string (msg, "[no addresses]")); - free (msg); -} -#endif diff --git a/src/native/clr/include/runtime-base/internal-pinvokes.hh b/src/native/clr/include/runtime-base/internal-pinvokes.hh index 0bc3f2d841f..b760dc262cb 100644 --- a/src/native/clr/include/runtime-base/internal-pinvokes.hh +++ b/src/native/clr/include/runtime-base/internal-pinvokes.hh @@ -34,9 +34,5 @@ extern "C" { void _monodroid_lref_log_new (int lrefc, jobject handle, char type, const char *threadName, int threadId, const char *from, int from_writable); void _monodroid_lref_log_delete (int lrefc, jobject handle, char type, const char *threadName, int threadId, const char *from, int from_writable); void _monodroid_gc_wait_for_bridge_processing (); - void* _monodroid_timezone_get_default_id (); void _monodroid_detect_cpu_and_architecture (unsigned short *built_for_cpu, unsigned short *running_on_cpu, unsigned char *is64bit); - - int _monodroid_getifaddrs (struct ifaddrs **ifap); - void _monodroid_freeifaddrs (struct ifaddrs *ifa); } diff --git a/src/native/clr/pinvoke-override/generate-pinvoke-tables.cc b/src/native/clr/pinvoke-override/generate-pinvoke-tables.cc index 148bd970c08..250fa15fcea 100644 --- a/src/native/clr/pinvoke-override/generate-pinvoke-tables.cc +++ b/src/native/clr/pinvoke-override/generate-pinvoke-tables.cc @@ -43,11 +43,9 @@ const std::vector internal_pinvoke_names = { // "monodroid_embedded_assemblies_set_assemblies_prefix", // "monodroid_fopen", "monodroid_free", - "_monodroid_freeifaddrs", "_monodroid_gc_wait_for_bridge_processing", // "_monodroid_get_dns_servers", // "monodroid_get_dylib", - "_monodroid_getifaddrs", // "monodroid_get_namespaced_system_property", // "_monodroid_get_network_interface_supports_multicast", // "_monodroid_get_network_interface_up_state", @@ -66,7 +64,6 @@ const std::vector internal_pinvoke_names = { // "monodroid_strdup_printf", // "monodroid_strfreev", // "monodroid_strsplit", - "_monodroid_timezone_get_default_id", "monodroid_timing_start", "monodroid_timing_stop", "monodroid_TypeManager_get_java_class_name", diff --git a/src/native/clr/pinvoke-override/pinvoke-tables.include b/src/native/clr/pinvoke-override/pinvoke-tables.include index 2372544e945..331798647fb 100644 --- a/src/native/clr/pinvoke-override/pinvoke-tables.include +++ b/src/native/clr/pinvoke-override/pinvoke-tables.include @@ -11,9 +11,7 @@ namespace { #if INTPTR_MAX == INT64_MAX //64-bit internal p/invoke table - std::array internal_pinvokes {{ - {0xa50ce5de13bf8b5, "_monodroid_timezone_get_default_id", reinterpret_cast(&_monodroid_timezone_get_default_id)}, - {0x3ade4348ac8ce0fa, "_monodroid_freeifaddrs", reinterpret_cast(&_monodroid_freeifaddrs)}, + std::array internal_pinvokes {{ {0x3b2467e7eadd4a6a, "_monodroid_lref_log_new", reinterpret_cast(&_monodroid_lref_log_new)}, {0x423c8f539a2c56d2, "_monodroid_lookup_replacement_type", reinterpret_cast(&_monodroid_lookup_replacement_type)}, {0x4310c1531ddddc14, "__android_log_print", reinterpret_cast(&__android_log_print)}, @@ -34,7 +32,6 @@ namespace { {0xd1e121b94ea63f2e, "_monodroid_gref_get", reinterpret_cast(&_monodroid_gref_get)}, {0xd5151b00eb33d85e, "monodroid_TypeManager_get_java_class_name", reinterpret_cast(&monodroid_TypeManager_get_java_class_name)}, {0xe27b9849b7e982cb, "_monodroid_max_gref_get", reinterpret_cast(&_monodroid_max_gref_get)}, - {0xe370a0d91cd63bc0, "_monodroid_getifaddrs", reinterpret_cast(&_monodroid_getifaddrs)}, {0xe86307aac9a2631a, "_monodroid_weak_gref_new", reinterpret_cast(&_monodroid_weak_gref_new)}, {0xf3048baf83034541, "_monodroid_gc_wait_for_bridge_processing", reinterpret_cast(&_monodroid_gc_wait_for_bridge_processing)}, {0xf41c48df6f9be476, "monodroid_free", reinterpret_cast(&monodroid_free)}, @@ -545,13 +542,12 @@ constexpr hash_t system_security_cryptography_native_android_library_hash = 0x18 constexpr hash_t system_globalization_native_library_hash = 0x28b5c8fca080abd5; #else //32-bit internal p/invoke table - std::array internal_pinvokes {{ + std::array internal_pinvokes {{ {0xb7a486a, "monodroid_TypeManager_get_java_class_name", reinterpret_cast(&monodroid_TypeManager_get_java_class_name)}, {0x2aea7c33, "_monodroid_max_gref_get", reinterpret_cast(&_monodroid_max_gref_get)}, {0x3227d81a, "monodroid_timing_start", reinterpret_cast(&monodroid_timing_start)}, {0x333d4835, "_monodroid_lookup_replacement_method_info", reinterpret_cast(&_monodroid_lookup_replacement_method_info)}, {0x39e5b5d4, "__android_log_print", reinterpret_cast(&__android_log_print)}, - {0x434ad3e4, "_monodroid_getifaddrs", reinterpret_cast(&_monodroid_getifaddrs)}, {0x656e00bd, "clr_typemap_managed_to_java", reinterpret_cast(&clr_typemap_managed_to_java)}, {0x9070e02c, "_monodroid_lref_log_delete", reinterpret_cast(&_monodroid_lref_log_delete)}, {0x910452d0, "monodroid_timing_stop", reinterpret_cast(&monodroid_timing_stop)}, @@ -559,14 +555,12 @@ constexpr hash_t system_globalization_native_library_hash = 0x28b5c8fca080abd5; {0x9c5b24a8, "_monodroid_weak_gref_new", reinterpret_cast(&_monodroid_weak_gref_new)}, {0xa04e5d1c, "monodroid_free", reinterpret_cast(&monodroid_free)}, {0xa3c1e548, "clr_initialize_gc_bridge", reinterpret_cast(&clr_initialize_gc_bridge)}, - {0xad511c82, "_monodroid_timezone_get_default_id", reinterpret_cast(&_monodroid_timezone_get_default_id)}, {0xb02468aa, "_monodroid_gref_get", reinterpret_cast(&_monodroid_gref_get)}, {0xb6431f9a, "clr_typemap_java_to_managed", reinterpret_cast(&clr_typemap_java_to_managed)}, {0xbe8d7701, "_monodroid_gref_log_new", reinterpret_cast(&_monodroid_gref_log_new)}, {0xc0d097a7, "_monodroid_lref_log_new", reinterpret_cast(&_monodroid_lref_log_new)}, {0xc439b5d7, "_monodroid_lookup_replacement_type", reinterpret_cast(&_monodroid_lookup_replacement_type)}, {0xc5146c54, "_monodroid_gref_log_delete", reinterpret_cast(&_monodroid_gref_log_delete)}, - {0xd3b5d2c1, "_monodroid_freeifaddrs", reinterpret_cast(&_monodroid_freeifaddrs)}, {0xe215a17c, "_monodroid_weak_gref_delete", reinterpret_cast(&_monodroid_weak_gref_delete)}, {0xe7e77ca5, "_monodroid_gref_log", reinterpret_cast(&_monodroid_gref_log)}, {0xea2184e3, "_monodroid_gc_wait_for_bridge_processing", reinterpret_cast(&_monodroid_gc_wait_for_bridge_processing)}, @@ -1079,6 +1073,6 @@ constexpr hash_t system_security_cryptography_native_android_library_hash = 0x93 constexpr hash_t system_globalization_native_library_hash = 0xa66f1e5a; #endif -constexpr size_t internal_pinvokes_count = 27; +constexpr size_t internal_pinvokes_count = 24; constexpr size_t dotnet_pinvokes_count = 490; } // end of anonymous namespace diff --git a/src/native/mono/libmono-android.map.txt b/src/native/mono/libmono-android.map.txt index 18bcab675ef..a3b2c7ccb57 100644 --- a/src/native/mono/libmono-android.map.txt +++ b/src/native/mono/libmono-android.map.txt @@ -7,8 +7,6 @@ LIBMONO_ANDROID { Java_mono_android_Runtime_notifyTimeZoneChanged; Java_mono_android_Runtime_propagateUncaughtException; Java_mono_android_Runtime_register; - _monodroid_freeifaddrs; - _monodroid_getifaddrs; local: *; diff --git a/src/native/mono/monodroid/CMakeLists.txt b/src/native/mono/monodroid/CMakeLists.txt index b8fffa6177c..1b5fa57bdbc 100644 --- a/src/native/mono/monodroid/CMakeLists.txt +++ b/src/native/mono/monodroid/CMakeLists.txt @@ -105,7 +105,6 @@ set(XAMARIN_MONODROID_SOURCES osbridge.cc runtime-util.cc timezones.cc - xamarin_getifaddrs.cc ) list(APPEND LOCAL_CLANG_CHECK_SOURCES diff --git a/src/native/mono/monodroid/internal-pinvokes.cc b/src/native/mono/monodroid/internal-pinvokes.cc index 48a107f83e8..0dfec9d6e4a 100644 --- a/src/native/mono/monodroid/internal-pinvokes.cc +++ b/src/native/mono/monodroid/internal-pinvokes.cc @@ -128,31 +128,6 @@ _monodroid_gc_wait_for_bridge_processing () mono_gc_wait_for_bridge_processing (); } -void* -_monodroid_timezone_get_default_id () -{ - JNIEnv *env = osBridge.ensure_jnienv (); - jmethodID getDefault = env->GetStaticMethodID (MonodroidRuntime::get_java_class_TimeZone (), "getDefault", "()Ljava/util/TimeZone;"); - jmethodID getID = env->GetMethodID (MonodroidRuntime::get_java_class_TimeZone (), "getID", "()Ljava/lang/String;"); - jobject d = env->CallStaticObjectMethod (MonodroidRuntime::get_java_class_TimeZone (), getDefault); - jstring id = reinterpret_cast (env->CallObjectMethod (d, getID)); - const char *mutf8 = env->GetStringUTFChars (id, nullptr); - - if (mutf8 == nullptr) { - log_error (LOG_DEFAULT, "Failed to convert Java TimeZone ID to UTF8 (out of memory?)"sv); - env->DeleteLocalRef (id); - env->DeleteLocalRef (d); - return nullptr; - } - - char *def_id = strdup (mutf8); - - env->ReleaseStringUTFChars (id, mutf8); - env->DeleteLocalRef (id); - env->DeleteLocalRef (d); - - return def_id; -} managed_timing_sequence* monodroid_timing_start (const char *message) diff --git a/src/native/mono/monodroid/xamarin_getifaddrs.cc b/src/native/mono/monodroid/xamarin_getifaddrs.cc deleted file mode 100644 index 23848f9910b..00000000000 --- a/src/native/mono/monodroid/xamarin_getifaddrs.cc +++ /dev/null @@ -1,1186 +0,0 @@ -#include - -#include -#include -#include -#include -#include - -#include -#include - -#include - -#ifdef HAVE_LINUX_NETLINK_H -#include -#endif - -#ifdef HAVE_LINUX_RTNETLINK_H -#include -#endif - -#ifdef HAVE_LINUX_IF_ARP_H -#include -#endif - -#include - -#if ANDROID -#include -#endif - -#include "logger.hh" -#include "util.hh" - -#include "globals.hh" -#include "xamarin_getifaddrs.h" - -using namespace xamarin::android; - -/* Some of these aren't defined in android's rtnetlink.h (as of ndk 16). We define values for all of - * them if they aren't found so that the debug code works properly. We could skip them but future - * versions of the NDK might include definitions for them. - * Values are taken from Linux headers shipped with glibc - */ -#ifndef IFLA_UNSPEC -#define IFLA_UNSPEC 0 -#endif - -#ifndef IFLA_ADDRESS -#define IFLA_ADDRESS 1 -#endif - -#ifndef IFLA_BROADCAST -#define IFLA_BROADCAST 2 -#endif - -#ifndef IFLA_IFNAME -#define IFLA_IFNAME 3 -#endif - -#ifndef IFLA_MTU -#define IFLA_MTU 4 -#endif - -#ifndef IFLA_LINK -#define IFLA_LINK 5 -#endif - -#ifndef IFLA_QDISC -#define IFLA_QDISC 6 -#endif - -#ifndef IFLA_STATS -#define IFLA_STATS 7 -#endif - -#ifndef IFLA_COST -#define IFLA_COST 8 -#endif - -#ifndef IFLA_PRIORITY -#define IFLA_PRIORITY 9 -#endif - -#ifndef IFLA_MASTER -#define IFLA_MASTER 10 -#endif - -#ifndef IFLA_WIRELESS -#define IFLA_WIRELESS 11 -#endif - -#ifndef IFLA_PROTINFO -#define IFLA_PROTINFO 12 -#endif - -#ifndef IFLA_TXQLEN -#define IFLA_TXQLEN 13 -#endif - -#ifndef IFLA_MAP -#define IFLA_MAP 14 -#endif - -#ifndef IFLA_WEIGHT -#define IFLA_WEIGHT 15 -#endif - -#ifndef IFLA_OPERSTATE -#define IFLA_OPERSTATE 16 -#endif - -#ifndef IFLA_LINKMODE -#define IFLA_LINKMODE 17 -#endif - -#ifndef IFLA_LINKINFO -#define IFLA_LINKINFO 18 -#endif - -#ifndef IFLA_NET_NS_PID -#define IFLA_NET_NS_PID 19 -#endif - -#ifndef IFLA_IFALIAS -#define IFLA_IFALIAS 20 -#endif - -#ifndef IFLA_NUM_VF -#define IFLA_NUM_VF 21 -#endif - -#ifndef IFLA_VFINFO_LIST -#define IFLA_VFINFO_LIST 22 -#endif - -#ifndef IFLA_STATS64 -#define IFLA_STATS64 23 -#endif - -#ifndef IFLA_VF_PORTS -#define IFLA_VF_PORTS 24 -#endif - -#ifndef IFLA_PORT_SELF -#define IFLA_PORT_SELF 25 -#endif - -#ifndef IFLA_AF_SPEC -#define IFLA_AF_SPEC 26 -#endif - -#ifndef IFLA_GROUP -#define IFLA_GROUP 27 -#endif - -#ifndef IFLA_NET_NS_FD -#define IFLA_NET_NS_FD 28 -#endif - -#ifndef IFLA_EXT_MASK -#define IFLA_EXT_MASK 29 -#endif - -#ifndef IFLA_PROMISCUITY -#define IFLA_PROMISCUITY 30 -#endif - -#ifndef IFLA_NUM_TX_QUEUES -#define IFLA_NUM_TX_QUEUES 31 -#endif - -#ifndef IFLA_NUM_RX_QUEUES -#define IFLA_NUM_RX_QUEUES 32 -#endif - -#ifndef IFLA_CARRIER -#define IFLA_CARRIER 33 -#endif - -#ifndef IFLA_PHYS_PORT_ID -#define IFLA_PHYS_PORT_ID 34 -#endif - -#ifndef IFLA_CARRIER_CHANGES -#define IFLA_CARRIER_CHANGES 35 -#endif - -#ifndef IFLA_PHYS_SWITCH_ID -#define IFLA_PHYS_SWITCH_ID 36 -#endif - -#ifndef IFLA_LINK_NETNSID -#define IFLA_LINK_NETNSID 37 -#endif - -#ifndef IFLA_PHYS_PORT_NAME -#define IFLA_PHYS_PORT_NAME 38 -#endif - -#ifndef IFLA_PROTO_DOWN -#define IFLA_PROTO_DOWN 39 -#endif - -#ifndef IFLA_GSO_MAX_SEGS -#define IFLA_GSO_MAX_SEGS 40 -#endif - -#ifndef IFLA_GSO_MAX_SIZE -#define IFLA_GSO_MAX_SIZE 41 -#endif - -#ifndef IFLA_PAD -#define IFLA_PAD 42 -#endif - -#ifndef IFLA_XDP -#define IFLA_XDP 43 -#endif - -/* Maximum interface address label size, should be more than enough */ -#define MAX_IFA_LABEL_SIZE 1024 - -#if defined (__linux__) || defined (__linux) - -/* This is the message we send to the kernel */ -typedef struct { - struct nlmsghdr header; - struct rtgenmsg message; -} netlink_request; - -typedef struct { - int sock_fd; - int seq; - struct sockaddr_nl them; /* kernel end */ - struct sockaddr_nl us; /* our end */ - struct msghdr message_header; /* for use with sendmsg */ - struct iovec payload_vector; /* Used to send netlink_request */ -} netlink_session; - -/* Turns out that quite a few link types have address length bigger than the 8 bytes allocated in - * this structure as defined by the OS. Examples are Infiniband or ipv6 tunnel devices - */ -struct sockaddr_ll_extended { - unsigned short int sll_family; - unsigned short int sll_protocol; - int sll_ifindex; - unsigned short int sll_hatype; - unsigned char sll_pkttype; - unsigned char sll_halen; - unsigned char sll_addr[24]; -}; - -static int parse_netlink_reply (netlink_session *session, struct _monodroid_ifaddrs **ifaddrs_head, struct _monodroid_ifaddrs **last_ifaddr); -static struct _monodroid_ifaddrs *get_link_info (const struct nlmsghdr *message); -static struct _monodroid_ifaddrs *get_link_address (const struct nlmsghdr *message, struct _monodroid_ifaddrs **ifaddrs_head); -static int open_netlink_session (netlink_session *session); -static int send_netlink_dump_request (netlink_session *session, int type); -static int append_ifaddr (struct _monodroid_ifaddrs *addr, struct _monodroid_ifaddrs **ifaddrs_head, struct _monodroid_ifaddrs **last_ifaddr); -static int fill_ll_address (struct sockaddr_ll_extended **sa, struct ifinfomsg *net_interface, void *rta_data, size_t rta_payload_length); -static int fill_sa_address (struct sockaddr **sa, struct ifaddrmsg *net_address, void *rta_data, size_t rta_payload_length); -static void free_single_xamarin_ifaddrs (struct _monodroid_ifaddrs **ifap); -static void get_ifaddrs_impl (int (**getifaddrs_impl) (struct _monodroid_ifaddrs **ifap), void (**freeifaddrs_impl) (struct _monodroid_ifaddrs *ifa)); -static struct _monodroid_ifaddrs *find_interface_by_index (int index, struct _monodroid_ifaddrs **ifaddrs_head); -static char *get_interface_name_by_index (int index, struct _monodroid_ifaddrs **ifaddrs_head); -static int get_interface_flags_by_index (int index, struct _monodroid_ifaddrs **ifaddrs_head); -static int calculate_address_netmask (struct _monodroid_ifaddrs *ifa, struct ifaddrmsg *net_address); -#if DEBUG -static void print_ifla_name (int id); -static void print_address_list (const char title[], struct _monodroid_ifaddrs *list); -#endif - -/* We don't use 'struct ifaddrs' since that doesn't exist in Android's bionic, but since our - * version of the structure is 100% compatible we can just use it instead - */ -typedef int (*getifaddrs_impl_fptr)(struct _monodroid_ifaddrs **); -typedef void (*freeifaddrs_impl_fptr)(struct _monodroid_ifaddrs *ifa); - -static getifaddrs_impl_fptr getifaddrs_impl = NULL; -static freeifaddrs_impl_fptr freeifaddrs_impl = NULL; -static bool initialized; -static xamarin::android::mutex init_lock; - -void -_monodroid_getifaddrs_init () -{ - get_ifaddrs_impl (&getifaddrs_impl, &freeifaddrs_impl); -} - -int -_monodroid_getifaddrs (struct _monodroid_ifaddrs **ifap) -{ - if (!initialized) { - xamarin::android::lock_guard lock (init_lock); - if (!initialized) { - _monodroid_getifaddrs_init (); - initialized = true; - } - } - - int ret = -1; - - if (getifaddrs_impl) - return (*getifaddrs_impl)(ifap); - - if (!ifap) - return ret; - - *ifap = NULL; - struct _monodroid_ifaddrs *ifaddrs_head = 0; - struct _monodroid_ifaddrs *last_ifaddr = 0; - netlink_session session; - - if (open_netlink_session (&session) < 0) { - goto cleanup; - } - - /* Request information about the specified link. In our case it will be all of them since we - request the root of the link tree below - */ - if ((send_netlink_dump_request (&session, RTM_GETLINK) < 0) || - (parse_netlink_reply (&session, &ifaddrs_head, &last_ifaddr) < 0) || - (send_netlink_dump_request (&session, RTM_GETADDR) < 0) || - (parse_netlink_reply (&session, &ifaddrs_head, &last_ifaddr) < 0)) { - _monodroid_freeifaddrs (ifaddrs_head); - goto cleanup; - } - - ret = 0; - *ifap = ifaddrs_head; -#if DEBUG - print_address_list ("Initial interfaces list", *ifap); -#endif - - cleanup: - if (session.sock_fd >= 0) { - close (session.sock_fd); - session.sock_fd = -1; - } - - return ret; -} - -void -_monodroid_freeifaddrs (struct _monodroid_ifaddrs *ifa) -{ - struct _monodroid_ifaddrs *cur, *next; - - if (!ifa) - return; - - if (freeifaddrs_impl) { - (*freeifaddrs_impl)(ifa); - return; - } - -#if DEBUG - print_address_list ("List passed to freeifaddrs", ifa); -#endif - cur = ifa; - while (cur) { - next = cur->ifa_next; - free_single_xamarin_ifaddrs (&cur); - cur = next; - } -} - -static void -get_ifaddrs_impl (int (**getifaddrs_implementation) (struct _monodroid_ifaddrs **ifap), void (**freeifaddrs_implementation) (struct _monodroid_ifaddrs *ifa)) -{ - void *libc; - - abort_if_invalid_pointer_argument (getifaddrs_implementation, "getifaddrs_implementation"); - abort_if_invalid_pointer_argument (freeifaddrs_implementation, "freeifaddrs_implementation"); - - libc = dlopen ("libc.so", RTLD_NOW); - if (libc) { - *getifaddrs_implementation = reinterpret_cast (dlsym (libc, "getifaddrs")); - if (*getifaddrs_implementation) - *freeifaddrs_implementation = reinterpret_cast (dlsym (libc, "freeifaddrs")); - } - - if (!*getifaddrs_implementation) { - log_info (LOG_NET, "This libc does not have getifaddrs/freeifaddrs, using Xamarin's"sv); - } else { - log_info (LOG_NET, "This libc has getifaddrs/freeifaddrs"sv); - } -} - -static void -free_single_xamarin_ifaddrs (struct _monodroid_ifaddrs **ifap) -{ - struct _monodroid_ifaddrs *ifa = ifap ? *ifap : NULL; - if (!ifa) - return; - - if (ifa->ifa_name) - free (ifa->ifa_name); - - if (ifa->ifa_addr) - free (ifa->ifa_addr); - - if (ifa->ifa_netmask) - free (ifa->ifa_netmask); - - if (ifa->_monodroid_ifa_broadaddr) - free (ifa->_monodroid_ifa_broadaddr); - - if (ifa->ifa_data) - free (ifa->ifa_data); - - free (ifa); - *ifap = NULL; -} - -static int -open_netlink_session (netlink_session *session) -{ - abort_if_invalid_pointer_argument (session, "session"); - - memset (session, 0, sizeof (*session)); - session->sock_fd = socket (AF_NETLINK, SOCK_RAW, NETLINK_ROUTE); - if (session->sock_fd == -1) { - log_warn (LOG_NETLINK, "Failed to create a netlink socket. {}", strerror (errno)); - return -1; - } - - /* Fill out addresses */ - session->us.nl_family = AF_NETLINK; - - /* We have previously used `getpid()` here but it turns out that WebView/Chromium does the same - and there can only be one session with the same PID. Setting it to 0 will cause the kernel to - assign some PID that's unique and valid instead. - - See: https://bugzilla.xamarin.com/show_bug.cgi?id=41860 - */ - session->us.nl_pid = 0; - session->us.nl_groups = 0; - - session->them.nl_family = AF_NETLINK; - - if (bind (session->sock_fd, (struct sockaddr *)&session->us, sizeof (session->us)) < 0) { - log_warn (LOG_NETLINK, "Failed to bind to the netlink socket. {}", strerror (errno)); - return -1; - } - - return 0; -} - -static int -send_netlink_dump_request (netlink_session *session, int type) -{ - netlink_request request; - - memset (&request, 0, sizeof (request)); - request.header.nlmsg_len = NLMSG_LENGTH (sizeof (struct rtgenmsg)); - /* Flags (from netlink.h): - NLM_F_REQUEST - it's a request message - NLM_F_DUMP - gives us the root of the link tree and returns all links matching our requested - AF, which in our case means all of them (AF_PACKET) - */ - request.header.nlmsg_flags = NLM_F_REQUEST | NLM_F_ROOT | NLM_F_MATCH; - request.header.nlmsg_seq = static_cast<__u32>(++session->seq); - request.header.nlmsg_pid = session->us.nl_pid; - request.header.nlmsg_type = static_cast<__u16>(type); - - /* AF_PACKET means we want to see everything */ - request.message.rtgen_family = AF_PACKET; - - memset (&session->payload_vector, 0, sizeof (session->payload_vector)); - session->payload_vector.iov_len = request.header.nlmsg_len; - session->payload_vector.iov_base = &request; - - memset (&session->message_header, 0, sizeof (session->message_header)); - session->message_header.msg_namelen = sizeof (session->them); - session->message_header.msg_name = &session->them; - session->message_header.msg_iovlen = 1; - session->message_header.msg_iov = &session->payload_vector; - - if (sendmsg (session->sock_fd, (const struct msghdr*)&session->message_header, 0) < 0) { - log_warn (LOG_NETLINK, "Failed to send netlink message. {}", strerror (errno)); - return -1; - } - - return 0; -} - -static int -append_ifaddr (struct _monodroid_ifaddrs *addr, struct _monodroid_ifaddrs **ifaddrs_head, struct _monodroid_ifaddrs **last_ifaddr) -{ - abort_if_invalid_pointer_argument (addr, "addr"); - abort_if_invalid_pointer_argument (ifaddrs_head, "ifaddrs_head"); - abort_if_invalid_pointer_argument (last_ifaddr, "last_ifaddr"); - - if (!*ifaddrs_head) { - *ifaddrs_head = *last_ifaddr = addr; - if (!*ifaddrs_head) - return -1; - } else if (!*last_ifaddr) { - struct _monodroid_ifaddrs *last = *ifaddrs_head; - - while (last->ifa_next) - last = last->ifa_next; - *last_ifaddr = last; - } - - addr->ifa_next = NULL; - if (addr == *last_ifaddr) - return 0; - - (*last_ifaddr)->ifa_next = addr; - *last_ifaddr = addr; - - return 0; -} - -static int -parse_netlink_reply (netlink_session *session, struct _monodroid_ifaddrs **ifaddrs_head, struct _monodroid_ifaddrs **last_ifaddr) -{ - struct msghdr netlink_reply; - struct iovec reply_vector; - struct nlmsghdr *current_message; - struct _monodroid_ifaddrs *addr; - int ret = -1; - unsigned char *response = NULL; - - abort_if_invalid_pointer_argument (session, "session"); - abort_if_invalid_pointer_argument (ifaddrs_head, "ifaddrs_head"); - abort_if_invalid_pointer_argument (last_ifaddr, "last_ifaddr"); - - size_t buf_size = static_cast(getpagesize ()); - log_debug (LOG_NETLINK, "receive buffer size == {}", buf_size); - - size_t alloc_size = Helpers::multiply_with_overflow_check (sizeof(*response), buf_size); - response = (unsigned char*)malloc (alloc_size); - ssize_t length = 0z; - if (!response) { - goto cleanup; - } - - while (1) { - memset (response, 0, buf_size); - memset (&reply_vector, 0, sizeof (reply_vector)); - reply_vector.iov_len = buf_size; - reply_vector.iov_base = response; - - memset (&netlink_reply, 0, sizeof (netlink_reply)); - netlink_reply.msg_namelen = sizeof (&session->them); - netlink_reply.msg_name = &session->them; - netlink_reply.msg_iovlen = 1; - netlink_reply.msg_iov = &reply_vector; - - length = recvmsg (session->sock_fd, &netlink_reply, 0); - log_debug (LOG_NETLINK, " length == {}", (int)length); - - if (length < 0) { - log_debug (LOG_NETLINK, "Failed to receive reply from netlink. {}", strerror (errno)); - goto cleanup; - } - -#if DEBUG - if (Util::should_log (LOG_NETLINK)) { - log_debug_nocheck (LOG_NETLINK, "response flags:"sv); - if (netlink_reply.msg_flags == 0) - log_debug_nocheck (LOG_NETLINK, " [NONE]"sv); - else { - if (netlink_reply.msg_flags & MSG_EOR) - log_debug_nocheck (LOG_NETLINK, " MSG_EOR"sv); - if (netlink_reply.msg_flags & MSG_TRUNC) - log_debug_nocheck (LOG_NETLINK, " MSG_TRUNC"sv); - if (netlink_reply.msg_flags & MSG_CTRUNC) - log_debug_nocheck (LOG_NETLINK, " MSG_CTRUNC"sv); - if (netlink_reply.msg_flags & MSG_OOB) - log_debug_nocheck (LOG_NETLINK, " MSG_OOB"sv); - if (netlink_reply.msg_flags & MSG_ERRQUEUE) - log_debug_nocheck (LOG_NETLINK, " MSG_ERRQUEUE"sv); - } - } -#endif - - if (length == 0) - break; - - for (current_message = (struct nlmsghdr*)response; current_message && NLMSG_OK (current_message, static_cast(length)); current_message = NLMSG_NEXT (current_message, length)) { - log_debug (LOG_NETLINK, "next message... (type: {})", current_message->nlmsg_type); - switch (current_message->nlmsg_type) { - /* See rtnetlink.h */ - case RTM_NEWLINK: - log_debug (LOG_NETLINK, " dumping link..."sv); - addr = get_link_info (current_message); - if (!addr || append_ifaddr (addr, ifaddrs_head, last_ifaddr) < 0) { - ret = -1; - goto cleanup; - } - log_debug (LOG_NETLINK, " done"sv); - break; - - case RTM_NEWADDR: - log_debug (LOG_NETLINK, " got an address"sv); - addr = get_link_address (current_message, ifaddrs_head); - if (!addr || append_ifaddr (addr, ifaddrs_head, last_ifaddr) < 0) { - ret = -1; - goto cleanup; - } - break; - - case NLMSG_DONE: - log_debug (LOG_NETLINK, " message done"sv); - ret = 0; - goto cleanup; - break; - - default: - log_debug (LOG_NETLINK, " message type: {}", current_message->nlmsg_type); - break; - } - } - } - - cleanup: - if (response) - free (response); - return ret; -} - -static int -fill_sa_address (struct sockaddr **sa, struct ifaddrmsg *net_address, void *rta_data, size_t rta_payload_length) -{ - abort_if_invalid_pointer_argument (sa, "sa"); - abort_if_invalid_pointer_argument (net_address, "net_address"); - abort_if_invalid_pointer_argument (rta_data, "rta_data"); - - switch (net_address->ifa_family) { - case AF_INET: { - struct sockaddr_in *sa4; - if (rta_payload_length != 4) /* IPv4 address length */ { - log_warn (LOG_NETLINK, "Unexpected IPv4 address payload length {}", rta_payload_length); - return -1; - } - sa4 = (struct sockaddr_in*)calloc (1, sizeof (*sa4)); - if (sa4 == nullptr) - return -1; - - sa4->sin_family = AF_INET; - memcpy (&sa4->sin_addr, rta_data, rta_payload_length); - *sa = (struct sockaddr*)sa4; - break; - } - - case AF_INET6: { - struct sockaddr_in6 *sa6; - if (rta_payload_length != 16) /* IPv6 address length */ { - log_warn (LOG_NETLINK, "Unexpected IPv6 address payload length {}", rta_payload_length); - return -1; - } - sa6 = (struct sockaddr_in6*)calloc (1, sizeof (*sa6)); - if (sa6 == nullptr) - return -1; - - sa6->sin6_family = AF_INET6; - memcpy (&sa6->sin6_addr, rta_data, rta_payload_length); - if (IN6_IS_ADDR_LINKLOCAL (&sa6->sin6_addr) || IN6_IS_ADDR_MC_LINKLOCAL (&sa6->sin6_addr)) - sa6->sin6_scope_id = net_address->ifa_index; - *sa = (struct sockaddr*)sa6; - break; - } - - default: { - struct sockaddr *sagen; - if (rta_payload_length > sizeof (sagen->sa_data)) { - log_warn (LOG_NETLINK, "Unexpected RTA payload length {} (wanted at most {})", rta_payload_length, sizeof (sagen->sa_data)); - return -1; - } - - *sa = sagen = (struct sockaddr*)calloc (1, sizeof (*sagen)); - if (!sagen) - return -1; - - sagen->sa_family = net_address->ifa_family; - memcpy (&sagen->sa_data, rta_data, rta_payload_length); - break; - } - } - - return 0; -} - -static int -fill_ll_address (struct sockaddr_ll_extended **sa, struct ifinfomsg *net_interface, void *rta_data, size_t rta_payload_length) -{ - abort_if_invalid_pointer_argument (sa, "sa"); - abort_if_invalid_pointer_argument (net_interface, "net_interface"); - - /* Always allocate, do not free - caller may reuse the same variable */ - *sa = reinterpret_cast(calloc (1, sizeof (**sa))); - if (!*sa) - return -1; - - (*sa)->sll_family = AF_PACKET; /* Always for physical links */ - - /* The assert can only fail for Iniband links, which are quite unlikely to be found - * in any mobile devices - */ - log_debug (LOG_NETLINK, "rta_payload_length == {}; sizeof sll_addr == {}; hw type == {:x}", rta_payload_length, sizeof ((*sa)->sll_addr), net_interface->ifi_type); - if (static_cast(rta_payload_length) > sizeof ((*sa)->sll_addr)) { - log_info (LOG_NETLINK, "Address is too long to place in sockaddr_ll ({} > {})", rta_payload_length, sizeof ((*sa)->sll_addr)); - free (*sa); - *sa = NULL; - return -1; - } - - if (rta_payload_length > std::numeric_limits::max ()) { - log_info (LOG_NETLINK, "Payload length too big to fit in the address structure"sv); - free (*sa); - *sa = NULL; - return -1; - } - - (*sa)->sll_ifindex = net_interface->ifi_index; - (*sa)->sll_hatype = net_interface->ifi_type; - (*sa)->sll_halen = static_cast(rta_payload_length); - memcpy ((*sa)->sll_addr, rta_data, rta_payload_length); - - return 0; -} - -static struct _monodroid_ifaddrs * -find_interface_by_index (int index, struct _monodroid_ifaddrs **ifaddrs_head) -{ - struct _monodroid_ifaddrs *cur; - if (!ifaddrs_head || !*ifaddrs_head) - return NULL; - - /* Normally expensive, but with the small amount of links in the chain we'll deal with it's not - * worth the extra houskeeping and memory overhead - */ - cur = *ifaddrs_head; - while (cur) { - if (cur->ifa_addr && cur->ifa_addr->sa_family == AF_PACKET && ((struct sockaddr_ll_extended*)cur->ifa_addr)->sll_ifindex == index) - return cur; - if (cur == cur->ifa_next) - break; - cur = cur->ifa_next; - } - - return NULL; -} - -static char * -get_interface_name_by_index (int index, struct _monodroid_ifaddrs **ifaddrs_head) -{ - struct _monodroid_ifaddrs *iface = find_interface_by_index (index, ifaddrs_head); - if (!iface || !iface->ifa_name) - return NULL; - - return iface->ifa_name; -} - -static int -get_interface_flags_by_index (int index, struct _monodroid_ifaddrs **ifaddrs_head) -{ - struct _monodroid_ifaddrs *iface = find_interface_by_index (index, ifaddrs_head); - if (!iface) - return 0; - - return static_cast(iface->ifa_flags); -} - -static int -calculate_address_netmask (struct _monodroid_ifaddrs *ifa, struct ifaddrmsg *net_address) -{ - if (ifa->ifa_addr && ifa->ifa_addr->sa_family != AF_UNSPEC && ifa->ifa_addr->sa_family != AF_PACKET) { - uint32_t prefix_length = 0; - uint32_t data_length = 0; - unsigned char *netmask_data = NULL; - - switch (ifa->ifa_addr->sa_family) { - case AF_INET: { - struct sockaddr_in *sa = (struct sockaddr_in*)calloc (1, sizeof (struct sockaddr_in)); - if (!sa) - return -1; - - ifa->ifa_netmask = (struct sockaddr*)sa; - prefix_length = net_address->ifa_prefixlen; - if (prefix_length > 32) - prefix_length = 32; - data_length = sizeof (sa->sin_addr); - netmask_data = (unsigned char*)&sa->sin_addr; - break; - } - - case AF_INET6: { - struct sockaddr_in6 *sa = (struct sockaddr_in6*)calloc (1, sizeof (struct sockaddr_in6)); - if (!sa) - return -1; - - ifa->ifa_netmask = (struct sockaddr*)sa; - prefix_length = net_address->ifa_prefixlen; - if (prefix_length > 128) - prefix_length = 128; - data_length = sizeof (sa->sin6_addr); - netmask_data = (unsigned char*)&sa->sin6_addr; - break; - } - } - - if (ifa->ifa_netmask && netmask_data) { - /* Fill the first X bytes with 255 */ - uint32_t prefix_bytes = prefix_length / 8; - uint32_t postfix_bytes; - - if (prefix_bytes > data_length) { - errno = EINVAL; - return -1; - } - postfix_bytes = data_length - prefix_bytes; - memset (netmask_data, 0xFF, prefix_bytes); - if (postfix_bytes > 0) - memset (netmask_data + prefix_bytes + 1, 0x00, postfix_bytes); - log_debug (LOG_NETLINK, " calculating netmask, prefix length is {} bits ({} bytes), data length is {} bytes\n", prefix_length, prefix_bytes, data_length); - if (prefix_bytes + 2 < data_length) - /* Set the rest of the mask bits in the byte following the last 0xFF value */ - netmask_data [prefix_bytes + 1] = static_cast(0xff << (8 - (prefix_length % 8))); - if (Util::should_log (LOG_NETLINK)) { - log_debug_nocheck (LOG_NETLINK, " netmask is: "sv); - for (uint32_t i = 0; i < data_length; i++) { - log_debug_nocheck_fmt (LOG_NETLINK, "{}{}", i == 0 ? " "sv : "."sv, (unsigned char)ifa->ifa_netmask->sa_data [i]); - } - } - } - } - - return 0; -} - - -static struct _monodroid_ifaddrs * -get_link_address (const struct nlmsghdr *message, struct _monodroid_ifaddrs **ifaddrs_head) -{ - ssize_t length = 0z; - struct rtattr *attribute; - struct ifaddrmsg *net_address; - struct _monodroid_ifaddrs *ifa = NULL; - struct sockaddr **sa; - size_t payload_size; - - abort_if_invalid_pointer_argument (message, "message"); - net_address = reinterpret_cast (NLMSG_DATA (message)); - length = static_cast(IFA_PAYLOAD (message)); - log_debug (LOG_NETLINK, " address data length: {}", length); - if (length <= 0) { - goto error; - } - - ifa = reinterpret_cast<_monodroid_ifaddrs*> (calloc (1, sizeof (*ifa))); - if (!ifa) { - goto error; - } - - // values < 0 are never returned, the cast is safe - ifa->ifa_flags = static_cast(get_interface_flags_by_index (static_cast(net_address->ifa_index), ifaddrs_head)); - - attribute = IFA_RTA (net_address); - log_debug (LOG_NETLINK, " reading attributes"sv); - while (RTA_OK (attribute, length)) { - payload_size = RTA_PAYLOAD (attribute); - log_debug (LOG_NETLINK, " attribute payload_size == {}", payload_size); - sa = NULL; - - switch (attribute->rta_type) { - case IFA_LABEL: { - size_t room_for_trailing_null = 0uz; - - log_debug (LOG_NETLINK, " attribute type: LABEL"sv); - if (payload_size > MAX_IFA_LABEL_SIZE) { - payload_size = MAX_IFA_LABEL_SIZE; - room_for_trailing_null = 1; - } - - if (payload_size > 0) { - size_t alloc_size = Helpers::add_with_overflow_check (payload_size, room_for_trailing_null); - ifa->ifa_name = (char*)malloc (alloc_size); - if (!ifa->ifa_name) { - goto error; - } - - memcpy (ifa->ifa_name, RTA_DATA (attribute), payload_size); - if (room_for_trailing_null) - ifa->ifa_name [payload_size] = '\0'; - } - break; - } - - case IFA_LOCAL: - log_debug (LOG_NETLINK, " attribute type: LOCAL"sv); - if (ifa->ifa_addr) { - /* P2P protocol, set the dst/broadcast address union from the original address. - * Since ifa_addr is set it means IFA_ADDRESS occured earlier and that address - * is indeed the P2P destination one. - */ - ifa->_monodroid_ifa_dstaddr = ifa->ifa_addr; - ifa->ifa_addr = 0; - } - sa = &ifa->ifa_addr; - break; - - case IFA_BROADCAST: - log_debug (LOG_NETLINK, " attribute type: BROADCAST"sv); - if (ifa->_monodroid_ifa_dstaddr) { - /* IFA_LOCAL happened earlier, undo its effect here */ - free (ifa->_monodroid_ifa_dstaddr); - ifa->_monodroid_ifa_dstaddr = NULL; - } - sa = &ifa->_monodroid_ifa_broadaddr; - break; - - case IFA_ADDRESS: - log_debug (LOG_NETLINK, " attribute type: ADDRESS"sv); - if (ifa->ifa_addr) { - /* Apparently IFA_LOCAL occured earlier and we have a P2P connection - * here. IFA_LOCAL carries the destination address, move it there - */ - ifa->_monodroid_ifa_dstaddr = ifa->ifa_addr; - ifa->ifa_addr = NULL; - } - sa = &ifa->ifa_addr; - break; - - case IFA_UNSPEC: - log_debug (LOG_NETLINK, " attribute type: UNSPEC"sv); - break; - - case IFA_ANYCAST: - log_debug (LOG_NETLINK, " attribute type: ANYCAST"sv); - break; - - case IFA_CACHEINFO: - log_debug (LOG_NETLINK, " attribute type: CACHEINFO"sv); - break; - - case IFA_MULTICAST: - log_debug (LOG_NETLINK, " attribute type: MULTICAST"sv); - break; - - default: - log_debug (LOG_NETLINK, " attribute type: {}", attribute->rta_type); - break; - } - - if (sa) { - if (fill_sa_address (sa, net_address, RTA_DATA (attribute), RTA_PAYLOAD (attribute)) < 0) { - goto error; - } - } - - attribute = RTA_NEXT (attribute, length); - } - - /* glibc stores the associated interface name in the address if IFA_LABEL never occured */ - if (!ifa->ifa_name) { - char *name = get_interface_name_by_index (static_cast(net_address->ifa_index), ifaddrs_head); - log_debug (LOG_NETLINK, " address has no name/label, getting one from interface"sv); - ifa->ifa_name = name ? strdup (name) : NULL; - } - log_debug (LOG_NETLINK, " address label: {}", optional_string (ifa->ifa_name)); - - if (calculate_address_netmask (ifa, net_address) < 0) { - goto error; - } - - return ifa; - - error: - { - /* errno may be modified by free, or any other call inside the free_single_xamarin_ifaddrs - * function. We don't care about errors in there since it is more important to know how we - * failed to obtain the link address and not that we went OOM. Save and restore the value - * after the resources are freed. - */ - int errno_save = errno; - free_single_xamarin_ifaddrs (&ifa); - errno = errno_save; - return NULL; - } - -} - -static struct _monodroid_ifaddrs * -get_link_info (const struct nlmsghdr *message) -{ - ssize_t length; - struct rtattr *attribute; - struct ifinfomsg *net_interface; - struct _monodroid_ifaddrs *ifa = NULL; - struct sockaddr_ll_extended *sa = NULL; - - abort_if_invalid_pointer_argument (message, "message"); - net_interface = reinterpret_cast (NLMSG_DATA (message)); - length = static_cast(message->nlmsg_len - NLMSG_LENGTH (sizeof (*net_interface))); - if (length <= 0) { - goto error; - } - - ifa = reinterpret_cast<_monodroid_ifaddrs*> (calloc (1, sizeof (*ifa))); - if (!ifa) { - goto error; - } - - ifa->ifa_flags = net_interface->ifi_flags; - attribute = IFLA_RTA (net_interface); - while (RTA_OK (attribute, length)) { - switch (attribute->rta_type) { - case IFLA_IFNAME: - ifa->ifa_name = strdup (reinterpret_cast (RTA_DATA (attribute))); - if (!ifa->ifa_name) { - goto error; - } - if (Util::should_log (LOG_NETLINK)) { - log_debug_nocheck_fmt (LOG_NETLINK, " interface name (payload length: {}; string length: {})", RTA_PAYLOAD (attribute), strlen (ifa->ifa_name)); - log_debug_nocheck_fmt (LOG_NETLINK, " {}", optional_string (ifa->ifa_name)); - } - break; - - case IFLA_BROADCAST: - log_debug (LOG_NETLINK, " interface broadcast ({} bytes)", RTA_PAYLOAD (attribute)); - if (fill_ll_address (&sa, net_interface, RTA_DATA (attribute), RTA_PAYLOAD (attribute)) < 0) { - goto error; - } - ifa->_monodroid_ifa_broadaddr = (struct sockaddr*)sa; - break; - - case IFLA_ADDRESS: - log_debug (LOG_NETLINK, " interface address ({} bytes)", RTA_PAYLOAD (attribute)); - if (fill_ll_address (&sa, net_interface, RTA_DATA (attribute), RTA_PAYLOAD (attribute)) < 0) { - goto error; - } - ifa->ifa_addr = (struct sockaddr*)sa; - break; - - default: -#if DEBUG - log_debug (LOG_NETLINK, " rta_type: "sv); - print_ifla_name (attribute->rta_type); -#endif // DEBUG - break; - } - - attribute = RTA_NEXT (attribute, length); - } - log_debug (LOG_NETLINK, "link flags: {:X}", ifa->ifa_flags); - return ifa; - - error: - if (sa) - free (sa); - free_single_xamarin_ifaddrs (&ifa); - - return NULL; -} -#else -void -_monodroid_getifaddrs_init (void) -{ - -} - -int -_monodroid_getifaddrs (struct _monodroid_ifaddrs **ifap) -{ - *ifap = NULL; - return 0; -} - -void _monodroid_freeifaddrs (struct _monodroid_ifaddrs *ifa) -{ - -} -#endif - -#if DEBUG -#define ENUM_VALUE_ENTRY(enumvalue) { enumvalue, #enumvalue } -struct enumvalue -{ - int value; - const char *name; -}; - -struct enumvalue iflas[] = { - ENUM_VALUE_ENTRY (IFLA_UNSPEC), - ENUM_VALUE_ENTRY (IFLA_ADDRESS), - ENUM_VALUE_ENTRY (IFLA_BROADCAST), - ENUM_VALUE_ENTRY (IFLA_IFNAME), - ENUM_VALUE_ENTRY (IFLA_MTU), - ENUM_VALUE_ENTRY (IFLA_LINK), - ENUM_VALUE_ENTRY (IFLA_QDISC), - ENUM_VALUE_ENTRY (IFLA_STATS), - ENUM_VALUE_ENTRY (IFLA_COST), - ENUM_VALUE_ENTRY (IFLA_PRIORITY), - ENUM_VALUE_ENTRY (IFLA_MASTER), - ENUM_VALUE_ENTRY (IFLA_WIRELESS), - ENUM_VALUE_ENTRY (IFLA_PROTINFO), - ENUM_VALUE_ENTRY (IFLA_TXQLEN), - ENUM_VALUE_ENTRY (IFLA_MAP), - ENUM_VALUE_ENTRY (IFLA_WEIGHT), - ENUM_VALUE_ENTRY (IFLA_OPERSTATE), - ENUM_VALUE_ENTRY (IFLA_LINKMODE), - ENUM_VALUE_ENTRY (IFLA_LINKINFO), - ENUM_VALUE_ENTRY (IFLA_NET_NS_PID), - ENUM_VALUE_ENTRY (IFLA_IFALIAS), - ENUM_VALUE_ENTRY (IFLA_NUM_VF), - ENUM_VALUE_ENTRY (IFLA_VFINFO_LIST), - ENUM_VALUE_ENTRY (IFLA_STATS64), - ENUM_VALUE_ENTRY (IFLA_VF_PORTS), - ENUM_VALUE_ENTRY (IFLA_PORT_SELF), - ENUM_VALUE_ENTRY (IFLA_AF_SPEC), - ENUM_VALUE_ENTRY (IFLA_GROUP), - ENUM_VALUE_ENTRY (IFLA_NET_NS_FD), - ENUM_VALUE_ENTRY (IFLA_EXT_MASK), - ENUM_VALUE_ENTRY (IFLA_PROMISCUITY), - ENUM_VALUE_ENTRY (IFLA_NUM_TX_QUEUES), - ENUM_VALUE_ENTRY (IFLA_NUM_RX_QUEUES), - ENUM_VALUE_ENTRY (IFLA_CARRIER), - ENUM_VALUE_ENTRY (IFLA_PHYS_PORT_ID), - ENUM_VALUE_ENTRY (IFLA_CARRIER_CHANGES), - ENUM_VALUE_ENTRY (IFLA_PHYS_SWITCH_ID), - ENUM_VALUE_ENTRY (IFLA_LINK_NETNSID), - ENUM_VALUE_ENTRY (IFLA_PHYS_PORT_NAME), - ENUM_VALUE_ENTRY (IFLA_PROTO_DOWN), - ENUM_VALUE_ENTRY (IFLA_GSO_MAX_SEGS), - ENUM_VALUE_ENTRY (IFLA_GSO_MAX_SIZE), - ENUM_VALUE_ENTRY (IFLA_PAD), - ENUM_VALUE_ENTRY (IFLA_XDP), - { -1, 0 } -}; - -static void -print_ifla_name (int id) -{ - if (!Util::should_log (LOG_NETLINK)) - return; - - int i = 0; - while (1) { - if (iflas [i].value == -1 && iflas [i].name == 0) { - log_info_nocheck_fmt (LOG_NETLINK, "Unknown ifla->name: unknown id {}", id); - break; - } - - if (iflas [i].value != id) { - i++; - continue; - } - log_info_nocheck_fmt (LOG_NETLINK, "ifla->name: {} ({})", optional_string (iflas [i].name), iflas [i].value); - break; - } -} - -static void -print_address_list (const char title[], struct _monodroid_ifaddrs *list) -{ - if (!Util::should_log (LOG_NETLINK)) - return; - - struct _monodroid_ifaddrs *cur; - char *msg, *tmp; - - if (!list) { - log_info_nocheck_fmt (LOG_NETLINK, "No list to print in {}", __FUNCTION__); - return; - } - - cur = list; - msg = NULL; - while (cur) { - tmp = NULL; - asprintf (&tmp, "%s%s%p (%s; %p)", msg ? msg : "", msg ? " -> " : "", cur, cur->ifa_name, cur->ifa_name); - if (msg) - free (msg); - msg = tmp; - cur = cur->ifa_next; - } - - log_info_nocheck_fmt (LOG_NETLINK, "{}: {}", title, optional_string (msg, "[no addresses]")); - free (msg); -} -#endif diff --git a/src/native/mono/pinvoke-override/generate-pinvoke-tables.cc b/src/native/mono/pinvoke-override/generate-pinvoke-tables.cc index baa7a20da27..b877459f246 100644 --- a/src/native/mono/pinvoke-override/generate-pinvoke-tables.cc +++ b/src/native/mono/pinvoke-override/generate-pinvoke-tables.cc @@ -41,10 +41,8 @@ const std::vector internal_pinvoke_names = { "monodroid_embedded_assemblies_set_assemblies_prefix", "monodroid_fopen", "monodroid_free", - "_monodroid_freeifaddrs", "_monodroid_gc_wait_for_bridge_processing", "monodroid_get_dylib", - "_monodroid_getifaddrs", "monodroid_get_system_property", "_monodroid_gref_get", "_monodroid_gref_log", @@ -58,7 +56,6 @@ const std::vector internal_pinvoke_names = { "_monodroid_max_gref_get", "monodroid_strdup_printf", "monodroid_strsplit", - "_monodroid_timezone_get_default_id", "monodroid_timing_start", "monodroid_timing_stop", "monodroid_TypeManager_get_java_class_name", diff --git a/src/native/mono/pinvoke-override/pinvoke-tables.include b/src/native/mono/pinvoke-override/pinvoke-tables.include index feb84c70218..f217fc4fcd1 100644 --- a/src/native/mono/pinvoke-override/pinvoke-tables.include +++ b/src/native/mono/pinvoke-override/pinvoke-tables.include @@ -11,10 +11,8 @@ namespace { #if INTPTR_MAX == INT64_MAX //64-bit internal p/invoke table - std::array internal_pinvokes {{ - {0xa50ce5de13bf8b5, "_monodroid_timezone_get_default_id", reinterpret_cast(&_monodroid_timezone_get_default_id)}, + std::array internal_pinvokes {{ {0x2b3b0ca1d14076da, "monodroid_get_dylib", reinterpret_cast(&monodroid_get_dylib)}, - {0x3ade4348ac8ce0fa, "_monodroid_freeifaddrs", reinterpret_cast(&_monodroid_freeifaddrs)}, {0x3b2467e7eadd4a6a, "_monodroid_lref_log_new", reinterpret_cast(&_monodroid_lref_log_new)}, {0x3c5532ecdab53f89, "set_world_accessable", reinterpret_cast(&set_world_accessable)}, {0x423c8f539a2c56d2, "_monodroid_lookup_replacement_type", reinterpret_cast(&_monodroid_lookup_replacement_type)}, @@ -41,7 +39,6 @@ namespace { {0xd5151b00eb33d85e, "monodroid_TypeManager_get_java_class_name", reinterpret_cast(&monodroid_TypeManager_get_java_class_name)}, {0xda517ef392b6a888, "java_interop_free", reinterpret_cast(&java_interop_free)}, {0xe27b9849b7e982cb, "_monodroid_max_gref_get", reinterpret_cast(&_monodroid_max_gref_get)}, - {0xe370a0d91cd63bc0, "_monodroid_getifaddrs", reinterpret_cast(&_monodroid_getifaddrs)}, {0xe78f1161604ae672, "send_uninterrupted", reinterpret_cast(&send_uninterrupted)}, {0xe86307aac9a2631a, "_monodroid_weak_gref_new", reinterpret_cast(&_monodroid_weak_gref_new)}, {0xebc2c68e10075cc9, "monodroid_fopen", reinterpret_cast(&monodroid_fopen)}, @@ -555,7 +552,7 @@ constexpr hash_t system_security_cryptography_native_android_library_hash = 0x18 constexpr hash_t system_globalization_native_library_hash = 0x28b5c8fca080abd5; #else //32-bit internal p/invoke table - std::array internal_pinvokes {{ + std::array internal_pinvokes {{ {0xb7a486a, "monodroid_TypeManager_get_java_class_name", reinterpret_cast(&monodroid_TypeManager_get_java_class_name)}, {0xf562bd9, "monodroid_embedded_assemblies_set_assemblies_prefix", reinterpret_cast(&monodroid_embedded_assemblies_set_assemblies_prefix)}, {0x2aea7c33, "_monodroid_max_gref_get", reinterpret_cast(&_monodroid_max_gref_get)}, @@ -563,7 +560,6 @@ constexpr hash_t system_globalization_native_library_hash = 0x28b5c8fca080abd5; {0x333d4835, "_monodroid_lookup_replacement_method_info", reinterpret_cast(&_monodroid_lookup_replacement_method_info)}, {0x395808e5, "monodroid_dylib_mono_free", reinterpret_cast(&monodroid_dylib_mono_free)}, {0x42b41fe4, "send_uninterrupted", reinterpret_cast(&send_uninterrupted)}, - {0x434ad3e4, "_monodroid_getifaddrs", reinterpret_cast(&_monodroid_getifaddrs)}, {0x4b58e0da, "monodroid_get_dylib", reinterpret_cast(&monodroid_get_dylib)}, {0x501ebdc2, "monodroid_dylib_mono_init", reinterpret_cast(&monodroid_dylib_mono_init)}, {0x7c94dbf5, "monodroid_fopen", reinterpret_cast(&monodroid_fopen)}, @@ -576,14 +572,12 @@ constexpr hash_t system_globalization_native_library_hash = 0x28b5c8fca080abd5; {0x9c5b24a8, "_monodroid_weak_gref_new", reinterpret_cast(&_monodroid_weak_gref_new)}, {0xa04e5d1c, "monodroid_free", reinterpret_cast(&monodroid_free)}, {0xa7ea4a5f, "path_combine", reinterpret_cast(&path_combine)}, - {0xad511c82, "_monodroid_timezone_get_default_id", reinterpret_cast(&_monodroid_timezone_get_default_id)}, {0xb02468aa, "_monodroid_gref_get", reinterpret_cast(&_monodroid_gref_get)}, {0xbe8d7701, "_monodroid_gref_log_new", reinterpret_cast(&_monodroid_gref_log_new)}, {0xc0d097a7, "_monodroid_lref_log_new", reinterpret_cast(&_monodroid_lref_log_new)}, {0xc439b5d7, "_monodroid_lookup_replacement_type", reinterpret_cast(&_monodroid_lookup_replacement_type)}, {0xc5146c54, "_monodroid_gref_log_delete", reinterpret_cast(&_monodroid_gref_log_delete)}, {0xc58eafa5, "java_interop_free", reinterpret_cast(&java_interop_free)}, - {0xd3b5d2c1, "_monodroid_freeifaddrs", reinterpret_cast(&_monodroid_freeifaddrs)}, {0xd91f3619, "create_public_directory", reinterpret_cast(&create_public_directory)}, {0xe215a17c, "_monodroid_weak_gref_delete", reinterpret_cast(&_monodroid_weak_gref_delete)}, {0xe7e77ca5, "_monodroid_gref_log", reinterpret_cast(&_monodroid_gref_log)}, @@ -1099,6 +1093,6 @@ constexpr hash_t system_security_cryptography_native_android_library_hash = 0x93 constexpr hash_t system_globalization_native_library_hash = 0xa66f1e5a; #endif -constexpr size_t internal_pinvokes_count = 38; +constexpr size_t internal_pinvokes_count = 35; constexpr size_t dotnet_pinvokes_count = 490; } // end of anonymous namespace diff --git a/src/native/mono/runtime-base/internal-pinvokes.hh b/src/native/mono/runtime-base/internal-pinvokes.hh index 62bb0fc72d9..ddfadfe4498 100644 --- a/src/native/mono/runtime-base/internal-pinvokes.hh +++ b/src/native/mono/runtime-base/internal-pinvokes.hh @@ -9,10 +9,6 @@ #include "log_types.hh" #include #include "xamarin-app.hh" -#include "xamarin_getifaddrs.h" - -int _monodroid_getifaddrs (struct _monodroid_ifaddrs **ifap); -void _monodroid_freeifaddrs (struct _monodroid_ifaddrs *ifa); int monodroid_get_system_property (const char *name, char **value); int monodroid_embedded_assemblies_set_assemblies_prefix (const char *prefix); @@ -29,7 +25,6 @@ void _monodroid_weak_gref_delete (jobject handle, char type, const char *threadN void _monodroid_lref_log_new (int lrefc, jobject handle, char type, const char *threadName, int threadId, const char *from, int from_writable); void _monodroid_lref_log_delete (int lrefc, jobject handle, char type, const char *threadName, int threadId, const char *from, int from_writable); void _monodroid_gc_wait_for_bridge_processing (); -void* _monodroid_timezone_get_default_id (); xamarin::android::managed_timing_sequence* monodroid_timing_start (const char *message); void monodroid_timing_stop (xamarin::android::managed_timing_sequence *sequence, const char *message); char** monodroid_strsplit (const char *str, const char *delimiter, size_t max_tokens); diff --git a/src/native/mono/runtime-base/xamarin_getifaddrs.h b/src/native/mono/runtime-base/xamarin_getifaddrs.h deleted file mode 100644 index b39c1fae9d0..00000000000 --- a/src/native/mono/runtime-base/xamarin_getifaddrs.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef __XAMARIN_GETIFADDRS_H -#define __XAMARIN_GETIFADDRS_H - -#include - -/* We're implementing getifaddrs behavior, this is the structure we use. It is exactly the same as - * struct ifaddrs defined in ifaddrs.h but since bionics doesn't have it we need to mirror it here. - */ -struct _monodroid_ifaddrs { - struct _monodroid_ifaddrs *ifa_next; /* Pointer to the next structure. */ - - char *ifa_name; /* Name of this network interface. */ - unsigned int ifa_flags; /* Flags as from SIOCGIFFLAGS ioctl. */ - - struct sockaddr *ifa_addr; /* Network address of this interface. */ - struct sockaddr *ifa_netmask; /* Netmask of this interface. */ - union { - /* At most one of the following two is valid. If the IFF_BROADCAST - bit is set in `ifa_flags', then `ifa_broadaddr' is valid. If the - IFF_POINTOPOINT bit is set, then `ifa_dstaddr' is valid. - It is never the case that both these bits are set at once. */ - struct sockaddr *ifu_broadaddr; /* Broadcast address of this interface. */ - struct sockaddr *ifu_dstaddr; /* Point-to-point destination address. */ - } ifa_ifu; - /* These very same macros are defined by for `struct ifaddr'. - So if they are defined already, the existing definitions will be fine. */ -# ifndef _monodroid_ifa_broadaddr -# define _monodroid_ifa_broadaddr ifa_ifu.ifu_broadaddr -# endif -# ifndef _monodroid_ifa_dstaddr -# define _monodroid_ifa_dstaddr ifa_ifu.ifu_dstaddr -# endif - - void *ifa_data; /* Address-specific data (may be unused). */ -}; - - void _monodroid_getifaddrs_init (void); -MONO_API int _monodroid_getifaddrs (struct _monodroid_ifaddrs **ifap); -MONO_API void _monodroid_freeifaddrs (struct _monodroid_ifaddrs *ifa); - -#endif