New platform xca6ll (macos, arm64, clang/llvm).

This commit is contained in:
Gareth Rees 2021-01-16 12:07:30 +00:00
parent 3810e9a5cb
commit ca146d96d6
18 changed files with 219 additions and 12 deletions

View file

@ -13,6 +13,7 @@ lii6gc
lii6ll
w3i3mv
w3i6mv
xca6ll
xci3gc
xci3ll
xci6gc

View file

@ -576,7 +576,13 @@
things like thread states. These definitions fix that. */
#if defined(MPS_OS_XC)
#if defined(MPS_ARCH_I6)
#if defined(MPS_ARCH_A6)
#define THREAD_STATE_COUNT ARM_THREAD_STATE64_COUNT
#define THREAD_STATE_FLAVOR ARM_THREAD_STATE64
#define THREAD_STATE_S arm_thread_state64_t
#elif defined(MPS_ARCH_I6)
#define THREAD_STATE_COUNT x86_THREAD_STATE64_COUNT
#define THREAD_STATE_FLAVOR x86_THREAD_STATE64

View file

@ -15,7 +15,7 @@
#include "event.h"
/* See <https://docs.python.org/3/library/struct.html#byte-order-size-and-alignment> */
#if defined(MPS_ARCH_I3) || defined(MPS_ARCH_I6)
#if defined(MPS_ARCH_A6) || defined(MPS_ARCH_I3) || defined(MPS_ARCH_I6)
#define BYTE_ORDER "<"
#else
#error "Can't determine byte order for platform architecture."

View file

@ -110,6 +110,20 @@
#include "prmcanan.c" /* generic architecture mutator context */
#include "span.c" /* generic stack probe */
/* macOS on ARM64 built with Clang */
#elif defined(MPS_PF_XCA6LL)
#include "lockix.c" /* Posix locks */
#include "thxc.c" /* macOS Mach threading */
#include "vmix.c" /* Posix virtual memory */
#include "protix.c" /* Posix protection */
#include "protxc.c" /* macOS Mach exception handling */
#include "prmcanan.c" /* generic architecture mutator context */
#include "prmcxc.c" /* macOS mutator context */
#include "prmcxca6.c" /* ARM64 for macOS mutator context */
#include "span.c" /* generic stack probe */
/* macOS on IA-32 built with Clang or GCC */
#elif defined(MPS_PF_XCI3LL) || defined(MPS_PF_XCI3GC)

View file

@ -165,6 +165,25 @@
#define MPS_PF_ALIGN 8
/* Apple clang version 12.0, clang -E -dM */
#elif defined(__APPLE__) && defined(__arm64__) && defined(__MACH__) \
&& defined(__clang__)
#if defined(CONFIG_PF_STRING) && ! defined(CONFIG_PF_XCA6LL)
#error "specified CONFIG_PF_... inconsistent with detected xca6ll"
#endif
#define MPS_PF_XCA6LL
#define MPS_PF_STRING "xca6ll"
#define MPS_OS_XC
#define MPS_ARCH_A6
#define MPS_BUILD_LL
#define MPS_T_WORD unsigned long
#define MPS_T_ULONGEST unsigned long
#define MPS_WORD_WIDTH 64
#define MPS_WORD_SHIFT 6
#define MPS_PF_ALIGN 8
/* Apple clang version 3.1, clang -E -dM */
#elif defined(__APPLE__) && defined(__i386__) && defined(__MACH__) \

View file

