Home | History | Annotate | Download | only in netbsd32
History log of /src/sys/compat/netbsd32/netbsd32_ioctl.c
RevisionDateAuthorComments
 1.122  10-Nov-2024  riastradh netbsd32_ioctl: Use fd_set_exclose instead of open-coding it.

No functional change intended -- this just reduces unnecessary
copies of open-coded logic which, when copied incompletely, led to:

PR kern/58822: close-on-exec is broken for dup3 and opening cloning
devices
 1.121  11-May-2024  martin PR 58235: add support for SIOCGIFDATA and SIOCZIFDATA ioctls.
 1.120  22-Dec-2021  roy branches: 1.120.4;
Handle the SIOCGNBRINFO ioctl for compat32.
arp -a works with compat32 now.

Credit to simonb@ for the ndp fix from which this is cribbed.
 1.119  14-Apr-2021  mlelstv Add DIOCGDISKINFO compat.
 1.118  17-Jan-2021  simonb branches: 1.118.2;
Handle the SIOCGNBRINFO_IN6 ioctl for compat32. ndp -a works with
compat32 now.
 1.117  14-Jan-2021  simonb Remove some blank lines to group the VND and FSS ioctls together.
 1.116  14-Jan-2021  simonb Handle the KFILTER_BYFILTER and KFILTER_BYNAME ioctls for compat32.
Passes "atf kernel/kqueue/t_ioctl".
 1.115  14-Jan-2021  simonb Handle FSSIOCSET and FSSIOCGET; vndconfig(8) works with compat32 now.
XXX: FSSIOCSET50 and FSSIOCGET50 are not (yet) handled.
 1.114  21-Jul-2020  simonb branches: 1.114.2;
Add lockstat(1) ioctl handling.

mrg@: "looks ok."
 1.113  18-Jul-2020  jmcneill Add BIOCSETWF32 (bpf)
 1.112  16-Mar-2020  christos Unfortunately all the clockctl ioctls contain pointers to structs instead
of the structs themselves, so they need special handling. Undo previous
and do the permissions checks explicitly. It would be better to fix the
clockctl ioctls to contain the structs themselves...
 1.111  16-Mar-2020  christos Don't open-code ioctls, pass back to the 64 bit ones (found by maxv@),
 1.110  14-Mar-2020  maxv wrong size passed to copyout
 1.109  11-Feb-2020  mlelstv Where did the +1 came from ?
 1.108  10-Feb-2020  mlelstv Don't use strlcpy to copy untrusted input, it may not be NUL-terminated.
 1.107  01-Feb-2020  riastradh Load struct filedesc::fd_dt with atomic_load_consume.

Exceptions: when fd_refcnt <= 1, or when holding fd_lock.

While here:

- Restore KASSERT(mutex_owned(&fdp->fd_lock)) in fd_unused.
=> This is used only in fd_close and fd_abort, where it holds.
- Move bounds check assertion in fd_putfile to where it matters.
- Store fd_dt with atomic_store_release.
- Move load of fd_dt under lock in knote_fdclose.
- Omit membar_consumer in fdesc_readdir.
=> atomic_load_consume serves the same purpose now.
=> Was needed only on alpha anyway.
 1.106  18-Nov-2019  rin branches: 1.106.2;
Sorry, revert unintentional parts of the previous commit:
http://mail-index.netbsd.org/source-changes/2019/11/18/msg110946.html

I was going to commit only netbsd32_signal.c.
 1.105  18-Nov-2019  rin Belatedly catch up with kern_sig.c rev 1.358:
http://cvsweb.netbsd.org/bsdweb.cgi/src/sys/kern/kern_sig.c#rev1.358

Provide syscall information with SIGTRAP TRAP_SCE/TRAP_SCX so that
picotrace/truss, for example, works fine on COMPAT_NETBSD32.

With some minor changes:

- Centralize netbsd32_si{,32}_si{32,}() into netbsd32_ksi{,32}_ksi{32,}().
- Provide si_status with SIGCHLD.
- Remove the remaining of SA.

XXX
pullup to netbsd-9
 1.104  20-Aug-2019  christos compat32 drm ioctl support from Surya Shankar at GSoC 2019
 1.103  17-May-2019  msaitoh branches: 1.103.2;
The max subtype of the ifmedia word is 31. It's too small for Ethernet now.
We currently use use it up to 30. We should extend the limit to be able to use
more than 10Gbps speeds. Our ifmedia(4) is inconvenience and have some problem
so we should redesign the interface, but it's too late for netbsd-9 to do it.
So, we keep the data structure size and modify the structure a bit. The
strategy is almost the same as FreeBSD. Many bits of IFM_OMASK for Ethernet
have not used, so use some of them for Ethernet's subtype.

The differences against FreeBSD are:
- We use NetBSD style compat code (i.e. no SIOCGIFXMEDIA).
- FreeBSD's IFM_ETH_XTYPE's bit location is from 11 to "14" even though
IFM_OMASK is from 8 to "15". We use _IFM_ETH_XTMASK from bit 13 to "15".
- FreeBSD changed the meaning of IFM_TYPE_MATCH(). I think we should
not do it. We keep it not changing and added new IFM_TYPE_SUBTYPE_MATCH()
macro for matching both TYPE and SUBTYPE.
- Added up to 400GBASE-SR16.

New layout of the media word is as follows (from ifmedia_h):

