loader: add skein/edonr support
[unleashed.git] / include / sys / systm.h
blobf0c5ec4c8a7f951a0990311e045779ff9a9cfc0c
1 /*
2 * CDDL HEADER START
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.
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.
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]
19 * CDDL HEADER END
22 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
23 /* All Rights Reserved */
26 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
27 * Use is subject to license terms.
28 * Copyright 2016 Nexenta Systems, Inc.
31 #ifndef _SYS_SYSTM_H
32 #define _SYS_SYSTM_H
34 #if defined(_STANDALONE)
35 #include <sys/cdefs.h>
36 #include <string.h>
37 #else
38 #include <sys/types.h>
39 #include <sys/t_lock.h>
40 #include <sys/proc.h>
41 #include <sys/dditypes.h>
42 #endif
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
48 #if !defined(_STANDALONE)
50 * The pc_t is the type of the kernel's program counter. In general, a
51 * pc_t is a uintptr_t -- except for a sparcv9 kernel, in which case all
52 * instruction text is below 4G, and a pc_t is thus a uint32_t.
54 #ifdef __sparcv9
55 typedef uint32_t pc_t;
56 #else
57 typedef uintptr_t pc_t;
58 #endif
61 * Random set of variables used by more than one routine.
64 #if defined(_KERNEL)
65 #include <sys/types32.h>
66 #include <sys/varargs.h>
67 #include <sys/uadmin.h>
69 extern int hz; /* system clock rate */
70 extern struct vnode *rootdir; /* pointer to vnode of root directory */
71 extern struct vnode *devicesdir; /* pointer to /devices vnode */
72 extern int interrupts_unleashed; /* set after the spl0() in main() */
74 extern pgcnt_t maxmem; /* max available memory (pages) */
75 extern pgcnt_t physmem; /* physical memory (pages) on this CPU */
76 extern pfn_t physmax; /* highest numbered physical page present */
77 extern pgcnt_t physinstalled; /* physical pages including PROM/boot use */
79 extern caddr_t s_text; /* start of kernel text segment */
80 extern caddr_t e_text; /* end of kernel text segment */
81 extern caddr_t s_data; /* start of kernel text segment */
82 extern caddr_t e_data; /* end of kernel text segment */
84 extern pgcnt_t availrmem; /* Available resident (not swapable) */
85 /* memory in pages. */
86 extern pgcnt_t availrmem_initial; /* initial value of availrmem */
87 extern pgcnt_t segspt_minfree; /* low water mark for availrmem in seg_spt */
88 extern pgcnt_t freemem; /* Current free memory. */
90 extern dev_t rootdev; /* device of the root */
91 extern struct vnode *rootvp; /* vnode of root device */
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 extern volatile int quiesce_active; /* quiesce(9E) is in progress */
98 extern int rstchown; /* 1 ==> restrictive chown(2) semantics */
99 extern int klustsize;
101 extern int abort_enable; /* Platform input-device abort policy */
103 extern int audit_active; /* Solaris Auditing module state */
105 extern int avenrun[]; /* array of load averages */
107 extern char *isa_list; /* For sysinfo's isalist option */
109 extern int noexec_user_stack; /* patchable via /etc/system */
110 extern int noexec_user_stack_log; /* patchable via /etc/system */
113 * Use NFS client operations in the global zone only. Under contract with
114 * admin/install; do not change without coordinating with that consolidation.
116 extern int nfs_global_client_only;
118 extern void report_stack_exec(proc_t *, caddr_t);
120 extern void startup(void);
121 extern void clkstart(void);
122 extern void post_startup(void);
123 extern void kern_setup1(void);
124 extern void ka_init(void);
125 extern void nodename_set(void);
128 * for tod fault detection
130 enum tod_fault_type {
131 TOD_REVERSED = 0,
132 TOD_STALLED,
133 TOD_JUMPED,
134 TOD_RATECHANGED,
135 TOD_RDONLY,
136 TOD_NOFAULT
139 #define TOD_GET_FAILED 0x1 /* TOD could not be read */
140 #define TOD_SET_DONE 0x2 /* TOD has been modified */
141 #define TOD_CPR_RESUME_DONE 0x4 /* CPR resume has occurred */
142 #define TOD_DR_RESUME_DONE 0x8 /* DR resume has occurred */
144 extern time_t tod_validate(time_t);
145 extern void tod_status_set(int);
146 extern void tod_status_clear(int);
147 extern void plat_tod_fault(enum tod_fault_type);
149 #ifndef _LP64
150 #ifndef min
151 int min(int, int);
152 #endif
154 #ifndef max
155 int max(int, int);
156 #endif
158 uint_t umin(uint_t, uint_t);
159 uint_t umax(uint_t, uint_t);
160 #endif /* !_LP64 */
161 int grow(caddr_t);
162 int grow_internal(caddr_t, uint_t);
163 int brk_internal(caddr_t, uint_t);
164 typedef uint64_t callout_id_t;
165 timeout_id_t timeout(void (*)(void *), void *, clock_t);
166 timeout_id_t realtime_timeout(void (*)(void *), void *, clock_t);
167 clock_t untimeout(timeout_id_t);
169 * The last argument to timeout_generic() is flags. See callo.h for the
170 * flags definitions.
172 callout_id_t timeout_generic(int, void (*)(void *), void *, hrtime_t, hrtime_t,
173 int);
174 callout_id_t timeout_default(void (*)(void *), void *, clock_t);
175 callout_id_t realtime_timeout_default(void (*)(void *), void *, clock_t);
177 * The last argument to untimeout_generic() is flags. See callout.c for the
178 * use.
180 hrtime_t untimeout_generic(callout_id_t, int);
181 clock_t untimeout_default(callout_id_t, int);
182 void delay(clock_t);
183 int delay_sig(clock_t);
184 void delay_random(clock_t);
185 extern void ddi_sleep(clock_t);
186 extern void ddi_msleep(clock_t);
187 extern void ddi_usleep(clock_t);
188 int nodev();
189 int nulldev();
190 major_t getudev(void);
191 int cmpldev(dev32_t *, dev_t);
192 dev_t expldev(dev32_t);
193 int bcmp(const void *, const void *, size_t) __PURE;
194 int stoi(char **);
195 void numtos(ulong_t, char *);
196 char *kmem_asprintf(const char *fmt, ...);
197 int strident_valid(const char *);
198 void strident_canon(char *, size_t);
199 int getsubopt(char **optionsp, char * const *tokens, char **valuep);
200 char *append_subopt(const char *, size_t, char *, const char *);
201 int ffs(uintmax_t);
202 int copyin(const void *, void *, size_t);
203 void copyin_noerr(const void *, void *, size_t);
204 int xcopyin(const void *, void *, size_t);
205 int xcopyin_nta(const void *, void *, size_t, int);
206 int copyout(const void *, void *, size_t);
207 void copyout_noerr(const void *, void *, size_t);
208 int xcopyout(const void *, void *, size_t);
209 int xcopyout_nta(const void *, void *, size_t, int);
210 int copyinstr(const char *, char *, size_t, size_t *);
211 int copyinstr_noerr(const char *, char *, size_t, size_t *);
212 int copyoutstr(const char *, char *, size_t, size_t *);
213 int copyoutstr_noerr(const char *, char *, size_t, size_t *);
214 int copystr(const char *, char *, size_t, size_t *);
215 void ucopy(const void *, void *, size_t);
216 void ucopystr(const char *, char *, size_t, size_t *);
217 void pgcopy(const void *, void *, size_t);
218 void ovbcopy(const void *, void *, size_t);
219 void uzero(void *, size_t);
220 int kcopy(const void *, void *, size_t);
221 int kcopy_nta(const void *, void *, size_t, int);
222 int kzero(void *, size_t);
224 int fuword8(const void *, uint8_t *);
225 int fuword16(const void *, uint16_t *);
226 int fuword32(const void *, uint32_t *);
227 int fulword(const void *, ulong_t *);
228 void fuword8_noerr(const void *, uint8_t *);
229 void fuword16_noerr(const void *, uint16_t *);
230 void fuword32_noerr(const void *, uint32_t *);
231 void fulword_noerr(const void *, ulong_t *);
233 #ifdef _LP64
234 int fuword64(const void *, uint64_t *);
235 void fuword64_noerr(const void *, uint64_t *);
236 #endif
238 int subyte(void *, uint8_t);
239 int suword8(void *, uint8_t);
240 int suword16(void *, uint16_t);
241 int suword32(void *, uint32_t);
242 int sulword(void *, ulong_t);
243 void subyte_noerr(void *, uint8_t);
244 void suword8_noerr(void *, uint8_t);
245 void suword16_noerr(void *, uint16_t);
246 void suword32_noerr(void *, uint32_t);
247 void sulword_noerr(void *, ulong_t);
249 #ifdef _LP64
250 int suword64(void *, uint64_t);
251 void suword64_noerr(void *, uint64_t);
252 #endif
254 #if !defined(_BOOT)
255 /* conflicts with libc definition */
256 int setjmp(label_t *) __RETURNS_TWICE;
257 extern void longjmp(label_t *)
258 __NORETURN;
259 #pragma unknown_control_flow(setjmp)
260 #endif
262 void prefetch_read_once(void *);
263 void prefetch_write_once(void *);
264 void prefetch_read_many(void *);
265 void prefetch_write_many(void *);
266 caddr_t caller(void);
267 caddr_t callee(void);
268 int getpcstack(pc_t *, int);
269 int on_fault(label_t *) __RETURNS_TWICE;
270 void no_fault(void);
271 void halt(char *);
272 int scanc(size_t, uchar_t *, uchar_t *, uchar_t);
273 int movtuc(size_t, uchar_t *, uchar_t *, uchar_t *);
274 int splr(int);
275 int splhigh(void);
276 int splhi(void);
277 int splzs(void);
278 int spl0(void);
279 int spl6(void);
280 int spl7(void);
281 int spl8(void);
282 void splx(int);
283 void set_base_spl(void);
284 int __ipltospl(int);
285 int spl_xcall(void);
287 void softcall_init(void);
288 void softcall(void (*)(void *), void *);
289 void softint(void);
291 extern void sync_icache(caddr_t, uint_t);
292 extern void sync_data_memory(caddr_t, size_t);
293 extern void hot_patch_kernel_text(caddr_t, uint32_t, uint_t);
295 void _insque(caddr_t, caddr_t);
296 void _remque(caddr_t);
298 /* casts to keep lint happy */
299 #define insque(q, p) _insque((caddr_t)q, (caddr_t)p)
300 #define remque(q) _remque((caddr_t)q)
302 #pragma unknown_control_flow(on_fault)
304 struct timeval;
305 extern void uniqtime(struct timeval *);
306 struct timeval32;
307 extern void uniqtime32(struct timeval32 *);
309 uint_t page_num_pagesizes(void);
310 size_t page_get_pagesize(uint_t n);
312 extern int maxusers;
313 extern int pidmax;
315 extern void param_preset(void);
316 extern void param_calc(int);
317 extern void param_init(void);
318 extern void param_check(void);
320 #endif /* _KERNEL */
323 * Structure of the system-entry table.
325 * Changes to struct sysent should maintain binary compatibility with
326 * loadable system calls, although the interface is currently private.
328 * This means it should only be expanded on the end, and flag values
329 * should not be reused.
331 * It is desirable to keep the size of this struct a power of 2 for quick
332 * indexing.
334 struct sysent {
335 char sy_narg; /* total number of arguments */
336 #ifdef _LP64
337 unsigned short sy_flags; /* various flags as defined below */
338 #else
339 unsigned char sy_flags; /* various flags as defined below */
340 #endif
341 int (*sy_call)(); /* argp, rvalp-style handler */
342 krwlock_t *sy_lock; /* lock for loadable system calls */
343 int64_t (*sy_callc)(); /* C-style call hander or wrapper */
346 extern struct sysent sysent[];
347 #ifdef _SYSCALL32_IMPL
348 extern struct sysent sysent32[];
349 #endif
351 extern struct sysent nosys_ent; /* entry for invalid system call */
353 #define NSYSCALL 256 /* number of system calls */
355 #define LOADABLE_SYSCALL(s) (s->sy_flags & SE_LOADABLE)
356 #define LOADED_SYSCALL(s) (s->sy_flags & SE_LOADED)
359 * sy_flags values
360 * Values 1, 2, and 4 were used previously for SETJUMP, ASYNC, and IOSYS.
362 #define SE_32RVAL1 0x0 /* handler returns int32_t in rval1 */
363 #define SE_32RVAL2 0x1 /* handler returns int32_t in rval2 */
364 #define SE_64RVAL 0x2 /* handler returns int64_t in rvals */
365 #define SE_RVAL_MASK 0x3 /* mask of rval_t bits */
367 #define SE_LOADABLE 0x08 /* syscall is loadable */
368 #define SE_LOADED 0x10 /* syscall is completely loaded */
369 #define SE_NOUNLOAD 0x20 /* syscall never needs unload */
370 #define SE_ARGC 0x40 /* syscall takes C-style args */
373 * Structure of the return-value parameter passed by reference to
374 * system entries.
376 union rval {
377 struct {
378 int r_v1;
379 int r_v2;
380 } r_v;
381 off_t r_off;
382 offset_t r_offset;
383 time_t r_time;
384 int64_t r_vals;
386 #define r_val1 r_v.r_v1
387 #define r_val2 r_v.r_v2
389 typedef union rval rval_t;
391 #if defined(_KERNEL)
393 extern void reset_syscall_args(void);
394 extern int save_syscall_args(void);
395 extern uint_t get_syscall_args(klwp_t *lwp, long *argp, int *nargsp);
396 #ifdef _SYSCALL32_IMPL
397 extern uint_t get_syscall32_args(klwp_t *lwp, int *argp, int *nargp);
398 #endif
400 extern uint_t set_errno(uint_t error);
401 #pragma rarely_called(set_errno)
403 extern int64_t syscall_ap(void);
404 extern int64_t loadable_syscall(long, long, long, long, long, long, long, long);
405 extern int64_t nosys(void);
407 extern void swtch(void);
409 extern uint_t kcpc_key; /* TSD key for performance counter context */
412 * initname holds the path to init and is used as a point of rendezvous
413 * between krtld (which processes the boot arguments) and the kernel.
415 #define INITNAME_SZ 32
416 extern char initname[INITNAME_SZ];
419 * initargs holds the arguments to init (such as -v, -s, -r, -m verbose) and
420 * is a point of rendezvous between krtld (which processes the boot arguments)
421 * and the kernel.
423 extern char initargs[BOOTARGS_MAX];
425 extern int exec_init(const char *, const char *);
426 extern int start_init_common(void);
428 #endif /* _KERNEL */
430 #if defined(_KERNEL) || defined(_BOOT)
432 size_t strlcat(char *, const char *, size_t);
433 size_t strlen(const char *) __PURE;
434 char *strcat(char *, const char *);
435 char *strncat(char *, const char *, size_t);
436 char *strcpy(char *, const char *);
437 char *strncpy(char *, const char *, size_t);
439 extern size_t strlcpy(char *, const char *, size_t);
440 extern size_t strspn(const char *, const char *);
441 extern size_t strcspn(const char *, const char *);
442 extern char *strdup(const char *);
443 extern void strfree(char *);
445 /* Need to be consistent with <string.h> C++ definitions */
446 #if __cplusplus >= 199711L
447 extern const char *strchr(const char *, int);
448 #ifndef _STRCHR_INLINE
449 #define _STRCHR_INLINE
450 extern "C++" {
451 inline char *strchr(char *__s, int __c) {
452 return (char *)strchr((const char *)__s, __c);
455 #endif /* _STRCHR_INLINE */
456 extern const char *strrchr(const char *, int);
457 #ifndef _STRRCHR_INLINE
458 #define _STRRCHR_INLINE
459 extern "C++" {
460 inline char *strrchr(char *__s, int __c) {
461 return (char *)strrchr((const char *)__s, __c);
464 #endif /* _STRRCHR_INLINE */
465 extern const char *strstr(const char *, const char *);
466 #ifndef _STRSTR_INLINE
467 #define _STRSTR_INLINE
468 extern "C++" {
469 inline char *strstr(char *__s1, const char *__s2) {
470 return (char *)strstr((const char *)__s1, __s2);
473 #endif /* _STRSTR_INLINE */
474 #else /* __cplusplus >= 199711L */
475 char *strchr(const char *, int);
476 char *strrchr(const char *, int);
477 char *strstr(const char *, const char *);
478 #endif /* __cplusplus >= 199711L */
479 char *strnrchr(const char *, int, size_t);
480 int strcmp(const char *, const char *) __PURE;
481 int strncmp(const char *, const char *, size_t) __PURE;
482 int strcasecmp(const char *, const char *) __PURE;
483 int strncasecmp(const char *, const char *, size_t) __PURE;
484 /* Need to be consistent with <string.h> C++ definitions */
485 #if __cplusplus >= 199711L
486 extern const char *strpbrk(const char *, const char *);
487 #ifndef _STRPBRK_INLINE
488 #define _STRPBRK_INLINE
489 extern "C++" {
490 inline char *strpbrk(char *__s1, const char *__s2) {
491 return (char *)strpbrk((const char *)__s1, __s2);
494 #endif /* _STRPBRK_INLINE */
495 #else /* __cplusplus >= 199711L */
496 char *strpbrk(const char *, const char *);
497 #endif /* __cplusplus >= 199711L */
498 void bcopy(const void *, void *, size_t);
499 void bzero(void *, size_t);
501 extern void *memset(void *, int, size_t);
502 extern void *memcpy(void *, const void *, size_t);
503 extern void *memmove(void *, const void *, size_t);
504 extern int memcmp(const void *, const void *, size_t);
506 #ifdef __lint
507 extern int __lintzero; /* for spoofing lint */
508 #else /* __lint */
509 #define __lintzero 0
510 #endif /* __lint */
511 #endif /* _KERNEL || _BOOT */
512 #endif /* !_STANDALONE */
514 #ifdef __cplusplus
516 #endif
518 #endif /* _SYS_SYSTM_H */