summaryrefslogtreecommitdiffstats
path: root/sys/sys/user.h
diff options
context:
space:
mode:
authorpeter <peter@FreeBSD.org>2008-12-02 06:50:26 +0000
committerpeter <peter@FreeBSD.org>2008-12-02 06:50:26 +0000
commit76037b082e725faf10083e8fe83315236781569b (patch)
tree5a4b696f7bcc8472ff22e36ac8044ca39efcc17b /sys/sys/user.h
parentfd1b5dd075223f114ecc0f3bb7c016032a129bc5 (diff)
parent0cd59a18e366e541876a23e59b53ce6246f0cec8 (diff)
downloadFreeBSD-src-76037b082e725faf10083e8fe83315236781569b.zip
FreeBSD-src-76037b082e725faf10083e8fe83315236781569b.tar.gz
Merge user/peter/kinfo branch as of r185547 into head.
This changes struct kinfo_filedesc and kinfo_vmentry such that they are same on both 32 and 64 bit platforms like i386/amd64 and won't require sysctl wrapping. Two new OIDs are assigned. The old ones are available under COMPAT_FREEBSD7 - but it isn't that simple. The superceded interface was never actually released on 7.x. The other main change is to pack the data passed to userland via the sysctl. kf_structsize and kve_structsize are reduced for the copyout. If you have a process with 100,000+ sockets open, the unpacked records require a 132MB+ copyout. With packing, it is "only" ~35MB. (Still seriously unpleasant, but not quite as devastating). A similar problem exists for the vmentry structure - have lots and lots of shared libraries and small mmaps and its copyout gets expensive too. My immediate problem is valgrind. It traditionally achieves this functionality by parsing procfs output, in a packed format. Secondly, when tracing 32 bit binaries on amd64 under valgrind, it uses a cross compiled 32 bit binary which ran directly into the differing data structures in 32 vs 64 bit mode. (valgrind uses this to track file descriptor operations and this therefore affected every single 32 bit binary) I've added two utility functions to libutil to unpack the structures into a fixed record length and to make it a little more convenient to use.
Diffstat (limited to 'sys/sys/user.h')
-rw-r--r--sys/sys/user.h85
1 files changed, 77 insertions, 8 deletions
diff --git a/sys/sys/user.h b/sys/sys/user.h
index a12669f..93a78d3 100644
--- a/sys/sys/user.h
+++ b/sys/sys/user.h
@@ -277,20 +277,55 @@ struct user {
#define KF_FLAG_DIRECT 0x00000040
#define KF_FLAG_HASLOCK 0x00000080
-struct kinfo_file {
+/*
+ * Old format. Has variable hidden padding due to alignment.
+ * This is a compatability hack for pre-build 7.1 packages.
+ */
+#if defined(__amd64__)
+#define KINFO_OFILE_SIZE 1328
+#endif
+#if defined(__i386__)
+#define KINFO_OFILE_SIZE 1324
+#endif
+
+struct kinfo_ofile {
int kf_structsize; /* Size of kinfo_file. */
int kf_type; /* Descriptor type. */
int kf_fd; /* Array index. */
int kf_ref_count; /* Reference count. */
int kf_flags; /* Flags. */
+ /* XXX Hidden alignment padding here on amd64 */
off_t kf_offset; /* Seek location. */
int kf_vnode_type; /* Vnode type. */
int kf_sock_domain; /* Socket domain. */
int kf_sock_type; /* Socket type. */
int kf_sock_protocol; /* Socket protocol. */
- char kf_path[PATH_MAX]; /* Path to file, if any. */
+ char kf_path[PATH_MAX]; /* Path to file, if any. */
+ struct sockaddr_storage kf_sa_local; /* Socket address. */
+ struct sockaddr_storage kf_sa_peer; /* Peer address. */
+};
+
+#if defined(__amd64__) || defined(__i386__)
+#define KINFO_FILE_SIZE 1392
+#endif
+
+struct kinfo_file {
+ int kf_structsize; /* Variable size of record. */
+ int kf_type; /* Descriptor type. */
+ int kf_fd; /* Array index. */
+ int kf_ref_count; /* Reference count. */
+ int kf_flags; /* Flags. */
+ int _kf_pad0; /* Round to 64 bit alignment */
+ uint64_t kf_offset; /* Seek location. */
+ int kf_vnode_type; /* Vnode type. */
+ int kf_sock_domain; /* Socket domain. */
+ int kf_sock_type; /* Socket type. */
+ int kf_sock_protocol; /* Socket protocol. */
struct sockaddr_storage kf_sa_local; /* Socket address. */
struct sockaddr_storage kf_sa_peer; /* Peer address. */
+ int _kf_ispare[16]; /* Space for more stuff. */
+ /* Truncated before copyout in sysctl */
+ char kf_path[PATH_MAX]; /* Path to file, if any. */
};
/*
@@ -313,11 +348,18 @@ struct kinfo_file {
#define KVME_FLAG_COW 0x00000001
#define KVME_FLAG_NEEDS_COPY 0x00000002
-struct kinfo_vmentry {
+#if defined(__amd64__)
+#define KINFO_OVMENTRY_SIZE 1168
+#endif
+#if defined(__i386__)
+#define KINFO_OVMENTRY_SIZE 1128
+#endif
+
+struct kinfo_ovmentry {
int kve_structsize; /* Size of kinfo_vmmapentry. */
int kve_type; /* Type of map entry. */
- void *kve_start; /* Starting pointer. */
- void *kve_end; /* Finishing pointer. */
+ void *kve_start; /* Starting address. */
+ void *kve_end; /* Finishing address. */
int kve_flags; /* Flags on map entry. */
int kve_resident; /* Number of resident pages. */
int kve_private_resident; /* Number of private pages. */
@@ -327,11 +369,35 @@ struct kinfo_vmentry {
char kve_path[PATH_MAX]; /* Path to VM obj, if any. */
void *_kve_pspare[8]; /* Space for more stuff. */
off_t kve_offset; /* Mapping offset in object */
- uint64_t kve_fileid; /* inode number of vnode */
+ uint64_t kve_fileid; /* inode number if vnode */
dev_t kve_fsid; /* dev_t of vnode location */
int _kve_ispare[3]; /* Space for more stuff. */
};
+#if defined(__amd64__) || defined(__i386__)
+#define KINFO_VMENTRY_SIZE 1160
+#endif
+
+struct kinfo_vmentry {
+ int kve_structsize; /* Variable size of record. */
+ int kve_type; /* Type of map entry. */
+ uint64_t kve_start; /* Starting address. */
+ uint64_t kve_end; /* Finishing address. */
+ uint64_t kve_offset; /* Mapping offset in object */
+ uint64_t kve_fileid; /* inode number if vnode */
+ uint32_t kve_fsid; /* dev_t of vnode location */
+ int kve_flags; /* Flags on map entry. */
+ int kve_resident; /* Number of resident pages. */
+ int kve_private_resident; /* Number of private pages. */
+ int kve_protection; /* Protection bitmask. */
+ int kve_ref_count; /* VM obj ref count. */
+ int kve_shadow_count; /* VM obj shadow count. */
+ int _kve_pad0; /* 64bit align next field */
+ int _kve_ispare[16]; /* Space for more stuff. */
+ /* Truncated before copyout in sysctl */
+ char kve_path[PATH_MAX]; /* Path to VM obj, if any. */
+};
+
/*
* The KERN_PROC_KSTACK sysctl allows a process to dump the kernel stacks of
* another process as a series of entries. Each stack is represented by a
@@ -343,12 +409,15 @@ struct kinfo_vmentry {
#define KKST_STATE_SWAPPED 1 /* Stack swapped out. */
#define KKST_STATE_RUNNING 2 /* Stack ephemeral. */
+#if defined(__amd64__) || defined(__i386__)
+#define KINFO_KSTACK_SIZE 1096
+#endif
+
struct kinfo_kstack {
lwpid_t kkst_tid; /* ID of thread. */
int kkst_state; /* Validity of stack. */
char kkst_trace[KKST_MAXLEN]; /* String representing stack. */
- void *_kkst_pspare[8]; /* Space for more stuff. */
- int _kkst_ispare[8]; /* Space for more stuff. */
+ int _kkst_ispare[16]; /* Space for more stuff. */
};
#endif
OpenPOWER on IntegriCloud