* if_media Options word:
* Bits Use
* ---- -------
* 0-4 Media subtype MAX SUBTYPE == 255 for ETH and 31 for others
* 5-7 Media type
* 8-15 Type specific options
* 16-18 Mode (for multi-mode devices)
* 19 (Reserved for Future Use)
* 20-27 Shared (global) options
* 28-31 Instance
*
* 3 2 1
* 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
* +-------+---------------+-+-----+---------------+-----+---------+
* | | |R| | | | |
* | IMASK | GMASK |F|MMASK+-----+ OMASK |NMASK| TMASK |
* | | |U| |XTMSK| | | |
* +-------+---------------+-+-----+-----+---------+-----+---------+
* <-----> <---> <--->
* IFM_INST() IFM_MODE() IFM_TYPE()
*
* IFM_SUBTYPE(other than ETH)<------->
*
* <---> IFM_SUBTYPE(ETH)<------->
*
*
* <-------------> <------------->
* IFM_OPTIONS()
 1.102  23-Apr-2019  msaitoh KNF. No functional change.
 1.101  27-Jan-2019  pgoyette Merge the [pgoyette-compat] branch
 1.100  25-Nov-2018  mlelstv Restore netbsd32 compat code for new NPF ABI.
 1.99  12-Oct-2018  rin PR kern/53666
Correct misleading names of dummy variables. No binary changes intended.
 1.98  11-Oct-2018  christos PR/53666: Rin Okuyama: tcpdump for i386 does not work with COMPAT_NETBSD32
on amd64. Add BIOCSRTIMEOUT32.
 1.97  06-Oct-2018  christos comment out unused
 1.96  29-Sep-2018  rmind NPF: Major rework -- migrate NPF to the libnv library.
- This conversion significantly simplifies the code and moves NPF to
a binary serialisation format (replacing the XML-like format).
- Fix some memory/reference leaks and possibly use-after-free bugs.
- Bump NPF_VERSION as this change makes libnpf incompatible with the
previous versions. Also, different serialisation format means NPF
connection/config saving and loading is not compatible with the
previous versions either.

Thanks to christos@ for extra testing.
 1.95  24-Sep-2018  jdolecek fix DIOCLWEDGES to at least not fail with ENOTTY due to struct size difference,
but probably more needs to be done to work if any actual wedges are configured
 1.94  24-Sep-2018  jdolecek add support for DIOCGSTRATEGY and DIOCSSTRATEGY
 1.93  03-Sep-2018  riastradh Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)
 1.92  06-Mar-2018  mlelstv branches: 1.92.2;
Add DIOCLWEDGES
 1.91  19-Jan-2018  macallan branches: 1.91.2;
add conversion goop for WSDISPLAYIO_LDFONT and _SFONT
tested on mips64
 1.90  26-Nov-2017  jmcneill Add support for SIOCGIFGENERIC and SIOCSIFGENERIC ioctls.
 1.89  14-Jan-2017  maya branches: 1.89.8;
appease coverity by using strlcpy instead of strncpy

ok riastradh
 1.88  26-Dec-2016  christos Sync NPF with the version on github: backport standalone NPF changes,
which allow us to create and run separate NPF instances. Minor fixes.
(from rmind@)
 1.87  21-Nov-2016  rin Handle CLOCKCTL_NTP_ADJTIME32 even when compiled with !NTP;
just return ENOTTY in order to avoid possible failure when
main kernel and compat_netbsd32 module are compiled with
different NTP options in future.

Suggested and approved by mlelstv
 1.86  15-Nov-2016  rin Protect NPT stuff by "#ifdef NTP". Fix non-NTP kernel.
Approved by martin.
 1.85  12-Nov-2016  mlelstv Fix netbsd32 emulation for clockctl_ntp_adjtime.

The ioctl args reference a timex structure that needs to be
transformed to 64bit layout and back.

The 32bit ioctl definition was wrong for mips, as register_t is 64bit
for N32 abi.
 1.84  13-Jul-2016  jmcneill branches: 1.84.2;
Add netbsd32 support for drvctl(4)
 1.83  08-Dec-2015  christos Replace DIOCGPART -> DIOCGPARTINFO which returns the data needed instead of
pointers.
 1.82  02-Aug-2015  maxv Wrong logic. Here, userland can control the size and the data copied, which
basically means it can overflow kernel memory.

ok martin@ christos@
 1.81  01-Jun-2015  roy Add support for NPF ioctls.
 1.80  01-Jun-2015  roy Back out prior

gimpy1@ we don't #include driver .h in netbsd32
 1.79  31-May-2015  roy Revert prior change, optionally include PPPOE and SPPP support again.
Fix compat_netbsd32 module building by enforcing both.
 1.78  31-May-2015  roy It seems we cannot depend on kernel config in modules, so always compile
in PPP(,oE) support.
 1.77  31-May-2015  roy Add support for PPPOEGETPARMS and PPPOESETPARMS.
 1.76  31-May-2015  roy Support SPPPGETAUTHCFG and SPPPSETAUTHCFG.
 1.75  31-May-2015  roy Fixup ifdrv parameter order.
 1.74  27-May-2015  matt Fix netbsd32 ifdrv copy routines to not use memcpy.
 1.73  27-May-2015  matt Add missing SIOCGDRVSPEC32
Fix SIOCGETSGCNT32
 1.72  20-May-2015  matt Rework ksym defines and includes.
 1.71  20-May-2015  matt Change the ksyms ioctls to more compat_netbsd32 friendly. Use _IOWR ioctls
