1*83762a71Sderaadt/* $OpenBSD: tfork_thread.S,v 1.5 2023/12/10 16:45:52 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 30c6f64c6fSguenther/* 3116b62b6aSguenther * int __tfork_thread(const struct __tfork *param, size_t psize, void (*func)(void *), void *arg); 32c6f64c6fSguenther */ 33c6f64c6fSguentherENTRY(__tfork_thread) 34c6f64c6fSguenther /* 35c6f64c6fSguenther * We can not invoke __tfork as a G2-style system call since we want 36c6f64c6fSguenther * different return paths. 37c6f64c6fSguenther */ 38c6f64c6fSguenther mov SYS___tfork, %g1 39*83762a71Sderaadt99: t ST_SYSCALL 40*83762a71Sderaadt PINSYSCALL(SYS___tfork, 99b) 41c6f64c6fSguenther bcs 9f 42c6f64c6fSguenther nop 43c6f64c6fSguenther 44c6f64c6fSguenther cmp %o0, 0 45c6f64c6fSguenther be 1f 46c6f64c6fSguenther nop 47c6f64c6fSguenther 48c6f64c6fSguenther /* 49c6f64c6fSguenther * In parent process: just return. 50c6f64c6fSguenther */ 51c6f64c6fSguenther retl 52c6f64c6fSguenther nop 53c6f64c6fSguenther 54c6f64c6fSguenther1: 55c6f64c6fSguenther /* 5616b62b6aSguenther * In child process: invoke function, then exit. 57c6f64c6fSguenther */ 58c6f64c6fSguenther call %o2 /* func */ 59c6f64c6fSguenther mov %o3, %o0 /* arg */ 60c6f64c6fSguenther 61c6f64c6fSguenther mov SYS___threxit, %g1 62c6f64c6fSguenther clr %o0 63*83762a71Sderaadt98: t ST_SYSCALL /* will not return */ 64*83762a71Sderaadt PINSYSCALL(SYS___threxit, 98b) 6513df6982Sderaadt unimp 66c6f64c6fSguenther 67c6f64c6fSguenther9: 68c6f64c6fSguenther /* 69c6f64c6fSguenther * System call failure. 70c6f64c6fSguenther */ 71c6f64c6fSguenther ERROR() 72aa797096SguentherEND(__tfork_thread) 73