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