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