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