aboutsummaryrefslogtreecommitdiff
path: root/src/lib9/ffork-FreeBSD.c
blob: 476ce7ab20bc379162501c08a5a6a7fdc602626d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <lib9.h>
#include "9proc.h"

extern int __isthreaded;
int
ffork(int flags, void(*fn)(void*), void *arg)
{
	int pid;
	void *p;

	_p9uproc(0);
	__isthreaded = 1;
	p = malloc(16384);
	if(p == nil)
		return -1;
	memset(p, 0xFE, 16384);
	pid = rfork_thread(RFPROC|flags, (char*)p+16000, (int(*)(void*))fn, arg);
	if(pid == 0)
		_p9uproc(0);
	return pid;
}

/*
 * For FreeBSD libc.
 */

typedef struct {
	volatile long	access_lock;
	volatile long	lock_owner;
	volatile char	*fname;
	volatile int	lineno;
} spinlock_t;

void
_spinlock(spinlock_t *lk)
{
	lock((Lock*)&lk->access_lock);
}

int
getfforkid(void)
{
	return getpid();
}