1 /* $NetBSD: kern_info_43.c,v 1.32.8.2 2008/11/01 21:22:25 christos Exp $ */
4 * Copyright (c) 1982, 1986, 1991, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * @(#)subr_xxx.c 8.1 (Berkeley) 6/10/93
34 #include <sys/cdefs.h>
35 __KERNEL_RCSID(0, "$NetBSD: kern_info_43.c,v 1.32.8.2 2008/11/01 21:22:25 christos Exp $");
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/filedesc.h>
40 #include <sys/kernel.h>
41 #include <sys/vnode.h>
44 #include <sys/socket.h>
45 #include <sys/socketvar.h>
47 #include <sys/ioctl.h>
48 #include <sys/fcntl.h>
49 #include <sys/syslog.h>
50 #include <sys/unistd.h>
51 #include <sys/resourcevar.h>
52 #include <sys/kauth.h>
54 #include <uvm/uvm_extern.h>
55 #include <sys/sysctl.h>
57 #include <sys/mount.h>
58 #include <sys/syscallargs.h>
59 #include <compat/sys/time.h>
62 compat_43_sys_getdtablesize(struct lwp
*l
, const void *v
, register_t
*retval
)
64 struct proc
*p
= l
->l_proc
;
66 mutex_enter(p
->p_lock
);
67 *retval
= min((int)p
->p_rlimit
[RLIMIT_NOFILE
].rlim_cur
, maxfiles
);
68 mutex_exit(p
->p_lock
);
75 compat_43_sys_gethostid(struct lwp
*l
, const void *v
, register_t
*retval
)
78 *(int32_t *)retval
= hostid
;
85 compat_43_sys_gethostname(struct lwp
*l
, const struct compat_43_sys_gethostname_args
*uap
, register_t
*retval
)
88 syscallarg(char *) hostname;
89 syscallarg(u_int) len;
95 name
[1] = KERN_HOSTNAME
;
97 return (old_sysctl(&name
[0], 2, SCARG(uap
, hostname
), &sz
, 0, 0, l
));
100 #define KINFO_PROC (0<<8)
101 #define KINFO_RT (1<<8)
102 #define KINFO_VNODE (2<<8)
103 #define KINFO_FILE (3<<8)
104 #define KINFO_METER (4<<8)
105 #define KINFO_LOADAVG (5<<8)
106 #define KINFO_CLOCKRATE (6<<8)
107 #define KINFO_BSDI_SYSINFO (101<<8)
111 * The string data is appended to the end of the bsdi_si structure during
112 * copyout. The "char *" offsets in the bsdi_si struct are relative to the
113 * base of the bsdi_si struct.
138 struct timeval50 boottime
;
143 compat_43_sys_getkerninfo(struct lwp
*l
, const struct compat_43_sys_getkerninfo_args
*uap
, register_t
*retval
)
147 syscallarg(char *) where;
148 syscallarg(int *) size;
154 if (SCARG(uap
, size
) && (error
= copyin((void *)SCARG(uap
, size
),
155 (void *)&size
, sizeof(size
))))
158 switch (SCARG(uap
, op
) & 0xff00) {
164 name
[3] = (SCARG(uap
, op
) & 0xff0000) >> 16;
165 name
[4] = SCARG(uap
, op
) & 0xff;
166 name
[5] = SCARG(uap
, arg
);
167 error
= old_sysctl(&name
[0], 6, SCARG(uap
, where
), &size
,
173 name
[1] = KERN_VNODE
;
174 error
= old_sysctl(&name
[0], 2, SCARG(uap
, where
), &size
,
181 name
[2] = SCARG(uap
, op
) & 0xff;
182 name
[3] = SCARG(uap
, arg
);
183 error
= old_sysctl(&name
[0], 4, SCARG(uap
, where
), &size
,
190 error
= old_sysctl(&name
[0], 2, SCARG(uap
, where
), &size
,
197 error
= old_sysctl(&name
[0], 2, SCARG(uap
, where
), &size
,
203 name
[1] = VM_LOADAVG
;
204 error
= old_sysctl(&name
[0], 2, SCARG(uap
, where
), &size
,
208 case KINFO_CLOCKRATE
:
210 name
[1] = KERN_CLOCKRATE
;
211 error
= old_sysctl(&name
[0], 2, SCARG(uap
, where
), &size
,
216 case KINFO_BSDI_SYSINFO
:
219 struct bsdi_si
*usi
=
220 (struct bsdi_si
*) SCARG(uap
, where
);
223 char *us
= (char *) &usi
[1];
227 strlen(ostype
) + strlen(cpu_model
) +
228 strlen(osrelease
) + strlen(machine
) +
229 strlen(version
) + strlen(hostname
) + 6;
235 ksi.fld = us - (u_long) usi; \
236 if ((error = copyoutstr(fld, us, 1024, &len)) != 0)\
242 ksi
.ncpu
= ncpu
; /* XXX */
243 ksi
.cpuspeed
= 40; /* XXX */
244 ksi
.hwflags
= 0; /* XXX */
245 ksi
.physmem
= ctob(physmem
);
246 ksi
.usermem
= ctob(physmem
); /* XXX */
247 ksi
.pagesize
= PAGE_SIZE
;
251 ksi
.os_revision
= NetBSD
; /* XXX */
252 ksi
.posix1_version
= _POSIX_VERSION
;
253 COPY(version
); /* XXX */
257 ksi
.ngroups_max
= NGROUPS_MAX
;
258 ksi
.arg_max
= ARG_MAX
;
259 ksi
.open_max
= OPEN_MAX
;
260 ksi
.child_max
= CHILD_MAX
;
262 TIMESPEC_TO_TIMEVAL(&tv
, &boottime
);
263 timeval_to_timeval50(&tv
, &ksi
.boottime
);
266 size
= (us
- (char *) &usi
[1]) + sizeof(ksi
);
268 if ((error
= copyout(&ksi
, usi
, sizeof(ksi
))) != 0)
279 if (SCARG(uap
, size
))
280 error
= copyout((void *)&size
, (void *)SCARG(uap
, size
),
288 compat_43_sys_sethostid(struct lwp
*l
, const struct compat_43_sys_sethostid_args
*uap
, register_t
*retval
)
293 uhostid
= SCARG(uap
, hostid
);
295 name
[1] = KERN_HOSTID
;
297 return (old_sysctl(&name
[0], 2, 0, 0, &uhostid
, sizeof(long), l
));
303 compat_43_sys_sethostname(struct lwp
*l
, const struct compat_43_sys_sethostname_args
*uap
, register_t
*retval
)
308 name
[1] = KERN_HOSTNAME
;
309 return (old_sysctl(&name
[0], 2, 0, 0, SCARG(uap
, hostname
),
310 SCARG(uap
, len
), l
));