]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix ps name in Android subprocesses
authorPo Lu <luangruo@yahoo.com>
Tue, 2 May 2023 08:44:46 +0000 (16:44 +0800)
committerPo Lu <luangruo@yahoo.com>
Tue, 2 May 2023 08:44:46 +0000 (16:44 +0800)
* 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.

exec/Makefile.in
exec/loader-aarch64.s
exec/loader-armeabi.s
exec/loader-mips64el.s
exec/loader-mipsel.s
exec/loader-x86.s
exec/loader-x86_64.s

index 365dc42e0b70fcb446e6583d24049d06888f5279..ae6bdf0041596c99228752143f4cde95c2c8ae69 100644 (file)
@@ -81,7 +81,7 @@ Makefile: config.status Makefile.in
 
 .SUFFIXES: .c .s
 .c.o:
-       $(CC) -c $(CPPFLAGS) $(CFLAGS) $(DEPFLAGS) -I$(srcdir) -I. $< -o $@
+       $(CC) -c $(CPPFLAGS) $(CFLAGS) $(DEPFLAGS) -I. -I$(srcdir) $< -o $@
 .s.o:
        $(M4) $< > $(notdir $<).s
        $(AS) $(ASFLAGS) $(notdir $<).s -o $@
index 1b99d238b92868ba614c938238a9f19fe124302c..da8ec1f4977d5d0afeb25657fe17d301e66e5a55 100644 (file)
@@ -92,14 +92,27 @@ _start:
        svc     #0                      // syscall
        cmp     x0, #-1                 // rc < 0?
        ble     .perror
+       mov     x19, x1                 // x19 == x1
 .nextc:
        ldrb    w2, [x1], #1            // b = *x1++
+       cmp     w2, #47                 // dir separator?
+       bne     .nextc1                 // not dir separator
+       mov     x19, x1                 // x19 = char past separator
+.nextc1:
        cbnz    w2, .nextc              // b?
        add     x1, x1, #7              // round up x1
        and     x20, x1, #-8            // mask for round, set x20
        tst     x11, #16                // primary fd?
        bne     .secondary              // secondary fd
        mov     x29, x0                 // primary fd
+       mov     x8, #167                // SYS_prctl
+       mov     x0, #15                 // PR_SET_NAME
+       mov     x1, x19                 // basename
+       mov     x2, #0                  // arg2
+       mov     x3, #0                  // arg3
+       mov     x4, #0                  // arg4
+       mov     x5, #0                  // arg5
+       svc     #0                      // syscall
        b       .next_action            // next action
 .secondary:
        mov     x28, x0                 // secondary fd
index 182ff11ec7acfefc1c624c6d918dbcdb2a8cd88e..32b2a5268d6efc0e31e27163e1b12a54f2edfa18 100644 (file)
@@ -104,15 +104,27 @@ _start:
        cmp     r0, #-1                 @ r0 <= -1?
        ble     .perror
        add     r8, r8, #4              @ r8 = start of string
+       mov     r1, r8                  @ r1 = r8
 .nextc:
-       ldrb    r1, [r8], #1            @ b = *r0++
-       cmp     r1, #0                  @ b?
+       ldrb    r2, [r8], #1            @ b = *r0++
+       cmp     r2, #47                 @ dir separator?
+       bne     .nextc1                 @ not dir separator
+       mov     r1, r8                  @ r1 = char past separator
+.nextc1:
+       cmp     r2, #0                  @ b?
        bne     .nextc                  @ next character
        add     r8, r8, #3              @ round up r8
        and     r8, r8, #-4             @ mask for round, set r8
        tst     r11, #16                @ primary fd?
        bne     .secondary              @ secondary fd
        mov     r10, r0                 @ primary fd
+       mov     r7, #172                @ SYS_prctl
+       mov     r0, #15                 @ PR_SET_NAME, r1 = name
+       mov     r2, #0                  @ arg2
+       mov     r3, #0                  @ arg3
+       mov     r4, #0                  @ arg4
+       mov     r5, #0                  @ arg5
+       swi     #0                      @ syscall
        b       .next_action            @ next action
 .secondary:
        mov     r14, r0                 @ secondary fd
index 73dc8c63fe81ce183970ccac62a7e3a5bd73a0ce..00a2765a9b6a1740989afd247bf61d620a76c1ef 100644 (file)
@@ -123,10 +123,16 @@ dnl       syscall                         # syscall
        bne     $a3, $zero, .perror     # perror
        nop                             # delay slot
        DADDI2( $s0, 8)                 # start of string
+       move    $t3, $s0                # t3 = s0
 .nextc:
        lb      $t0, ($s0)              # load byte
        DADDI2( $s0, 1)                 # s0++
-       bne     $t0, $zero, .nextc      # next character?
+       li      $t1, 47                 # directory separator `/'
+       bne     $t0, $t1, .nextc1       # is separator char?
+       nop                             # delay slot
+       move    $t3, $s0                # t3 = char past separator
+.nextc1:
+       bnez    $t0, .nextc             # next character?
        nop                             # delay slot
        DADDI2( $s0, 7)                 # adjust for round
        li      $t2, -8                 # t2 = -8
