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