to avoid extra copyouts. With these changes, netstat and vmstat work on
mips64eb with the normal N32 userland and a N64 kernel.
 1.70  18-May-2015  martin Implement SIOCIFGCLONERS for netbsd32, so ifconfig -C works.
 1.69  24-Jan-2014  bouyer branches: 1.69.4; 1.69.6;
Support WSDISPLAYIO_GETCMAP/WSDISPLAYIO_PUTCMAP. Tested on evbmips/loongson
 1.68  24-Jan-2014  manu Add ATAIOCCOMMAND ioctl form COMPAT_NETBSD32

This enables SMART monitoring by a netbsd32 binary.
 1.67  06-Aug-2012  skrll branches: 1.67.2; 1.67.4;
Ensure correct alignment for stack buffers when long != 64-bit, e.g.
arm.
 1.66  28-May-2012  christos compat for 80211 ioctls from jmcneill
 1.65  11-May-2012  christos provide clockctl ioctl emulation
 1.64  06-Oct-2011  macallan branches: 1.64.2; 1.64.6; 1.64.8; 1.64.12; 1.64.14;
fix pasto, now SIOCS80211NWKEY and SIOCG80211NWKEY actually work
 1.63  05-Oct-2011  macallan forgot SIOCG80211NWKEY32 when adding SIOCS80211NWKEY32
 1.62  28-Sep-2011  macallan support WSDISPLAYIO_GCURSOR and WSDISPLAYIO_SCURSOR
 1.61  07-Sep-2011  macallan support ioctl(POWER_EVENT_RECVDICT) - now powerd turns my gdium's backlight
off when the lid is closed
 1.60  30-Aug-2011  bouyer Provide netbsd32 compat for bpf. Beside the ioctls, the structure
returned to userland by read(2) also needs to be converted.
For this, the bpf descriptor is flagged as compat32 (or not) in the
open and ioctl functions (where the user process's pid is also updated
in the descriptor). When the bpf buffer is filled in, the 32bits or native
header is used depending on the information stored in the descriptor.

This won't work if a 64bit binary does the open and ioctls, and then
exec a 32bit program which will do the read. But this is very
unlikely to happen in real life ...

Tested on i386 and loongson; with these changes my loongson can run
dhclient and tcpdump with a n32 userland.
 1.59  30-Aug-2011  macallan support SIOCG80211NWKEY
 1.58  30-Aug-2011  macallan add WSDISPLAYIO_ADDSCREEN
 1.57  27-Aug-2011  bouyer translate WDOGIOC_GWDOGS
 1.56  04-Apr-2011  ahoka remove FLASH_GET_INFO compat as it is no longer using size_t
 1.55  19-Mar-2011  cliff compat/netbsd32 ioctl support for FLASH_GET_INFO
 1.54  01-Feb-2011  matt Define 32bit version of SIOC[GS]IFADDRPREF32. We wouldn't need this to
if i386 actually aligned a uint64_t on a 64bit boundary but it doesn't.
So all that work in sockaddr_storage goes for naught.
 1.53  22-Jan-2011  matt Fix c&p error.
 1.52  18-Jan-2011  matt branches: 1.52.2;
Make struct disklabel 8 byte aligned. This increases its size by 4 bytes
on IPL32 platforms so add code in sys_ioctl (and netbsd32_ioctl) to deal
with the older/smaller diskabel size. This change makes disklabel the
same for both IPL32 and LP64 platforms.
 1.51  24-Sep-2010  njoly branches: 1.51.2;
Add support for envsys(4) version 2 ioctls.
 1.50  19-Sep-2010  mrg add (runtime untested) support for AUDIO_WSEEK.
 1.49  19-Sep-2010  mrg add support for the netbsd 5.0 versions of the VND* ioctls.
 1.48  19-Sep-2010  mrg support VND* ioctls.
 1.47  23-Apr-2010  rmind Replace M_IOV and some malloc(9)s with kmem(9), and while there:
- Fix invalid free (M_TEMP vs M_IOV) in do_sys_recvmsg(), spotted by jakllsch@.
Also, same fix in osf1_sys_sendmsg_xopen().
- Fix attempt to free non-allocated memory in error path in netbsd32___getfh30().
- Plug a memory leak in compat_43_netbsd32_orecvmsg().
 1.46  11-Dec-2009  njoly branches: 1.46.2; 1.46.4;
In netbsd32_from_{ifreq,oifreq}(), use the compat structure size for
memcpy.

From mrg.
 1.45  10-Dec-2009  njoly Kill debug printf.
 1.44  10-Dec-2009  njoly Make netbsd32_from_{ifreq,oifreq}() copy the whole structure, not only
the interface name. Finally fix my own PR/39424.

ok by christos.
 1.43  09-Dec-2009  christos Add netbsd32_oifreq and fix issue in copying the interface name. With this
patch OSIOC{G,S}IFFLAGS is supposed to work, but unfortunately getifaddrs
seems to be the next problem getting the 4.99.x i386 ifconfig working on an
amd64 current machine.
 1.42  24-May-2009  ad More changes to improve kern_descrip.c.

- Avoid atomics in more places.
- Remove the per-descriptor mutex, and just use filedesc_t::fd_lock.
It was only being used to synchronize close, and in any case we needed
to take fd_lock to free the descriptor slot.
- Optimize certain paths for the <NDFDFILE case.
- Sprinkle more comments and assertions.
- Cache more stuff in filedesc_t.
- Fix numerous minor bugs spotted along the way.
- Restructure how the open files array is maintained, for clarity and so
that we can eliminate the membar_consumer() call in fd_getfile(). This is
mostly syntactic sugar; the main functional change is that fd_nfiles now
lives alongside the open file array.

