HardenedBSD/lib/libprocstat/libprocstat_compat.c

145 lines
4.4 KiB
C
Raw Normal View History

Commit the 64-bit inode project. Extend the ino_t, dev_t, nlink_t types to 64-bit ints. Modify struct dirent layout to add d_off, increase the size of d_fileno to 64-bits, increase the size of d_namlen to 16-bits, and change the required alignment. Increase struct statfs f_mntfromname[] and f_mntonname[] array length MNAMELEN to 1024. ABI breakage is mitigated by providing compatibility using versioned symbols, ingenious use of the existing padding in structures, and by employing other tricks. Unfortunately, not everything can be fixed, especially outside the base system. For instance, third-party APIs which pass struct stat around are broken in backward and forward incompatible ways. Kinfo sysctl MIBs ABI is changed in backward-compatible way, but there is no general mechanism to handle other sysctl MIBS which return structures where the layout has changed. It was considered that the breakage is either in the management interfaces, where we usually allow ABI slip, or is not important. Struct xvnode changed layout, no compat shims are provided. For struct xtty, dev_t tty device member was reduced to uint32_t. It was decided that keeping ABI compat in this case is more useful than reporting 64-bit dev_t, for the sake of pstat. Update note: strictly follow the instructions in UPDATING. Build and install the new kernel with COMPAT_FREEBSD11 option enabled, then reboot, and only then install new world. Credits: The 64-bit inode project, also known as ino64, started life many years ago as a project by Gleb Kurtsou (gleb). Kirk McKusick (mckusick) then picked up and updated the patch, and acted as a flag-waver. Feedback, suggestions, and discussions were carried by Ed Maste (emaste), John Baldwin (jhb), Jilles Tjoelker (jilles), and Rick Macklem (rmacklem). Kris Moore (kris) performed an initial ports investigation followed by an exp-run by Antoine Brodin (antoine). Essential and all-embracing testing was done by Peter Holm (pho). The heavy lifting of coordinating all these efforts and bringing the project to completion were done by Konstantin Belousov (kib). Sponsored by: The FreeBSD Foundation (emaste, kib) Differential revision: https://reviews.freebsd.org/D10439
2017-05-23 11:29:05 +02:00
/*-
* Copyright (c) 2014 Gleb Kurtsou <gleb@FreeBSD.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/user.h>
#include <sys/socket.h>
#include <string.h>
#include "libprocstat.h"
struct freebsd11_ptsstat {
uint32_t dev;
char devname[SPECNAMELEN + 1];
};
struct freebsd11_vnstat {
uint64_t vn_fileid;
uint64_t vn_size;
char *vn_mntdir;
uint32_t vn_dev;
uint32_t vn_fsid;
int vn_type;
uint16_t vn_mode;
char vn_devname[SPECNAMELEN + 1];
};
struct freebsd11_semstat {
uint32_t value;
uint16_t mode;
};
struct freebsd11_shmstat {
uint64_t size;
uint16_t mode;
};
int freebsd11_procstat_get_pts_info(struct procstat *procstat,
struct filestat *fst, struct freebsd11_ptsstat *pts, char *errbuf);
int freebsd11_procstat_get_sem_info(struct procstat *procstat,
struct filestat *fst, struct freebsd11_semstat *sem, char *errbuf);
int freebsd11_procstat_get_shm_info(struct procstat *procstat,
struct filestat *fst, struct freebsd11_shmstat *shm, char *errbuf);
int freebsd11_procstat_get_vnode_info(struct procstat *procstat,
struct filestat *fst, struct freebsd11_vnstat *vn, char *errbuf);
int
freebsd11_procstat_get_pts_info(struct procstat *procstat,
struct filestat *fst, struct freebsd11_ptsstat *pts_compat, char *errbuf)
{
struct ptsstat pts;
int r;
r = procstat_get_pts_info(procstat, fst, &pts, errbuf);
if (r != 0)
return (r);
pts_compat->dev = pts.dev;
memcpy(pts_compat->devname, pts.devname,
sizeof(pts_compat->devname));
return (0);
}
int
freebsd11_procstat_get_sem_info(struct procstat *procstat,
struct filestat *fst, struct freebsd11_semstat *sem_compat, char *errbuf)
{
struct semstat sem;
int r;
r = procstat_get_sem_info(procstat, fst, &sem, errbuf);
if (r != 0)
return (r);
sem_compat->value = sem.value;
sem_compat->mode = sem.mode;
return (0);
}
int
freebsd11_procstat_get_shm_info(struct procstat *procstat,
struct filestat *fst, struct freebsd11_shmstat *shm_compat, char *errbuf)
{
struct shmstat shm;
int r;
r = procstat_get_shm_info(procstat, fst, &shm, errbuf);
if (r != 0)
return (r);
shm_compat->size = shm.size;
shm_compat->mode = shm.mode;
return (0);
}
int
freebsd11_procstat_get_vnode_info(struct procstat *procstat,
struct filestat *fst, struct freebsd11_vnstat *vn_compat, char *errbuf)
{
struct vnstat vn;
int r;
r = procstat_get_vnode_info(procstat, fst, &vn, errbuf);
if (r != 0)
return (r);
vn_compat->vn_fileid = vn.vn_fileid;
vn_compat->vn_size = vn.vn_size;
vn_compat->vn_mntdir = vn.vn_mntdir;
vn_compat->vn_dev = vn.vn_dev;
vn_compat->vn_fsid = vn.vn_fsid;
vn_compat->vn_type = vn.vn_type;
vn_compat->vn_mode = vn.vn_mode;
memcpy(vn_compat->vn_devname, vn.vn_devname,
sizeof(vn_compat->vn_devname));
return (0);
}
__sym_compat(procstat_get_pts_info, freebsd11_procstat_get_pts_info, FBSD_1.2);
__sym_compat(procstat_get_vnode_info, freebsd11_procstat_get_vnode_info,
FBSD_1.2);
__sym_compat(procstat_get_sem_info, freebsd11_procstat_get_sem_info, FBSD_1.3);
__sym_compat(procstat_get_shm_info, freebsd11_procstat_get_shm_info, FBSD_1.3);