aboutsummaryrefslogtreecommitdiffstats
path: root/exec
diff options
context:
space:
mode:
authorPo Lu2023-05-02 16:44:46 +0800
committerPo Lu2023-05-02 16:44:46 +0800
commitf4512cca0b996e5343ebe57511f45a29f64c4a8e (patch)
treed7eca09f5d2f3a4db3b10212c10e66e24253c046 /exec
parent5a58a6bc477f290ee0b8a6111e92df56ff538719 (diff)
downloademacs-f4512cca0b996e5343ebe57511f45a29f64c4a8e.tar.gz
emacs-f4512cca0b996e5343ebe57511f45a29f64c4a8e.zip
Fix ps name in Android subprocesses
* exec/Makefile.in (.SUFFIXES): Include ., then `srcdir'. * exec/loader-aarch64.s (_start): * exec/loader-armeabi.s (_start): * exec/loader-mips64el.s (__start): * exec/loader-mipsel.s (__start): * exec/loader-x86.s (_start): * exec/loader-x86_64.s (_start): Get basename of opened exec file and make it the command name. Fix envp skipping on x86 and various leaks.
Diffstat (limited to 'exec')
-rw-r--r--exec/Makefile.in2
-rw-r--r--exec/loader-aarch64.s13
-rw-r--r--exec/loader-armeabi.s16
-rw-r--r--exec/loader-mips64el.s19
-rw-r--r--exec/loader-mipsel.s27
-rw-r--r--exec/loader-x86.s37
-rw-r--r--exec/loader-x86_64.s29
7 files changed, 115 insertions, 28 deletions
diff --git a/exec/Makefile.in b/exec/Makefile.in
index 365dc42e0b7..ae6bdf00415 100644
--- a/exec/Makefile.in
+++ b/exec/Makefile.in
@@ -81,7 +81,7 @@ Makefile: config.status Makefile.in
81 81
82.SUFFIXES: .c .s 82.SUFFIXES: .c .s
83.c.o: 83.c.o:
84 $(CC) -c $(CPPFLAGS) $(CFLAGS) $(DEPFLAGS) -I$(srcdir) -I. $< -o $@ 84 $(CC) -c $(CPPFLAGS) $(CFLAGS) $(DEPFLAGS) -I. -I$(srcdir) $< -o $@
85.s.o: 85.s.o:
86 $(M4) $< > $(notdir $<).s 86 $(M4) $< > $(notdir $<).s
87 $(AS) $(ASFLAGS) $(notdir $<).s -o $@ 87 $(AS) $(ASFLAGS) $(notdir $<).s -o $@
diff --git a/exec/loader-aarch64.s b/exec/loader-aarch64.s
index 1b99d238b92..da8ec1f4977 100644
--- a/exec/loader-aarch64.s
+++ b/exec/loader-aarch64.s
@@ -92,14 +92,27 @@ _start:
92 svc #0 // syscall 92 svc #0 // syscall
93 cmp x0, #-1 // rc < 0? 93 cmp x0, #-1 // rc < 0?
94 ble .perror 94 ble .perror
95 mov x19, x1 // x19 == x1
95.nextc: 96.nextc:
96 ldrb w2, [x1], #1 // b = *x1++ 97 ldrb w2, [x1], #1 // b = *x1++
98 cmp w2, #47 // dir separator?
99 bne .nextc1 // not dir separator
100 mov x19, x1 // x19 = char past separator
101.nextc1:
97 cbnz w2, .nextc // b? 102 cbnz w2, .nextc // b?
98 add x1, x1, #7 // round up x1 103 add x1, x1, #7 // round up x1
99 and x20, x1, #-8 // mask for round, set x20 104 and x20, x1, #-8 // mask for round, set x20
100 tst x11, #16 // primary fd? 105 tst x11, #16 // primary fd?
101 bne .secondary // secondary fd 106 bne .secondary // secondary fd
102 mov x29, x0 // primary fd 107 mov x29, x0 // primary fd
108 mov x8, #167 // SYS_prctl
109 mov x0, #15 // PR_SET_NAME
110 mov x1, x19 // basename
111 mov x2, #0 // arg2
112 mov x3, #0 // arg3
113 mov x4, #0 // arg4
114 mov x5, #0 // arg5
115 svc #0 // syscall
103 b .next_action // next action 116 b .next_action // next action
104.secondary: 117.secondary:
105 mov x28, x0 // secondary fd 118 mov x28, x0 // secondary fd
diff --git a/exec/loader-armeabi.s b/exec/loader-armeabi.s
index 182ff11ec7a..32b2a5268d6 100644
--- a/exec/loader-armeabi.s
+++ b/exec/loader-armeabi.s
@@ -104,15 +104,27 @@ _start:
104 cmp r0, #-1 @ r0 <= -1? 104 cmp r0, #-1 @ r0 <= -1?
105 ble .perror 105 ble .perror
106 add r8, r8, #4 @ r8 = start of string 106 add r8, r8, #4 @ r8 = start of string
107 mov r1, r8 @ r1 = r8
107.nextc: 108.nextc:
108 ldrb r1, [r8], #1 @ b = *r0++ 109 ldrb r2, [r8], #1 @ b = *r0++
109 cmp r1, #0 @ b? 110 cmp r2, #47 @ dir separator?
111 bne .nextc1 @ not dir separator
112 mov r1, r8 @ r1 = char past separator
113.nextc1:
114 cmp r2, #0 @ b?
110 bne .nextc @ next character 115 bne .nextc @ next character
111 add r8, r8, #3 @ round up r8 116 add r8, r8, #3 @ round up r8
112 and r8, r8, #-4 @ mask for round, set r8 117 and r8, r8, #-4 @ mask for round, set r8
113 tst r11, #16 @ primary fd? 118 tst r11, #16 @ primary fd?
114 bne .secondary @ secondary fd 119 bne .secondary @ secondary fd
115 mov r10, r0 @ primary fd 120 mov r10, r0 @ primary fd
121 mov r7, #172 @ SYS_prctl
122 mov r0, #15 @ PR_SET_NAME, r1 = name
123 mov r2, #0 @ arg2
124 mov r3, #0 @ arg3
125 mov r4, #0 @ arg4
126 mov r5, #0 @ arg5
127 swi #0 @ syscall
116 b .next_action @ next action 128 b .next_action @ next action
117.secondary: 129.secondary:
118 mov r14, r0 @ secondary fd 130 mov r14, r0 @ secondary fd
diff --git a/exec/loader-mips64el.s b/exec/loader-mips64el.s
index 73dc8c63fe8..00a2765a9b6 100644
--- a/exec/loader-mips64el.s
+++ b/exec/loader-mips64el.s
@@ -123,10 +123,16 @@ dnl syscall # syscall
123 bne $a3, $zero, .perror # perror 123 bne $a3, $zero, .perror # perror
124 nop # delay slot 124 nop # delay slot
125 DADDI2( $s0, 8) # start of string 125 DADDI2( $s0, 8) # start of string
126 move $t3, $s0 # t3 = s0
126.nextc: 127.nextc:
127 lb $t0, ($s0) # load byte 128 lb $t0, ($s0) # load byte
128 DADDI2( $s0, 1) # s0++ 129 DADDI2( $s0, 1) # s0++
129 bne $t0, $zero, .nextc # next character? 130 li $t1, 47 # directory separator `/'
131 bne $t0, $t1, .nextc1 # is separator char?
132 nop # delay slot
133 move $t3, $s0 # t3 = char past separator
134.nextc1:
135 bnez $t0, .nextc # next character?
130 nop # delay slot 136 nop # delay slot
131 DADDI2( $s0, 7) # adjust for round 137 DADDI2( $s0, 7) # adjust for round
132 li $t2, -8 # t2 = -8 138 li $t2, -8 # t2 = -8
@@ -136,8 +142,19 @@ dnl syscall # syscall
136 beqz $t0, .primary # primary fd? 142 beqz $t0, .primary # primary fd?
137 nop # delay slot 143 nop # delay slot
138 DADDI2( $t1, 8) # address of secondary fd 144 DADDI2( $t1, 8) # address of secondary fd
145 sd $v0, ($t1) # store fd
146 j .next_action # next action
147 nop # delay slot
139.primary: 148.primary:
140 sd $v0, ($t1) # store fd 149 sd $v0, ($t1) # store fd
150 li $v0, 5153 # SYS_prctl
151 li $a0, 15 # PR_SET_NAME
152 move $a1, $t3 # char past separator
153 move $a2, $zero # a2
154 move $a3, $zero # a3
155 move $a4, $zero # a4
156 move $a5, $zero # a5
157 syscall # syscall
141 j .next_action # next action 158 j .next_action # next action
142 nop # delay slot 159 nop # delay slot
143.perror: 160.perror:
diff --git a/exec/loader-mipsel.s b/exec/loader-mipsel.s
index 2ad9d97dfed..8537a0d2fe2 100644
--- a/exec/loader-mipsel.s
+++ b/exec/loader-mipsel.s
@@ -24,10 +24,10 @@ include(`config-mips.m4')
24 .section .text 24 .section .text
25 .global __start 25 .global __start
26__start: 26__start:
27dnl li $v0, SYSCALL_nanosleep # SYS_nanosleep 27 li $v0, SYSCALL_nanosleep # SYS_nanosleep
28dnl la $a0, .timespec # rqtp 28 la $a0, .timespec # rqtp
29dnl li $a1, 0 # rmtp 29 li $a1, 0 # rmtp
30dnl syscall # syscall 30 syscall # syscall
31 lw $s6, ($sp) # original stack pointer 31 lw $s6, ($sp) # original stack pointer
32 addi $s0, $sp, 8 # start of load area 32 addi $s0, $sp, 8 # start of load area
33 addi $sp, -8 # primary fd, secondary fd 33 addi $sp, -8 # primary fd, secondary fd
@@ -121,10 +121,16 @@ RESTORE() # delay slot, restore sp
121 syscall # syscall 121 syscall # syscall
122 bne $a3, $zero, .perror # perror 122 bne $a3, $zero, .perror # perror
123 addi $s0, $s0, 4 # start of string, delay slot 123 addi $s0, $s0, 4 # start of string, delay slot
124 move $t3, $s0 # t3 = char past separator
124.nextc: 125.nextc:
125 lb $t0, ($s0) # load byte 126 lb $t0, ($s0) # load byte
126 addi $s0, $s0, 1 # s0++ 127 addi $s0, $s0, 1 # s0++
127 bne $t0, $zero, .nextc # next character? 128 li $t1, 47 # directory separator `/'
129 bne $t0, $t1, .nextc1 # is separator char?
130 nop # delay slot
131 move $t3, $s0 # t3 = char past separator
132.nextc1:
133 bnez $t0, .nextc # next character?
128 nop # delay slot 134 nop # delay slot
129 addi $s0, $s0, 3 # adjust for round 135 addi $s0, $s0, 3 # adjust for round
130 li $t2, -4 # t2 = -4 136 li $t2, -4 # t2 = -4
@@ -133,8 +139,17 @@ RESTORE() # delay slot, restore sp
133 beqz $t0, .primary # primary fd? 139 beqz $t0, .primary # primary fd?
134 move $t0, $sp # address of primary fd, delay slot 140 move $t0, $sp # address of primary fd, delay slot
135 addi $t0, $t0, 4 # address of secondary fd 141 addi $t0, $t0, 4 # address of secondary fd
142 j .next_action # next action
136.primary: 143.primary:
137 sw $v0, ($t0) # store fd 144 sw $v0, ($t0) # store fd, delay slot
145 li $v0, SYSCALL_prctl # SYS_prctl
146 li $a0, 15 # PR_SET_NAME
147 move $a1, $t3 # name
148 move $a2, $zero # arg1
149 move $a3, $zero # arg2
150SYSCALL(`$a2',`$a2',`$a2',`$a2') # syscall args
151 syscall # syscall
152RESTORE() # restore sp
138 j .next_action # next action 153 j .next_action # next action
139 nop # delay slot 154 nop # delay slot
140.perror: 155.perror:
diff --git a/exec/loader-x86.s b/exec/loader-x86.s
index ee69b26d78b..6329e7f33b1 100644
--- a/exec/loader-x86.s
+++ b/exec/loader-x86.s
@@ -21,10 +21,10 @@ CC along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
21 .section .text 21 .section .text
22 .global _start 22 .global _start
23_start: 23_start:
24 #movl $162, %eax CC SYS_nanosleep 24dnl movl $162, %eax CC SYS_nanosleep
25 #leal timespec, %ebx 25dnl leal timespec, %ebx
26 #xorl %ecx, %ecx 26dnl xorl %ecx, %ecx
27 #int $0x80 27dnl int $0x80
28 leal 8(%esp), %ebp CC ebp = start of load area 28 leal 8(%esp), %ebp CC ebp = start of load area
29 subl $8, %esp CC (%esp) = primary fd, 4(%esp) = secondary fd 29 subl $8, %esp CC (%esp) = primary fd, 4(%esp) = secondary fd
30 movl $-1, 4(%esp) 30 movl $-1, 4(%esp)
@@ -102,10 +102,16 @@ _start:
102 jle .perror 102 jle .perror
103 movl %ebp, %esi CC (esi) = original action number 103 movl %ebp, %esi CC (esi) = original action number
104 popl %ebp CC ebp = start of string 104 popl %ebp CC ebp = start of string
105 movl %ebp, %ecx CC char past separator
105 decl %ebp 106 decl %ebp
106.nextc: 107.nextc:
107 incl %ebp 108 incl %ebp
108 cmpb $0, (%ebp) CC *ebp == 0? 109 movb (%ebp), %dl CC dl = *ebp
110 cmpb $47, %dl CC dl == '\?'?
111 jne .nextc1
112 leal 1(%ebp), %ecx CC ecx = char past separator
113.nextc1:
114 cmpb $0, %dl CC dl == 0?
109 jne .nextc 115 jne .nextc
110 addl $4, %ebp CC adjust past ebp prior to rounding 116 addl $4, %ebp CC adjust past ebp prior to rounding
111 andl $-4, %ebp CC round ebp up to the next long 117 andl $-4, %ebp CC round ebp up to the next long
@@ -114,7 +120,16 @@ _start:
114 movl %eax, 4(%esp) CC secondary fd = eax 120 movl %eax, 4(%esp) CC secondary fd = eax
115 jmp .next_action 121 jmp .next_action
116.primary: 122.primary:
117 movl %eax, (%esp) CC primary fd = eax 123 pushl %ebp
124 xorl %esi, %esi CC arg3
125 movl %eax, 4(%esp) CC primary fd = eax
126 xorl %edx, %edx CC arg2
127 movl $15, %ebx CC PR_SET_NAME, arg1 = ecx
128 xorl %edi, %edi CC arg4
129 movl $172, %eax CC SYS_prctl
130 xorl %ebp, %ebp CC arg5
131 int $0x80 CC syscall
132 popl %ebp
118 jmp .next_action 133 jmp .next_action
119.perror: 134.perror:
120 movl %eax, %ebx 135 movl %eax, %ebx
@@ -127,7 +142,7 @@ _start:
127 leal 8(%ecx, %esi, 4), %ecx CC ecx = start of environ 142 leal 8(%ecx, %esi, 4), %ecx CC ecx = start of environ
128.skip_environ: 143.skip_environ:
129 movl (%ecx), %esi CC envp[N] 144 movl (%ecx), %esi CC envp[N]
130 subl $4, %ecx 145 addl $4, %ecx
131 testl %esi, %esi CC envp[n] ? 146 testl %esi, %esi CC envp[n] ?
132 jnz .skip_environ CC otherwise, esi is now at the start of auxv 147 jnz .skip_environ CC otherwise, esi is now at the start of auxv
133.one_auxv: 148.one_auxv:
@@ -168,12 +183,12 @@ _start:
168 jmp .one_auxv 183 jmp .one_auxv
169.cleanup: 184.cleanup:
170 movl $6, %eax CC SYS_close 185 movl $6, %eax CC SYS_close
171 cmpl $1, -4(%esp) CC see if interpreter fd is set 186 cmpl $-1, 4(%esp) CC see if interpreter fd is set
172 jne .cleanup_1 187 je .cleanup_1
173 movl -4(%esp), %ebx 188 movl 4(%esp), %ebx
174 int $0x80 189 int $0x80
175.cleanup_1:
176 movl $6, %eax CC SYS_close 190 movl $6, %eax CC SYS_close
191.cleanup_1:
177 movl (%esp), %ebx 192 movl (%esp), %ebx
178 int $0x80 193 int $0x80
179.enter: 194.enter:
diff --git a/exec/loader-x86_64.s b/exec/loader-x86_64.s
index 07227d38396..acba609b202 100644
--- a/exec/loader-x86_64.s
+++ b/exec/loader-x86_64.s
@@ -21,10 +21,10 @@ CC along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
21 .section .text 21 .section .text
22 .global _start 22 .global _start
23_start: 23_start:
24 #movq $35, %rax CC SYS_nanosleep 24dnl movq $35, %rax CC SYS_nanosleep
25 #leaq timespec(%rip), %rdi 25dnl leaq timespec(%rip), %rdi
26 #xorq %rsi, %rsi 26dnl xorq %rsi, %rsi
27 #syscall 27dnl syscall
28 popq %r13 CC original SP 28 popq %r13 CC original SP
29 popq %r15 CC size of load area. 29 popq %r15 CC size of load area.
30 movq $-1, %r12 CC r12 is the interpreter fd 30 movq $-1, %r12 CC r12 is the interpreter fd
@@ -87,9 +87,16 @@ _start:
87 jle .perror 87 jle .perror
88 movq %rdi, %rsp CC rsp = start of string 88 movq %rdi, %rsp CC rsp = start of string
89 subq $1, %rsp 89 subq $1, %rsp
90 movq %rsp, %r14 CC r14 = start of string
90.nextc: 91.nextc:
91 addq $1, %rsp 92 addq $1, %rsp
92 cmpb $0, (%rsp) CC *rsp == 0? 93 movb (%rsp), %dil CC rdi = *rsp
94 cmpb $47, %dil CC *rsp == '/'?
95 jne .nextc1
96 movq %rsp, %r14 CC r14 = rsp
97 addq $1, %r14 CC r14 = char past separator
98.nextc1:
99 cmpb $0, %dil CC *rsp == 0?
93 jne .nextc 100 jne .nextc
94 addq $8, %rsp CC adjust past rsp prior to rounding 101 addq $8, %rsp CC adjust past rsp prior to rounding
95 andq $-8, %rsp CC round rsp up to the next quad 102 andq $-8, %rsp CC round rsp up to the next quad
@@ -99,6 +106,14 @@ _start:
99 jmp .next_action 106 jmp .next_action
100.primary: 107.primary:
101 movq %rax, %rbx CC if not, move fd to rbx 108 movq %rax, %rbx CC if not, move fd to rbx
109 movq $157, %rax CC SYS_prctl
110 movq $15, %rdi CC PR_SET_NAME
111 movq %r14, %rsi CC arg1
112 xorq %rdx, %rdx CC arg2
113 xorq %r10, %r10 CC arg3
114 xorq %r8, %r8 CC arg4
115 xorq %r9, %r9 CC arg5
116 syscall
102 jmp .next_action 117 jmp .next_action
103.perror: 118.perror:
104 movq %rax, %r12 CC error code 119 movq %rax, %r12 CC error code
@@ -159,11 +174,11 @@ _start:
159.cleanup: 174.cleanup:
160 movq $3, %rax CC SYS_close 175 movq $3, %rax CC SYS_close
161 cmpq $-1, %r12 CC see if interpreter fd is set 176 cmpq $-1, %r12 CC see if interpreter fd is set
162 jne .cleanup_1 177 je .cleanup_1
163 movq %r12, %rdi 178 movq %r12, %rdi
164 syscall 179 syscall
165.cleanup_1:
166 movq $3, %rax CC SYS_close 180 movq $3, %rax CC SYS_close
181.cleanup_1:
167 movq %rbx, %rdi 182 movq %rbx, %rdi
168 syscall 183 syscall
169.enter: 184.enter: