xref: /illumos-gate/usr/src/uts/common/sys/systm.h (revision b4203d757c7c247e39c94c09a94021a3a8121062)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
53f2f09c1Sdp  * Common Development and Distribution License (the "License").
63f2f09c1Sdp  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
215f10ef69SYuri Pankov 
227c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
23*b4203d75SMarcel Telka /*	  All Rights Reserved	*/
247c478bd9Sstevel@tonic-gate 
257c478bd9Sstevel@tonic-gate /*
268fc99e42STrevor Thompson  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
277c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
285f10ef69SYuri Pankov  * Copyright 2016 Nexenta Systems, Inc.
297c478bd9Sstevel@tonic-gate  */
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #ifndef _SYS_SYSTM_H
327c478bd9Sstevel@tonic-gate #define	_SYS_SYSTM_H
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate #include <sys/types.h>
357c478bd9Sstevel@tonic-gate #include <sys/t_lock.h>
367c478bd9Sstevel@tonic-gate #include <sys/proc.h>
377c478bd9Sstevel@tonic-gate #include <sys/dditypes.h>
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
407c478bd9Sstevel@tonic-gate extern "C" {
417c478bd9Sstevel@tonic-gate #endif
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate /*
447c478bd9Sstevel@tonic-gate  * The pc_t is the type of the kernel's program counter.  In general, a
457c478bd9Sstevel@tonic-gate  * pc_t is a uintptr_t -- except for a sparcv9 kernel, in which case all
467c478bd9Sstevel@tonic-gate  * instruction text is below 4G, and a pc_t is thus a uint32_t.
477c478bd9Sstevel@tonic-gate  */
487c478bd9Sstevel@tonic-gate #ifdef __sparcv9
497c478bd9Sstevel@tonic-gate typedef uint32_t pc_t;
507c478bd9Sstevel@tonic-gate #else
517c478bd9Sstevel@tonic-gate typedef uintptr_t pc_t;
527c478bd9Sstevel@tonic-gate #endif
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate /*
557c478bd9Sstevel@tonic-gate  * Random set of variables used by more than one routine.
567c478bd9Sstevel@tonic-gate  */
577c478bd9Sstevel@tonic-gate 
58b819cea2SGordon Ross #if defined(_KERNEL) || defined(_FAKE_KERNEL)
59b819cea2SGordon Ross #include <sys/types32.h>
607c478bd9Sstevel@tonic-gate #include <sys/varargs.h>
613f2f09c1Sdp #include <sys/uadmin.h>
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate extern int hz;			/* system clock rate */
647c478bd9Sstevel@tonic-gate extern struct vnode *rootdir;	/* pointer to vnode of root directory */
657c478bd9Sstevel@tonic-gate extern struct vnode *devicesdir;	/* pointer to /devices vnode */
667c478bd9Sstevel@tonic-gate extern int interrupts_unleashed;	/* set after the spl0() in main() */
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate extern char runin;		/* scheduling flag */
697c478bd9Sstevel@tonic-gate extern char runout;		/* scheduling flag */
707c478bd9Sstevel@tonic-gate extern char wake_sched;		/* causes clock to wake swapper on next tick */
717c478bd9Sstevel@tonic-gate extern char wake_sched_sec;	/* causes clock to wake swapper after a sec */
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate extern pgcnt_t	maxmem;		/* max available memory (pages) */
747c478bd9Sstevel@tonic-gate extern pgcnt_t	physmem;	/* physical memory (pages) on this CPU */
757c478bd9Sstevel@tonic-gate extern pfn_t	physmax;	/* highest numbered physical page present */
767c478bd9Sstevel@tonic-gate extern pgcnt_t	physinstalled;	/* physical pages including PROM/boot use */
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate extern caddr_t	s_text;		/* start of kernel text segment */
797c478bd9Sstevel@tonic-gate extern caddr_t	e_text;		/* end of kernel text segment */
807c478bd9Sstevel@tonic-gate extern caddr_t	s_data;		/* start of kernel text segment */
817c478bd9Sstevel@tonic-gate extern caddr_t	e_data;		/* end of kernel text segment */
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate extern pgcnt_t	availrmem;	/* Available resident (not swapable)	*/
847c478bd9Sstevel@tonic-gate 				/* memory in pages.			*/
857c478bd9Sstevel@tonic-gate extern pgcnt_t	availrmem_initial;	/* initial value of availrmem	*/
867c478bd9Sstevel@tonic-gate extern pgcnt_t	segspt_minfree;	/* low water mark for availrmem in seg_spt */
877c478bd9Sstevel@tonic-gate extern pgcnt_t	freemem;	/* Current free memory.			*/
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate extern dev_t	rootdev;	/* device of the root */
907c478bd9Sstevel@tonic-gate extern struct vnode *rootvp;	/* vnode of root device */
91986fd29aSsetje extern boolean_t root_is_ramdisk;	/* root is boot_archive ramdisk */
92986fd29aSsetje extern uint32_t  ramdisk_size;		/* (KB) set only for sparc netboots */
937c478bd9Sstevel@tonic-gate extern char *volatile panicstr;	/* panic string pointer */
947c478bd9Sstevel@tonic-gate extern va_list  panicargs;	/* panic arguments */
95753a6d45SSherry Moore extern volatile int quiesce_active;	/* quiesce(9E) is in progress */
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate extern int	rstchown;	/* 1 ==> restrictive chown(2) semantics */
987c478bd9Sstevel@tonic-gate extern int	klustsize;
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate extern int	abort_enable;	/* Platform input-device abort policy */
1017c478bd9Sstevel@tonic-gate 
102005d3febSMarek Pospisil extern int	audit_active;	/* Solaris Auditing module state */
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate extern int	avenrun[];	/* array of load averages */
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate extern char *isa_list;		/* For sysinfo's isalist option */
1077c478bd9Sstevel@tonic-gate 
1087c478bd9Sstevel@tonic-gate extern int noexec_user_stack;		/* patchable via /etc/system */
1097c478bd9Sstevel@tonic-gate extern int noexec_user_stack_log;	/* patchable via /etc/system */
1107c478bd9Sstevel@tonic-gate 
111108322fbScarlsonj /*
112108322fbScarlsonj  * Use NFS client operations in the global zone only.  Under contract with
113108322fbScarlsonj  * admin/install; do not change without coordinating with that consolidation.
114108322fbScarlsonj  */
115108322fbScarlsonj extern int nfs_global_client_only;
116108322fbScarlsonj 
1177c478bd9Sstevel@tonic-gate extern void report_stack_exec(proc_t *, caddr_t);
1187c478bd9Sstevel@tonic-gate 
1197c478bd9Sstevel@tonic-gate extern void startup(void);
1207c478bd9Sstevel@tonic-gate extern void clkstart(void);
1217c478bd9Sstevel@tonic-gate extern void post_startup(void);
1227c478bd9Sstevel@tonic-gate extern void kern_setup1(void);
1237c478bd9Sstevel@tonic-gate extern void ka_init(void);
1247c478bd9Sstevel@tonic-gate extern void nodename_set(void);
1257c478bd9Sstevel@tonic-gate 
1267c478bd9Sstevel@tonic-gate /*
1277c478bd9Sstevel@tonic-gate  * for tod fault detection
1287c478bd9Sstevel@tonic-gate  */
1297c478bd9Sstevel@tonic-gate enum tod_fault_type {
1307c478bd9Sstevel@tonic-gate 	TOD_REVERSED = 0,
1317c478bd9Sstevel@tonic-gate 	TOD_STALLED,
1327c478bd9Sstevel@tonic-gate 	TOD_JUMPED,
1337c478bd9Sstevel@tonic-gate 	TOD_RATECHANGED,
134843e1988Sjohnlev 	TOD_RDONLY,
1357c478bd9Sstevel@tonic-gate 	TOD_NOFAULT
1367c478bd9Sstevel@tonic-gate };
1377c478bd9Sstevel@tonic-gate 
1388fc99e42STrevor Thompson #define	TOD_GET_FAILED		0x1	/* TOD could not be read */
1398fc99e42STrevor Thompson #define	TOD_SET_DONE		0x2	/* TOD has been modified */
1408fc99e42STrevor Thompson #define	TOD_CPR_RESUME_DONE	0x4	/* CPR resume has occurred */
1418fc99e42STrevor Thompson #define	TOD_DR_RESUME_DONE	0x8	/* DR resume has occurred */
1428fc99e42STrevor Thompson 
1437c478bd9Sstevel@tonic-gate extern time_t tod_validate(time_t);
1448fc99e42STrevor Thompson extern void tod_status_set(int);
1458fc99e42STrevor Thompson extern void tod_status_clear(int);
1467c478bd9Sstevel@tonic-gate extern void plat_tod_fault(enum tod_fault_type);
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate #ifndef _LP64
1497c478bd9Sstevel@tonic-gate #ifndef min
1507c478bd9Sstevel@tonic-gate int min(int, int);
1517c478bd9Sstevel@tonic-gate #endif
1527c478bd9Sstevel@tonic-gate 
1537c478bd9Sstevel@tonic-gate #ifndef max
1547c478bd9Sstevel@tonic-gate int max(int, int);
1557c478bd9Sstevel@tonic-gate #endif
1567c478bd9Sstevel@tonic-gate 
1577c478bd9Sstevel@tonic-gate uint_t umin(uint_t, uint_t);
1587c478bd9Sstevel@tonic-gate uint_t umax(uint_t, uint_t);
1597c478bd9Sstevel@tonic-gate #endif /* !_LP64 */
1607c478bd9Sstevel@tonic-gate int grow(caddr_t);
1617c478bd9Sstevel@tonic-gate int grow_internal(caddr_t, uint_t);
1627c478bd9Sstevel@tonic-gate int brk_internal(caddr_t, uint_t);
16387a18d3fSMadhavan Venkataraman typedef uint64_t callout_id_t;
1647c478bd9Sstevel@tonic-gate timeout_id_t timeout(void (*)(void *), void *, clock_t);
1657c478bd9Sstevel@tonic-gate timeout_id_t realtime_timeout(void (*)(void *), void *, clock_t);
1667c478bd9Sstevel@tonic-gate clock_t untimeout(timeout_id_t);
16787a18d3fSMadhavan Venkataraman /*
16887a18d3fSMadhavan Venkataraman  * The last argument to timeout_generic() is flags. See callo.h for the
16987a18d3fSMadhavan Venkataraman  * flags definitions.
17087a18d3fSMadhavan Venkataraman  */
17187a18d3fSMadhavan Venkataraman callout_id_t timeout_generic(int, void (*)(void *), void *, hrtime_t, hrtime_t,
17287a18d3fSMadhavan Venkataraman     int);
17387a18d3fSMadhavan Venkataraman callout_id_t timeout_default(void (*)(void *), void *, clock_t);
17487a18d3fSMadhavan Venkataraman callout_id_t realtime_timeout_default(void (*)(void *), void *, clock_t);
17587a18d3fSMadhavan Venkataraman /*
17687a18d3fSMadhavan Venkataraman  * The last argument to untimeout_generic() is flags. See callout.c for the
17787a18d3fSMadhavan Venkataraman  * use.
17887a18d3fSMadhavan Venkataraman  */
17987a18d3fSMadhavan Venkataraman hrtime_t untimeout_generic(callout_id_t, int);
18087a18d3fSMadhavan Venkataraman clock_t untimeout_default(callout_id_t, int);
1817c478bd9Sstevel@tonic-gate void delay(clock_t);
1827c478bd9Sstevel@tonic-gate int delay_sig(clock_t);
1834c06356bSdh void delay_random(clock_t);
1847c478bd9Sstevel@tonic-gate int nodev();
1857c478bd9Sstevel@tonic-gate int nulldev();
1867c478bd9Sstevel@tonic-gate major_t getudev(void);
1877c478bd9Sstevel@tonic-gate int cmpldev(dev32_t *, dev_t);
1887c478bd9Sstevel@tonic-gate dev_t expldev(dev32_t);
1897c478bd9Sstevel@tonic-gate int bcmp(const void *, const void *, size_t) __PURE;
1907c478bd9Sstevel@tonic-gate int stoi(char **);
1917c478bd9Sstevel@tonic-gate void numtos(ulong_t, char *);
192ae46e4c7SMatthew Ahrens char *kmem_asprintf(const char *fmt, ...);
1937c478bd9Sstevel@tonic-gate int strident_valid(const char *);
1947c478bd9Sstevel@tonic-gate void strident_canon(char *, size_t);
1957c478bd9Sstevel@tonic-gate int getsubopt(char **optionsp, char * const *tokens, char **valuep);
1967c478bd9Sstevel@tonic-gate char *append_subopt(const char *, size_t, char *, const char *);
197b819cea2SGordon Ross #ifndef	_FAKE_KERNEL
198b819cea2SGordon Ross /* conflicts with libc definition */
19969bb4bb4Scarlsonj int ffs(uintmax_t);
200b819cea2SGordon Ross #endif
2017c478bd9Sstevel@tonic-gate int copyin(const void *, void *, size_t);
2027c478bd9Sstevel@tonic-gate void copyin_noerr(const void *, void *, size_t);
2037c478bd9Sstevel@tonic-gate int xcopyin(const void *, void *, size_t);
2047c478bd9Sstevel@tonic-gate int xcopyin_nta(const void *, void *, size_t, int);
2057c478bd9Sstevel@tonic-gate int copyout(const void *, void *, size_t);
2067c478bd9Sstevel@tonic-gate void copyout_noerr(const void *, void *, size_t);
2077c478bd9Sstevel@tonic-gate int xcopyout(const void *, void *, size_t);
2087c478bd9Sstevel@tonic-gate int xcopyout_nta(const void *, void *, size_t, int);
2097c478bd9Sstevel@tonic-gate int copyinstr(const char *, char *, size_t, size_t *);
2107c478bd9Sstevel@tonic-gate int copyinstr_noerr(const char *, char *, size_t, size_t *);
2117c478bd9Sstevel@tonic-gate int copyoutstr(const char *, char *, size_t, size_t *);
2127c478bd9Sstevel@tonic-gate int copyoutstr_noerr(const char *, char *, size_t, size_t *);
2137c478bd9Sstevel@tonic-gate int copystr(const char *, char *, size_t, size_t *);
2147c478bd9Sstevel@tonic-gate void ucopy(const void *, void *, size_t);
2159acbbeafSnn void ucopystr(const char *, char *, size_t, size_t *);
2167c478bd9Sstevel@tonic-gate void pgcopy(const void *, void *, size_t);
2177c478bd9Sstevel@tonic-gate void ovbcopy(const void *, void *, size_t);
2187c478bd9Sstevel@tonic-gate void uzero(void *, size_t);
2197c478bd9Sstevel@tonic-gate int kcopy(const void *, void *, size_t);
2207c478bd9Sstevel@tonic-gate int kcopy_nta(const void *, void *, size_t, int);
2217c478bd9Sstevel@tonic-gate int kzero(void *, size_t);
2227c478bd9Sstevel@tonic-gate 
2237c478bd9Sstevel@tonic-gate int fuword8(const void *, uint8_t *);
2247c478bd9Sstevel@tonic-gate int fuword16(const void *, uint16_t *);
2257c478bd9Sstevel@tonic-gate int fuword32(const void *, uint32_t *);
2267c478bd9Sstevel@tonic-gate int fulword(const void *, ulong_t *);
2277c478bd9Sstevel@tonic-gate void fuword8_noerr(const void *, uint8_t *);
2287c478bd9Sstevel@tonic-gate void fuword16_noerr(const void *, uint16_t *);
2297c478bd9Sstevel@tonic-gate void fuword32_noerr(const void *, uint32_t *);
2307c478bd9Sstevel@tonic-gate void fulword_noerr(const void *, ulong_t *);
2317c478bd9Sstevel@tonic-gate 
2327c478bd9Sstevel@tonic-gate #ifdef _LP64
2337c478bd9Sstevel@tonic-gate int fuword64(const void *, uint64_t *);
2347c478bd9Sstevel@tonic-gate void fuword64_noerr(const void *, uint64_t *);
2357c478bd9Sstevel@tonic-gate #endif
2367c478bd9Sstevel@tonic-gate 
2377c478bd9Sstevel@tonic-gate int subyte(void *, uint8_t);
2387c478bd9Sstevel@tonic-gate int suword8(void *, uint8_t);
2397c478bd9Sstevel@tonic-gate int suword16(void *, uint16_t);
2407c478bd9Sstevel@tonic-gate int suword32(void *, uint32_t);
2417c478bd9Sstevel@tonic-gate int sulword(void *, ulong_t);
2427c478bd9Sstevel@tonic-gate void subyte_noerr(void *, uint8_t);
2437c478bd9Sstevel@tonic-gate void suword8_noerr(void *, uint8_t);
2447c478bd9Sstevel@tonic-gate void suword16_noerr(void *, uint16_t);
2457c478bd9Sstevel@tonic-gate void suword32_noerr(void *, uint32_t);
2467c478bd9Sstevel@tonic-gate void sulword_noerr(void *, ulong_t);
2477c478bd9Sstevel@tonic-gate 
2487c478bd9Sstevel@tonic-gate #ifdef _LP64
2497c478bd9Sstevel@tonic-gate int suword64(void *, uint64_t);
2507c478bd9Sstevel@tonic-gate void suword64_noerr(void *, uint64_t);
2517c478bd9Sstevel@tonic-gate #endif
2527c478bd9Sstevel@tonic-gate 
253b819cea2SGordon Ross #if !defined(_BOOT) && !defined(_FAKE_KERNEL)
254b819cea2SGordon Ross /* conflicts with libc definition */
2556a3e8e86SRichard Lowe int setjmp(label_t *) __RETURNS_TWICE;
2567c478bd9Sstevel@tonic-gate extern void longjmp(label_t *)
2577c478bd9Sstevel@tonic-gate 	__NORETURN;
2587c478bd9Sstevel@tonic-gate #pragma unknown_control_flow(setjmp)
2597c478bd9Sstevel@tonic-gate #endif
2607c478bd9Sstevel@tonic-gate 
26194e7edb1Slucy wang - Sun Microsystems - Beijing China void prefetch_read_once(void *);
26294e7edb1Slucy wang - Sun Microsystems - Beijing China void prefetch_write_once(void *);
26394e7edb1Slucy wang - Sun Microsystems - Beijing China void prefetch_read_many(void *);
26494e7edb1Slucy wang - Sun Microsystems - Beijing China void prefetch_write_many(void *);
2657c478bd9Sstevel@tonic-gate caddr_t caller(void);
2667c478bd9Sstevel@tonic-gate caddr_t callee(void);
2677c478bd9Sstevel@tonic-gate int getpcstack(pc_t *, int);
2686a3e8e86SRichard Lowe int on_fault(label_t *) __RETURNS_TWICE;
2697c478bd9Sstevel@tonic-gate void no_fault(void);
2707c478bd9Sstevel@tonic-gate void halt(char *);
2717c478bd9Sstevel@tonic-gate int scanc(size_t, uchar_t *, uchar_t *, uchar_t);
2727c478bd9Sstevel@tonic-gate int movtuc(size_t, uchar_t *, uchar_t *, uchar_t *);
2737c478bd9Sstevel@tonic-gate int splr(int);
2747c478bd9Sstevel@tonic-gate int splhigh(void);
2757c478bd9Sstevel@tonic-gate int splhi(void);
2767c478bd9Sstevel@tonic-gate int splzs(void);
2777c478bd9Sstevel@tonic-gate int spl0(void);
2787c478bd9Sstevel@tonic-gate int spl6(void);
2797c478bd9Sstevel@tonic-gate int spl7(void);
2807c478bd9Sstevel@tonic-gate int spl8(void);
2817c478bd9Sstevel@tonic-gate void splx(int);
2827c478bd9Sstevel@tonic-gate void set_base_spl(void);
2837c478bd9Sstevel@tonic-gate int __ipltospl(int);
284b885580bSAlexander Kolbasov int spl_xcall(void);
2857c478bd9Sstevel@tonic-gate 
2867c478bd9Sstevel@tonic-gate void softcall_init(void);
2877c478bd9Sstevel@tonic-gate void softcall(void (*)(void *), void *);
2887c478bd9Sstevel@tonic-gate void softint(void);
2897c478bd9Sstevel@tonic-gate 
2907c478bd9Sstevel@tonic-gate extern void sync_icache(caddr_t, uint_t);
2917c478bd9Sstevel@tonic-gate extern void sync_data_memory(caddr_t, size_t);
2927c478bd9Sstevel@tonic-gate extern void hot_patch_kernel_text(caddr_t, uint32_t, uint_t);
2937c478bd9Sstevel@tonic-gate 
2947c478bd9Sstevel@tonic-gate void _insque(caddr_t, caddr_t);
2957c478bd9Sstevel@tonic-gate void _remque(caddr_t);
2967c478bd9Sstevel@tonic-gate 
2977c478bd9Sstevel@tonic-gate /* casts to keep lint happy */
2987c478bd9Sstevel@tonic-gate #define	insque(q, p)	_insque((caddr_t)q, (caddr_t)p)
2997c478bd9Sstevel@tonic-gate #define	remque(q)	_remque((caddr_t)q)
3007c478bd9Sstevel@tonic-gate 
3017c478bd9Sstevel@tonic-gate #pragma unknown_control_flow(on_fault)
3027c478bd9Sstevel@tonic-gate 
3037c478bd9Sstevel@tonic-gate struct timeval;
3047c478bd9Sstevel@tonic-gate extern void	uniqtime(struct timeval *);
3057c478bd9Sstevel@tonic-gate struct timeval32;
3067c478bd9Sstevel@tonic-gate extern void	uniqtime32(struct timeval32 *);
3077c478bd9Sstevel@tonic-gate 
3087c478bd9Sstevel@tonic-gate uint_t page_num_pagesizes(void);
3097c478bd9Sstevel@tonic-gate size_t page_get_pagesize(uint_t n);
3107c478bd9Sstevel@tonic-gate 
3117c478bd9Sstevel@tonic-gate extern int maxusers;
3127c478bd9Sstevel@tonic-gate extern int pidmax;
3137c478bd9Sstevel@tonic-gate 
3147c478bd9Sstevel@tonic-gate extern void param_preset(void);
3157c478bd9Sstevel@tonic-gate extern void param_calc(int);
3167c478bd9Sstevel@tonic-gate extern void param_init(void);
3177c478bd9Sstevel@tonic-gate extern void param_check(void);
3187c478bd9Sstevel@tonic-gate 
3197c478bd9Sstevel@tonic-gate #endif /* _KERNEL */
3207c478bd9Sstevel@tonic-gate 
3217c478bd9Sstevel@tonic-gate /*
3227c478bd9Sstevel@tonic-gate  * Structure of the system-entry table.
3237c478bd9Sstevel@tonic-gate  *
3247c478bd9Sstevel@tonic-gate  * 	Changes to struct sysent should maintain binary compatibility with
3257c478bd9Sstevel@tonic-gate  *	loadable system calls, although the interface is currently private.
3267c478bd9Sstevel@tonic-gate  *
3277c478bd9Sstevel@tonic-gate  *	This means it should only be expanded on the end, and flag values
3287c478bd9Sstevel@tonic-gate  * 	should not be reused.
3297c478bd9Sstevel@tonic-gate  *
3307c478bd9Sstevel@tonic-gate  *	It is desirable to keep the size of this struct a power of 2 for quick
3317c478bd9Sstevel@tonic-gate  *	indexing.
3327c478bd9Sstevel@tonic-gate  */
3337c478bd9Sstevel@tonic-gate struct sysent {
3347c478bd9Sstevel@tonic-gate 	char		sy_narg;	/* total number of arguments */
3357c478bd9Sstevel@tonic-gate #ifdef _LP64
3367c478bd9Sstevel@tonic-gate 	unsigned short	sy_flags;	/* various flags as defined below */
3377c478bd9Sstevel@tonic-gate #else
3387c478bd9Sstevel@tonic-gate 	unsigned char	sy_flags;	/* various flags as defined below */
3397c478bd9Sstevel@tonic-gate #endif
3407c478bd9Sstevel@tonic-gate 	int		(*sy_call)();	/* argp, rvalp-style handler */
3417c478bd9Sstevel@tonic-gate 	krwlock_t	*sy_lock;	/* lock for loadable system calls */
3427c478bd9Sstevel@tonic-gate 	int64_t		(*sy_callc)();	/* C-style call hander or wrapper */
3437c478bd9Sstevel@tonic-gate };
3447c478bd9Sstevel@tonic-gate 
3457c478bd9Sstevel@tonic-gate extern struct sysent	sysent[];
3467c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32_IMPL
3477c478bd9Sstevel@tonic-gate extern struct sysent	sysent32[];
3487c478bd9Sstevel@tonic-gate #endif
3497c478bd9Sstevel@tonic-gate 
3507c478bd9Sstevel@tonic-gate extern struct sysent	nosys_ent;	/* entry for invalid system call */
3517c478bd9Sstevel@tonic-gate 
3527c478bd9Sstevel@tonic-gate #define	NSYSCALL 	256		/* number of system calls */
3537c478bd9Sstevel@tonic-gate 
3547c478bd9Sstevel@tonic-gate #define	LOADABLE_SYSCALL(s)	(s->sy_flags & SE_LOADABLE)
3557c478bd9Sstevel@tonic-gate #define	LOADED_SYSCALL(s)	(s->sy_flags & SE_LOADED)
3567c478bd9Sstevel@tonic-gate 
3577c478bd9Sstevel@tonic-gate /*
3587c478bd9Sstevel@tonic-gate  * sy_flags values
3597c478bd9Sstevel@tonic-gate  * 	Values 1, 2, and 4 were used previously for SETJUMP, ASYNC, and IOSYS.
3607c478bd9Sstevel@tonic-gate  */
3617c478bd9Sstevel@tonic-gate #define	SE_32RVAL1	0x0		/* handler returns int32_t in rval1 */
3627c478bd9Sstevel@tonic-gate #define	SE_32RVAL2	0x1		/* handler returns int32_t in rval2 */
3637c478bd9Sstevel@tonic-gate #define	SE_64RVAL	0x2		/* handler returns int64_t in rvals */
3647c478bd9Sstevel@tonic-gate #define	SE_RVAL_MASK	0x3		/* mask of rval_t bits */
3657c478bd9Sstevel@tonic-gate 
3667c478bd9Sstevel@tonic-gate #define	SE_LOADABLE	0x08		/* syscall is loadable */
3677c478bd9Sstevel@tonic-gate #define	SE_LOADED	0x10		/* syscall is completely loaded */
3687c478bd9Sstevel@tonic-gate #define	SE_NOUNLOAD	0x20		/* syscall never needs unload */
3697c478bd9Sstevel@tonic-gate #define	SE_ARGC		0x40		/* syscall takes C-style args */
3707c478bd9Sstevel@tonic-gate 
3717c478bd9Sstevel@tonic-gate /*
3727c478bd9Sstevel@tonic-gate  * Structure of the return-value parameter passed by reference to
3737c478bd9Sstevel@tonic-gate  * system entries.
3747c478bd9Sstevel@tonic-gate  */
3757c478bd9Sstevel@tonic-gate union rval {
3767c478bd9Sstevel@tonic-gate 	struct	{
3777c478bd9Sstevel@tonic-gate 		int	r_v1;
3787c478bd9Sstevel@tonic-gate 		int	r_v2;
3797c478bd9Sstevel@tonic-gate 	} r_v;
3807c478bd9Sstevel@tonic-gate 	off_t	r_off;
3817c478bd9Sstevel@tonic-gate 	offset_t r_offset;
3827c478bd9Sstevel@tonic-gate 	time_t	r_time;
3837c478bd9Sstevel@tonic-gate 	int64_t	r_vals;
3847c478bd9Sstevel@tonic-gate };
3857c478bd9Sstevel@tonic-gate #define	r_val1	r_v.r_v1
3867c478bd9Sstevel@tonic-gate #define	r_val2	r_v.r_v2
3877c478bd9Sstevel@tonic-gate 
3887c478bd9Sstevel@tonic-gate typedef union rval rval_t;
3897c478bd9Sstevel@tonic-gate 
390b819cea2SGordon Ross #if defined(_KERNEL) || defined(_FAKE_KERNEL)
3917c478bd9Sstevel@tonic-gate 
3927c478bd9Sstevel@tonic-gate extern void reset_syscall_args(void);
3937c478bd9Sstevel@tonic-gate extern int save_syscall_args(void);
3947c478bd9Sstevel@tonic-gate extern uint_t get_syscall_args(klwp_t *lwp, long *argp, int *nargsp);
3957c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32_IMPL
3967c478bd9Sstevel@tonic-gate extern uint_t get_syscall32_args(klwp_t *lwp, int *argp, int *nargp);
3977c478bd9Sstevel@tonic-gate #endif
3987c478bd9Sstevel@tonic-gate 
3997c478bd9Sstevel@tonic-gate extern uint_t set_errno(uint_t error);
4007c478bd9Sstevel@tonic-gate #pragma rarely_called(set_errno)
4017c478bd9Sstevel@tonic-gate 
4027c478bd9Sstevel@tonic-gate extern int64_t syscall_ap(void);
4037c478bd9Sstevel@tonic-gate extern int64_t loadable_syscall(long, long, long, long, long, long, long, long);
4047c478bd9Sstevel@tonic-gate extern int64_t nosys(void);
4057c478bd9Sstevel@tonic-gate 
4067c478bd9Sstevel@tonic-gate extern void swtch(void);
4077c478bd9Sstevel@tonic-gate 
4087c478bd9Sstevel@tonic-gate extern uint_t	kcpc_key;	/* TSD key for performance counter context */
4097c478bd9Sstevel@tonic-gate 
4107c478bd9Sstevel@tonic-gate /*
4113f2f09c1Sdp  * initname holds the path to init and is used as a point of rendezvous
4123f2f09c1Sdp  * between krtld (which processes the boot arguments) and the kernel.
4137c478bd9Sstevel@tonic-gate  */
4147c478bd9Sstevel@tonic-gate #define	INITNAME_SZ	32
4157c478bd9Sstevel@tonic-gate extern char initname[INITNAME_SZ];
4167c478bd9Sstevel@tonic-gate 
4173f2f09c1Sdp /*
4183f2f09c1Sdp  * initargs holds the arguments to init (such as -v, -s, -r, -m verbose) and
4193f2f09c1Sdp  * is a point of rendezvous between krtld (which processes the boot arguments)
4203f2f09c1Sdp  * and the kernel.
4213f2f09c1Sdp  */
4223f2f09c1Sdp extern char initargs[BOOTARGS_MAX];
4233f2f09c1Sdp 
4243f2f09c1Sdp extern int exec_init(const char *, const char *);
4253f2f09c1Sdp extern int start_init_common(void);
4267c478bd9Sstevel@tonic-gate 
4277c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
4287c478bd9Sstevel@tonic-gate 
429b819cea2SGordon Ross #if defined(_KERNEL) || defined(_FAKE_KERNEL) || defined(_BOOT)
430ae115bc7Smrj 
431ae115bc7Smrj size_t strlcat(char *, const char *, size_t);
432ae115bc7Smrj size_t strlen(const char *) __PURE;
433ae115bc7Smrj char *strcat(char *, const char *);
434ae115bc7Smrj char *strncat(char *, const char *, size_t);
435ae115bc7Smrj char *strcpy(char *, const char *);
436ae115bc7Smrj char *strncpy(char *, const char *, size_t);
437b819cea2SGordon Ross 
438b819cea2SGordon Ross extern size_t strlcpy(char *, const char *, size_t);
439b819cea2SGordon Ross extern size_t strspn(const char *, const char *);
440b819cea2SGordon Ross extern size_t strcspn(const char *, const char *);
441b819cea2SGordon Ross extern char *strdup(const char *);
442b819cea2SGordon Ross extern void strfree(char *);
443b819cea2SGordon Ross 
444ae115bc7Smrj /* Need to be consistent with <string.h> C++ definitions */
445ae115bc7Smrj #if __cplusplus >= 199711L
446ae115bc7Smrj extern const char *strchr(const char *, int);
447ae115bc7Smrj #ifndef _STRCHR_INLINE
448ae115bc7Smrj #define	_STRCHR_INLINE
449ae115bc7Smrj extern "C++" {
450ae115bc7Smrj 	inline char *strchr(char *__s, int __c) {
451ae115bc7Smrj 		return (char *)strchr((const char *)__s, __c);
452ae115bc7Smrj 	}
453ae115bc7Smrj }
454ae115bc7Smrj #endif /* _STRCHR_INLINE */
455ae115bc7Smrj extern const char *strrchr(const char *, int);
456ae115bc7Smrj #ifndef	_STRRCHR_INLINE
457ae115bc7Smrj #define	_STRRCHR_INLINE
458ae115bc7Smrj extern "C++" {
459ae115bc7Smrj 	inline char *strrchr(char *__s, int __c) {
460ae115bc7Smrj 		return (char *)strrchr((const char *)__s, __c);
461ae115bc7Smrj 	}
462ae115bc7Smrj }
463ae115bc7Smrj #endif	/* _STRRCHR_INLINE */
464ae115bc7Smrj extern const char *strstr(const char *, const char *);
465ae115bc7Smrj #ifndef	_STRSTR_INLINE
466ae115bc7Smrj #define	_STRSTR_INLINE
467ae115bc7Smrj extern "C++" {
468ae115bc7Smrj 	inline char *strstr(char *__s1, const char *__s2) {
469ae115bc7Smrj 		return (char *)strstr((const char *)__s1, __s2);
470ae115bc7Smrj 	}
471ae115bc7Smrj }
472ae115bc7Smrj #endif  /* _STRSTR_INLINE */
473ae115bc7Smrj #else	/* __cplusplus >= 199711L */
474ae115bc7Smrj char *strchr(const char *, int);
475ae115bc7Smrj char *strrchr(const char *, int);
476ae115bc7Smrj char *strstr(const char *, const char *);
477ae115bc7Smrj #endif	/* __cplusplus >= 199711L */
478ae115bc7Smrj char *strnrchr(const char *, int, size_t);
479ae115bc7Smrj int strcmp(const char *, const char *) __PURE;
480ae115bc7Smrj int strncmp(const char *, const char *, size_t) __PURE;
481ae115bc7Smrj int strcasecmp(const char *, const char *) __PURE;
482ae115bc7Smrj int strncasecmp(const char *, const char *, size_t) __PURE;
483ae115bc7Smrj /* Need to be consistent with <string.h> C++ definitions */
484ae115bc7Smrj #if __cplusplus >= 199711L
485ae115bc7Smrj extern const char *strpbrk(const char *, const char *);
486ae115bc7Smrj #ifndef _STRPBRK_INLINE
487ae115bc7Smrj #define	_STRPBRK_INLINE
488ae115bc7Smrj extern "C++" {
489ae115bc7Smrj 	inline char *strpbrk(char *__s1, const char *__s2) {
490ae115bc7Smrj 		return (char *)strpbrk((const char *)__s1, __s2);
491ae115bc7Smrj 	}
492ae115bc7Smrj }
493ae115bc7Smrj #endif /* _STRPBRK_INLINE */
494ae115bc7Smrj #else /* __cplusplus >= 199711L */
495ae115bc7Smrj char *strpbrk(const char *, const char *);
496ae115bc7Smrj #endif /* __cplusplus >= 199711L */
497ae115bc7Smrj void bcopy(const void *, void *, size_t);
498ae115bc7Smrj void bzero(void *, size_t);
499ae115bc7Smrj 
500ae115bc7Smrj extern void *memset(void *, int, size_t);
501ae115bc7Smrj extern void *memcpy(void *, const void *, size_t);
502ae115bc7Smrj extern void *memmove(void *, const void *, size_t);
503ae115bc7Smrj extern int memcmp(const void *, const void *, size_t);
504ae115bc7Smrj 
505ae115bc7Smrj #ifdef __lint
506ae115bc7Smrj extern	int	__lintzero;	/* for spoofing lint */
507ae115bc7Smrj #else	/* __lint */
508ae115bc7Smrj #define	__lintzero 0
509ae115bc7Smrj #endif	/* __lint */
510ae115bc7Smrj #endif /* _KERNEL || _BOOT */
511ae115bc7Smrj 
5127c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
5137c478bd9Sstevel@tonic-gate }
5147c478bd9Sstevel@tonic-gate #endif
5157c478bd9Sstevel@tonic-gate 
5167c478bd9Sstevel@tonic-gate #endif	/* _SYS_SYSTM_H */
517