Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
363 views
in Technique[技术] by (71.8m points)

c - How to determine ARMv8 features at runtime on iOS?

I am trying to determine when optional ARMv8 cpu features are available on iOS at runtime. On OS X desktops, like i686, x86_64, PPC and PPC64 we can use sysctl. See, for example, PR 3108, SIGILL-free processor capabilities detection on MacOS X.

The "SIGILL-free processor capabilities" part is important because SIGILL-based feature probes corrupt memory on Apple platforms. At least three projects I follow have had problems with it, including Crypto++ and OpenSSL. Another part of the problem is questions like Does Apple Clang lack CRC32 for ARMv8/Aarch64 under Xcode 10?, where core ARMv8 features that should be present seem to be missing or unsupported.

I've looked for the iOS equivalent of the OS X desktops but I cannot find them (see below).

We really prefer to avoid Apple frameworks like CommonCrypto. We try hard to stay platform agnostic. We don't use CommonCrypto, but I would consider using an Apple functions like below if there's nothing agnostic available (I'm making them up):

BOOL CCHasAes();
BOOL CCHasSHA1();
BOOL CCHasSHA2();

Does Apple publish a method to determine cpu features at runtime?

How do we determine cpu features at runtime on iOS?


These may be related, but I'm not sure if that's the best we have, or if that's the only thing we have, or if there are other ways to approach it.


Below I am looking for CRC-32, CRC-32C, AES, PMULL, SHA1 and SHA2 features. I don't see any hits that resemble what I am looking for. Apple supports ARMv8 since Xcode 7, so 8.2 supports the CPU.

$ grep -IR CTL_ /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.2.sdk | 
  sed 's|/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.2.sdk/usr/include|...|g'
.../c++/4.2.1/bits/c++config.h:#define _GLIBCXX_HAVE_SYS_IOCTL_H 1
.../netinet/in.h:#define        IPCTL_FORWARDING        1       /* act as router */
.../netinet/in.h:#define        IPCTL_SENDREDIRECTS     2       /* may send redirects when forwarding */
.../netinet/in.h:#define        IPCTL_DEFTTL            3       /* default TTL */
.../netinet/in.h:#define        IPCTL_DEFMTU            4       /* default MTU */
.../netinet/in.h:#define IPCTL_RTEXPIRE         5       /* cloned route expiration time */
.../netinet/in.h:#define IPCTL_RTMINEXPIRE      6       /* min value for expiration time */
.../netinet/in.h:#define IPCTL_RTMAXCACHE       7       /* trigger level for dynamic expire */
.../netinet/in.h:#define        IPCTL_SOURCEROUTE       8       /* may perform source routes */
.../netinet/in.h:#define        IPCTL_DIRECTEDBROADCAST 9       /* may re-broadcast received packets */
.../netinet/in.h:#define IPCTL_INTRQMAXLEN      10      /* max length of netisr queue */
.../netinet/in.h:#define        IPCTL_INTRQDROPS        11      /* number of netisr q drops */
.../netinet/in.h:#define        IPCTL_STATS             12      /* ipstat structure */
.../netinet/in.h:#define        IPCTL_ACCEPTSOURCEROUTE 13      /* may accept source routed packets */
.../netinet/in.h:#define        IPCTL_FASTFORWARDING    14      /* use fast IP forwarding code */
.../netinet/in.h:#define        IPCTL_KEEPFAITH         15      /* deprecated */
.../netinet/in.h:#define        IPCTL_GIF_TTL           16      /* default TTL for gif encap packet */
.../netinet/in.h:#define        IPCTL_MAXID             17
.../netinet6/in6.h:#define      IPV6CTL_FORWARDING      1       /* act as router */
.../netinet6/in6.h:#define      IPV6CTL_SENDREDIRECTS   2       /* may send redirects when forwarding */
.../netinet6/in6.h:#define      IPV6CTL_DEFHLIM         3       /* default Hop-Limit */
.../netinet6/in6.h:#define      IPV6CTL_DEFMTU          4       /* default MTU */
.../netinet6/in6.h:#define      IPV6CTL_FORWSRCRT       5       /* forward source-routed dgrams */
.../netinet6/in6.h:#define      IPV6CTL_STATS           6       /* stats */
.../netinet6/in6.h:#define      IPV6CTL_MRTSTATS        7       /* multicast forwarding stats */
.../netinet6/in6.h:#define      IPV6CTL_MRTPROTO        8       /* multicast routing protocol */
.../netinet6/in6.h:#define      IPV6CTL_MAXFRAGPACKETS  9       /* max packets reassembly queue */
.../netinet6/in6.h:#define      IPV6CTL_SOURCECHECK     10      /* verify source route and intf */
.../netinet6/in6.h:#define      IPV6CTL_SOURCECHECK_LOGINT 11   /* minimume logging interval */
.../netinet6/in6.h:#define      IPV6CTL_ACCEPT_RTADV    12
.../netinet6/in6.h:#define      IPV6CTL_KEEPFAITH       13      /* deprecated */
.../netinet6/in6.h:#define      IPV6CTL_LOG_INTERVAL    14
.../netinet6/in6.h:#define      IPV6CTL_HDRNESTLIMIT    15
.../netinet6/in6.h:#define      IPV6CTL_DAD_COUNT       16
.../netinet6/in6.h:#define      IPV6CTL_AUTO_FLOWLABEL  17
.../netinet6/in6.h:#define      IPV6CTL_DEFMCASTHLIM    18
.../netinet6/in6.h:#define      IPV6CTL_GIF_HLIM        19      /* default HLIM for gif encap packet */
.../netinet6/in6.h:#define      IPV6CTL_KAME_VERSION    20
.../netinet6/in6.h:#define      IPV6CTL_USE_DEPRECATED  21      /* use deprec addr (RFC2462 5.5.4) */
.../netinet6/in6.h:#define      IPV6CTL_RR_PRUNE        22      /* walk timer for router renumbering */
.../netinet6/in6.h:#define      IPV6CTL_MAPPED_ADDR     23
.../netinet6/in6.h:#define      IPV6CTL_V6ONLY          24
.../netinet6/in6.h:#define      IPV6CTL_RTEXPIRE        25      /* cloned route expiration time */
.../netinet6/in6.h:#define      IPV6CTL_RTMINEXPIRE     26      /* min value for expiration time */
.../netinet6/in6.h:#define      IPV6CTL_RTMAXCACHE      27      /* trigger level for dynamic expire */
.../netinet6/in6.h:#define      IPV6CTL_USETEMPADDR     32      /* use temporary addresses [RFC 4941] */
.../netinet6/in6.h:#define      IPV6CTL_TEMPPLTIME      33      /* preferred lifetime for tmpaddrs */
.../netinet6/in6.h:#define      IPV6CTL_TEMPVLTIME      34      /* valid lifetime for tmpaddrs */
.../netinet6/in6.h:#define      IPV6CTL_AUTO_LINKLOCAL  35      /* automatic link-local addr assign */
.../netinet6/in6.h:#define      IPV6CTL_RIP6STATS       36      /* raw_ip6 stats */
.../netinet6/in6.h:#define      IPV6CTL_PREFER_TEMPADDR 37      /* prefer temporary addr as src */
.../netinet6/in6.h:#define      IPV6CTL_ADDRCTLPOLICY   38      /* get/set address selection policy */
.../netinet6/in6.h:#define      IPV6CTL_USE_DEFAULTZONE 39      /* use default scope zone */
.../netinet6/in6.h:#define      IPV6CTL_MAXFRAGS        41      /* max fragments */
.../netinet6/in6.h:#define      IPV6CTL_MCAST_PMTU      44      /* enable pMTU discovery for mcast? */
.../netinet6/in6.h:#define      IPV6CTL_NEIGHBORGCTHRESH 46
.../netinet6/in6.h:#define      IPV6CTL_MAXIFPREFIXES   47
.../netinet6/in6.h:#define      IPV6CTL_MAXIFDEFROUTERS 48
.../netinet6/in6.h:#define      IPV6CTL_MAXDYNROUTES    49
.../netinet6/in6.h:#define      ICMPV6CTL_ND6_ONLINKNSRFC4861   50
.../netinet6/in6.h:/* New entries should be added here from current IPV6CTL_MAXID value. */
.../netinet6/in6.h:#define      IPV6CTL_MAXID           51
.../sys/ioctl.h:#ifndef _SYS_IOCTL_H_
.../sys/ioctl.h:#define _SYS_IOCTL_H_
.../sys/ioctl.h:#endif /* !_SYS_IOCTL_H_ */
.../sys/ioctl.h: * Keep outside _SYS_IOCTL_H_
.../sys/ioctl.h:#endif /* !_SYS_IOCTL_H_ */
.../sys/mount.h: * Sysctl CTL_VFS definitions.
.../sys/mount.h:        int             vc_vers;        /* should be VFSIDCTL_VERS1 (below) */
.../sys/mount.h:#define VFS_CTL_VERS1   0x01
.../sys/mount.h:#define VFS_CTL_STATFS  0x00010001      /* statfs */
.../sys/mount.h:#define VFS_CTL_UMOUNT  0x00010002      /* unmount */
.../sys/mount.h:#define VFS_CTL_QUERY   0x00010003      /* anything wrong? (vfsquery) */
.../sys/mount.h:#define VFS_CTL_NEWADDR 0x00010004      /* reconnect to new address */
.../sys/mount.h:#define VFS_CTL_TIMEO   0x00010005      /* set timeout for vfs notification */
.../sys/mount.h:#define VFS_CTL_NOLOCKS 0x00010006      /* disable file locking */
.../sys/mount.h:#define VFS_CTL_SADDR   0x00010007      /* get server address */
.../sys/mount.h:#define VFS_CTL_DISC    0x00010008      /* server disconnected */
.../sys/mount.h:#define VFS_CTL_SERVERINFO  0x00010009  /* information about fs server */
.../sys/mount.h:#define VFS_CTL_NSTATUS 0x0001000A      /* netfs mount status */
.../sys/mount.h: * NetFS mount status - returned by VFS_CTL_NSTATUS
.../sys/socket.h: * Definitions for network related sysctl, CTL_NET.
.../sys/sysctl.h:#ifndef _SYS_SYSCTL_H_
.../sys/sysctl.h:#define        _SYS_SYSCTL_H_
.../sys/sysctl.h:#define CTL_MAXNAME    12      /* largest number of components supported */
.../sys/sysctl.h: *                     SYSCTL_OUT(rey, local buffer, length)
.../sys/sysctl.h: * e.g. SYSCTL_INT(_parent, OID_AUTO, name, CTLFLAG_RW, &variable, 0, "");
.../sys/sysctl.h:#define SYSCTL_DEF_ENABLED
.../sys/sysctl.h:#ifdef SYSCTL_DEF_ENABLED
.../sys/sysctl.h:#define        CTL_UNSPEC      0               /* unused */
.../sys/sysctl.h:#define        CTL_KERN        1               /* "high kernel": proc, limits */
.../sys/sysctl.h:#define        CTL_VM          2               /* virtual memory */
.../sys/sysctl.h:#define        CTL_VFS         3               /* file system, mount type is next */
.../sys/sysctl.h:#define        CTL_NET         4               /* network, see socket.h */
.../sys/sysctl.h:#define        CTL_DEBUG       5               /* debugging parameters */
.../sys/sysctl.h:#define        CTL_HW          6               /* generic cpu/io */
.../sys/sysctl.h:#define        CTL_MACHDEP     7               /* machine dependent */
.../sys/sysctl.h:#define        CTL_USER        8               /* user-level */
.../sys/sysctl.h:#define        CTL_MAXID       9               /* number of valid top-level ids */
.../sys/sysctl.h:#define CTL_NAMES { 
.../sys/sysctl.h: * CTL_KERN identifiers
.../sys/sysctl.h: * Don't add any more sysctls like this.  Instead, use the SYSCTL_*() macros
.../sys/sysctl.h:#define CTL_KERN_NAMES { 
.../sys/sysctl.h: * CTL_VFS identifiers
.../sys/sysctl.h:#define CTL_VFS_NAMES { 
.../sys/sysctl.h: * CTL_VM identifiers
.../sys/sysctl.h:#define        CTL_VM_NAMES { 
.../sys/sysctl.h: * CTL_HW identifiers
.../sys/sysctl.h:#define CTL_HW_NAMES { 
.../sys/sysctl.h: * CTL_USER definitions
.../sys/sysctl.h:#define        CTL_USER_NAMES { 
.../sys/sysctl.h: * CTL_DEBUG definitions
.../sys/sysctl.h:#define        CTL_DEBUG_NAME          0       /* string: variable name */
.../sys/sysctl.h:#define        CTL_DEBUG_VALUE         1       /* int: variable value */
.../sys/sysctl.h:#define        CTL_DEBUG_MAXID         20
.../sys/sysctl.h:#if (CTL_MAXID != 9) || (KERN_MAXID != 72) || (VM_MAXID != 6) || (HW_MAXID != 26) || (USER_MAXID != 21) || (CTL_DEBUG_MAXID != 20)
.../sys/sysctl.h:#error Use the SYSCTL_*() macros and OID_AUTO instead!
.../sys/sysctl.h:#endif /* SYSCTL_DEF_ENABLED */
.../sys/sysctl.h:#endif /* !_SYS_SYSCTL_H_ */
.../sys/termios.h:#if !defined(_SYS_IOCTL_COMPAT_H_) || __DARWIN_UNIX03
.../sys/termios.h:#endif        /* !_SYS_IOCTL_COMPAT_H_ */
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

As far as I know Apple is going to remove the support to 32-bit chips this year. Since Apple A7 processors Apple uses ArmV8-A cores for its SoCs...so maybe you cannot choose them with the new APIs because you have nothing to choose...Apple usually is cryptic about those kind of things and uses automatic switching for certain features on mobile platforms. However basically every iOS 11 SoC will have the same basic hardware features except for the number of cores and the energy management (which is different for SoC >= A10 Fusion). I was searching for the same thing some month ago but apparently on iOS you have to be in the hands of the OS.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...