From 30976ef9d2407092b44f2f6126dcddef717252ca Mon Sep 17 00:00:00 2001 From: Ken Brown Date: Mon, 9 Dec 2024 13:29:04 -0500 Subject: [PATCH 1/4] Porting to Cygwin, first attempt Add Cygwin as a recognized platform. Mostly copy the FreeBSD case. This builds but fails to work properly because of an mmap problem on Cygwin: You can't remap without first unmapping. See https://cygwin.com/pipermail/cygwin/2018-February/236044.html It's probably possible to work around this by replacing mmap and friends by direct calls to VirtualAlloc and friends. --- code/config.h | 4 ++-- code/cyi6gc.gmk | 55 ++++++++++++++++++++++++++++++++++++++++++++++ code/lockix.c | 5 +++-- code/mps.c | 15 +++++++++++++ code/mpstd.h | 19 ++++++++++++++++ code/prmccyi6.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++ code/prmcix.c | 4 ++-- code/protix.c | 5 +++-- code/protsgix.c | 4 ++-- code/pthrdext.c | 4 ++-- code/testthr.h | 3 ++- code/thix.c | 4 ++-- code/vmix.c | 5 +++-- 13 files changed, 168 insertions(+), 17 deletions(-) create mode 100644 code/cyi6gc.gmk create mode 100644 code/prmccyi6.c diff --git a/code/config.h b/code/config.h index 02d335efec6f..5abf6c982596 100644 --- a/code/config.h +++ b/code/config.h @@ -543,7 +543,7 @@ * */ -#if defined(MPS_OS_LI) +#if defined(MPS_OS_LI) || defined(MPS_OS_CY) #if defined(_XOPEN_SOURCE) && _XOPEN_SOURCE < 500 #undef _XOPEN_SOURCE @@ -616,7 +616,7 @@ /* POSIX thread extensions configuration -- see */ -#if defined(MPS_OS_LI) || defined(MPS_OS_FR) +#if defined(MPS_OS_LI) || defined(MPS_OS_FR) || defined(MPS_OS_CY) /* PTHREADEXT_SIGSUSPEND -- signal used to suspend a thread * diff --git a/code/cyi6gc.gmk b/code/cyi6gc.gmk new file mode 100644 index 000000000000..98b863274bac --- /dev/null +++ b/code/cyi6gc.gmk @@ -0,0 +1,55 @@ +# -*- makefile -*- +# +# cyi6gc.gmk: BUILD FOR CYGWIN/x64/GCC PLATFORM +# +# $Id$ +# Copyright (c) 2001-2020 Ravenbrook Limited. See end of file for license. + +PFM = cyi6gc + +MPMPF = \ + lockix.c \ + prmcanan.c \ + prmccyi6.c \ + prmci6.c \ + protix.c \ + protsgix.c \ + pthrdext.c \ + span.c \ + thix.c \ + vmix.c + +LIBS = -lm -lpthread + +include gc.gmk +include comm.gmk + + +# C. COPYRIGHT AND LICENSE +# +# Copyright (C) 2001-2020 Ravenbrook Limited . +# +# 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. + diff --git a/code/lockix.c b/code/lockix.c index a6555f5bb360..3c4e1939c739 100644 --- a/code/lockix.c +++ b/code/lockix.c @@ -31,8 +31,9 @@ #include "mpm.h" -#if !defined(MPS_OS_FR) && !defined(MPS_OS_LI) && !defined(MPS_OS_XC) -#error "lockix.c is specific to MPS_OS_FR, MPS_OS_LI or MPS_OS_XC" +#if !defined(MPS_OS_FR) && !defined(MPS_OS_LI) && !defined(MPS_OS_XC) \ + && !defined(MPS_OS_CY) +#error "lockix.c is specific to MPS_OS_FR, MPS_OS_LI, MPS_OS_XC, or MPS_OS_CY" #endif #include "lock.h" diff --git a/code/mps.c b/code/mps.c index e7872b3c14a0..a2bb7f003f5d 100644 --- a/code/mps.c +++ b/code/mps.c @@ -256,6 +256,21 @@ #include "spw3i6.c" /* Windows on x86-64 stack probe */ #include "mpsiw3.c" /* Windows interface layer extras */ +/* Cygwin on x86-64 built with GCC */ + +#elif defined(MPS_PF_CYI6GC) + +#include "lockix.c" /* Posix locks */ +#include "thix.c" /* Posix threading */ +#include "pthrdext.c" /* Posix thread extensions */ +#include "vmix.c" /* Posix virtual memory */ +#include "protix.c" /* Posix protection */ +#include "protsgix.c" /* Posix signal handling */ +#include "prmcanan.c" /* generic architecture mutator context */ +#include "prmcix.c" /* Posix mutator context */ +#include "prmccyi6.c" /* x86-64 for Cygwin mutator context */ +#include "span.c" /* generic stack probe */ + #else #error "Unknown platform -- can't determine platform specific parts." diff --git a/code/mpstd.h b/code/mpstd.h index 7df1c2a12f6d..d2c21d263064 100644 --- a/code/mpstd.h +++ b/code/mpstd.h @@ -392,6 +392,25 @@ #define MPS_PF_ALIGN 8 +/* GCC 12.4.0, gcc -E -dM */ + +#elif defined(__CYGWIN__) && defined(__x86_64__) && defined(__GNUC__) \ + && !defined(__clang__) +#if defined(CONFIG_PF_STRING) && ! defined(CONFIG_PF_CYI6GC) +#error "specified CONFIG_PF_... inconsistent with detected cyi6gc" +#endif +#define MPS_PF_CYI6GC +#define MPS_PF_STRING "cyi6gc" +#define MPS_OS_CY +#define MPS_ARCH_I6 +#define MPS_BUILD_GC +#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 + + #else #error "The MPS Kit does not have a configuration for this platform out of the box; see manual/build.txt" #endif diff --git a/code/prmccyi6.c b/code/prmccyi6.c new file mode 100644 index 000000000000..e5085185b369 --- /dev/null +++ b/code/prmccyi6.c @@ -0,0 +1,58 @@ +/* prmccyi6.c: MUTATOR CONTEXT x64 (CYGWIN) + * + * $Id$ + * Copyright (c) 2001-2020 Ravenbrook Limited. See end of file for license. + * + * .purpose: Implement the mutator context module. . + * + * + * ASSUMPTIONS + * + * .sp: The stack pointer in the context is RSP. + */ + +#include "prmcix.h" +#include "prmci6.h" + +SRCID(prmcfri6, "$Id$"); + +#if !defined(MPS_OS_CY) || !defined(MPS_ARCH_I6) +#error "prmccyi6.c is specific to MPS_OS_CY and MPS_ARCH_I6" +#endif + + +Addr MutatorContextSP(MutatorContext context) +{ + AVERT(MutatorContext, context); + return (Addr)context->ucontext->uc_mcontext.rsp; /* .sp */ +} + + +/* C. COPYRIGHT AND LICENSE + * + * Copyright (C) 2001-2020 Ravenbrook Limited . + * + * 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. + */ diff --git a/code/prmcix.c b/code/prmcix.c index 8529405ae9c7..0af391eb45c7 100644 --- a/code/prmcix.c +++ b/code/prmcix.c @@ -14,8 +14,8 @@ #include "mpm.h" -#if !defined(MPS_OS_FR) && !defined(MPS_OS_LI) -#error "prmcix.c is specific to MPS_OS_FR or MPS_OS_LI" +#if !defined(MPS_OS_FR) && !defined(MPS_OS_LI) && !defined(MPS_OS_CY) +#error "prmcix.c is specific to MPS_OS_FR, MPS_OS_LI, or MPS_OS_CY" #endif #include "prmcix.h" diff --git a/code/protix.c b/code/protix.c index fa6541913b71..18f29430e07d 100644 --- a/code/protix.c +++ b/code/protix.c @@ -35,8 +35,9 @@ #include "mpm.h" -#if !defined(MPS_OS_FR) && !defined(MPS_OS_LI) && !defined(MPS_OS_XC) -#error "protix.c is specific to MPS_OS_FR, MPS_OS_LI or MPS_OS_XC" +#if !defined(MPS_OS_FR) && !defined(MPS_OS_LI) && !defined(MPS_OS_XC) \ + && !defined(MPS_OS_CY) +#error "protix.c is specific to MPS_OS_FR, MPS_OS_LI, MPS_OS_XC, or MPS_OS_CY" #endif #include "vm.h" diff --git a/code/protsgix.c b/code/protsgix.c index 966569c92934..9540908300d8 100644 --- a/code/protsgix.c +++ b/code/protsgix.c @@ -22,8 +22,8 @@ #include "mpm.h" -#if !defined(MPS_OS_FR) && !defined(MPS_OS_LI) -#error "protsgix.c is specific to MPS_OS_FR or MPS_OS_LI" +#if !defined(MPS_OS_FR) && !defined(MPS_OS_LI) && !defined(MPS_OS_CY) +#error "protsgix.c is specific to MPS_OS_FR, MPS_OS_LI, or MPS_OS_CY" #endif #include "prmcix.h" diff --git a/code/pthrdext.c b/code/pthrdext.c index 7619468a1872..c143b5cf4db2 100644 --- a/code/pthrdext.c +++ b/code/pthrdext.c @@ -16,8 +16,8 @@ #include "mpm.h" -#if !defined(MPS_OS_FR) && !defined(MPS_OS_LI) -#error "pthrdext.c is specific to MPS_OS_FR or MPS_OS_LI" +#if !defined(MPS_OS_FR) && !defined(MPS_OS_LI) && !defined(MPS_OS_CY) +#error "pthrdext.c is specific to MPS_OS_FR, MPS_OS_LI, or MPS_OS_CY" #endif #include "pthrdext.h" diff --git a/code/testthr.h b/code/testthr.h index a50dad1e5d09..13dcb3fc8924 100644 --- a/code/testthr.h +++ b/code/testthr.h @@ -45,7 +45,8 @@ typedef struct testthr_t { void *result; /* result returned from start */ } testthr_t; -#elif defined(MPS_OS_FR) || defined(MPS_OS_LI) || defined(MPS_OS_XC) +#elif defined(MPS_OS_FR) || defined(MPS_OS_LI) || defined(MPS_OS_XC) \ + || defined(MPS_OS_CY) #include diff --git a/code/thix.c b/code/thix.c index c47f82ad3b87..b89a6b4f43ab 100644 --- a/code/thix.c +++ b/code/thix.c @@ -34,8 +34,8 @@ #include "mpm.h" -#if !defined(MPS_OS_FR) && !defined(MPS_OS_LI) -#error "thix.c is specific to MPS_OS_FR or MPS_OS_LI" +#if !defined(MPS_OS_FR) && !defined(MPS_OS_LI) && !defined(MPS_OS_CY) +#error "thix.c is specific to MPS_OS_FR, MPS_OS_LI, or MPS_OS_CY" #endif #include "prmcix.h" diff --git a/code/vmix.c b/code/vmix.c index 4bdd0caefadc..8fce9389e742 100644 --- a/code/vmix.c +++ b/code/vmix.c @@ -40,8 +40,9 @@ #include "mpm.h" -#if !defined(MPS_OS_FR) && !defined(MPS_OS_LI) && !defined(MPS_OS_XC) -#error "vmix.c is specific to MPS_OS_FR, MPS_OS_LI or MPS_OS_XC" +#if !defined(MPS_OS_FR) && !defined(MPS_OS_LI) && !defined(MPS_OS_XC) \ + && !defined(MPS_OS_CY) +#error "vmix.c is specific to MPS_OS_FR, MPS_OS_LI, MPS_OS_XC, or MPS_OS_CY" #endif #include "vm.h" -- 2.45.1