Some measurements with libmicro:

- simple file syscalls are like close() are between 1 to 10% faster.
- some nice improvements, e.g. poll(1000) which is ~50% faster.
 1.41  02-Jul-2008  matt branches: 1.41.10; 1.41.12;
Change {ff,fd}_exclose and ff_allocated to bool. Change exclose arg to
fd_dup to bool. Switch assignments from 1/0 to true/false.

This make alpha kernels compile. Bump kern to 4.99.69 since structure
changed.
 1.40  23-Jun-2008  njoly Update compat netbsd32 SIOCGIFCONF ioctls definitions to follow native
ones.
 1.39  29-May-2008  mrg branches: 1.39.2;
remove clause #3 from my license where there are no other
copyright holders involved.
 1.38  21-Mar-2008  ad branches: 1.38.2; 1.38.4; 1.38.6;
Catch up with descriptor handling changes. See kern_descrip.c revision
1.173 for details.
 1.37  20-Dec-2007  dsl branches: 1.37.6;
Convert all the system call entry points from:
int foo(struct lwp *l, void *v, register_t *retval)
to:
int foo(struct lwp *l, const struct foo_args *uap, register_t *retval)
Fixup compat code to not write into 'uap' and (in some cases) to actually
pass a correctly formatted 'uap' structure with the right name to the
next routine.
A few 'compat' routines that just call standard ones have been deleted.
All the 'compat' code compiles (along with the kernels required to test
build it).
98% done by automated scripts.
 1.36  08-Dec-2007  dsl branches: 1.36.4;
ANSIfy most of the function definitions in sys/compat (but not ndis).
All by the magic of sed ...
 1.35  15-Aug-2007  ad branches: 1.35.2; 1.35.10;
Changes to make ktrace LKM friendly and reduce ifdef KTRACE. Proposed
on tech-kern.
 1.34  30-May-2007  christos branches: 1.34.2; 1.34.6;
make this compile again
XXX: The ioctls will need to be fixed.
 1.33  20-Mar-2007  njoly Add ktrace I/O support to netbsd32_ioctl() syscall.
Reviewed by cube.
 1.32  18-Mar-2007  dsl Change all the NETBSD32PTR64(SCARG(uap, xxx))) to SCARG_P32(uap, xxx).
 1.31  16-Mar-2007  dsl remove all the double (and triple) casts used to convert 32bit userspace
pointers to and from 64bit kernel pointers. Instead use the defines
NETBSD32PTR64(p32) to read a 32bit pointer and (the new) NETBSD32PTR32(p32,p64)
to write a 32bit pointer throughout.
The 32bit pointer is now a struct to enforce the above.
amd64 (with linux emul) and sparc64 will both compile (when the arch stuff
goes in soon), and amd64 still runs some i386 binaries.
 1.30  04-Mar-2007  christos branches: 1.30.2; 1.30.4; 1.30.6;
fix fallout from caddr_t changes.
 1.29  04-Mar-2007  christos Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.28  09-Feb-2007  ad branches: 1.28.2;
Merge newlock2 to head.
 1.27  29-Jan-2007  hubertf Remove more duplicate headers.
Patch by Slava Semushin <slava.semushin@gmail.com>

Again, this was tested by comparing obj files from a pristine and a patched
source tree against an i386/ALL kernel, and also for src/sbin/fsck_ffs,
src/sbin/fsdb and src/usr.sbin/makefs. Only changes in assert() line numbers
were detected in 'objdump -d' output.
 1.26  24-Sep-2006  fvdl EPASSTHROUGH from lower layers is returned as ENOTTY to the (system) caller.
Make it so.
 1.25  24-Dec-2005  perry branches: 1.25.20; 1.25.22;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.24  11-Dec-2005  christos merge ktrace-lwp.
 1.23  26-Feb-2005  perry branches: 1.23.4;
nuke trailing whitespace
 1.22  15-Jan-2004  mrg branches: 1.22.8; 1.22.10;
begin to implement some ifreq ioctls... long long way to go.
 1.21  21-Sep-2003  jdolecek cleanup & uniform descriptor owner handling:
* introduce fsetown(), fgetown(), fownsignal() - this sets/retrieves/signals
the owner of descriptor, according to appropriate sematics
of TIOCSPGRP/FIOSETOWN/SIOCSPGRP/TIOCGPGRP/FIOGETOWN/SIOCGPGRP ioctl; use
these routines instead of custom code where appropriate
* make every place handling TIOCSPGRP/TIOCGPGRP handle also FIOSETOWN/FIOGETOWN
properly, and remove the translation of FIO[SG]OWN to TIOC[SG]PGRP
in sys_ioctl() & sys_fcntl()
* also remove the socket-specific hack in sys_ioctl()/sys_fcntl() and
pass the ioctls down to soo_ioctl() as any other ioctl

change discussed on tech-kern@
 1.20  29-Jun-2003  fvdl branches: 1.20.2;
Back out the lwp/ktrace changes. They contained a lot of colateral damage,
and need to be examined and discussed more.
 1.19  29-Jun-2003  martin struct proc * -> struct lwp *
 1.18  12-Apr-2003  christos get rid of the ASYNCMAP ioctls
 1.17  24-Jan-2003  fvdl Bump daddr_t to 64 bits. Replace it with int32_t in all places where
