xref: /openbsd-src/lib/libc/arch/sh/sys/tfork_thread.S (revision fc31befaf105b97a112f7671f6f1ed3695619019)
1/*	$OpenBSD: tfork_thread.S,v 1.6 2024/03/27 20:03:29 miod Exp $	*/
2
3/*
4 * Copyright (c) 2007 Miodrag Vallat.
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, this permission notice, and the disclaimer below
9 * appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 */
19
20#include "SYS.h"
21
22/*
23 * int __tfork_thread(const struct __tfork *param, size_t psize, void (*func)(void *), void *arg);
24 *			r4			r5		   r6		r7
25 */
26ENTRY(__tfork_thread)
27	systrap SYS___tfork
28	bf	9f
29
30	tst	r0, r0
31	bt	1f
32
33	/*
34	 * In parent process: just return.
35	 */
36	rts
37	 nop
38
39	systrap_data SYS___tfork
40
411:
42	/*
43	 * In child process: invoke function, then exit.
44	 */
45	jsr	@r6
46	 mov	r7, r4
47
48	systrap SYS___threxit
49	systrap_data SYS___threxit
50
519:
52	/*
53	 * System call failure.
54	 */
55	SET_ERRNO_AND_RETURN(__tfork)
56
57	SET_ENTRY_SIZE(__tfork_thread)
58