svn commit: r220378 - in stable/8/sys: compat/freebsd32 kern sys
Konstantin Belousov
kib at FreeBSD.org
Wed Apr 6 11:12:06 UTC 2011
Author: kib
Date: Wed Apr 6 11:12:05 2011
New Revision: 220378
URL: http://svn.freebsd.org/changeset/base/220378
Log:
MFC r220158:
Provide compat32 shims for kldstat(2).
Modified:
stable/8/sys/compat/freebsd32/freebsd32.h
stable/8/sys/compat/freebsd32/freebsd32_misc.c
stable/8/sys/compat/freebsd32/syscalls.master
stable/8/sys/kern/kern_linker.c
stable/8/sys/sys/syscallsubr.h
Directory Properties:
stable/8/sys/ (props changed)
stable/8/sys/amd64/include/xen/ (props changed)
stable/8/sys/cddl/contrib/opensolaris/ (props changed)
stable/8/sys/contrib/dev/acpica/ (props changed)
stable/8/sys/contrib/pf/ (props changed)
Modified: stable/8/sys/compat/freebsd32/freebsd32.h
==============================================================================
--- stable/8/sys/compat/freebsd32/freebsd32.h Tue Apr 5 22:13:33 2011 (r220377)
+++ stable/8/sys/compat/freebsd32/freebsd32.h Wed Apr 6 11:12:05 2011 (r220378)
@@ -335,4 +335,23 @@ struct kinfo_proc32 {
int ki_tdflags;
};
+struct kld32_file_stat_1 {
+ int version; /* set to sizeof(struct kld_file_stat_1) */
+ char name[MAXPATHLEN];
+ int refs;
+ int id;
+ uint32_t address; /* load address */
+ uint32_t size; /* size in bytes */
+};
+
+struct kld32_file_stat {
+ int version; /* set to sizeof(struct kld_file_stat) */
+ char name[MAXPATHLEN];
+ int refs;
+ int id;
+ uint32_t address; /* load address */
+ uint32_t size; /* size in bytes */
+ char pathname[MAXPATHLEN];
+};
+
#endif /* !_COMPAT_FREEBSD32_FREEBSD32_H_ */
Modified: stable/8/sys/compat/freebsd32/freebsd32_misc.c
==============================================================================
--- stable/8/sys/compat/freebsd32/freebsd32_misc.c Tue Apr 5 22:13:33 2011 (r220377)
+++ stable/8/sys/compat/freebsd32/freebsd32_misc.c Wed Apr 6 11:12:05 2011 (r220378)
@@ -43,6 +43,7 @@ __FBSDID("$FreeBSD$");
#include <sys/jail.h>
#include <sys/kernel.h>
#include <sys/limits.h>
+#include <sys/linker.h>
#include <sys/lock.h>
#include <sys/malloc.h>
#include <sys/file.h> /* Must come after sys/malloc.h */
@@ -2645,3 +2646,29 @@ freebsd32_copyout_strings(struct image_p
return ((register_t *)stack_base);
}
+int
+freebsd32_kldstat(struct thread *td, struct freebsd32_kldstat_args *uap)
+{
+ struct kld_file_stat stat;
+ struct kld32_file_stat stat32;
+ int error, version;
+
+ if ((error = copyin(&uap->stat->version, &version, sizeof(version)))
+ != 0)
+ return (error);
+ if (version != sizeof(struct kld32_file_stat_1) &&
+ version != sizeof(struct kld32_file_stat))
+ return (EINVAL);
+
+ error = kern_kldstat(td, uap->fileid, &stat);
+ if (error != 0)
+ return (error);
+
+ bcopy(&stat.name[0], &stat32.name[0], sizeof(stat.name));
+ CP(stat, stat32, refs);
+ CP(stat, stat32, id);
+ PTROUT_CP(stat, stat32, address);
+ CP(stat, stat32, size);
+ bcopy(&stat.pathname[0], &stat32.pathname[0], sizeof(stat.pathname));
+ return (copyout(&stat32, uap->stat, version));
+}
Modified: stable/8/sys/compat/freebsd32/syscalls.master
==============================================================================
--- stable/8/sys/compat/freebsd32/syscalls.master Tue Apr 5 22:13:33 2011 (r220377)
+++ stable/8/sys/compat/freebsd32/syscalls.master Wed Apr 6 11:12:05 2011 (r220378)
@@ -534,8 +534,8 @@
305 AUE_MODUNLOAD NOPROTO { int kldunload(int fileid); }
306 AUE_NULL NOPROTO { int kldfind(const char *file); }
307 AUE_NULL NOPROTO { int kldnext(int fileid); }
-308 AUE_NULL NOPROTO { int kldstat(int fileid, \
- struct kld_file_stat* stat); }
+308 AUE_NULL STD { int freebsd32_kldstat(int fileid, \
+ struct kld32_file_stat* stat); }
309 AUE_NULL NOPROTO { int kldfirstmod(int fileid); }
310 AUE_GETSID NOPROTO { int getsid(pid_t pid); }
311 AUE_SETRESUID NOPROTO { int setresuid(uid_t ruid, uid_t euid, \
Modified: stable/8/sys/kern/kern_linker.c
==============================================================================
--- stable/8/sys/kern/kern_linker.c Tue Apr 5 22:13:33 2011 (r220377)
+++ stable/8/sys/kern/kern_linker.c Wed Apr 6 11:12:05 2011 (r220378)
@@ -1196,29 +1196,39 @@ int
kldstat(struct thread *td, struct kldstat_args *uap)
{
struct kld_file_stat stat;
- linker_file_t lf;
- int error, namelen, version, version_num;
+ int error, version;
/*
* Check the version of the user's structure.
*/
- if ((error = copyin(&uap->stat->version, &version, sizeof(version))) != 0)
+ if ((error = copyin(&uap->stat->version, &version, sizeof(version)))
+ != 0)
return (error);
- if (version == sizeof(struct kld_file_stat_1))
- version_num = 1;
- else if (version == sizeof(struct kld_file_stat))
- version_num = 2;
- else
+ if (version != sizeof(struct kld_file_stat_1) &&
+ version != sizeof(struct kld_file_stat))
return (EINVAL);
+ error = kern_kldstat(td, uap->fileid, &stat);
+ if (error != 0)
+ return (error);
+ return (copyout(&stat, uap->stat, version));
+}
+
+int
+kern_kldstat(struct thread *td, int fileid, struct kld_file_stat *stat)
+{
+ linker_file_t lf;
+ int namelen;
#ifdef MAC
+ int error;
+
error = mac_kld_check_stat(td->td_ucred);
if (error)
return (error);
#endif
KLD_LOCK();
- lf = linker_find_file_by_id(uap->fileid);
+ lf = linker_find_file_by_id(fileid);
if (lf == NULL) {
KLD_UNLOCK();
return (ENOENT);
@@ -1228,23 +1238,20 @@ kldstat(struct thread *td, struct kldsta
namelen = strlen(lf->filename) + 1;
if (namelen > MAXPATHLEN)
namelen = MAXPATHLEN;
- bcopy(lf->filename, &stat.name[0], namelen);
- stat.refs = lf->refs;
- stat.id = lf->id;
- stat.address = lf->address;
- stat.size = lf->size;
- if (version_num > 1) {
- /* Version 2 fields: */
- namelen = strlen(lf->pathname) + 1;
- if (namelen > MAXPATHLEN)
- namelen = MAXPATHLEN;
- bcopy(lf->pathname, &stat.pathname[0], namelen);
- }
+ bcopy(lf->filename, &stat->name[0], namelen);
+ stat->refs = lf->refs;
+ stat->id = lf->id;
+ stat->address = lf->address;
+ stat->size = lf->size;
+ /* Version 2 fields: */
+ namelen = strlen(lf->pathname) + 1;
+ if (namelen > MAXPATHLEN)
+ namelen = MAXPATHLEN;
+ bcopy(lf->pathname, &stat->pathname[0], namelen);
KLD_UNLOCK();
td->td_retval[0] = 0;
-
- return (copyout(&stat, uap->stat, version));
+ return (0);
}
int
Modified: stable/8/sys/sys/syscallsubr.h
==============================================================================
--- stable/8/sys/sys/syscallsubr.h Tue Apr 5 22:13:33 2011 (r220377)
+++ stable/8/sys/sys/syscallsubr.h Wed Apr 6 11:12:05 2011 (r220378)
@@ -48,6 +48,7 @@ struct sockaddr;
struct stat;
struct kevent;
struct kevent_copyops;
+struct kld_file_stat;
struct sendfile_args;
struct thr_param;
@@ -112,6 +113,7 @@ int kern_jail_set(struct thread *td, str
int kern_kevent(struct thread *td, int fd, int nchanges, int nevents,
struct kevent_copyops *k_ops, const struct timespec *timeout);
int kern_kldload(struct thread *td, const char *file, int *fileid);
+int kern_kldstat(struct thread *td, int fileid, struct kld_file_stat *stat);
int kern_kldunload(struct thread *td, int fileid, int flags);
int kern_lchown(struct thread *td, char *path, enum uio_seg pathseg,
int uid, int gid);
More information about the svn-src-stable
mailing list