it was used on-disk, so that on-disk formats remain the same.
Remove ufs_daddr_t and ufs_lbn_t for the time being.
 1.16  18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.15  23-Oct-2002  scw In preparation for COMPAT_NETBSD32 on SH-5:

- The MD netbsd32_machdep.h header now defines the 32-bit pointer type
instead of using u_int32_t everywhere,
- The MD netbsd32_machdep.h header now defines a macro (at least on
current implementations) which converts a 32-bit pointer to its 64-bit
equivalent,
- Change the MI code to utilise the above two items in all the right places,
- Implement netbsd32___sigaction_sigtramp().

Tested on Sparc64 by Matt Green.
 1.14  03-Jan-2002  mrg move sparc specific ioctl handling (fb & openprom) into arch/sparc64.
 1.13  13-Nov-2001  lukem add RCSIDs (including regeneration of files as appropriate)
 1.12  19-Sep-2001  thorpej machine/fbio.h -> dev/sun/fbio.h
 1.11  25-Aug-2001  mrg branches: 1.11.2;
update copyright notices.
 1.10  19-Jun-2001  fvdl branches: 1.10.2;
Some of this was sparc-specific, so ifdef __sparc__ it (XXX). Also,
change the alignment of one structure with an MD ifdef. Should
be moved into the netbsd32_machdep parts.
 1.9  14-Jun-2001  thorpej Fix a partial construction problem that can cause race conditions
between creation of a file descriptor and close(2) when using kernel
assisted threads. What we do is stick descriptors in the table, but
mark them as "larval". This causes essentially everything to treat
it as a non-existent descriptor, except for fdalloc(), which sees a
filled slot so that it won't (incorrectly) allocate it again. When
a descriptor is fully constructed, the code that has constructed it
marks it as "mature" (which actually clears the "larval" flag), and
things continue to work as normal.

While here, gather all the code that gets a descriptor from the table
into a fd_getfile() function, and call it, rather than having the
same (sometimes incorrect) code copied all over the place.
 1.8  05-Dec-2000  eeh branches: 1.8.2;
Fix uninitialized pointer bug.
 1.7  19-Aug-2000  eeh Fix netbsd32_ioctls.
 1.6  09-Jul-2000  mrg - massive warning fix fest.
- fix pread/pwrite return values (plus some other syscalls that looked
similarly broken).
- prototypes and clean up for netbsd32_ioctl.c

now getpw*() works under compat32!
 1.5  30-Dec-1999  eeh branches: 1.5.4;
Update to 32-bit compatibility routines.
 1.4  11-Oct-1999  eeh branches: 1.4.2;
Add netbsd32_compat_14.c

Rename everything from compat_netbsd32 -> netbsd32 so we don't have silly
names like compat_14_compat_netbsd32_sys_shmctl().
 1.3  25-Mar-1999  mrg branches: 1.3.8;
SPARC32->NETBSD32
 1.2  25-Mar-1999  mrg move sparc32 to netbsd32; split out MD part (signal handling) (mostly via repository copy, rename and perl -pi :-)
 1.1  26-Aug-1998  mrg add a 32-bit compatibility module for the sparc64 port, so it can run NetBSD/sparc binaries with a LP64 kernel.
 1.3.8.1  27-Dec-1999  wrstuden Pull up to last week's -current.
 1.4.2.2  08-Dec-2000  bouyer Sync with HEAD.
 1.4.2.1  20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
 1.5.4.1  26-Aug-2000  mrg pull up 1.7. approved by thorpej:
>Fix netbsd32_ioctls.
 1.8.2.8  11-Nov-2002  nathanw Catch up to -current
 1.8.2.7  23-Aug-2002  petrov lwpification.
 1.8.2.6  29-May-2002  nathanw #include <sys/sa.h> before <sys/syscallargs.h>, to provide sa_upcall_t
now that <sys/param.h> doesn't include <sys/sa.h>.

(Behold the Power of Ed)
 1.8.2.5  28-Feb-2002  nathanw Catch up to -current.
 1.8.2.4  11-Jan-2002  nathanw More catchup.
 1.8.2.3  14-Nov-2001  nathanw Catch up to -current.
 1.8.2.2  21-Sep-2001  nathanw Catch up to -current.
 1.8.2.1  21-Jun-2001  nathanw Catch up to -current.
 1.10.2.2  10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.10.2.1  13-Sep-2001  thorpej Update the kqueue branch to HEAD.
 1.11.2.1  01-Oct-2001  fvdl Catch up with -current.
 1.20.2.5  04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.20.2.4  21-Sep-2004  skrll Fix the sync with head I botched.
 1.20.2.3  18-Sep-2004  skrll Sync with HEAD.
 1.20.2.2  26-Aug-2004  skrll Adapt to branch.

