Skip to content

Commit

Permalink
Rework and simplify the ksyms(4) implementation.
Browse files Browse the repository at this point in the history
- Store the symbol table contents in an anonymous swap-backed object. Have
  mmap(/dev/ksyms) map that object, and stop mapping the symbol table into
  the calling process in ksyms_open(). Previously we would cache a pointer
  to the pmap of the opening process, and mmap(/dev/ksyms) would create a
  mapping using the physical address found by a pmap lookup at the initial
  mapping address. However, this assumes that the cached pmap is valid,
  which may not be the case. [1]
- Remove the ksyms ioctl interface. It appears to have been added to work
  around a limitation in libelf that no longer exists; see r321842.
  Moreover, the interface is difficult to support and isn't present in
  illumos. Since ksyms was added specifically to support lockstat(1), it
  is expected that this removal won't have any real impact.
- Simplify ksyms_read() to avoid unnecessary copying.
- Don't call the device handle destructor if we fail to capture a snapshot
  of the kernel's symbol table. devfs will do that for us.

Reported by:	Ilja van Sprundel <[email protected]> [1]
Reviewed by:	kib (previous revision)
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D11789
  • Loading branch information
markjdb committed Aug 3, 2017
1 parent baa75b8 commit 09b1c6f
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 239 deletions.
3 changes: 3 additions & 0 deletions ObsoleteFiles.inc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
# xargs -n1 | sort | uniq -d;
# done

# 20170802: ksyms(4) ioctl interface was removed
OLD_FILES+=usr/include/sys/ksyms.h

# 20170722: new clang import which bumps version from 4.0.0 to 5.0.0.
OLD_FILES+=usr/lib/clang/4.0.0/include/sanitizer/allocator_interface.h
OLD_FILES+=usr/lib/clang/4.0.0/include/sanitizer/asan_interface.h
Expand Down
1 change: 0 additions & 1 deletion cddl/contrib/opensolaris/cmd/lockstat/sym.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
#include <kstat.h>
#else
#include <sys/elf.h>
#include <sys/ksyms.h>
#include <sys/param.h>
#include <sys/module.h>
#include <sys/linker.h>
Expand Down
30 changes: 1 addition & 29 deletions share/man/man4/ksyms.4
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
.\"
.\" $FreeBSD$
.\"
.Dd April 5, 2009
.Dd August 2, 2017
.Dt KSYMS 4
.Os
.Sh NAME
Expand Down Expand Up @@ -69,24 +69,6 @@ driver does not block the loading or unloading of modules into the kernel
while the
.Pa /dev/ksyms
file is open but may contain stale data.
.Sh IOCTLS
The
.Xr ioctl 2
command codes below are defined in
.Aq Pa sys/ksyms.h .
.Pp
The (third) argument to the
.Xr ioctl 2
should be a pointer to the type indicated.
.Bl -tag -width indent -offset indent
.It Dv KIOCGSIZE (size_t)
Returns the total size of the current symbol table.
This can be used when allocating a buffer to make a copy of
the kernel symbol table.
.It Dv KIOCGADDR (void *)
Returns the address of the kernel symbol table mapped in
the process memory.
.El
.Sh FILES
.Bl -tag -width /dev/ksymsX
.It Pa /dev/ksyms
Expand All @@ -112,7 +94,6 @@ This may occur if the kernel was in the process of loading or
unloading a module.
.El
.Sh SEE ALSO
.Xr ioctl 2 ,
.Xr nlist 3 ,
.Xr elf 5 ,
.Xr kldload 8
Expand Down Expand Up @@ -152,12 +133,3 @@ file once at a time.
The process must close the
.Pa /dev/ksyms
before it is allowed to open it again.
.Pp
The
.Nm
driver uses the calling process' memory address space to store the snapshot.
.Xr ioctl 2
can be used to get the memory address where the symbol table is stored to
save kernel memory.
.Xr mmap 2
may also be used but it will map it to another address.
Loading

0 comments on commit 09b1c6f

Please sign in to comment.