blob: 9878e8d9f8c60b082710f551eb79787e518edbf1 [file] [log] [blame]
Serban Constantinescue2104882013-09-26 11:37:10 +01001/*
Dan Albert6a918872014-08-05 20:53:31 +00002 * Copyright (C) 2013 The Android Open Source Project
Elliott Hughes54a74942014-01-03 16:40:37 -08003 * All rights reserved.
Serban Constantinescue2104882013-09-26 11:37:10 +01004 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in
12 * the documentation and/or other materials provided with the
13 * distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
Christopher Ferrisc5d3a432019-09-25 17:50:36 -070029#include <platform/bionic/tls_defines.h>
Dan Albert6a918872014-08-05 20:53:31 +000030#include <private/bionic_asm.h>
31#include <asm/signal.h>
Christopher Ferrisb8a95e22019-10-02 18:29:20 -070032
33// Must match the defines in linux/sched.h
34#define CLONE_VM 0x00000100
35#define CLONE_VFORK 0x00004000
Serban Constantinescue2104882013-09-26 11:37:10 +010036
Dan Albert6a918872014-08-05 20:53:31 +000037ENTRY(vfork)
dimitryfa432522017-10-25 13:07:45 +020038__BIONIC_WEAK_ASM_FOR_NATIVE_BRIDGE(vfork)
Josh Gao23032832020-05-07 17:02:19 -070039 // x9 = __get_tls()[TLS_SLOT_THREAD_ID]
40 mrs x9, tpidr_el0
41 ldr x9, [x9, #(TLS_SLOT_THREAD_ID * 8)]
42
43 // Set cached_pid_ to 0, vforked_ to 1, and stash the previous value.
44 mov w0, #0x80000000
45 ldr w10, [x9, #20]
46 str w0, [x9, #20]
Elliott Hughes5891abd2015-08-07 18:27:47 -070047
Evgenii Stepanov3031a7e2022-05-12 15:50:47 -070048 // Clear vfork_child_stack_bottom_.
49 str xzr, [x9, #776]
50
Dan Albert6a918872014-08-05 20:53:31 +000051 mov x0, #(CLONE_VM | CLONE_VFORK | SIGCHLD)
52 mov x1, xzr
53 mov x2, xzr
54 mov x3, xzr
55 mov x4, xzr
56
57 mov x8, __NR_clone
58 svc #0
59
Josh Gao23032832020-05-07 17:02:19 -070060 cbz x0, .L_exit
61
62 // rc != 0: reset cached_pid_ and vforked_.
63 str w10, [x9, #20]
Dan Albert6a918872014-08-05 20:53:31 +000064 cmn x0, #(MAX_ERRNO + 1)
65 cneg x0, x0, hi
Elliott Hughes011e1112014-09-08 15:25:01 -070066 b.hi __set_errno_internal
Dan Albert6a918872014-08-05 20:53:31 +000067
Evgenii Stepanov505168e2019-02-28 18:44:56 -080068 // Clean up stack shadow in the parent process.
69 // https://github.com/google/sanitizers/issues/925
Elliott Hughes3e1d5562021-01-25 08:49:01 -080070 paciasp
Tamas Petzf5bdee72020-08-31 15:09:40 +020071 .cfi_negate_ra_state
Evgenii Stepanov505168e2019-02-28 18:44:56 -080072 stp x0, x30, [sp, #-16]!
73 .cfi_adjust_cfa_offset 16
74 .cfi_rel_offset x0, 0
75 .cfi_rel_offset x30, 8
76
77 add x0, sp, #16
Evgenii Stepanov3031a7e2022-05-12 15:50:47 -070078 bl memtag_handle_vfork
Evgenii Stepanov505168e2019-02-28 18:44:56 -080079
80 ldp x0, x30, [sp], #16
81 .cfi_adjust_cfa_offset -16
82 .cfi_restore x0
83 .cfi_restore x30
Elliott Hughes3e1d5562021-01-25 08:49:01 -080084 autiasp
Tamas Petzf5bdee72020-08-31 15:09:40 +020085 .cfi_negate_ra_state
Evgenii Stepanov505168e2019-02-28 18:44:56 -080086
Evgenii Stepanov505168e2019-02-28 18:44:56 -080087.L_exit:
Dan Albert6a918872014-08-05 20:53:31 +000088 ret
89END(vfork)
Tamas Petzf5bdee72020-08-31 15:09:40 +020090
91NOTE_GNU_PROPERTY()