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