@@ -136,8 +142,19 @@ dnl        syscall                         # syscall
        beqz    $t0, .primary           # primary fd?
        nop                             # delay slot
        DADDI2( $t1, 8)                 # address of secondary fd
+       sd      $v0, ($t1)              # store fd
+       j       .next_action            # next action
+       nop                             # delay slot
 .primary:
        sd      $v0, ($t1)              # store fd
+       li      $v0, 5153               # SYS_prctl
+       li      $a0, 15                 # PR_SET_NAME
+       move    $a1, $t3                # char past separator
+       move    $a2, $zero              # a2
+       move    $a3, $zero              # a3
+       move    $a4, $zero              # a4
+       move    $a5, $zero              # a5
+       syscall                         # syscall
        j       .next_action            # next action
        nop                             # delay slot
 .perror:
index 2ad9d97dfed7a6740c072d65544d9893298b2777..8537a0d2fe2131b307e166d8ea68243ae90ca3cd 100644 (file)
@@ -24,10 +24,10 @@ include(`config-mips.m4')
        .section .text
        .global __start
 __start:
-dnl    li      $v0, SYSCALL_nanosleep  # SYS_nanosleep
-dnl    la      $a0, .timespec          # rqtp
-dnl    li      $a1, 0                  # rmtp
-dnl    syscall                         # syscall
+       li      $v0, SYSCALL_nanosleep  # SYS_nanosleep
+       la      $a0, .timespec          # rqtp
+       li      $a1, 0                  # rmtp
+       syscall                         # syscall
        lw      $s6, ($sp)              # original stack pointer
        addi    $s0, $sp, 8             # start of load area
        addi    $sp, -8                 # primary fd, secondary fd
@@ -121,10 +121,16 @@ RESTORE()                         # delay slot, restore sp
        syscall                         # syscall
        bne     $a3, $zero, .perror     # perror
        addi    $s0, $s0, 4             # start of string, delay slot
+       move    $t3, $s0                # t3 = char past separator
 .nextc:
        lb      $t0, ($s0)              # load byte
        addi    $s0, $s0, 1             # s0++
-       bne     $t0, $zero, .nextc      # next character?
+       li      $t1, 47                 # directory separator `/'
+       bne     $t0, $t1, .nextc1       # is separator char?
+       nop                             # delay slot
+       move    $t3, $s0                # t3 = char past separator
+.nextc1:
+       bnez    $t0, .nextc             # next character?
        nop                             # delay slot
        addi    $s0, $s0, 3             # adjust for round
        li      $t2, -4                 # t2 = -4
@@ -133,8 +139,17 @@ RESTORE()                          # delay slot, restore sp
        beqz    $t0, .primary           # primary fd?
        move    $t0, $sp                # address of primary fd, delay slot
        addi    $t0, $t0, 4             # address of secondary fd
+       j       .next_action            # next action
 .primary:
-       sw      $v0, ($t0)              # store fd
+       sw      $v0, ($t0)              # store fd, delay slot
+       li      $v0, SYSCALL_prctl      # SYS_prctl
+       li      $a0, 15                 # PR_SET_NAME
+       move    $a1, $t3                # name
+       move    $a2, $zero              # arg1
+       move    $a3, $zero              # arg2
+SYSCALL(`$a2',`$a2',`$a2',`$a2')       # syscall args
+       syscall                         # syscall
+RESTORE()                              # restore sp
        j       .next_action            # next action
        nop                             # delay slot
 .perror:
index ee69b26d78bab159040f43c2a10b8aa76e083e2d..6329e7f33b181369db152192ded458efa4279525 100644 (file)
@@ -21,10 +21,10 @@ CC along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.
        .section .text
        .global _start
 _start:
-       #movl   $162, %eax              CC SYS_nanosleep
-       #leal   timespec, %ebx
-       #xorl   %ecx, %ecx
-       #int    $0x80
+dnl    movl    $162, %eax              CC SYS_nanosleep
+dnl    leal    timespec, %ebx
+dnl    xorl    %ecx, %ecx
+dnl    int     $0x80
        leal    8(%esp), %ebp           CC ebp = start of load area
        subl    $8, %esp                CC (%esp) = primary fd, 4(%esp) = secondary fd
        movl    $-1, 4(%esp)
@@ -102,10 +102,16 @@ _start:
        jle     .perror
        movl    %ebp, %esi              CC (esi) = original action number
        popl    %ebp                    CC ebp = start of string
+       movl    %ebp, %ecx              CC char past separator
        decl    %ebp
 .nextc:
        incl    %ebp
-       cmpb    $0, (%ebp)              CC *ebp == 0?
+       movb    (%ebp), %dl             CC dl = *ebp
+       cmpb    $47, %dl                CC dl == '\?'?
+       jne     .nextc1
+       leal    1(%ebp), %ecx           CC ecx = char past separator
+.nextc1:
+       cmpb    $0, %dl                 CC dl == 0?
        jne     .nextc
        addl    $4, %ebp                CC adjust past ebp prior to rounding
        andl    $-4, %ebp               CC round ebp up to the next long
@@ -114,7 +120,16 @@ _start:
        movl    %eax, 4(%esp)           CC secondary fd = eax
        jmp     .next_action
 .primary:
-       movl    %eax, (%esp)            CC primary fd = eax
+       pushl   %ebp
+       xorl    %esi, %esi              CC arg3
+       movl    %eax, 4(%esp)           CC primary fd = eax
+       xorl    %edx, %edx              CC arg2
+       movl    $15, %ebx               CC PR_SET_NAME, arg1 = ecx
+       xorl    %edi, %edi              CC arg4
+       movl    $172, %eax              CC SYS_prctl
+       xorl    %ebp, %ebp              CC arg5
+       int     $0x80                   CC syscall
+       popl    %ebp
        jmp     .next_action
 .perror:
        movl    %eax, %ebx
@@ -127,7 +142,7 @@ _start:
        leal    8(%ecx, %esi, 4), %ecx  CC ecx = start of environ
 .skip_environ:
        movl    (%ecx), %esi            CC envp[N]
-       subl    $4, %ecx
+       addl    $4, %ecx
        testl   %esi, %esi              CC envp[n] ?
        jnz     .skip_environ           CC otherwise, esi is now at the start of auxv
 .one_auxv:
@@ -168,12 +183,12 @@ _start:
        jmp     .one_auxv
 .cleanup:
        movl    $6, %eax                CC SYS_close
-       cmpl    $1, -4(%esp)            CC see if interpreter fd is set
-       jne     .cleanup_1
-       movl    -4(%esp), %ebx
+       cmpl    $-1, 4(%esp)            CC see if interpreter fd is set
+       j     .cleanup_1
+       movl    4(%esp), %ebx
        int     $0x80
-.cleanup_1:
        movl    $6, %eax                CC SYS_close
+.cleanup_1:
        movl    (%esp), %ebx
        int     $0x80
 .enter:
index 07227d38396fb8524635a16b277f875c842032cd..acba609b202f776c00c2448b4d1940a7843eab5b 100644 (file)
@@ -21,10 +21,10 @@ CC along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.
        .section .text
        .global _start
 _start:
-       #movq   $35, %rax               CC SYS_nanosleep
-       #leaq   timespec(%rip), %rdi
-       #xorq   %rsi, %rsi
-       #syscall
+dnl    movq    $35, %rax               CC SYS_nanosleep
+dnl    leaq    timespec(%rip), %rdi
+dnl    xorq    %rsi, %rsi
+dnl    syscall
        popq    %r13                    CC original SP
        popq    %r15                    CC size of load area.
        movq    $-1, %r12               CC r12 is the interpreter fd
@@ -87,9 +87,16 @@ _start:
        jle     .perror
        movq    %rdi, %rsp              CC rsp = start of string
        subq    $1, %rsp
+       movq    %rsp, %r14              CC r14 = start of string
 .nextc:
        addq    $1, %rsp
-       cmpb    $0, (%rsp)              CC *rsp == 0?
+       movb    (%rsp), %dil            CC rdi = *rsp
+       cmpb    $47, %dil               CC *rsp == '/'?
+       jne     .nextc1
+       movq    %rsp, %r14              CC r14 = rsp
+       addq    $1, %r14                CC r14 = char past separator
+.nextc1:
+       cmpb    $0, %dil                CC *rsp == 0?
        jne     .nextc
        addq    $8, %rsp                CC adjust past rsp prior to rounding
        andq    $-8, %rsp               CC round rsp up to the next quad
@@ -99,6 +106,14 @@ _start:
        jmp     .next_action
 .primary:
        movq    %rax, %rbx              CC if not, move fd to rbx
+       movq    $157, %rax              CC SYS_prctl
+       movq    $15, %rdi               CC PR_SET_NAME
+       movq    %r14, %rsi              CC arg1
+       xorq    %rdx, %rdx              CC arg2
+       xorq    %r10, %r10              CC arg3
+       xorq    %r8, %r8                CC arg4
+       xorq    %r9, %r9                CC arg5
+       syscall
        jmp     .next_action
 .perror:
        movq    %rax, %r12              CC error code
@@ -159,11 +174,11 @@ _start:
 .cleanup:
        movq    $3, %rax                CC SYS_close
        cmpq    $-1, %r12               CC see if interpreter fd is set
-       jne     .cleanup_1
+       j     .cleanup_1
        movq    %r12, %rdi
        syscall
-.cleanup_1:
        movq    $3, %rax                CC SYS_close
+.cleanup_1:
        movq    %rbx, %rdi
        syscall
 .enter: