[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2] include: Add ucontext_t for all architectures
From: |
Ekaitz Zarraga |
Subject: |
[PATCH v2] include: Add ucontext_t for all architectures |
Date: |
Sat, 24 Feb 2024 21:43:19 +0100 |
ucontext_t is used by `tcc -run` and it affects the compilation process
of that. If we don't have the data structures defined the build process
of tcc-mob later in the chain fails. We don't use the `-run` option for
anything in the bootstrapping process, but as we do `ONE_SOURCE` that
affect our building process. The cleanest solution is to add the proper
support here and forget about it.
This commit copies the code from musl libc, using the GNU_SOURCE part of
the `#ifdef`s in there as that's what tcc expects. We can do better but
the goal of the commit is to make the bare minimum.
* include/signal.h (ucontext_t): Move current i386 support to separate
file.
* include/gnu/x86/signal.h: Add it.
* include/linux/x86/signal.h: Add it.
* include/linux/x86_64/signal.h: Add it.
* include/linux/arm/signal.h: Add it.
* include/linux/riscv64/signal.h: Add it.
* simple.sh: Add support for multiple signal.h files.
* configure.sh: Add support for multiple signal.h files.
* configure: Add support for multiple signal.h files.
---
configure | 2 +-
configure.sh | 1 +
include/gnu/x86/signal.h | 90 +++++++++++++++++++++++++++++
include/linux/arm/signal.h | 47 +++++++++++++++
include/linux/riscv64/signal.h | 89 ++++++++++++++++++++++++++++
include/linux/x86/signal.h | 90 +++++++++++++++++++++++++++++
include/linux/x86_64/signal.h | 102 +++++++++++++++++++++++++++++++++
include/signal.h | 75 +-----------------------
simple.sh | 1 +
9 files changed, 422 insertions(+), 75 deletions(-)
create mode 100644 include/gnu/x86/signal.h
create mode 100644 include/linux/arm/signal.h
create mode 100644 include/linux/riscv64/signal.h
create mode 100644 include/linux/x86/signal.h
create mode 100644 include/linux/x86_64/signal.h
diff --git a/configure b/configure
index 36ffc017..29525b3a 100755
--- a/configure
+++ b/configure
@@ -709,7 +709,7 @@ See \"Porting GNU Mes\" in the manual, or try
--with-courage\n" mes-system)
(string-append arch-dir "/" file-name)
(string-append "include/arch/" file-name)))
(system* "mkdir" "-p" "include/arch")
- (for-each copy-header '("kernel-stat.h" "syscall.h")))
+ (for-each copy-header '("kernel-stat.h" "syscall.h" "signal.h")))
(let ((make (and=> (file-name "make" deps) basename)))
(display (string-append "
diff --git a/configure.sh b/configure.sh
index b9c9589e..f5e652fe 100755
--- a/configure.sh
+++ b/configure.sh
@@ -267,6 +267,7 @@ EOF
mkdir -p include/arch
cp -f -v ${srcdest}include/${mes_kernel}/${mes_cpu}/kernel-stat.h include/arch
cp -f -v ${srcdest}include/${mes_kernel}/${mes_cpu}/syscall.h include/arch
+cp -f -v ${srcdest}include/${mes_kernel}/${mes_cpu}/signal.h include/arch
cat <<EOF
GNU Mes is configured for
diff --git a/include/gnu/x86/signal.h b/include/gnu/x86/signal.h
new file mode 100644
index 00000000..f71be644
--- /dev/null
+++ b/include/gnu/x86/signal.h
@@ -0,0 +1,90 @@
+/* -*-comment-start: "//";comment-end:""-*-
+ * GNU Mes --- Maxwell Equations of Software
+ * Copyright © 2017 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
+ *
+ * This file is part of GNU Mes.
+ *
+ * GNU Mes is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or (at
+ * your option) any later version.
+ *
+ * GNU Mes is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
+ */
+#define EBX 0
+#define ECX 1
+#define EDX 2
+#define ESI 3
+#define EDI 4
+#define EBP 5
+#define EAX 6
+#define DS 7
+#define ES 8
+#define FS 9
+#define GS 10
+#define ORIG_EAX 11
+#define EIP 12
+#define CS 13
+#define EFL 14
+#define UESP 15
+#define SS 16
+#define FRAME_SIZE 17
+
+/* Type for general register. */
+typedef int greg_t;
+
+/* Number of general registers. */
+#define NGREG 19
+
+/* Container for all general registers. */
+typedef greg_t gregset_t[NGREG];
+
+/* Definitions taken from the kernel headers. */
+struct _libc_fpreg
+{
+ unsigned short int significand[4];
+ unsigned short int exponent;
+};
+
+struct _libc_fpstate
+{
+ unsigned long int cw;
+ unsigned long int sw;
+ unsigned long int tag;
+ unsigned long int ipoff;
+ unsigned long int cssel;
+ unsigned long int dataoff;
+ unsigned long int datasel;
+ struct _libc_fpreg _st[8];
+ unsigned long int status;
+};
+
+/* Structure to describe FPU registers. */
+typedef struct _libc_fpstate *fpregset_t;
+
+typedef struct
+{
+ gregset_t gregs;
+ /* Due to Linux's history we have to use a pointer here. The SysV/i386
+ ABI requires a struct with the values. */
+ fpregset_t fpregs;
+ unsigned long int oldmask;
+ unsigned long int cr2;
+} mcontext_t;
+
+/* Userlevel context. */
+typedef struct ucontext
+{
+ unsigned long int uc_flags;
+ struct ucontext *uc_link;
+ stack_t uc_stack;
+ mcontext_t uc_mcontext;
+ sigset_t uc_sigmask;
+ struct _libc_fpstate __fpregs_mem;
+} ucontext_t;
diff --git a/include/linux/arm/signal.h b/include/linux/arm/signal.h
new file mode 100644
index 00000000..d273ef66
--- /dev/null
+++ b/include/linux/arm/signal.h
@@ -0,0 +1,47 @@
+/* -*-comment-start: "//";comment-end:""-*-
+ * GNU Mes --- Maxwell Equations of Software
+ * Copyright © 2024 Ekaitz Zarraga <ekaitz@elenq.tech>
+ *
+ * This file is part of GNU Mes.
+ *
+ * GNU Mes is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or (at
+ * your option) any later version.
+ *
+ * GNU Mes is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+// Taken from musl libc (4a16ddf5)
+
+typedef int greg_t
+typedef int gregset_t[18];
+typedef struct sigcontext {
+ unsigned long trap_no, error_code, oldmask;
+ unsigned long arm_r0, arm_r1, arm_r2, arm_r3;
+ unsigned long arm_r4, arm_r5, arm_r6, arm_r7;
+ unsigned long arm_r8, arm_r9, arm_r10, arm_fp;
+ unsigned long arm_ip, arm_sp, arm_lr, arm_pc;
+ unsigned long arm_cpsr, fault_address;
+} mcontext_t;
+
+struct sigaltstack {
+ void *ss_sp;
+ int ss_flags;
+ size_t ss_size;
+};
+
+typedef struct __ucontext {
+ unsigned long uc_flags;
+ struct __ucontext *uc_link;
+ stack_t uc_stack;
+ mcontext_t uc_mcontext;
+ sigset_t uc_sigmask;
+ unsigned long long uc_regspace[64];
+} ucontext_t;
diff --git a/include/linux/riscv64/signal.h b/include/linux/riscv64/signal.h
new file mode 100644
index 00000000..74e17ac7
--- /dev/null
+++ b/include/linux/riscv64/signal.h
@@ -0,0 +1,89 @@
+/* -*-comment-start: "//";comment-end:""-*-
+ * GNU Mes --- Maxwell Equations of Software
+ * Copyright © 2024 Ekaitz Zarraga <ekaitz@elenq.tech>
+ *
+ * This file is part of GNU Mes.
+ *
+ * GNU Mes is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or (at
+ * your option) any later version.
+ *
+ * GNU Mes is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+// Taken from musl libc (4a16ddf5)
+
+#define REG_PC 0
+#define REG_RA 1
+#define REG_SP 2
+#define REG_TP 4
+#define REG_S0 8
+#define REG_A0 10
+
+typedef unsigned long __riscv_mc_gp_state[32];
+
+struct __riscv_mc_f_ext_state
+{
+ unsigned int __f[32];
+ unsigned int __fcsr;
+};
+
+struct __riscv_mc_d_ext_state
+{
+ unsigned long long __f[32];
+ unsigned int __fcsr;
+};
+
+struct __riscv_mc_q_ext_state
+{
+ unsigned long long __f[64]; // __attribute__((aligned(16)))
+ unsigned int __fcsr;
+ unsigned int __reserved[3];
+};
+
+union __riscv_mc_fp_state
+{
+ struct __riscv_mc_f_ext_state __f;
+ struct __riscv_mc_d_ext_state __d;
+ struct __riscv_mc_q_ext_state __q;
+};
+
+typedef struct mcontext_t
+{
+ __riscv_mc_gp_state __gregs;
+ union __riscv_mc_fp_state __fpregs;
+} mcontext_t;
+
+typedef unsigned long greg_t;
+typedef unsigned long gregset_t[32];
+typedef union __riscv_mc_fp_state fpregset_t;
+
+struct sigcontext
+{
+ gregset_t gregs;
+ fpregset_t fpregs;
+};
+
+struct sigaltstack
+{
+ void *ss_sp;
+ int ss_flags;
+ size_t ss_size;
+};
+
+typedef struct __ucontext
+{
+ unsigned long uc_flags;
+ struct __ucontext *uc_link;
+ stack_t uc_stack;
+ sigset_t uc_sigmask;
+ mcontext_t uc_mcontext;
+} ucontext_t;
+
diff --git a/include/linux/x86/signal.h b/include/linux/x86/signal.h
new file mode 100644
index 00000000..f71be644
--- /dev/null
+++ b/include/linux/x86/signal.h
@@ -0,0 +1,90 @@
+/* -*-comment-start: "//";comment-end:""-*-
+ * GNU Mes --- Maxwell Equations of Software
+ * Copyright © 2017 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
+ *
+ * This file is part of GNU Mes.
+ *
+ * GNU Mes is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or (at
+ * your option) any later version.
+ *
+ * GNU Mes is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
+ */
+#define EBX 0
+#define ECX 1
+#define EDX 2
+#define ESI 3
+#define EDI 4
+#define EBP 5
+#define EAX 6
+#define DS 7
+#define ES 8
+#define FS 9
+#define GS 10
+#define ORIG_EAX 11
+#define EIP 12
+#define CS 13
+#define EFL 14
+#define UESP 15
+#define SS 16
+#define FRAME_SIZE 17
+
+/* Type for general register. */
+typedef int greg_t;
+
+/* Number of general registers. */
+#define NGREG 19
+
+/* Container for all general registers. */
+typedef greg_t gregset_t[NGREG];
+
+/* Definitions taken from the kernel headers. */
+struct _libc_fpreg
+{
+ unsigned short int significand[4];
+ unsigned short int exponent;
+};
+
+struct _libc_fpstate
+{
+ unsigned long int cw;
+ unsigned long int sw;
+ unsigned long int tag;
+ unsigned long int ipoff;
+ unsigned long int cssel;
+ unsigned long int dataoff;
+ unsigned long int datasel;
+ struct _libc_fpreg _st[8];
+ unsigned long int status;
+};
+
+/* Structure to describe FPU registers. */
+typedef struct _libc_fpstate *fpregset_t;
+
+typedef struct
+{
+ gregset_t gregs;
+ /* Due to Linux's history we have to use a pointer here. The SysV/i386
+ ABI requires a struct with the values. */
+ fpregset_t fpregs;
+ unsigned long int oldmask;
+ unsigned long int cr2;
+} mcontext_t;
+
+/* Userlevel context. */
+typedef struct ucontext
+{
+ unsigned long int uc_flags;
+ struct ucontext *uc_link;
+ stack_t uc_stack;
+ mcontext_t uc_mcontext;
+ sigset_t uc_sigmask;
+ struct _libc_fpstate __fpregs_mem;
+} ucontext_t;
diff --git a/include/linux/x86_64/signal.h b/include/linux/x86_64/signal.h
new file mode 100644
index 00000000..35eacf80
--- /dev/null
+++ b/include/linux/x86_64/signal.h
@@ -0,0 +1,102 @@
+/* -*-comment-start: "//";comment-end:""-*-
+ * GNU Mes --- Maxwell Equations of Software
+ * Copyright © 2024 Ekaitz Zarraga <ekaitz@elenq.tech>
+ *
+ * This file is part of GNU Mes.
+ *
+ * GNU Mes is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or (at
+ * your option) any later version.
+ *
+ * GNU Mes is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+// Taken from musl libc (4a16ddf5) and simplified
+
+#define REG_R8 0
+#define REG_R9 1
+#define REG_R10 2
+#define REG_R11 3
+#define REG_R12 4
+#define REG_R13 5
+#define REG_R14 6
+#define REG_R15 7
+#define REG_RDI 8
+#define REG_RSI 9
+#define REG_RBP 10
+#define REG_RBX 11
+#define REG_RDX 12
+#define REG_RAX 13
+#define REG_RCX 14
+#define REG_RSP 15
+#define REG_RIP 16
+#define REG_EFL 17
+#define REG_CSGSFS 18
+#define REG_ERR 19
+#define REG_TRAPNO 20
+#define REG_OLDMASK 21
+#define REG_CR2 22
+
+typedef long long greg_t;
+typedef long long gregset_t[23];
+
+struct __st
+{
+ unsigned short significand[4], exponent, padding[3];
+};
+
+struct _xmm
+{
+ unsigned element[4];
+};
+
+typedef struct _fpstate
+{
+ unsigned short cwd, swd, ftw, fop;
+ unsigned long long rip, rdp;
+ unsigned mxcsr, mxcr_mask;
+ struct __st _st[8];
+ struct _xmm _xmm[16];
+ unsigned padding[24];
+} *fpregset_t;
+
+struct sigcontext
+{
+ unsigned long r8, r9, r10, r11, r12, r13, r14, r15;
+ unsigned long rdi, rsi, rbp, rbx, rdx, rax, rcx, rsp, rip, eflags;
+ unsigned short cs, gs, fs, __pad0;
+ unsigned long err, trapno, oldmask, cr2;
+ struct _fpstate *fpstate;
+ unsigned long __reserved1[8];
+};
+
+typedef struct
+{
+ gregset_t gregs;
+ fpregset_t fpregs;
+ unsigned long long __reserved1[8];
+} mcontext_t;
+
+struct sigaltstack
+{
+ void *ss_sp;
+ int ss_flags;
+ size_t ss_size;
+};
+
+typedef struct __ucontext
+{
+ unsigned long uc_flags;
+ struct __ucontext *uc_link;
+ stack_t uc_stack;
+ mcontext_t uc_mcontext;
+ sigset_t uc_sigmask;
+ unsigned long __fpregs_mem[64];
+} ucontext_t;
diff --git a/include/signal.h b/include/signal.h
index aef1da50..10862b14 100644
--- a/include/signal.h
+++ b/include/signal.h
@@ -167,80 +167,7 @@ struct sigaction
#define SIG_IGN ((sighandler_t)1)
#define SIG_ERR ((sighandler_t)-1)
-#ifdef __i386__
-
-#define EBX 0
-#define ECX 1
-#define EDX 2
-#define ESI 3
-#define EDI 4
-#define EBP 5
-#define EAX 6
-#define DS 7
-#define ES 8
-#define FS 9
-#define GS 10
-#define ORIG_EAX 11
-#define EIP 12
-#define CS 13
-#define EFL 14
-#define UESP 15
-#define SS 16
-#define FRAME_SIZE 17
-
-/* Type for general register. */
-typedef int greg_t;
-
-/* Number of general registers. */
-#define NGREG 19
-
-/* Container for all general registers. */
-typedef greg_t gregset_t[NGREG];
-
-/* Definitions taken from the kernel headers. */
-struct _libc_fpreg
-{
- unsigned short int significand[4];
- unsigned short int exponent;
-};
-
-struct _libc_fpstate
-{
- unsigned long int cw;
- unsigned long int sw;
- unsigned long int tag;
- unsigned long int ipoff;
- unsigned long int cssel;
- unsigned long int dataoff;
- unsigned long int datasel;
- struct _libc_fpreg _st[8];
- unsigned long int status;
-};
-
-/* Structure to describe FPU registers. */
-typedef struct _libc_fpstate *fpregset_t;
-
-typedef struct
-{
- gregset_t gregs;
- /* Due to Linux's history we have to use a pointer here. The SysV/i386
- ABI requires a struct with the values. */
- fpregset_t fpregs;
- unsigned long int oldmask;
- unsigned long int cr2;
-} mcontext_t;
-
-/* Userlevel context. */
-typedef struct ucontext
-{
- unsigned long int uc_flags;
- struct ucontext *uc_link;
- stack_t uc_stack;
- mcontext_t uc_mcontext;
- sigset_t uc_sigmask;
- struct _libc_fpstate __fpregs_mem;
-} ucontext_t;
-#endif // !__i386__
+#include <arch/signal.h>
int kill (pid_t pid, int signum);
int raise (int);
diff --git a/simple.sh b/simple.sh
index 44e6445b..d407d1bc 100755
--- a/simple.sh
+++ b/simple.sh
@@ -169,6 +169,7 @@ EOF
mkdir -p include/arch
cp -f include/$mes_kernel/$mes_cpu/kernel-stat.h include/arch
cp -f include/$mes_kernel/$mes_cpu/syscall.h include/arch
+cp -f include/$mes_kernel/$mes_cpu/signal.h include/arch
## Build ##
compiler=gcc # not configurable
--
2.41.0