2005-10-16 15:49:27 +00:00
|
|
|
/* Create new context.
|
2020-01-01 00:14:33 +00:00
|
|
|
Copyright (C) 2005-2020 Free Software Foundation, Inc.
|
2005-10-16 15:49:27 +00:00
|
|
|
This file is part of the GNU C Library.
|
|
|
|
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
The GNU C Library 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
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
2012-02-09 23:18:22 +00:00
|
|
|
License along with the GNU C Library; if not, see
|
Prefer https to http for gnu.org and fsf.org URLs
Also, change sources.redhat.com to sourceware.org.
This patch was automatically generated by running the following shell
script, which uses GNU sed, and which avoids modifying files imported
from upstream:
sed -ri '
s,(http|ftp)(://(.*\.)?(gnu|fsf|sourceware)\.org($|[^.]|\.[^a-z])),https\2,g
s,(http|ftp)(://(.*\.)?)sources\.redhat\.com($|[^.]|\.[^a-z]),https\2sourceware.org\4,g
' \
$(find $(git ls-files) -prune -type f \
! -name '*.po' \
! -name 'ChangeLog*' \
! -path COPYING ! -path COPYING.LIB \
! -path manual/fdl-1.3.texi ! -path manual/lgpl-2.1.texi \
! -path manual/texinfo.tex ! -path scripts/config.guess \
! -path scripts/config.sub ! -path scripts/install-sh \
! -path scripts/mkinstalldirs ! -path scripts/move-if-change \
! -path INSTALL ! -path locale/programs/charmap-kw.h \
! -path po/libc.pot ! -path sysdeps/gnu/errlist.c \
! '(' -name configure \
-execdir test -f configure.ac -o -f configure.in ';' ')' \
! '(' -name preconfigure \
-execdir test -f preconfigure.ac ';' ')' \
-print)
and then by running 'make dist-prepare' to regenerate files built
from the altered files, and then executing the following to cleanup:
chmod a+x sysdeps/unix/sysv/linux/riscv/configure
# Omit irrelevant whitespace and comment-only changes,
# perhaps from a slightly-different Autoconf version.
git checkout -f \
sysdeps/csky/configure \
sysdeps/hppa/configure \
sysdeps/riscv/configure \
sysdeps/unix/sysv/linux/csky/configure
# Omit changes that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/powerpc/powerpc64/ppc-mcount.S: trailing lines
git checkout -f \
sysdeps/powerpc/powerpc64/ppc-mcount.S \
sysdeps/unix/sysv/linux/s390/s390-64/syscall.S
# Omit change that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S: last line does not end in newline
git checkout -f sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S
2019-09-07 05:40:42 +00:00
|
|
|
<https://www.gnu.org/licenses/>. */
|
2005-10-16 15:49:27 +00:00
|
|
|
|
|
|
|
#include <sysdep.h>
|
2012-06-23 09:47:39 +00:00
|
|
|
#include <abort-instr.h>
|
2005-10-16 15:49:27 +00:00
|
|
|
|
|
|
|
#include "ucontext_i.h"
|
|
|
|
|
2017-06-26 22:03:58 +00:00
|
|
|
/* void __makecontext (ucontext_t *ucp, void (*func)(), int argc, ...);
|
2005-10-16 15:49:27 +00:00
|
|
|
__makecontext sets up a stack and registers for context to run a given
|
|
|
|
function. The registers are set up like this:
|
|
|
|
r4-r7: parameters 1 to 4
|
|
|
|
r8 : uc_link from ucontext structure
|
|
|
|
pc : (*func) pointer
|
|
|
|
pr : address of exitcode
|
|
|
|
r15 : stack pointer for func. */
|
|
|
|
|
|
|
|
.text
|
|
|
|
.align 5
|
|
|
|
ENTRY(__makecontext)
|
|
|
|
mov #4, r3
|
2012-06-23 09:22:47 +00:00
|
|
|
mov.l @(oSS_SP,r4), r1 /* r1 <- ucb->stack_base */
|
|
|
|
mov.l @(oSS_SIZE,r4), r2 /* r2 <- ucb->stack_size */
|
|
|
|
add r1, r2 /* r2 <- stack_top */
|
2012-06-23 09:28:23 +00:00
|
|
|
cmp/gt r3, r6 /* argc > 4? */
|
2005-10-16 15:49:27 +00:00
|
|
|
bf/s 1f
|
2012-06-23 09:22:47 +00:00
|
|
|
shlr2 r2 /* r2 <- stack_top / 4 */
|
2005-10-16 15:49:27 +00:00
|
|
|
sub r6, r2
|
|
|
|
add r3, r2
|
|
|
|
1:
|
2012-06-23 09:22:47 +00:00
|
|
|
shll2 r2 /* r2 <- stack_top - ((argc > 4) ? 4 * (argc - 4) : 0 */
|
2005-10-16 15:49:27 +00:00
|
|
|
mov #oR15, r0
|
|
|
|
mov.l @(oLINK,r4), r1
|
2012-06-23 09:22:47 +00:00
|
|
|
mov.l r2, @(r0,r4) /* ucp->r15 <- r2 */
|
|
|
|
mov.l r1, @(oR8,r4) /* ucp->r8 <- ucp->uc_link */
|
2005-10-16 15:49:27 +00:00
|
|
|
mov #oPC, r0
|
2012-06-23 09:22:47 +00:00
|
|
|
mov.l r5, @(r0,r4) /* ucp->PC <- func */
|
2005-10-16 15:49:27 +00:00
|
|
|
|
2012-06-23 09:22:47 +00:00
|
|
|
cmp/pl r6 /* argc > 0? */
|
2005-10-16 15:49:27 +00:00
|
|
|
bf/s .L1
|
|
|
|
dt r6
|
2012-06-23 09:22:47 +00:00
|
|
|
mov.l r7, @(oR4,r4) /* ucp->r4 <- argv[0] */
|
|
|
|
cmp/pl r6 /* argc > 1? */
|
2005-10-16 15:49:27 +00:00
|
|
|
bf/s .L1
|
|
|
|
dt r6
|
|
|
|
mov.l @(0,r15), r1
|
2012-06-23 09:22:47 +00:00
|
|
|
mov.l r1, @(oR5,r4) /* ucp->r5 <- argv[1] */
|
|
|
|
cmp/pl r6 /* argc > 2? */
|
2005-10-16 15:49:27 +00:00
|
|
|
bf/s .L1
|
|
|
|
dt r6
|
|
|
|
mov.l @(4,r15), r1
|
2012-06-23 09:22:47 +00:00
|
|
|
mov.l r1, @(oR6,r4) /* ucp->r6 <- argv[2] */
|
|
|
|
cmp/pl r6 /* argc > 3? */
|
2005-10-16 15:49:27 +00:00
|
|
|
bf/s .L1
|
|
|
|
dt r6
|
|
|
|
mov.l @(8,r15), r1
|
2012-06-23 09:22:47 +00:00
|
|
|
mov.l r1, @(oR7,r4) /* ucp->r7 <- argv[3] */
|
2005-10-16 15:49:27 +00:00
|
|
|
mov #12,r0
|
2012-06-23 09:22:47 +00:00
|
|
|
.L0: /* Save remaining argv[] on the stack. */
|
2005-10-16 15:49:27 +00:00
|
|
|
cmp/pl r6
|
|
|
|
bf/s .L1
|
|
|
|
dt r6
|
|
|
|
mov.l @(r0,r15), r1
|
|
|
|
mov.l r1, @r2
|
|
|
|
add #4, r0
|
|
|
|
bra .L0
|
|
|
|
add #4, r2
|
|
|
|
.L1:
|
|
|
|
#ifdef PIC
|
|
|
|
mova .Lexitcode, r0
|
|
|
|
#else
|
|
|
|
mov.l .L2, r0
|
|
|
|
#endif
|
|
|
|
add #oPR, r4
|
|
|
|
rts
|
2012-06-23 09:22:47 +00:00
|
|
|
mov.l r0, @r4 /* ucp->pr <- exitcode */
|
2005-10-16 15:49:27 +00:00
|
|
|
#ifndef PIC
|
|
|
|
.align 2
|
|
|
|
.L2:
|
|
|
|
.long .Lexitcode
|
|
|
|
#endif
|
|
|
|
cfi_endproc
|
|
|
|
|
|
|
|
.align 5
|
2012-06-23 10:11:13 +00:00
|
|
|
cfi_startproc
|
2005-10-16 15:49:27 +00:00
|
|
|
.Lexitcode:
|
|
|
|
#ifdef PIC
|
2012-06-23 10:11:13 +00:00
|
|
|
mov.l r12, @-r15
|
|
|
|
cfi_adjust_cfa_offset (4)
|
|
|
|
cfi_rel_offset (r12, 0)
|
2005-10-16 15:49:27 +00:00
|
|
|
mova .Lgot, r0
|
|
|
|
mov.l .Lgot, r12
|
|
|
|
add r0, r12
|
2012-06-23 09:42:29 +00:00
|
|
|
#endif
|
|
|
|
tst r8, r8 /* ucb->uc_link == NULL? */
|
|
|
|
bt/s 2f
|
|
|
|
mov r8, r4 /* r4 <- ucb->uc_link */
|
2012-06-23 09:22:47 +00:00
|
|
|
mov.l .Lsetcontext, r1
|
2012-06-23 10:11:13 +00:00
|
|
|
sts.l pr, @-r15
|
|
|
|
cfi_adjust_cfa_offset (4)
|
|
|
|
cfi_rel_offset (pr, 0)
|
2012-06-23 09:42:29 +00:00
|
|
|
#ifdef PIC
|
2005-10-16 15:49:27 +00:00
|
|
|
bsrf r1
|
|
|
|
.LPCS0:
|
|
|
|
nop
|
|
|
|
#else
|
|
|
|
jsr @r1
|
|
|
|
nop
|
|
|
|
#endif
|
2012-06-23 10:11:13 +00:00
|
|
|
/* Restore to keep CFI/CFA balanced. */
|
|
|
|
lds.l @r15+, pr
|
|
|
|
cfi_adjust_cfa_offset (-4)
|
|
|
|
cfi_restore (pr)
|
2012-06-23 09:42:29 +00:00
|
|
|
/* If this returns (which can happen if the syscall fails) we'll exit
|
|
|
|
the program with the return error value (-1). */
|
2012-07-17 08:06:06 +00:00
|
|
|
mov r0, r4
|
2012-06-23 09:42:29 +00:00
|
|
|
|
2005-10-16 15:49:27 +00:00
|
|
|
2:
|
2012-06-23 09:22:47 +00:00
|
|
|
mov.l .Lexit, r1
|
2005-10-16 15:49:27 +00:00
|
|
|
#ifdef PIC
|
|
|
|
add r12, r1
|
|
|
|
#endif
|
|
|
|
jsr @r1
|
2012-07-17 08:06:06 +00:00
|
|
|
nop
|
2012-06-23 09:47:39 +00:00
|
|
|
/* The 'exit' call should never return. In case it does cause the
|
|
|
|
process to terminate. */
|
|
|
|
ABORT_INSTRUCTION_ASM
|
2005-10-16 15:49:27 +00:00
|
|
|
|
|
|
|
.align 2
|
|
|
|
#ifdef PIC
|
|
|
|
.Lgot:
|
|
|
|
.long _GLOBAL_OFFSET_TABLE_
|
2012-06-23 09:22:47 +00:00
|
|
|
.Lsetcontext:
|
2005-10-16 15:49:27 +00:00
|
|
|
.long __setcontext@PLT-(.LPCS0+2-(.))
|
2012-06-23 09:22:47 +00:00
|
|
|
.Lexit:
|
2005-10-16 15:49:27 +00:00
|
|
|
.long HIDDEN_JUMPTARGET(exit)@GOTOFF
|
|
|
|
#else
|
2012-06-23 09:22:47 +00:00
|
|
|
.Lsetcontext:
|
2005-10-16 15:49:27 +00:00
|
|
|
.long __setcontext
|
2012-06-23 09:22:47 +00:00
|
|
|
.Lexit:
|
2005-10-16 15:49:27 +00:00
|
|
|
.long HIDDEN_JUMPTARGET(exit)
|
|
|
|
#endif
|
|
|
|
PSEUDO_END(__makecontext)
|
|
|
|
|
|
|
|
weak_alias (__makecontext, makecontext)
|