Gentoo Archives: gentoo-commits

From: "Jakov Smolić" <jsmolic@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: app-misc/reptyr/files/, app-misc/reptyr/
Date: Tue, 10 May 2022 17:22:19
Message-Id: 1652203215.72ac7a65fce9351185111a2b42573aa4636efe8c.jsmolic@gentoo
1 commit: 72ac7a65fce9351185111a2b42573aa4636efe8c
2 Author: Raymond Wong <infiwang <AT> pm <DOT> me>
3 AuthorDate: Tue May 10 15:46:31 2022 +0000
4 Commit: Jakov Smolić <jsmolic <AT> gentoo <DOT> org>
5 CommitDate: Tue May 10 17:20:15 2022 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=72ac7a65
7
8 app-misc/reptyr: add riscv64 support
9
10 Patch is already done upstream, drop on next version bump.
11
12 Signed-off-by: Raymond Wong <infiwang <AT> pm.me>
13 Signed-off-by: Jakov Smolić <jsmolic <AT> gentoo.org>
14
15 .../files/reptyr-0.8.0-riscv64-support.patch | 115 +++++++++++++++++++++
16 app-misc/reptyr/reptyr-0.8.0.ebuild | 5 +
17 2 files changed, 120 insertions(+)
18
19 diff --git a/app-misc/reptyr/files/reptyr-0.8.0-riscv64-support.patch b/app-misc/reptyr/files/reptyr-0.8.0-riscv64-support.patch
20 new file mode 100644
21 index 000000000000..6cedd3a55c5d
22 --- /dev/null
23 +++ b/app-misc/reptyr/files/reptyr-0.8.0-riscv64-support.patch
24 @@ -0,0 +1,115 @@
25 +Taken from https://github.com/nelhage/reptyr/commit/e26724cc1ae5fe7af0c9fb6369f6cf09d1d12900
26 +
27 +From ae0b4ec014c1a01b1c3409e5404cf0fa0102c349 Mon Sep 17 00:00:00 2001
28 +From: Ast-x64 <Ast-x64@××××××××××.com>
29 +Date: Wed, 10 Nov 2021 09:39:45 +0800
30 +Subject: [PATCH] Support riscv64 on Linux.
31 +
32 +---
33 + platform/linux/arch/riscv64.h | 68 +++++++++++++++++++++++++++++++++++
34 + platform/linux/linux_ptrace.c | 2 ++
35 + ptrace.h | 3 ++
36 + 3 files changed, 73 insertions(+)
37 + create mode 100644 platform/linux/arch/riscv64.h
38 +
39 +diff --git a/platform/linux/arch/riscv64.h b/platform/linux/arch/riscv64.h
40 +new file mode 100644
41 +index 0000000..96221c3
42 +--- /dev/null
43 ++++ b/platform/linux/arch/riscv64.h
44 +@@ -0,0 +1,68 @@
45 ++/*
46 ++ * Copyright (C) 2021 by Ast-x64
47 ++ *
48 ++ * Permission is hereby granted, free of charge, to any person obtaining a copy
49 ++ * of this software and associated documentation files (the "Software"), to deal
50 ++ * in the Software without restriction, including without limitation the rights
51 ++ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
52 ++ * copies of the Software, and to permit persons to whom the Software is
53 ++ * furnished to do so, subject to the following conditions:
54 ++ *
55 ++ * The above copyright notice and this permission notice shall be included in
56 ++ * all copies or substantial portions of the Software.
57 ++ *
58 ++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
59 ++ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
60 ++ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
61 ++ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
62 ++ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
63 ++ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
64 ++ * THE SOFTWARE.
65 ++ */
66 ++static struct ptrace_personality arch_personality[1] = {
67 ++ {
68 ++ offsetof(struct user_regs_struct, a0),
69 ++ offsetof(struct user_regs_struct, a0),
70 ++ offsetof(struct user_regs_struct, a1),
71 ++ offsetof(struct user_regs_struct, a2),
72 ++ offsetof(struct user_regs_struct, a3),
73 ++ offsetof(struct user_regs_struct, a4),
74 ++ offsetof(struct user_regs_struct, a5),
75 ++ offsetof(struct user_regs_struct, pc),
76 ++ }
77 ++};
78 ++
79 ++static inline void arch_fixup_regs(struct ptrace_child *child) {
80 ++ child->regs.pc -= 4;
81 ++}
82 ++
83 ++static inline int arch_set_syscall(struct ptrace_child *child,
84 ++ unsigned long sysno) {
85 ++ unsigned long x_reg[18];
86 ++ struct iovec reg_iovec = {
87 ++ .iov_base = x_reg,
88 ++ .iov_len = sizeof(x_reg)
89 ++ };
90 ++ if (ptrace_command(child, PTRACE_GETREGSET, NT_PRSTATUS, &reg_iovec) < 0)
91 ++ return -1;
92 ++
93 ++ x_reg[17] = sysno;
94 ++ return ptrace_command(child, PTRACE_SETREGSET, NT_PRSTATUS, &reg_iovec);
95 ++}
96 ++
97 ++static inline int arch_save_syscall(struct ptrace_child *child) {
98 ++ unsigned long x_reg[18];
99 ++ struct iovec reg_iovec = {
100 ++ .iov_base = x_reg,
101 ++ .iov_len = sizeof(x_reg)
102 ++ };
103 ++ if (ptrace_command(child, PTRACE_GETREGSET, NT_PRSTATUS, &reg_iovec) < 0)
104 ++ return -1;
105 ++
106 ++ child->saved_syscall = x_reg[17];
107 ++ return 0;
108 ++}
109 ++
110 ++static inline int arch_restore_syscall(struct ptrace_child *child) {
111 ++ return arch_set_syscall(child, child->saved_syscall);
112 ++}
113 +diff --git a/platform/linux/linux_ptrace.c b/platform/linux/linux_ptrace.c
114 +index d065199..bcbe600 100644
115 +--- a/platform/linux/linux_ptrace.c
116 ++++ b/platform/linux/linux_ptrace.c
117 +@@ -84,6 +84,8 @@ static struct ptrace_personality *personality(struct ptrace_child *child);
118 + #include "arch/aarch64.h"
119 + #elif defined(__powerpc__)
120 + #include "arch/powerpc.h"
121 ++#elif defined(__riscv) && __riscv_xlen == 64
122 ++#include "arch/riscv64.h"
123 + #else
124 + #error Unsupported architecture.
125 + #endif
126 +diff --git a/ptrace.h b/ptrace.h
127 +index ee05bd7..8e3a7f4 100644
128 +--- a/ptrace.h
129 ++++ b/ptrace.h
130 +@@ -25,6 +25,9 @@
131 + #ifdef __powerpc__
132 + #include <asm/ptrace.h>
133 + #endif
134 ++#ifdef __riscv
135 ++#include <asm/ptrace.h>
136 ++#endif
137 + #include <sys/ptrace.h>
138 + #include <sys/types.h>
139 + #include <sys/user.h>
140
141 diff --git a/app-misc/reptyr/reptyr-0.8.0.ebuild b/app-misc/reptyr/reptyr-0.8.0.ebuild
142 index 960ac099ad2a..012379e3b3ed 100644
143 --- a/app-misc/reptyr/reptyr-0.8.0.ebuild
144 +++ b/app-misc/reptyr/reptyr-0.8.0.ebuild
145 @@ -15,6 +15,11 @@ KEYWORDS="amd64 ~arm ~arm64 ~ppc64 x86 ~amd64-linux ~x86-linux"
146
147 RESTRICT="test"
148
149 +PATCHES=(
150 + # drop on next version bump
151 + "${FILESDIR}"/${PN}-0.8.0-riscv64-support.patch
152 +)
153 +
154 src_prepare() {
155 default
156 # respect CFLAGS