Skip to content

Commit 527b42f

Browse files
committed
cleanup: make arch_sigreturn.c files more readable
Make arch_sigreturn.c files more self-sustained. While they are still being included by sigreturn.c, the latter no longer defines arch_sigreturn function. * linux/alpha/arch_sigreturn.c (arch_sigreturn): Define. * linux/arm/arch_sigreturn.c: Likewise. * linux/crisv10/arch_sigreturn.c: Likewise. * linux/i386/arch_sigreturn.c: Likewise. * linux/ia64/arch_sigreturn.c: Likewise. * linux/m68k/arch_sigreturn.c: Likewise. * linux/microblaze/arch_sigreturn.c: Likewise. * linux/mips/arch_sigreturn.c: Likewise. * linux/powerpc/arch_sigreturn.c: Likewise. * linux/s390/arch_sigreturn.c: Likewise. * linux/sparc/arch_sigreturn.c: Likewise. * linux/tile/arch_sigreturn.c: Likewise. * linux/x32/arch_sigreturn.c: Remove code. Include "x86_64/arch_sigreturn.c". * linux/x86_64/arch_sigreturn.c: Stop including "x32/arch_sigreturn.c". Include "i386/arch_sigreturn.c" with arch_sigreturn temporarily defined to i386_arch_sigreturn. (arch_sigreturn): Define. Add x32 personality support there. * sigreturn.c: Remove arch_sigreturn header and footer. Requested-by: Denys Vlasenko <[email protected]>
1 parent 690235a commit 527b42f

File tree

15 files changed

+219
-167
lines changed

15 files changed

+219
-167
lines changed

linux/alpha/arch_sigreturn.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
long addr;
1+
static void
2+
arch_sigreturn(struct tcb *tcp)
3+
{
4+
long addr;
25

3-
if (upeek(tcp->pid, REG_FP, &addr) < 0)
4-
return;
5-
addr += offsetof(struct sigcontext, sc_mask);
6+
if (upeek(tcp->pid, REG_FP, &addr) < 0)
7+
return;
8+
addr += offsetof(struct sigcontext, sc_mask);
69

7-
tprints("{mask=");
8-
print_sigset_addr_len(tcp, addr, NSIG / 8);
9-
tprints("}");
10+
tprints("{mask=");
11+
print_sigset_addr_len(tcp, addr, NSIG / 8);
12+
tprints("}");
13+
}

linux/arm/arch_sigreturn.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1+
static void
2+
arch_sigreturn(struct tcb *tcp)
3+
{
14
#define SIZEOF_STRUCT_SIGINFO 128
25
#define SIZEOF_STRUCT_SIGCONTEXT (21 * 4)
36
#define OFFSETOF_STRUCT_UCONTEXT_UC_SIGMASK (5 * 4 + SIZEOF_STRUCT_SIGCONTEXT)
47

5-
const long addr =
8+
const long addr =
69
#ifdef AARCH64
7-
current_personality == 1 ?
8-
(*aarch64_sp_ptr + SIZEOF_STRUCT_SIGINFO +
9-
offsetof(struct ucontext, uc_sigmask)) :
10+
current_personality == 1 ?
11+
(*aarch64_sp_ptr + SIZEOF_STRUCT_SIGINFO +
12+
offsetof(struct ucontext, uc_sigmask)) :
1013
#endif
11-
(*arm_sp_ptr +
12-
OFFSETOF_STRUCT_UCONTEXT_UC_SIGMASK);
13-
tprints("{mask=");
14-
print_sigset_addr_len(tcp, addr, NSIG / 8);
15-
tprints("}");
14+
(*arm_sp_ptr +
15+
OFFSETOF_STRUCT_UCONTEXT_UC_SIGMASK);
16+
tprints("{mask=");
17+
print_sigset_addr_len(tcp, addr, NSIG / 8);
18+
tprints("}");
19+
}

linux/crisv10/arch_sigreturn.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
long regs[PT_MAX + 1];
1+
static void
2+
arch_sigreturn(struct tcb *tcp)
3+
{
4+
long regs[PT_MAX + 1];
25

3-
if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (long)regs) < 0) {
4-
perror_msg("sigreturn: PTRACE_GETREGS");
5-
return;
6-
}
7-
const long addr = regs[PT_USP] + offsetof(struct sigcontext, oldmask);
6+
if (ptrace(PTRACE_GETREGS, tcp->pid, NULL, (long)regs) < 0) {
7+
perror_msg("sigreturn: PTRACE_GETREGS");
8+
return;
9+
}
10+
const long addr = regs[PT_USP] + offsetof(struct sigcontext, oldmask);
811

9-
tprints("{mask=");
10-
print_sigset_addr_len(tcp, addr, NSIG / 8);
11-
tprints("}");
12+
tprints("{mask=");
13+
print_sigset_addr_len(tcp, addr, NSIG / 8);
14+
tprints("}");
15+
}

