systm.h revision 9160:1517e6edbc6f
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21/*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
22/*	  All Rights Reserved  	*/
23
24
25/*
26 * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
27 * Use is subject to license terms.
28 */
29
30#ifndef _SYS_SYSTM_H
31#define	_SYS_SYSTM_H
32
33#include <sys/types.h>
34#include <sys/t_lock.h>
35#include <sys/proc.h>
36#include <sys/dditypes.h>
37
38#ifdef	__cplusplus
39extern "C" {
40#endif
41
42/*
43 * The pc_t is the type of the kernel's program counter.  In general, a
44 * pc_t is a uintptr_t -- except for a sparcv9 kernel, in which case all
45 * instruction text is below 4G, and a pc_t is thus a uint32_t.
46 */
47#ifdef __sparcv9
48typedef uint32_t pc_t;
49#else
50typedef uintptr_t pc_t;
51#endif
52
53/*
54 * Random set of variables used by more than one routine.
55 */
56
57#ifdef _KERNEL
58#include <sys/varargs.h>
59#include <sys/uadmin.h>
60
61extern int hz;			/* system clock rate */
62extern struct vnode *rootdir;	/* pointer to vnode of root directory */
63extern struct vnode *devicesdir;	/* pointer to /devices vnode */
64extern volatile clock_t lbolt;	/* time in HZ since last boot */
65extern volatile int64_t lbolt64;	/* lbolt computed as 64-bit value */
66extern int interrupts_unleashed;	/* set after the spl0() in main() */
67
68extern char runin;		/* scheduling flag */
69extern char runout;		/* scheduling flag */
70extern char wake_sched;		/* causes clock to wake swapper on next tick */
71extern char wake_sched_sec;	/* causes clock to wake swapper after a sec */
72
73extern pgcnt_t	maxmem;		/* max available memory (pages) */
74extern pgcnt_t	physmem;	/* physical memory (pages) on this CPU */
75extern pfn_t	physmax;	/* highest numbered physical page present */
76extern pgcnt_t	physinstalled;	/* physical pages including PROM/boot use */
77
78extern caddr_t	s_text;		/* start of kernel text segment */
79extern caddr_t	e_text;		/* end of kernel text segment */
80extern caddr_t	s_data;		/* start of kernel text segment */
81extern caddr_t	e_data;		/* end of kernel text segment */
82
83extern pgcnt_t	availrmem;	/* Available resident (not swapable)	*/
84				/* memory in pages.			*/
85extern pgcnt_t	availrmem_initial;	/* initial value of availrmem	*/
86extern pgcnt_t	segspt_minfree;	/* low water mark for availrmem in seg_spt */
87extern pgcnt_t	freemem;	/* Current free memory.			*/
88
89extern dev_t	rootdev;	/* device of the root */
90extern struct vnode *rootvp;	/* vnode of root device */
91extern boolean_t root_is_svm;		/* root is a mirrored device flag */
92extern boolean_t root_is_ramdisk;	/* root is boot_archive ramdisk */
93extern uint32_t  ramdisk_size;		/* (KB) set only for sparc netboots */
94extern char *volatile panicstr;	/* panic string pointer */
95extern va_list  panicargs;	/* panic arguments */
96extern volatile int quiesce_active;	/* quiesce(9E) is in progress */
97
98extern int	rstchown;	/* 1 ==> restrictive chown(2) semantics */
99extern int	klustsize;
100
101extern int	abort_enable;	/* Platform input-device abort policy */
102
103extern int	audit_active;	/* Solaris Auditing active 1, absent 0. */
104
105extern int	avenrun[];	/* array of load averages */
106
107extern char *isa_list;		/* For sysinfo's isalist option */
108
109extern int noexec_user_stack;		/* patchable via /etc/system */
110extern int noexec_user_stack_log;	/* patchable via /etc/system */
111
112/*
113 * Use NFS client operations in the global zone only.  Under contract with
114 * admin/install; do not change without coordinating with that consolidation.
115 */
116extern int nfs_global_client_only;
117
118extern void report_stack_exec(proc_t *, caddr_t);
119
120extern void startup(void);
121extern void clkstart(void);
122extern void post_startup(void);
123extern void kern_setup1(void);
124extern void ka_init(void);
125extern void nodename_set(void);
126
127/*
128 * for tod fault detection
129 */
130enum tod_fault_type {
131	TOD_REVERSED = 0,
132	TOD_STALLED,
133	TOD_JUMPED,
134	TOD_RATECHANGED,
135	TOD_RDONLY,
136	TOD_NOFAULT
137};
138
139extern time_t tod_validate(time_t);
140extern void tod_fault_reset(void);
141extern void plat_tod_fault(enum tod_fault_type);
142
143#ifndef _LP64
144#ifndef min
145int min(int, int);
146#endif
147
148#ifndef max
149int max(int, int);
150#endif
151
152uint_t umin(uint_t, uint_t);
153uint_t umax(uint_t, uint_t);
154#endif /* !_LP64 */
155int grow(caddr_t);
156int grow_internal(caddr_t, uint_t);
157int brk_internal(caddr_t, uint_t);
158typedef uint64_t callout_id_t;
159timeout_id_t timeout(void (*)(void *), void *, clock_t);
160timeout_id_t realtime_timeout(void (*)(void *), void *, clock_t);
161clock_t untimeout(timeout_id_t);
162/*
163 * The last argument to timeout_generic() is flags. See callo.h for the
164 * flags definitions.
165 */
166callout_id_t timeout_generic(int, void (*)(void *), void *, hrtime_t, hrtime_t,
167    int);
168callout_id_t timeout_default(void (*)(void *), void *, clock_t);
169callout_id_t realtime_timeout_default(void (*)(void *), void *, clock_t);
170/*
171 * The last argument to untimeout_generic() is flags. See callout.c for the
172 * use.
173 */
174hrtime_t untimeout_generic(callout_id_t, int);
175clock_t untimeout_default(callout_id_t, int);
176void delay(clock_t);
177int delay_sig(clock_t);
178int nodev();
179int nulldev();
180major_t getudev(void);
181int cmpldev(dev32_t *, dev_t);
182dev_t expldev(dev32_t);
183int bcmp(const void *, const void *, size_t) __PURE;
184int stoi(char **);
185void numtos(ulong_t, char *);
186int strident_valid(const char *);
187void strident_canon(char *, size_t);
188int getsubopt(char **optionsp, char * const *tokens, char **valuep);
189char *append_subopt(const char *, size_t, char *, const char *);
190int ffs(uintmax_t);
191int copyin(const void *, void *, size_t);
192void copyin_noerr(const void *, void *, size_t);
193int xcopyin(const void *, void *, size_t);
194int xcopyin_nta(const void *, void *, size_t, int);
195int copyout(const void *, void *, size_t);
196void copyout_noerr(const void *, void *, size_t);
197int xcopyout(const void *, void *, size_t);
198int xcopyout_nta(const void *, void *, size_t, int);
199int copyinstr(const char *, char *, size_t, size_t *);
200int copyinstr_noerr(const char *, char *, size_t, size_t *);
201int copyoutstr(const char *, char *, size_t, size_t *);
202int copyoutstr_noerr(const char *, char *, size_t, size_t *);
203int copystr(const char *, char *, size_t, size_t *);
204void ucopy(const void *, void *, size_t);
205void ucopystr(const char *, char *, size_t, size_t *);
206void pgcopy(const void *, void *, size_t);
207void ovbcopy(const void *, void *, size_t);
208void uzero(void *, size_t);
209int kcopy(const void *, void *, size_t);
210int kcopy_nta(const void *, void *, size_t, int);
211int kzero(void *, size_t);
212
213int fuword8(const void *, uint8_t *);
214int fuword16(const void *, uint16_t *);
215int fuword32(const void *, uint32_t *);
216int fulword(const void *, ulong_t *);
217void fuword8_noerr(const void *, uint8_t *);
218void fuword16_noerr(const void *, uint16_t *);
219void fuword32_noerr(const void *, uint32_t *);
220void fulword_noerr(const void *, ulong_t *);
221
222#ifdef _LP64
223int fuword64(const void *, uint64_t *);
224void fuword64_noerr(const void *, uint64_t *);
225#endif
226
227int subyte(void *, uint8_t);
228int suword8(void *, uint8_t);
229int suword16(void *, uint16_t);
230int suword32(void *, uint32_t);
231int sulword(void *, ulong_t);
232void subyte_noerr(void *, uint8_t);
233void suword8_noerr(void *, uint8_t);
234void suword16_noerr(void *, uint16_t);
235void suword32_noerr(void *, uint32_t);
236void sulword_noerr(void *, ulong_t);
237
238#ifdef _LP64
239int suword64(void *, uint64_t);
240void suword64_noerr(void *, uint64_t);
241#endif
242
243#if !defined(_BOOT)
244int setjmp(label_t *);
245extern void longjmp(label_t *)
246	__NORETURN;
247#pragma unknown_control_flow(setjmp)
248#endif
249
250void prefetch64(caddr_t);
251caddr_t caller(void);
252caddr_t callee(void);
253int getpcstack(pc_t *, int);
254int on_fault(label_t *);
255void no_fault(void);
256void halt(char *);
257int scanc(size_t, uchar_t *, uchar_t *, uchar_t);
258int movtuc(size_t, uchar_t *, uchar_t *, uchar_t *);
259int splr(int);
260int splhigh(void);
261int splhi(void);
262int splzs(void);
263int spl0(void);
264int spl6(void);
265int spl7(void);
266int spl8(void);
267void splx(int);
268void set_base_spl(void);
269int __ipltospl(int);
270
271void softcall_init(void);
272void softcall(void (*)(void *), void *);
273void softint(void);
274
275extern void sync_icache(caddr_t, uint_t);
276extern void sync_data_memory(caddr_t, size_t);
277extern void hot_patch_kernel_text(caddr_t, uint32_t, uint_t);
278
279void _insque(caddr_t, caddr_t);
280void _remque(caddr_t);
281
282/* casts to keep lint happy */
283#define	insque(q, p)	_insque((caddr_t)q, (caddr_t)p)
284#define	remque(q)	_remque((caddr_t)q)
285
286#pragma unknown_control_flow(on_fault)
287
288struct timeval;
289extern void	uniqtime(struct timeval *);
290struct timeval32;
291extern void	uniqtime32(struct timeval32 *);
292
293uint_t page_num_pagesizes(void);
294size_t page_get_pagesize(uint_t n);
295
296extern int maxusers;
297extern int pidmax;
298
299extern void param_preset(void);
300extern void param_calc(int);
301extern void param_init(void);
302extern void param_check(void);
303
304#endif /* _KERNEL */
305
306/*
307 * Structure of the system-entry table.
308 *
309 * 	Changes to struct sysent should maintain binary compatibility with
310 *	loadable system calls, although the interface is currently private.
311 *
312 *	This means it should only be expanded on the end, and flag values
313 * 	should not be reused.
314 *
315 *	It is desirable to keep the size of this struct a power of 2 for quick
316 *	indexing.
317 */
318struct sysent {
319	char		sy_narg;	/* total number of arguments */
320#ifdef _LP64
321	unsigned short	sy_flags;	/* various flags as defined below */
322#else
323	unsigned char	sy_flags;	/* various flags as defined below */
324#endif
325	int		(*sy_call)();	/* argp, rvalp-style handler */
326	krwlock_t	*sy_lock;	/* lock for loadable system calls */
327	int64_t		(*sy_callc)();	/* C-style call hander or wrapper */
328};
329
330extern struct sysent	sysent[];
331#ifdef _SYSCALL32_IMPL
332extern struct sysent	sysent32[];
333#endif
334
335extern struct sysent	nosys_ent;	/* entry for invalid system call */
336
337#define	NSYSCALL 	256		/* number of system calls */
338
339#define	LOADABLE_SYSCALL(s)	(s->sy_flags & SE_LOADABLE)
340#define	LOADED_SYSCALL(s)	(s->sy_flags & SE_LOADED)
341
342/*
343 * sy_flags values
344 * 	Values 1, 2, and 4 were used previously for SETJUMP, ASYNC, and IOSYS.
345 */
346#define	SE_32RVAL1	0x0		/* handler returns int32_t in rval1 */
347#define	SE_32RVAL2	0x1		/* handler returns int32_t in rval2 */
348#define	SE_64RVAL	0x2		/* handler returns int64_t in rvals */
349#define	SE_RVAL_MASK	0x3		/* mask of rval_t bits */
350
351#define	SE_LOADABLE	0x08		/* syscall is loadable */
352#define	SE_LOADED	0x10		/* syscall is completely loaded */
353#define	SE_NOUNLOAD	0x20		/* syscall never needs unload */
354#define	SE_ARGC		0x40		/* syscall takes C-style args */
355
356/*
357 * Structure of the return-value parameter passed by reference to
358 * system entries.
359 */
360union rval {
361	struct	{
362		int	r_v1;
363		int	r_v2;
364	} r_v;
365	off_t	r_off;
366	offset_t r_offset;
367	time_t	r_time;
368	int64_t	r_vals;
369};
370#define	r_val1	r_v.r_v1
371#define	r_val2	r_v.r_v2
372
373typedef union rval rval_t;
374
375#ifdef	_KERNEL
376
377extern void reset_syscall_args(void);
378extern int save_syscall_args(void);
379extern uint_t get_syscall_args(klwp_t *lwp, long *argp, int *nargsp);
380#ifdef _SYSCALL32_IMPL
381extern uint_t get_syscall32_args(klwp_t *lwp, int *argp, int *nargp);
382#endif
383
384extern uint_t set_errno(uint_t error);
385#pragma rarely_called(set_errno)
386
387extern int64_t syscall_ap(void);
388extern int64_t loadable_syscall(long, long, long, long, long, long, long, long);
389extern int64_t nosys(void);
390
391extern void swtch(void);
392
393extern uint_t	kcpc_key;	/* TSD key for performance counter context */
394
395/*
396 * initname holds the path to init and is used as a point of rendezvous
397 * between krtld (which processes the boot arguments) and the kernel.
398 */
399#define	INITNAME_SZ	32
400extern char initname[INITNAME_SZ];
401
402/*
403 * initargs holds the arguments to init (such as -v, -s, -r, -m verbose) and
404 * is a point of rendezvous between krtld (which processes the boot arguments)
405 * and the kernel.
406 */
407extern char initargs[BOOTARGS_MAX];
408
409extern int exec_init(const char *, const char *);
410extern int start_init_common(void);
411
412#endif	/* _KERNEL */
413
414#if defined(_KERNEL) || defined(_BOOT)
415
416size_t strlcat(char *, const char *, size_t);
417size_t strlen(const char *) __PURE;
418char *strcat(char *, const char *);
419char *strncat(char *, const char *, size_t);
420char *strcpy(char *, const char *);
421char *strncpy(char *, const char *, size_t);
422/* Need to be consistent with <string.h> C++ definitions */
423#if __cplusplus >= 199711L
424extern const char *strchr(const char *, int);
425#ifndef _STRCHR_INLINE
426#define	_STRCHR_INLINE
427extern "C++" {
428	inline char *strchr(char *__s, int __c) {
429		return (char *)strchr((const char *)__s, __c);
430	}
431}
432#endif /* _STRCHR_INLINE */
433extern const char *strrchr(const char *, int);
434#ifndef	_STRRCHR_INLINE
435#define	_STRRCHR_INLINE
436extern "C++" {
437	inline char *strrchr(char *__s, int __c) {
438		return (char *)strrchr((const char *)__s, __c);
439	}
440}
441#endif	/* _STRRCHR_INLINE */
442extern const char *strstr(const char *, const char *);
443#ifndef	_STRSTR_INLINE
444#define	_STRSTR_INLINE
445extern "C++" {
446	inline char *strstr(char *__s1, const char *__s2) {
447		return (char *)strstr((const char *)__s1, __s2);
448	}
449}
450#endif  /* _STRSTR_INLINE */
451#else	/* __cplusplus >= 199711L */
452char *strchr(const char *, int);
453char *strrchr(const char *, int);
454char *strstr(const char *, const char *);
455#endif	/* __cplusplus >= 199711L */
456char *strnrchr(const char *, int, size_t);
457int strcmp(const char *, const char *) __PURE;
458int strncmp(const char *, const char *, size_t) __PURE;
459int strcasecmp(const char *, const char *) __PURE;
460int strncasecmp(const char *, const char *, size_t) __PURE;
461/* Need to be consistent with <string.h> C++ definitions */
462#if __cplusplus >= 199711L
463extern const char *strpbrk(const char *, const char *);
464#ifndef _STRPBRK_INLINE
465#define	_STRPBRK_INLINE
466extern "C++" {
467	inline char *strpbrk(char *__s1, const char *__s2) {
468		return (char *)strpbrk((const char *)__s1, __s2);
469	}
470}
471#endif /* _STRPBRK_INLINE */
472#else /* __cplusplus >= 199711L */
473char *strpbrk(const char *, const char *);
474#endif /* __cplusplus >= 199711L */
475void bcopy(const void *, void *, size_t);
476void bzero(void *, size_t);
477
478extern void *memset(void *, int, size_t);
479extern void *memcpy(void *, const void *, size_t);
480extern void *memmove(void *, const void *, size_t);
481extern int memcmp(const void *, const void *, size_t);
482
483#ifdef __lint
484extern	int	__lintzero;	/* for spoofing lint */
485#else	/* __lint */
486#define	__lintzero 0
487#endif	/* __lint */
488#endif /* _KERNEL || _BOOT */
489
490#ifdef	__cplusplus
491}
492#endif
493
494#endif	/* _SYS_SYSTM_H */
495