@ -12,7 +12,13 @@
#include "mpm.h"
#include <mach/mach_types.h>
#if defined(MPS_ARCH_A6)
#include <mach/arm/thread_status.h>
#elif defined(MPS_ARCH_I3) || defined(MPS_ARCH_I6)
#include <mach/i386/thread_status.h>
#else
#error "Unknown macOS architecture"
#endif
typedef struct MutatorContextStruct {
Sig sig; /* <design/sig> */

57
mps/code/prmcxca6.c Normal file
View file

@ -0,0 +1,57 @@
/* prmcxca6.c: MUTATOR CONTEXT ARM64 (macOS)
*
* $Id$
* Copyright (c) 2001-2021 Ravenbrook Limited. See end of file for license.
*
* .purpose: Implement the mutator context module. <design/prmc>.
*
*
* ASSUMPTIONS
*
* .sp: The stack pointer in the context is SP.
*/
#include "prmcxc.h"
SRCID(prmcxca6, "$Id$");
#if !defined(MPS_OS_XC) || !defined(MPS_ARCH_A6)
#error "prmcxca6.c is specific to MPS_OS_XC and MPS_ARCH_A6"
#endif
Addr MutatorContextSP(MutatorContext context)
{
AVERT(MutatorContext, context);
return (Addr)arm_thread_state64_get_sp(*(context->threadState)); /* .sp */
}
/* C. COPYRIGHT AND LICENSE
*
* Copyright (C) 2001-2021 Ravenbrook Limited <https://www.ravenbrook.com/>.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

View file

@ -70,7 +70,6 @@
#include <mach/thread_act.h>
#include <mach/thread_status.h>
#include <mach/mach_error.h>
#include <mach/i386/thread_status.h>
#include <mach/exc.h>
#include <pthread.h>
#include <stdlib.h> /* see .trans.stdlib */

View file

@ -104,7 +104,7 @@
* tests to root out any incompatible assumptions by breaking.
*/
#if defined(MPS_ARCH_I6)
#if defined(MPS_ARCH_A6) || defined(MPS_ARCH_I6)
#define PRIwWORD "16"
#elif defined(MPS_ARCH_I3)
#define PRIwWORD "8"

58
mps/code/xca6ll.gmk Normal file
View file

@ -0,0 +1,58 @@
# -*- makefile -*-
#
# xca6ll.gmk: BUILD FOR macOS/ARM64/Clang/LLVM PLATFORM
#
# $Id$
# Copyright (c) 2001-2021 Ravenbrook Limited. See end of file for license.
#
# .prefer.xcode: The documented and preferred way to develop the MPS
# for this platform is to use the Xcode project (mps.xcodeproj). This
# makefile provides a way to compile the MPS one source file at a
# time, rather than all at once via mps.c (which can hide errors due
# to missing headers).
PFM = xca6ll
MPMPF = \
lockix.c \
prmcanan.c \
prmcxc.c \
prmcxca6.c \
protix.c \
protxc.c \
span.c \
thxc.c \
vmix.c
include ll.gmk
include comm.gmk
# C. COPYRIGHT AND LICENSE
#
# Copyright (C) 2001-2021 Ravenbrook Limited <https://www.ravenbrook.com/>.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the
# distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

12
mps/configure vendored
View file

@ -3478,6 +3478,18 @@ $as_echo "Linux x86_64" >&6; }
MPS_BUILD_NAME=ll
PFMCFLAGS="$CFLAGS_LL"
;;
aarch64-*-darwin*/*)
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Mac OS X ARM64" >&5
$as_echo "Mac OS X ARM64" >&6; }
MPS_OS_NAME=xc
MPS_ARCH_NAME=a6
MPS_BUILD_NAME=ll
BUILD_TARGET=build-via-xcode
CLEAN_TARGET=clean-xcode-build
INSTALL_TARGET=install-xcode-build
TEST_TARGET=test-xcode-build
PFMCFLAGS="$CFLAGS_LL"
;;
i*86-*-darwin*/*)
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Mac OS X x86" >&5
$as_echo "Mac OS X x86" >&6; }

View file

@ -66,6 +66,17 @@ case $host/$CLANG in
MPS_BUILD_NAME=ll
PFMCFLAGS="$CFLAGS_LL"
;;
aarch64-*-darwin*/*)
AC_MSG_RESULT([Mac OS X ARM64])
MPS_OS_NAME=xc
MPS_ARCH_NAME=a6
MPS_BUILD_NAME=ll
BUILD_TARGET=build-via-xcode
CLEAN_TARGET=clean-xcode-build
INSTALL_TARGET=install-xcode-build
TEST_TARGET=test-xcode-build
PFMCFLAGS="$CFLAGS_LL"
;;
i*86-*-darwin*/*)
AC_MSG_RESULT([Mac OS X x86])
MPS_OS_NAME=xc

View file

@ -268,13 +268,14 @@ macOS implementation
_`.impl.xc`: In ``prmcix.c`` and ``prmcxc.c``, with processor-specific
parts in ``prmci3.c`` and ``prmci6.c``, and other platform-specific
parts in ``prmcxci3.c`` and ``prmcxci6.c``.
parts in ``prmcxca6.c``, ``prmcxci3.c`` and ``prmcxci6.c``.
_`.impl.xc.context`: The context consists of the
``__Request__mach_exception_raise_state_identity_t`` and
``x86_thread_state32_t`` or ``x86_thread_state64_t`` structures. There
doesn't seem to be any documentation for these structures, but they
are defined in the Mach headers.
``arm_thread_state_t``, ``x86_thread_state32_t`` or
``x86_thread_state64_t`` structures. There doesn't seem to be any
documentation for these structures, but they are defined in the Mach
headers.
_`.impl.xc.fault.addr`: ``__Request__mach_exception_raise_state_identity_t.code[1]`` is the
address that the faulting instruction was trying to access.
@ -292,9 +293,11 @@ calling |thread_get_state|_.
.. _thread_get_state: https://www.gnu.org/software/hurd/gnumach-doc/Thread-Execution.html
_`.impl.xc.context.scan`: The thread's registers are found in the
``x86_thread_state32_t`` or ``x86_thread_state64_t`` structure.
``arm_thread_state64_t``, ``x86_thread_state32_t`` or
``x86_thread_state64_t`` structure.
_`.impl.xc.context.sp`: The stack pointer is obtained from
_`.impl.xc.context.sp`: The stack pointer is obtained using the
``arm_thread_state64_get_sp()`` macro (on ARM64), or from
``x86_thread_state32_t.__esp`` (on IA-32) or
``x86_thread_state64_t.__rsp`` (on x86-64).

