1*52024a07Sguenther/* $OpenBSD: Ovfork.S,v 1.10 2023/05/18 04:26:06 guenther Exp $ */ 2118f6189Smickey/* $NetBSD: Ovfork.S,v 1.2 2002/06/03 18:30:33 fvdl Exp $ */ 3118f6189Smickey 4118f6189Smickey/*- 5118f6189Smickey * Copyright (c) 1990 The Regents of the University of California. 6118f6189Smickey * All rights reserved. 7118f6189Smickey * 8118f6189Smickey * This code is derived from software contributed to Berkeley by 9118f6189Smickey * William Jolitz. 10118f6189Smickey * 11118f6189Smickey * Redistribution and use in source and binary forms, with or without 12118f6189Smickey * modification, are permitted provided that the following conditions 13118f6189Smickey * are met: 14118f6189Smickey * 1. Redistributions of source code must retain the above copyright 15118f6189Smickey * notice, this list of conditions and the following disclaimer. 16118f6189Smickey * 2. Redistributions in binary form must reproduce the above copyright 17118f6189Smickey * notice, this list of conditions and the following disclaimer in the 18118f6189Smickey * documentation and/or other materials provided with the distribution. 1924fdaee6Sjsg * 3. Neither the name of the University nor the names of its contributors 20118f6189Smickey * may be used to endorse or promote products derived from this software 21118f6189Smickey * without specific prior written permission. 22118f6189Smickey * 23118f6189Smickey * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24118f6189Smickey * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25118f6189Smickey * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26118f6189Smickey * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27118f6189Smickey * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28118f6189Smickey * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29118f6189Smickey * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30118f6189Smickey * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31118f6189Smickey * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32118f6189Smickey * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33118f6189Smickey * SUCH DAMAGE. 34118f6189Smickey * 35118f6189Smickey * from: @(#)Ovfork.s 5.1 (Berkeley) 4/23/90 36118f6189Smickey */ 37118f6189Smickey 38118f6189Smickey#include <machine/asm.h> 39118f6189Smickey 40118f6189Smickey#include "SYS.h" 41118f6189Smickey 42*52024a07Sguenther/* 43*52024a07Sguenther * This is written to support a potential vfork(2) that would share 44*52024a07Sguenther * the parent's vmspace to the child. For that, the parent must 45*52024a07Sguenther * not rely on anything on the stack at the time of the syscall, 46*52024a07Sguenther * as the child will overwrite it. So, keep both the return address 47*52024a07Sguenther * and retguard value in registers (r9 and r8) across the call. 48*52024a07Sguenther * This used to do an indirect jump on success, but that doesn't 49*52024a07Sguenther * work if indirect-branch-tracking is enabled as the _caller_ of 50*52024a07Sguenther * this vfork() stub won't know to place an endbr64 instruction 51*52024a07Sguenther * after the call. So, just push it back on the stack and return. 52*52024a07Sguenther */ 53fe38b55cSguentherSYSENTRY_HIDDEN(vfork) 54*52024a07Sguenther RETGUARD_SETUP(_thread_sys_vfork, r8); 55118f6189Smickey popq %r9 /* my rta into r9 */ 56118f6189Smickey SYSTRAP(vfork) 57118f6189Smickey pushq %r9 58*52024a07Sguenther jnc 1f 59fe38b55cSguenther SET_ERRNO 60*52024a07Sguenther1: RETGUARD_CHECK(_thread_sys_vfork, r8); 61fe38b55cSguenther ret 62fe38b55cSguentherSYSCALL_END_HIDDEN(vfork) 63