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 22 /* 23 * Copyright 2010 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 /* 28 * This is where all the interfaces that are internal to libc 29 * which do not have a better home live 30 */ 31 32 #ifndef _LIBC_H 33 #define _LIBC_H 34 35 #include <thread.h> 36 #include <stdio.h> 37 #include <dirent.h> 38 #include <ucontext.h> 39 #include <nsswitch.h> 40 #include <stddef.h> 41 #include <poll.h> 42 #include <sys/dl.h> 43 #include <sys/door.h> 44 #include <sys/ieeefp.h> 45 #include <sys/mount.h> 46 #include <sys/fdsync.h> 47 #include <floatingpoint.h> 48 #include <nl_types.h> 49 #include <regex.h> 50 #include <stdarg.h> 51 #include <wchar.h> 52 #include <wctype.h> 53 #include <libnvpair.h> 54 #include <setjmp.h> 55 56 #ifdef __cplusplus 57 extern "C" { 58 #endif 59 60 extern void __set_panicstr(const char *); 61 extern void _rewind_unlocked(FILE *); 62 extern long _sysconfig(int); 63 extern int kill(pid_t pid, int sig); 64 65 extern int primary_link_map; 66 extern void _thr_exit(void *) __NORETURN; 67 extern int thr_main(void); 68 extern int thr_kill(thread_t tid, int sig); 69 extern thread_t thr_self(void); 70 extern int mutex_lock(mutex_t *mp); 71 extern int mutex_unlock(mutex_t *mp); 72 extern void callout_lock_enter(void); 73 extern void callout_lock_exit(void); 74 extern void *lmalloc(size_t); 75 extern void lfree(void *, size_t); 76 extern void libc_nvlist_free(nvlist_t *); 77 extern int libc_nvlist_lookup_uint64(nvlist_t *, const char *, uint64_t *); 78 extern void *libc_malloc(size_t); 79 extern void *libc_realloc(void *, size_t); 80 extern void libc_free(void *); 81 extern char *libc_strdup(const char *); 82 extern int _pollsys(struct pollfd *, nfds_t, const timespec_t *, 83 const sigset_t *); 84 85 /* 86 * The private_DIR structure is the same as the DIR structure, 87 * with the addition of a mutex lock for libc's internal use. 88 */ 89 typedef struct { 90 DIR dd_dir; 91 mutex_t dd_lock; 92 } private_DIR; 93 94 #if !defined(_LP64) 95 /* 96 * getdents64 transitional interface is intentionally internal to libc 97 */ 98 extern int getdents64(int, struct dirent64 *, size_t); 99 #endif 100 101 extern int _scrwidth(wchar_t); 102 103 extern int64_t __div64(int64_t, int64_t); 104 extern int64_t __rem64(int64_t, int64_t); 105 extern uint64_t __udiv64(uint64_t, uint64_t); 106 extern uint64_t __urem64(uint64_t, uint64_t); 107 extern int64_t __mul64(int64_t, int64_t); 108 extern uint64_t __umul64(uint64_t, uint64_t); 109 110 111 /* 112 * Rounding direction functions 113 */ 114 #if defined(__i386) || defined(__amd64) 115 extern enum fp_direction_type __xgetRD(void); 116 #elif defined(__sparc) 117 extern enum fp_direction_type _QgetRD(void); 118 #else 119 #error Unknown architecture! 120 #endif 121 122 /* 123 * defined in open.c 124 */ 125 extern int __open(const char *, int, mode_t); 126 extern int __open64(const char *, int, mode_t); 127 extern int __openat(int, const char *, int, mode_t); 128 extern int __openat64(int, const char *, int, mode_t); 129 130 /* 131 * defined in hex_bin.c 132 */ 133 extern void __hex_to_single(decimal_record *, enum fp_direction_type, 134 single *, fp_exception_field_type *); 135 extern void __hex_to_double(decimal_record *, enum fp_direction_type, 136 double *, fp_exception_field_type *); 137 #if defined(__sparc) 138 extern void __hex_to_quadruple(decimal_record *, enum fp_direction_type, 139 quadruple *, fp_exception_field_type *); 140 #elif defined(__i386) || defined(__amd64) 141 extern void __hex_to_extended(decimal_record *, enum fp_direction_type, 142 extended *, fp_exception_field_type *); 143 #else 144 #error Unknown architecture 145 #endif 146 147 /* 148 * defined in ctime.c 149 */ 150 extern char *__posix_asctime_r(const struct tm *, char *); 151 152 /* 153 * Internal routine from fsync.c 154 */ 155 extern int __fdsync(int, uint32_t); /* 2nd arg may be wrong in 64bit mode */ 156 157 /* 158 * Internal routine from _xregs_clrptr.c 159 */ 160 extern void _xregs_clrptr(ucontext_t *); 161 162 /* 163 * Internal routine from nfssys.c 164 */ 165 extern int _nfssys(int, void *); /* int in 64bit mode ???, void * ??? */ 166 167 /* 168 * Internal routine from psetsys.c 169 */ 170 extern int _pset(int, ...); /* int in 64bit mode ??? */ 171 172 /* 173 * defined in sigpending.s 174 */ 175 extern int __sigfillset(sigset_t *); 176 177 /* 178 * defined in sparc/fp/_Q_set_except.c and i386/fp/exception.c 179 */ 180 extern int _Q_set_exception(unsigned int); 181 182 /* 183 * defined in nsparse.c 184 */ 185 extern struct __nsw_switchconfig *_nsw_getoneconfig(const char *name, 186 char *linep, enum __nsw_parse_err *); 187 extern struct __nsw_switchconfig_v1 *_nsw_getoneconfig_v1(const char *name, 188 char *linep, enum __nsw_parse_err *); 189 190 /* 191 * Internal routine from getusershell.c 192 */ 193 extern char *getusershell(void); 194 195 /* 196 * defined in _sigaction.s 197 */ 198 extern int __sigaction(int, const struct sigaction *, struct sigaction *); 199 200 /* 201 * defined in siglongjmp.c 202 */ 203 extern void _siglongjmp(sigjmp_buf, int) __NORETURN; 204 205 /* 206 * defined in _getsp.s 207 */ 208 extern greg_t _getsp(void); 209 210 /* 211 * defined in _so_setsockopt.s 212 */ 213 extern int _so_setsockopt(int, int, int, const char *, int); 214 215 /* 216 * defined in _so_getsockopt.s 217 */ 218 extern int _so_getsockopt(int, int, int, char *, int *); 219 220 /* 221 * defined in lsign.s 222 */ 223 extern int lsign(dl_t); 224 225 /* 226 * defined in getctxt.c 227 */ 228 extern int _getcontext(ucontext_t *) __RETURNS_TWICE; 229 230 /* 231 * defined in ucontext.s 232 */ 233 extern int __getcontext(ucontext_t *); 234 extern int __getcontext_extd(ucontext_t *); 235 236 /* 237 * defined in door.s 238 */ 239 extern int __door_info(int, door_info_t *); 240 extern int __door_call(int, door_arg_t *); 241 242 /* 243 * defined in _portfs.s 244 */ 245 extern int64_t _portfs(int, uintptr_t, uintptr_t, uintptr_t, uintptr_t, 246 uintptr_t); 247 248 /* 249 * defined in xpg4.c 250 */ 251 extern int __xpg4; /* global */ 252 extern int libc__xpg4; /* copy of __xpg4, private to libc */ 253 254 /* 255 * defined in xpg6.c 256 */ 257 extern uint_t __xpg6; /* global */ 258 extern uint_t libc__xpg6; /* copy of __xpg6, private to libc */ 259 260 /* 261 * defined in port/stdio/doscan.c 262 */ 263 extern int _doscan(FILE *, const char *, va_list); 264 extern int __doscan_u(FILE *, const char *, va_list, int); 265 extern int __wdoscan_u(FILE *, const wchar_t *, va_list, int); 266 267 #ifndef _LP64 268 /* Flag for _ndoprnt() and _doscan_u() */ 269 #define _F_INTMAX32 0x1 /* if set read 4 bytes for u/intmax %j */ 270 extern int _fprintf_c89(FILE *, const char *, ...); 271 extern int _printf_c89(const char *, ...); 272 extern int _snprintf_c89(char *, size_t, const char *, ...); 273 extern int _sprintf_c89(char *, const char *, ...); 274 extern int _wprintf_c89(const wchar_t *, ...); 275 extern int _fwprintf_c89(FILE *, const wchar_t *, ...); 276 extern int _swprintf_c89(wchar_t *, size_t, const wchar_t *, ...); 277 extern int _vfprintf_c89(FILE *, const char *, va_list); 278 extern int _vprintf_c89(const char *, va_list); 279 extern int _vsnprintf_c89(char *, size_t, const char *, va_list); 280 extern int _vsprintf_c89(char *, const char *, va_list); 281 extern int _vwprintf_c89(const wchar_t *, va_list); 282 extern int _vfwprintf_c89(FILE *, const wchar_t *, va_list); 283 extern int _vswprintf_c89(wchar_t *, size_t, const wchar_t *, va_list); 284 extern int _scanf_c89(const char *, ...); 285 extern int _fscanf_c89(FILE *, const char *, ...); 286 extern int _sscanf_c89(const char *, const char *, ...); 287 extern int _vscanf_c89(const char *, va_list); 288 extern int _vfscanf_c89(FILE *, const char *, va_list); 289 extern int _vsscanf_c89(const char *, const char *, va_list); 290 extern int _vwscanf_c89(const wchar_t *, va_list); 291 extern int _vfwscanf_c89(FILE *, const wchar_t *, va_list); 292 extern int _vswscanf_c89(const wchar_t *, const wchar_t *, va_list); 293 extern int _wscanf_c89(const wchar_t *, ...); 294 extern int _fwscanf_c89(FILE *, const wchar_t *, ...); 295 extern int _swscanf_c89(const wchar_t *, const wchar_t *, ...); 296 #endif /* _LP64 */ 297 298 /* 299 * defined in port/stdio/popen.c 300 */ 301 extern int _insert(pid_t pid, int fd); 302 extern pid_t _delete(int fd); 303 304 /* 305 * defined in port/print/doprnt.c 306 */ 307 extern ssize_t _wdoprnt(const wchar_t *, va_list, FILE *); 308 309 /* 310 * defined in fgetwc.c 311 */ 312 extern wint_t _fgetwc_unlocked(FILE *); 313 extern wint_t __getwc_xpg5(FILE *); 314 extern wint_t __fgetwc_xpg5(FILE *); 315 extern wint_t _getwc(FILE *); 316 317 /* 318 * defined in fputwc.c 319 */ 320 extern wint_t __putwc_xpg5(wint_t, FILE *); 321 extern wint_t _putwc(wint_t, FILE *); 322 323 /* 324 * defined in ungetwc.c 325 */ 326 extern wint_t __ungetwc_xpg5(wint_t, FILE *); 327 328 /* 329 * Defined in setlocale.c. 330 */ 331 extern char *current_locale(locale_t, int); 332 333 /* 334 * defined in set_constraint_handler_s.c. 335 */ 336 extern void __throw_constraint_handler_s(const char *_RESTRICT_KYWD, int); 337 338 /* 339 * defined in assfail.c. 340 * 341 * the implementation of these functions in libc will never return 342 * 343 * HOWEVER, some compilers will generate code that exhibits undefined 344 * control flow behavor (returns to non-instructions) for calls to a 345 * function declared __NORETURN that actually does return; moreover, there 346 * are alternate implementations of assfail and assfail3 in the gate which 347 * will return under certain circumstances. 348 */ 349 extern void common_panic(const char *, const char *) __NORETURN; 350 extern void assfail(const char *, const char *, int); 351 extern void _assfail(const char *, const char *, int) __NORETURN; 352 extern void __assfail(const char *, const char *, int) __NORETURN; 353 extern void assfail3(const char *, uintmax_t, const char *, 354 uintmax_t, const char *, int); 355 356 /* 357 * defined in mbrtowc.c. 358 */ 359 extern size_t mbrtowc_nz_l(wchar_t *_RESTRICT_KYWD, const char *_RESTRICT_KYWD, 360 size_t, mbstate_t *_RESTRICT_KYWD, locale_t); 361 extern size_t mbrtowc_nz(wchar_t *_RESTRICT_KYWD, const char *_RESTRICT_KYWD, 362 size_t, mbstate_t *_RESTRICT_KYWD); 363 364 /* 365 * defined in getauxv.c. 366 */ 367 extern long ___getauxval(int); 368 extern void *___getauxptr(int); 369 370 #ifdef __cplusplus 371 } 372 #endif 373 374 #endif /* _LIBC_H */ 375