View file

@ -144,6 +144,7 @@ Platform OS Architecture Compiler Makefile
``lii6ll`` Linux x86-64 Clang ``lii6ll.gmk``
``w3i3mv`` Windows IA-32 Microsoft C ``w3i3mv.nmk``
``w3i6mv`` Windows x86-64 Microsoft C ``w3i6mv.nmk``
``xca6ll`` macOS ARM64 Clang ``mps.xcodeproj``
``xci3ll`` macOS IA-32 Clang ``mps.xcodeproj``
``xci6ll`` macOS x86-64 Clang ``mps.xcodeproj``
========== ========= ============= ============ =================

View file

@ -183,6 +183,7 @@ prmcw3i3.c Mutator context implementation for Windows, IA-32.
prmcw3i6.c Mutator context implementation for Windows, x86-64.
prmcxc.c Mutator context implementation for macOS.
prmcxc.h Mutator context interface for macOS.
prmcxca6.c Mutator context implementation for macOS, ARM64.
prmcxci3.c Mutator context implementation for macOS, IA-32.
prmcxci6.c Mutator context implementation for macOS, x86-64.
prot.h Protection interface. See design.mps.prot_.
@ -393,6 +394,7 @@ w3i3mv.nmk NMAKE file for platform W3I3MV.
w3i3pc.nmk NMAKE file for platform W3I3PC.
w3i6mv.nmk NMAKE file for platform W3I6MV.
w3i6pc.nmk NMAKE file for platform W3I6PC.
xca6ll.gmk GNU makefile for platform XCA6LL.
xci3gc.gmk GNU makefile for platform XCI3GC.
xci3ll.gmk GNU makefile for platform XCI3LL.
xci6gc.gmk GNU makefile for platform XCI6GC.

View file

@ -12,6 +12,8 @@ Release 1.118.0
New features
............
#. New supported platform ``xca6ll`` (macOS, ARM64, Clang/LLVM).
#. The MPS no longer supports building for the xci3ll platform (macOS,
IA-32, Clang/LLVM) using Xcode. This is because Xcode 10.0 no
longer supports this platform. The platform is still supported via

View file

@ -28,6 +28,7 @@ The second pair of characters names the processor architecture:
====== ====================== ======================
``AR`` Processor architecture Constant
====== ====================== ======================
``a6`` ARM64 :c:macro:`MPS_ARCH_A6`
``i3`` Intel/AMD IA-32 :c:macro:`MPS_ARCH_I3`
``i6`` Intel/AMD x86-64 :c:macro:`MPS_ARCH_I6`
====== ====================== ======================
@ -66,6 +67,13 @@ Platform interface
#include "mpstd.h"
.. c:macro:: MPS_ARCH_A6
A :term:`C` preprocessor macro that indicates, if defined, that
the target processor architecture of the compilation is a member
of the ARM64 family of 64-bit processors.
.. c:macro:: MPS_ARCH_I3
A :term:`C` preprocessor macro that indicates, if defined, that
@ -206,6 +214,13 @@ Platform interface
compiler.
.. c:macro:: MPS_PF_XCA6LL
A :term:`C` preprocessor macro that indicates, if defined, that
the :term:`platform` consists of the macOS operating system, the
ARM64 processor architecture, and the Clang/LLVM compiler.
.. c:macro:: MPS_PF_XCI3GC
A :term:`C` preprocessor macro that indicates, if defined, that
@ -378,6 +393,7 @@ Platform Status
``w3i6mv`` Supported
``w3i6pc`` *Not supported*
``w3ppmv`` *Not supported*
``xca6ll`` Supported
``xci3gc`` *Not supported*
``xci3ll`` Supported
``xci6gc`` *Not supported*

View file

@ -76,8 +76,8 @@ usable.
stack` can be scanned.
See :ref:`design-prmc` for the design, and ``prmc.h`` for the
interface. There are implementations on Unix, Windows, and macOS for
IA-32 and x86-64.
interface. There are implementations on Unix and Windows for
IA-32 and x86-64, and on macOS for IA-32, x86-64, and ARM64.
There is a generic implementation in ``prmcan.c``, which can't
provide these features, and so only supports a single thread.