linux/i386/arch_sigreturn.c

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
1-
/*
2-
* On i386, sigcontext is followed on stack by struct fpstate
3-
* and after it an additional u32 extramask which holds
4-
* upper half of the mask.
5-
*/
6-
struct {
7-
uint32_t struct_sigcontext_padding1[20];
8-
uint32_t oldmask;
9-
uint32_t struct_sigcontext_padding2;
10-
uint32_t struct_fpstate_padding[156];
11-
uint32_t extramask;
12-
} frame;
1+
static void
2+
arch_sigreturn(struct tcb *tcp)
3+
{
4+
/*
5+
* On i386, sigcontext is followed on stack by struct fpstate
6+
* and after it an additional u32 extramask which holds
7+
* upper half of the mask.
8+
*/
9+
struct {
10+
uint32_t struct_sigcontext_padding1[20];
11+
uint32_t oldmask;
12+
uint32_t struct_sigcontext_padding2;
13+
uint32_t struct_fpstate_padding[156];
14+
uint32_t extramask;
15+
} frame;
1316

14-
if (umove(tcp, *i386_esp_ptr, &frame) < 0) {
15-
tprintf("{mask=%#lx}", (unsigned long) *i386_esp_ptr);
16-
} else {
17-
uint32_t mask[2] = { frame.oldmask, frame.extramask };
18-
tprintsigmask_addr("{mask=", mask);
19-
tprints("}");
17+
if (umove(tcp, *i386_esp_ptr, &frame) < 0) {
18+
tprintf("{mask=%#lx}", (unsigned long) *i386_esp_ptr);
19+
} else {
20+
uint32_t mask[2] = { frame.oldmask, frame.extramask };
21+
tprintsigmask_addr("{mask=", mask);
22+
tprints("}");
23+
}
2024
}

linux/ia64/arch_sigreturn.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
/* offsetof(struct sigframe, sc) */
1+
static void
2+
arch_sigreturn(struct tcb *tcp)
3+
{
4+
/* offsetof(struct sigframe, sc) */
25
#define OFFSETOF_STRUCT_SIGFRAME_SC 0xA0
3-
const long addr = *ia64_frame_ptr + 16 +
4-
OFFSETOF_STRUCT_SIGFRAME_SC +
5-
offsetof(struct sigcontext, sc_mask);
6-
tprints("{mask=");
7-
print_sigset_addr_len(tcp, addr, NSIG / 8);
8-
tprints("}");
6+
const long addr = *ia64_frame_ptr + 16 +
7+
OFFSETOF_STRUCT_SIGFRAME_SC +
8+
offsetof(struct sigcontext, sc_mask);
9+
tprints("{mask=");
10+
print_sigset_addr_len(tcp, addr, NSIG / 8);
11+
tprints("}");
12+
}

linux/m68k/arch_sigreturn.c

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
1-
long addr;
1+
static void
2+
arch_sigreturn(struct tcb *tcp)
3+
{
4+
long addr;
25

3-
if (upeek(tcp->pid, 4*PT_USP, &addr) < 0)
4-
return;
5-
/* Fetch pointer to struct sigcontext. */
6-
if (umove(tcp, addr + 2 * sizeof(int), &addr) < 0)
7-
return;
6+
if (upeek(tcp->pid, 4*PT_USP, &addr) < 0)
7+
return;
8+
/* Fetch pointer to struct sigcontext. */
9+
if (umove(tcp, addr + 2 * sizeof(int), &addr) < 0)
10+
return;
811

9-
unsigned long mask[NSIG / 8 / sizeof(long)];
10-
/* Fetch first word of signal mask. */
11-
if (umove(tcp, addr, &mask[0]) < 0)
12-
return;
12+
unsigned long mask[NSIG / 8 / sizeof(long)];
13+
/* Fetch first word of signal mask. */
14+
if (umove(tcp, addr, &mask[0]) < 0)
15+
return;
1316

14-
/* Fetch remaining words of signal mask, located immediately before. */
15-
addr -= sizeof(mask) - sizeof(long);
16-
if (umoven(tcp, addr, sizeof(mask) - sizeof(long), &mask[1]) < 0)
17-
return;
17+
/* Fetch remaining words of signal mask, located immediately before. */
18+
addr -= sizeof(mask) - sizeof(long);
19+
if (umoven(tcp, addr, sizeof(mask) - sizeof(long), &mask[1]) < 0)
20+
return;
1821

19-
tprintsigmask_addr("{mask=", mask);
20-
tprints("}");
22+
tprintsigmask_addr("{mask=", mask);
23+
tprints("}");
24+
}

linux/microblaze/arch_sigreturn.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
/* TODO: Verify that this is correct... */
1+
static void
2+
arch_sigreturn(struct tcb *tcp)
3+
{
4+
/* TODO: Verify that this is correct... */
25

3-
long addr;
6+
long addr;
47

5-
/* Read r1, the stack pointer. */
6-
if (upeek(tcp->pid, 1 * 4, &addr) < 0)
7-
return;
8-
addr += offsetof(struct sigcontext, oldmask);
8+
/* Read r1, the stack pointer. */
9+
if (upeek(tcp->pid, 1 * 4, &addr) < 0)
10+
return;
11+
addr += offsetof(struct sigcontext, oldmask);
912

10-
tprints("{mask=");
11-
print_sigset_addr_len(tcp, addr, NSIG / 8);
12-
tprints("}");
13+
tprints("{mask=");
14+
print_sigset_addr_len(tcp, addr, NSIG / 8);
15+
tprints("}");
16+
}

linux/mips/arch_sigreturn.c

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
1+
static void
2+
arch_sigreturn(struct tcb *tcp)
3+
{
14
#if defined LINUX_MIPSO32
2-
/*
3-
* offsetof(struct sigframe, sf_mask) ==
4-
* sizeof(sf_ass) + sizeof(sf_pad) + sizeof(struct sigcontext)
5-
*/
6-
const long addr = mips_REG_SP + 6 * 4 +
7-
sizeof(struct sigcontext);
5+
/*
6+
* offsetof(struct sigframe, sf_mask) ==
7+
* sizeof(sf_ass) + sizeof(sf_pad) + sizeof(struct sigcontext)
8+
*/
9+
const long addr = mips_REG_SP + 6 * 4 +
10+
sizeof(struct sigcontext);
811
#else
9-
/*
10-
* This decodes rt_sigreturn.
11-
* The 64-bit ABIs do not have sigreturn.
12-
*
13-
* offsetof(struct rt_sigframe, rs_uc) ==
14-
* sizeof(sf_ass) + sizeof(sf_pad) + sizeof(struct siginfo)
15-
*/
16-
const long addr = mips_REG_SP + 6 * 4 + 128 +
17-
offsetof(struct ucontext, uc_sigmask);
12+
/*
13+
* This decodes rt_sigreturn.
14+
* The 64-bit ABIs do not have sigreturn.
15+
*
16+
* offsetof(struct rt_sigframe, rs_uc) ==
17+
* sizeof(sf_ass) + sizeof(sf_pad) + sizeof(struct siginfo)
18+
*/
19+
const long addr = mips_REG_SP + 6 * 4 + 128 +
20+
offsetof(struct ucontext, uc_sigmask);
1821
#endif
1922

20-
tprints("{mask=");
21-
print_sigset_addr_len(tcp, addr, NSIG / 8);
22-
tprints("}");
23+
tprints("{mask=");
24+
print_sigset_addr_len(tcp, addr, NSIG / 8);
25+
tprints("}");
26+
}

linux/powerpc/arch_sigreturn.c

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,28 @@
1-
long esp = ppc_regs.gpr[1];
2-
struct sigcontext sc;
1+
static void
2+
arch_sigreturn(struct tcb *tcp)
3+
{
4+
long esp = ppc_regs.gpr[1];
5+
struct sigcontext sc;
36

4-
/* Skip dummy stack frame. */
7+
/* Skip dummy stack frame. */
58
#ifdef POWERPC64
6-
if (current_personality == 0)
7-
esp += 128;
8-
else
9+
if (current_personality == 0)
10+
esp += 128;
11+
else
912
#endif
10-
esp += 64;
13+
esp += 64;
1114

12-
if (umove(tcp, esp, &sc) < 0) {
13-
tprintf("{mask=%#lx}", esp);
14-
} else {
15-
unsigned long mask[NSIG / 8 / sizeof(long)];
15+
if (umove(tcp, esp, &sc) < 0) {
16+
tprintf("{mask=%#lx}", esp);
17+
} else {
18+
unsigned long mask[NSIG / 8 / sizeof(long)];
1619
#ifdef POWERPC64
17-
mask[0] = sc.oldmask | (sc._unused[3] << 32);
20+
mask[0] = sc.oldmask | (sc._unused[3] << 32);
1821
#else
19-
mask[0] = sc.oldmask;
20-
mask[1] = sc._unused[3];
22+
mask[0] = sc.oldmask;
23+
mask[1] = sc._unused[3];
2124
#endif
22-
tprintsigmask_addr("{mask=", mask);
23-
tprints("}");
25+
tprintsigmask_addr("{mask=", mask);
26+
tprints("}");
27+
}
2428
}

linux/s390/arch_sigreturn.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1-
long mask[NSIG / 8 / sizeof(long)];
2-
const long addr = *s390_frame_ptr + __SIGNAL_FRAMESIZE;
1+
static void
2+
arch_sigreturn(struct tcb *tcp)
3+
{
4+
long mask[NSIG / 8 / sizeof(long)];
5+
const long addr = *s390_frame_ptr + __SIGNAL_FRAMESIZE;
36

4-
if (umove(tcp, addr, &mask) < 0) {
5-
tprintf("{mask=%#lx}", addr);
6-
} else {
7+
if (umove(tcp, addr, &mask) < 0) {
8+
tprintf("{mask=%#lx}", addr);
9+
} else {
710
#ifdef S390
8-
long v = mask[0];
9-
mask[0] = mask[1];
10-
mask[1] = v;
11+
long v = mask[0];
12+
mask[0] = mask[1];
13+
mask[1] = v;
1114
#endif
12-
tprintsigmask_addr("{mask=", mask);
13-
tprints("}");
15+
tprintsigmask_addr("{mask=", mask);
16+
tprints("}");
17+
}
1418
}

0 commit comments

Comments
 (0)