1*83762a71Sderaadt/* $OpenBSD: tfork_thread.S,v 1.8 2023/12/10 16:45:51 deraadt Exp $ */ 2c6f64c6fSguenther 3c6f64c6fSguenther/* 4c6f64c6fSguenther * Copyright (c) 2005, Miodrag Vallat 5c6f64c6fSguenther * 6c6f64c6fSguenther * Redistribution and use in source and binary forms, with or without 7c6f64c6fSguenther * modification, are permitted provided that the following conditions 8c6f64c6fSguenther * are met: 9c6f64c6fSguenther * 1. Redistributions of source code must retain the above copyright 10c6f64c6fSguenther * notice, this list of conditions and the following disclaimer. 11c6f64c6fSguenther * 2. Redistributions in binary form must reproduce the above copyright 12c6f64c6fSguenther * notice, this list of conditions and the following disclaimer in the 13c6f64c6fSguenther * documentation and/or other materials provided with the distribution. 14c6f64c6fSguenther * 15c6f64c6fSguenther * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16c6f64c6fSguenther * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17c6f64c6fSguenther * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18c6f64c6fSguenther * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 19c6f64c6fSguenther * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20c6f64c6fSguenther * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21c6f64c6fSguenther * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22c6f64c6fSguenther * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 23c6f64c6fSguenther * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 24c6f64c6fSguenther * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25c6f64c6fSguenther * POSSIBILITY OF SUCH DAMAGE. 26c6f64c6fSguenther */ 27c6f64c6fSguenther 28c6f64c6fSguenther#include "SYS.h" 29c6f64c6fSguenther 30ea0d283dSaoyama#define NOP or %r0, %r0, %r0 31ea0d283dSaoyama 32c6f64c6fSguenther/* 3316b62b6aSguenther * int __tfork_thread(const struct __tfork *param, size_t psize, void (*func)(void *), void *arg); 34c6f64c6fSguenther */ 35c6f64c6fSguentherENTRY(__tfork_thread) 360b514a07Smiod or %r13, %r0, __SYSCALLNAME(SYS_,__tfork) 37*83762a71Sderaadt99: tb0 0, %r0, 450 /* corrupts r2 and r3 in the child */ 38*83762a71Sderaadt PINSYSCALL(SYS___tfork, 99b) 39c90cd26bSmiod br CERROR 40c6f64c6fSguenther 410b514a07Smiod bcnd eq0, %r2, 1f 42c6f64c6fSguenther 43c6f64c6fSguenther /* 44c6f64c6fSguenther * In parent process: just return. 45c6f64c6fSguenther */ 460b514a07Smiod jmp %r1 47c6f64c6fSguenther 48c6f64c6fSguenther1: 49c6f64c6fSguenther /* 5016b62b6aSguenther * In child process: invoke function, then exit. 51c6f64c6fSguenther */ 520b514a07Smiod jsr.n %r4 /* func */ 530b514a07Smiod or %r2, %r5, %r0 /* arg */ 54c6f64c6fSguenther 550b514a07Smiod or %r13, %r0, __SYSCALLNAME(SYS_,__threxit) 56*83762a71Sderaadt98: tb0 0, %r0, 450 57*83762a71Sderaadt PINSYSCALL(SYS___threxit, 98b) 58ea0d283dSaoyama NOP 5913df6982Sderaadt tb0 0, %r0, 130 /* breakpoint */ 60c90cd26bSmiodEND(__tfork_thread) 61