proc.h revision 196456
175111Sfenner/*-
275111Sfenner * Copyright (c) 2007 Pawel Jakub Dawidek <pjd@FreeBSD.org>
375111Sfenner * All rights reserved.
4146772Ssam *
5146772Ssam * Redistribution and use in source and binary forms, with or without
698529Sfenner * modification, are permitted provided that the following conditions
798529Sfenner * are met:
898529Sfenner * 1. Redistributions of source code must retain the above copyright
998529Sfenner *    notice, this list of conditions and the following disclaimer.
1098529Sfenner * 2. Redistributions in binary form must reproduce the above copyright
1198529Sfenner *    notice, this list of conditions and the following disclaimer in the
1298529Sfenner *    documentation and/or other materials provided with the distribution.
1398529Sfenner *
14146772Ssam * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
15146772Ssam * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16146772Ssam * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17172681Smlaier * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
18181690Sed * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19172681Smlaier * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20146772Ssam * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21146772Ssam * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22146772Ssam * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23172681Smlaier * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24172681Smlaier * SUCH DAMAGE.
25172681Smlaier *
26172681Smlaier * $FreeBSD: head/sys/cddl/compat/opensolaris/sys/proc.h 196456 2009-08-23 11:22:46Z pjd $
27172681Smlaier */
28172681Smlaier
29146772Ssam#ifndef _OPENSOLARIS_SYS_PROC_H_
30146772Ssam#define	_OPENSOLARIS_SYS_PROC_H_
31146772Ssam
32146772Ssam#include <sys/param.h>
33146772Ssam#include <sys/kthread.h>
34146772Ssam#include_next <sys/proc.h>
35146772Ssam#include <sys/stdint.h>
36146772Ssam#include <sys/smp.h>
3775111Sfenner#include <sys/sched.h>
3875111Sfenner#include <sys/lock.h>
39172681Smlaier#include <sys/mutex.h>
40172681Smlaier#include <sys/debug.h>
4175111Sfenner
42146772Ssam#ifdef _KERNEL
43146772Ssam
4475111Sfenner#define	CPU		curcpu
45146772Ssam#define	minclsyspri	PRIBIO
46146772Ssam#define	maxclsyspri	PVM
4775111Sfenner#define	max_ncpus	mp_ncpus
48146772Ssam#define	boot_max_ncpus	mp_ncpus
49146772Ssam
50146772Ssam#define	TS_RUN	0
51146772Ssam
5298529Sfenner#define	p0	proc0
5398529Sfenner
54146772Ssamtypedef	short		pri_t;
55146772Ssamtypedef	struct thread	_kthread;
56146772Ssamtypedef	struct thread	kthread_t;
57146772Ssamtypedef struct thread	*kthread_id_t;
58146772Ssamtypedef struct proc	proc_t;
59146772Ssam
60146772Ssamstatic __inline kthread_t *
6175111Sfennerthread_create(caddr_t stk, size_t stksize, void (*proc)(void *), void *arg,
6275111Sfenner    size_t len, proc_t *pp, int state, pri_t pri)
63172681Smlaier{
64172681Smlaier	kthread_t *td;
65172681Smlaier	proc_t *p;
66172681Smlaier	int error;
67146772Ssam
68146772Ssam	/*
69146772Ssam	 * Be sure there are no surprises.
70172681Smlaier	 */
71172681Smlaier	ASSERT(stk == NULL);
72172681Smlaier	ASSERT(len == 0);
73146772Ssam	ASSERT(state == TS_RUN);
74146772Ssam
75146772Ssam	error = kproc_create(proc, arg, &p, 0, stksize / PAGE_SIZE,
76172681Smlaier	    "solthread %p", proc);
77172681Smlaier	if (error != 0)
78172681Smlaier		td = NULL;
79146772Ssam	else {
80146772Ssam		td = FIRST_THREAD_IN_PROC(p);
81146772Ssam		thread_lock(td);
82146772Ssam		sched_prio(td, pri);
83146772Ssam		thread_unlock(td);
84146772Ssam	}
85146772Ssam	return (td);
86146772Ssam}
87146772Ssam
88146772Ssam#define	thread_exit()	kproc_exit(0)
89146772Ssam
90146772Ssam#endif	/* _KERNEL */
91146772Ssam
92146772Ssam#endif	/* _OPENSOLARIS_SYS_PROC_H_ */
93146772Ssam