sparc64 GENERIC compiles.
 1.20.2.1  03-Aug-2004  skrll Sync with HEAD
 1.22.10.1  19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.22.8.1  29-Apr-2005  kent sync with -current
 1.23.4.6  24-Mar-2008  yamt sync with head.
 1.23.4.5  21-Jan-2008  yamt sync with head
 1.23.4.4  03-Sep-2007  yamt sync with head.
 1.23.4.3  26-Feb-2007  yamt sync with head.
 1.23.4.2  30-Dec-2006  yamt sync with head.
 1.23.4.1  21-Jun-2006  yamt sync with head.
 1.25.22.1  22-Oct-2006  yamt sync with head
 1.25.20.3  01-Feb-2007  ad Sync with head.
 1.25.20.2  30-Jan-2007  ad Remove support for SA. Ok core@.
 1.25.20.1  18-Nov-2006  ad Sync with head.
 1.28.2.2  24-Mar-2007  yamt sync with head.
 1.28.2.1  12-Mar-2007  rmind Sync with HEAD.
 1.30.6.2  29-Mar-2007  reinoud Pullup to -current
 1.30.6.1  18-Mar-2007  reinoud First attempt to bring branch in sync with HEAD
 1.30.4.1  11-Jul-2007  mjf Sync with head.
 1.30.2.3  20-Aug-2007  ad Sync with HEAD.
 1.30.2.2  09-Jun-2007  ad Sync with head.
 1.30.2.1  10-Apr-2007  ad Sync with head.
 1.34.6.2  09-Dec-2007  jmcneill Sync with HEAD.
 1.34.6.1  16-Aug-2007  jmcneill Sync with HEAD.
 1.34.2.1  03-Sep-2007  skrll Sync with HEAD.
 1.35.10.1  26-Dec-2007  ad Sync with head.
 1.35.2.1  09-Jan-2008  matt sync with HEAD
 1.36.4.1  02-Jan-2008  bouyer Sync with HEAD
 1.37.6.4  02-Jul-2008  mjf Sync with HEAD.
 1.37.6.3  29-Jun-2008  mjf Sync with HEAD.
 1.37.6.2  02-Jun-2008  mjf Sync with HEAD.
 1.37.6.1  03-Apr-2008  mjf Sync with HEAD.
 1.38.6.4  18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.38.6.3  23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.38.6.2  14-May-2008  wrstuden Per discussion with ad, remove most of the #include <sys/sa.h> lines
as they were including sa.h just for the type(s) needed for syscallargs.h.

Instead, create a new file, sys/satypes.h, which contains just the
types needed for syscallargs.h. Yes, there's only one now, but that
may change and it's probably more likely to change if it'd be difficult
to handle. :-)

Per discussion with matt at n dot o, add an include of satypes.h to
sigtypes.h. Upcall handlers are kinda signal handlers, and signalling
is the header file that's already included for syscallargs.h that
closest matches SA.

This shaves about 3000 lines off of the diff of the branch relative
to the base. That also represents about 18% of the total before this
checkin.

I think this reduction is very good thing.
 1.38.6.1  10-May-2008  wrstuden Initial checkin of re-adding SA. Everything except kern_sa.c
compiles in GENERIC for i386. This is still a work-in-progress, but
this checkin covers most of the mechanical work (changing signalling
to be able to accomidate SA's process-wide signalling and re-adding
includes of sys/sa.h and savar.h). Subsequent changes will be much
more interesting.

Also, kern_sa.c has received partial cleanup. There's still more
to do, though.
 1.38.4.5  09-Oct-2010  yamt sync with head
 1.38.4.4  11-Aug-2010  yamt sync with head.
 1.38.4.3  11-Mar-2010  yamt sync with head
 1.38.4.2  20-Jun-2009  yamt sync with head
 1.38.4.1  04-May-2009  yamt sync with head.
 1.38.2.1  04-Jun-2008  yamt sync with head
 1.39.2.2  03-Jul-2008  simonb Sync with head.
 1.39.2.1  27-Jun-2008  simonb Sync with head.
 1.41.12.1  23-Jul-2009  jym Sync with HEAD.
 1.41.10.2  02-Jul-2008  matt Change {ff,fd}_exclose and ff_allocated to bool. Change exclose arg to
fd_dup to bool. Switch assignments from 1/0 to true/false.

