blob: 9eb82d8ecd20b8858673360c319d417f3f1647bc [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>
Elliott Hughesfaac8e62022-10-14 21:36:58 +000032#include <linux/sched.h>
Serban Constantinescue2104882013-09-26 11:37:10 +010033
Dan Albert6a918872014-08-05 20:53:31 +000034ENTRY(vfork)
dimitryfa432522017-10-25 13:07:45 +020035__BIONIC_WEAK_ASM_FOR_NATIVE_BRIDGE(vfork)
Josh Gao23032832020-05-07 17:02:19 -070036 // x9 = __get_tls()[TLS_SLOT_THREAD_ID]
37 mrs x9, tpidr_el0
38 ldr x9, [x9, #(TLS_SLOT_THREAD_ID * 8)]
39
40 // Set cached_pid_ to 0, vforked_ to 1, and stash the previous value.
41 mov w0, #0x80000000
42 ldr w10, [x9, #20]
43 str w0, [x9, #20]
Elliott Hughes5891abd2015-08-07 18:27:47 -070044
Evgenii Stepanov3031a7e2022-05-12 15:50:47 -070045 // Clear vfork_child_stack_bottom_.
46 str xzr, [x9, #776]
47
Dan Albert6a918872014-08-05 20:53:31 +000048 mov x0, #(CLONE_VM | CLONE_VFORK | SIGCHLD)
49 mov x1, xzr
50 mov x2, xzr
51 mov x3, xzr
52 mov x4, xzr
53
54 mov x8, __NR_clone
55 svc #0
56
Josh Gao23032832020-05-07 17:02:19 -070057 cbz x0, .L_exit
58
59 // rc != 0: reset cached_pid_ and vforked_.
60 str w10, [x9, #20]
Dan Albert6a918872014-08-05 20:53:31 +000061 cmn x0, #(MAX_ERRNO + 1)
62 cneg x0, x0, hi
Elliott Hughes011e1112014-09-08 15:25:01 -070063 b.hi __set_errno_internal
Dan Albert6a918872014-08-05 20:53:31 +000064
Evgenii Stepanov505168e2019-02-28 18:44:56 -080065 // Clean up stack shadow in the parent process.
66 // https://github.com/google/sanitizers/issues/925
Elliott Hughes3e1d5562021-01-25 08:49:01 -080067 paciasp
Tamas Petzf5bdee72020-08-31 15:09:40 +020068 .cfi_negate_ra_state
Evgenii Stepanov505168e2019-02-28 18:44:56 -080069 stp x0, x30, [sp, #-16]!
70 .cfi_adjust_cfa_offset 16
71 .cfi_rel_offset x0, 0
72 .cfi_rel_offset x30, 8
73
74 add x0, sp, #16
Evgenii Stepanov3031a7e2022-05-12 15:50:47 -070075 bl memtag_handle_vfork
Evgenii Stepanov505168e2019-02-28 18:44:56 -080076
77 ldp x0, x30, [sp], #16
78 .cfi_adjust_cfa_offset -16
79 .cfi_restore x0
80 .cfi_restore x30
Elliott Hughes3e1d5562021-01-25 08:49:01 -080081 autiasp
Tamas Petzf5bdee72020-08-31 15:09:40 +020082 .cfi_negate_ra_state
Evgenii Stepanov505168e2019-02-28 18:44:56 -080083
Evgenii Stepanov505168e2019-02-28 18:44:56 -080084.L_exit:
Dan Albert6a918872014-08-05 20:53:31 +000085 ret
86END(vfork)
Tamas Petzf5bdee72020-08-31 15:09:40 +020087
88NOTE_GNU_PROPERTY()