1*83762a71Sderaadt/* $OpenBSD: tfork_thread.S,v 1.11 2023/12/10 16:45:51 deraadt Exp $ */ 2c6f64c6fSguenther 3c6f64c6fSguenther/* 4c6f64c6fSguenther * Copyright (c) 2005 Tim Wiess <tim@nop.cx> 5c6f64c6fSguenther * 6c6f64c6fSguenther * Permission to use, copy, modify, and distribute this software for any 7c6f64c6fSguenther * purpose with or without fee is hereby granted, provided that the above 8c6f64c6fSguenther * copyright notice and this permission notice appear in all copies. 9c6f64c6fSguenther * 10c6f64c6fSguenther * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11c6f64c6fSguenther * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12c6f64c6fSguenther * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13c6f64c6fSguenther * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14c6f64c6fSguenther * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15c6f64c6fSguenther * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16c6f64c6fSguenther * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17c6f64c6fSguenther */ 18c6f64c6fSguenther 195e1df623Sguenther#include "SYS.h" 20c6f64c6fSguenther 21c6f64c6fSguentherENTRY(__tfork_thread) 2215572fcfSgkoehler RETGUARD_SETUP(__tfork_thread, %r11, %r12) 23c6f64c6fSguenther /* call __tfork */ 24c6f64c6fSguenther li %r0, SYS___tfork 25*83762a71Sderaadt99: sc 26*83762a71Sderaadt PINSYSCALL(SYS___tfork, 99b) 27c6f64c6fSguenther cmpwi %r0, 0 285e1df623Sguenther bne 1f 29c6f64c6fSguenther 30c6f64c6fSguenther /* check if we are parent or child */ 31c6f64c6fSguenther cmpwi %r3, 0 32d2c5a474Sgkoehler bne 9f 33c6f64c6fSguenther 34c6f64c6fSguenther /* child */ 35c6f64c6fSguenther mtlr %r5 /* fp */ 36c6f64c6fSguenther mr %r3, %r6 /* arg */ 3716b62b6aSguenther subi %r1, %r1, 16 /* fixup sp to get headroom */ 38c6f64c6fSguenther blrl 39c6f64c6fSguenther 4033b1d6e2Sguenther /* child returned, call __threxit */ 41c6f64c6fSguenther li %r0, SYS___threxit 42*83762a71Sderaadt98: sc 43*83762a71Sderaadt PINSYSCALL(SYS___threxit, 98b) 4413df6982Sderaadt .long 0 /* illegal */ 4513df6982Sderaadt 46c6f64c6fSguenther1: 475e1df623Sguenther stw 0, R2_OFFSET_ERRNO(%r2) 48c6f64c6fSguenther li %r3, -1 49d2c5a474Sgkoehler9: 5015572fcfSgkoehler RETGUARD_CHECK(__tfork_thread, %r11, %r12) 515e1df623Sguenther blr 52aa797096SguentherEND(__tfork_thread) 53