This make alpha kernels compile. Bump kern to 4.99.69 since structure
changed.
 1.41.10.1  02-Jul-2008  matt file netbsd32_ioctl.c was added on branch christos-time_t on 2008-07-02 16:45:21 +0000
 1.46.4.3  21-Apr-2011  rmind sync with head
 1.46.4.2  05-Mar-2011  rmind sync with head
 1.46.4.1  30-May-2010  rmind sync with head
 1.46.2.2  22-Oct-2010  uebayasi Sync with HEAD (-D20101022).
 1.46.2.1  30-Apr-2010  uebayasi Sync with HEAD.
 1.51.2.1  06-Jun-2011  jruoho Sync with HEAD.
 1.52.2.1  08-Feb-2011  bouyer Sync with HEAD
 1.64.14.1  02-Aug-2015  martin Pull up following revision(s) (requested by maxv in ticket #1318):
sys/compat/netbsd32/netbsd32_ioctl.c: revision 1.82
Wrong logic. Here, userland can control the size and the data copied, which
basically means it can overflow kernel memory.
ok martin@ christos@
 1.64.12.1  02-Aug-2015  martin Pull up following revision(s) (requested by maxv in ticket #1318):
sys/compat/netbsd32/netbsd32_ioctl.c: revision 1.82
Wrong logic. Here, userland can control the size and the data copied, which
basically means it can overflow kernel memory.
ok martin@ christos@
 1.64.8.2  02-Aug-2015  martin Pull up following revision(s) (requested by maxv in ticket #1318):
sys/compat/netbsd32/netbsd32_ioctl.c: revision 1.82
Wrong logic. Here, userland can control the size and the data copied, which
basically means it can overflow kernel memory.
ok martin@ christos@
 1.64.8.1  18-Mar-2014  msaitoh Pull up following revision(s) (requested by manu in ticket #1022):
sys/compat/netbsd32/netbsd32_ioctl.h: revision 1.44
sys/compat/netbsd32/netbsd32_ioctl.c: revision 1.68
Add ATAIOCCOMMAND ioctl form COMPAT_NETBSD32
This enables SMART monitoring by a netbsd32 binary.
 1.64.6.1  02-Jun-2012  mrg sync to latest -current.
 1.64.2.3  22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.64.2.2  30-Oct-2012  yamt sync with head
 1.64.2.1  23-May-2012  yamt sync with head.
 1.67.4.1  18-May-2014  rmind sync with head
 1.67.2.2  03-Dec-2017  jdolecek update from HEAD
 1.67.2.1  20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.69.6.6  05-Feb-2017  skrll Sync with HEAD
 1.69.6.5  05-Dec-2016  skrll Sync with HEAD
 1.69.6.4  05-Oct-2016  skrll Sync with HEAD
 1.69.6.3  27-Dec-2015  skrll Sync with HEAD (as of 26th Dec)
 1.69.6.2  22-Sep-2015  skrll Sync with HEAD
 1.69.6.1  06-Jun-2015  skrll Sync with HEAD
 1.69.4.1  02-Aug-2015  martin Pull up following revision(s) (requested by maxv in ticket #930):
sys/compat/netbsd32/netbsd32_ioctl.c: revision 1.82
Wrong logic. Here, userland can control the size and the data copied, which
basically means it can overflow kernel memory.
ok martin@ christos@
 1.84.2.2  20-Mar-2017  pgoyette Sync with HEAD
 1.84.2.1  07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.89.8.3  13-Feb-2020  martin Pull up following revision(s) (requested by mlelstv in ticket #1504):

sys/compat/netbsd32/netbsd32_ioctl.c: revision 1.108
sys/compat/netbsd32/netbsd32_ioctl.c: revision 1.109

Don't use strlcpy to copy untrusted input, it may not be NUL-terminated.

Where did the +1 came from ?
 1.89.8.2  22-Jul-2019  martin Pull up following revision(s) (requested by rin in ticket #1054):

sys/compat/netbsd32/netbsd32_ioctl.h: revision 1.65
sys/compat/netbsd32/netbsd32_ioctl.c: revision 1.98
sys/compat/netbsd32/netbsd32_ioctl.c: revision 1.99

PR/53666: Rin Okuyama: tcpdump for i386 does not work with COMPAT_NETBSD32
on amd64. Add BIOCSRTIMEOUT32.

-

Correct misleading names of dummy variables. No binary changes intended.
 1.89.8.1  27-Nov-2017  martin Pull up following revision(s) (requested by jmcneill in ticket #396):
sys/compat/netbsd32/netbsd32_ioctl.h: revision 1.57
sys/compat/netbsd32/netbsd32_ioctl.c: revision 1.90
Add support for SIOCGIFGENERIC and SIOCSIFGENERIC ioctls.
 1.91.2.6  26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.91.2.5  20-Oct-2018  pgoyette Sync with head
 1.91.2.4  30-Sep-2018  pgoyette Ssync with HEAD
 1.91.2.3  25-Sep-2018  pgoyette Additional use of NTP function pointers, since the NTP code might not
exist in the kernel. (NTP is not (yet) a module, so we don't need to
use the MP-safe mechanism.)
 1.91.2.2  06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.91.2.1  15-Mar-2018  pgoyette Synch with HEAD
 1.92.2.3  13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.92.2.2  08-Apr-2020  martin Merge changes from current as of 20200406
 1.92.2.1  10-Jun-2019  christos Sync with HEAD
 1.103.2.3  20-Nov-2024  martin Pull up following revision(s) (requested by riastradh in ticket #1921):

sys/kern/kern_event.c: revision 1.106
sys/kern/sys_select.c: revision 1.51
sys/kern/subr_exec_fd.c: revision 1.10
sys/kern/sys_aio.c: revision 1.46
sys/kern/kern_descrip.c: revision 1.244
sys/kern/kern_descrip.c: revision 1.245
sys/ddb/db_xxx.c: revision 1.72
sys/ddb/db_xxx.c: revision 1.73
sys/miscfs/fdesc/fdesc_vnops.c: revision 1.132
sys/kern/uipc_usrreq.c: revision 1.195
sys/kern/sys_descrip.c: revision 1.36
sys/kern/uipc_usrreq.c: revision 1.196
sys/kern/uipc_socket2.c: revision 1.135
sys/kern/uipc_socket2.c: revision 1.136
sys/kern/kern_sig.c: revision 1.383
sys/kern/kern_sig.c: revision 1.384
sys/compat/netbsd32/netbsd32_ioctl.c: revision 1.107
sys/miscfs/procfs/procfs_vnops.c: revision 1.208
sys/kern/subr_exec_fd.c: revision 1.9
sys/kern/kern_descrip.c: revision 1.252
(all via patch)

Load struct filedesc::fd_dt with atomic_load_consume.

Exceptions: when fd_refcnt <= 1, or when holding fd_lock.

While here:
- Restore KASSERT(mutex_owned(&fdp->fd_lock)) in fd_unused.
=> This is used only in fd_close and fd_abort, where it holds.
- Move bounds check assertion in fd_putfile to where it matters.
- Store fd_dt with atomic_store_release.
- Move load of fd_dt under lock in knote_fdclose.
- Omit membar_consumer in fdesc_readdir.
=> atomic_load_consume serves the same purpose now.
=> Was needed only on alpha anyway.

Load struct fdfile::ff_file with atomic_load_consume.
Exceptions: when we're only testing whether it's there, not about to
dereference it.

Note: We do not use atomic_store_release to set it because the
preceding mutex_exit should be enough.

(That said, it's not clear the mutex_enter/exit is needed unless
refcnt > 0 already, in which case maybe it would be a win to switch
from the membar implied by mutex_enter to the membar implied by
atomic_store_release -- which I would generally expect to be much
cheaper. And a little clearer without a long comment.)
kern_descrip.c: Fix membars around reference count decrement.

In general, the `last one out hit the lights' style of reference
counting (as opposed to the `whoever's destroying must wait for
pending users to finish' style) requires memory barriers like so:

... usage of resources associated with object ...
membar_release();
if (atomic_dec_uint_nv(&obj->refcnt) != 0)
return;
membar_acquire();
... freeing of resources associated with object ...

This way, all usage happens-before all freeing. This fixes several
errors:
- fd_close failed to ensure whatever its caller did would
happen-before the freeing, in the case where another thread is
concurrently trying to close the fd (ff->ff_file == NULL).
Fix: Add membar_release before atomic_dec_uint(&ff->ff_refcnt) in
that branch.
- fd_close failed to ensure all loads its caller had issued will have
happened-before the freeing, in the case where the fd is still in
use by another thread (fdp->fd_refcnt > 1 and ff->ff_refcnt-- > 0).
Fix: Change membar_producer to membar_release before
atomic_dec_uint(&ff->ff_refcnt).
- fd_close failed to ensure that any usage of fp by other callers
would happen-before any freeing it does.
Fix: Add membar_acquire after atomic_dec_uint_nv(&ff->ff_refcnt).
- fd_free failed to ensure that any usage of fdp by other callers
would happen-before any freeing it does.
Fix: Add membar_acquire after atomic_dec_uint_nv(&fdp->fd_refcnt).

While here, change membar_exit -> membar_release. No semantic
change, just updating away from the legacy API.
 1.103.2.2  18-Nov-2024  martin Pull up following revision(s) (requested by 1922):

tests/kernel/Makefile: revision 1.83
sys/sys/filedesc.h: revision 1.71
distrib/sets/lists/tests/mi: revision 1.1346
tests/kernel/h_cloexec.c: revision 1.1
tests/kernel/t_cloexec.c: revision 1.1
sys/compat/netbsd32/netbsd32_ioctl.c: revision 1.122
distrib/sets/lists/debug/mi: revision 1.454

tests/kernel/t_cloexec: New tests for close-on-exec.

Verified that the following tests fail on a netbsd-10 kernel:
- clonedev_posixspawn
- dup3_posixspawn
- fcntldupfd_posixspawn

PR kern/58822: close-on-exec is broken for dup3 and opening cloning
devices
sys/filedesc.h: Add a note about writing to ff_exclose.
No functional change intended -- just a reminder to avoid repeating a
class of bugs we've had.

PR kern/58822: close-on-exec is broken for dup3 and opening cloning
devices

netbsd32_ioctl: Use fd_set_exclose instead of open-coding it.
No functional change intended -- this just reduces unnecessary
copies of open-coded logic which, when copied incompletely, led to:

PR kern/58822: close-on-exec is broken for dup3 and opening cloning
devices
 1.103.2.1  13-Feb-2020  martin Pull up following revision(s) (requested by mlelstv in ticket #706):

sys/compat/netbsd32/netbsd32_ioctl.c: revision 1.108
sys/compat/netbsd32/netbsd32_ioctl.c: revision 1.109

Don't use strlcpy to copy untrusted input, it may not be NUL-terminated.

Where did the +1 came from ?
 1.106.2.1  29-Feb-2020  ad Sync with head.
 1.114.2.1  03-Apr-2021  thorpej Sync with HEAD.
 1.118.2.1  17-Apr-2021  thorpej Sync with HEAD.
 1.120.4.2  17-Nov-2024  martin Pull up following revision(s) (requested by riastradh in ticket #1007):

tests/kernel/Makefile: revision 1.83
sys/sys/filedesc.h: revision 1.71
distrib/sets/lists/tests/mi: revision 1.1346
tests/kernel/h_cloexec.c: revision 1.1
tests/kernel/t_cloexec.c: revision 1.1
sys/compat/netbsd32/netbsd32_ioctl.c: revision 1.122
distrib/sets/lists/debug/mi: revision 1.454

tests/kernel/t_cloexec: New tests for close-on-exec.
Verified that the following tests fail on a netbsd-10 kernel:
- clonedev_posixspawn
- dup3_posixspawn
- fcntldupfd_posixspawn
PR kern/58822: close-on-exec is broken for dup3 and opening cloning
devices


sys/filedesc.h: Add a note about writing to ff_exclose.
No functional change intended -- just a reminder to avoid repeating a
class of bugs we've had.
PR kern/58822: close-on-exec is broken for dup3 and opening cloning
devices


netbsd32_ioctl: Use fd_set_exclose instead of open-coding it.
No functional change intended -- this just reduces unnecessary
copies of open-coded logic which, when copied incompletely, led to:
PR kern/58822: close-on-exec is broken for dup3 and opening cloning
devices
 1.120.4.1  26-Oct-2024  martin Pull up following revision(s) (requested by rin in ticket #988):

sys/compat/netbsd32/netbsd32_ioctl.h: revision 1.80
sys/compat/netbsd32/netbsd32_ioctl.c: revision 1.121

PR 58235: add support for SIOCGIFDATA and SIOCZIFDATA ioctls.

RSS XML Feed