Date: Fri, 9 Mar 2012 22:36:48 +0100 From: Robert Millan <rmh@freebsd.org> To: freebsd-arch@freebsd.org Subject: [PATCH] Add compatibility <sys/io.h> Message-ID: <CAOfDtXPGPP0reN9NTBw_5%2BNwXZ56Yy0oyx_fH%2BDOvmpc1O%2BQdQ@mail.gmail.com>
next in thread | raw e-mail | index | archive | help
--e89a8f3baf01a5d70304bad630a5 Content-Type: text/plain; charset=UTF-8 This patch adds a compatibility <sys/io.h> that would make it easier to build on FreeBSD software that has been written for glibc (see example1.c). The functionality in <sys/io.h> is more or less equivalent to <machine/cpufunc.h> but provides some declarations which are incompatible with those in <machine/cpufunc.h>. One of these cases is very unfortunate because it alters I/O semantics, it applies to outb(), outw() and outl(): FreeBSD code: outw(port, data); Glibc code: outw(data, port); The undefined I/O behaviour that could potentially result from this is very scary. Because of this I've written a few checks to prevent both headers from being used at the same time. Overall, aside from the portability benefit, my proposed addition has some less obvious side-effects: Desireable side-effect: Adding <sys/io.h> would break buildability of code that attempts to use both headers at the same time _WITHOUT_ changing the outw() call semantics (see example2.c). Undesireable side-effect: Adding <sys/io.h> would break buildability of code that attempts to use both headers at the same time, and was otherwise fine due to conditionalized outw() calls (see example3.c [1]). [1] I found a real case where this happens, in sane-backends-1.0.22/backend/umax_pp_low.c. In case my patch is accepted, I commit to provide a fix for sane-backends and also to adjust Debian GNU/kFreeBSD headers to follow the same route [2]. [2] This means: reenable outb(), outw() and outl() in <machine/cpufunc.h>. Currently we provide both headers, but outb(), outw() and outl() are entirely disabled. I think it's better for both projects to provide <sys/io.h> since the majority of code out there is written with GNU/Linux in mind. Attached patch is tested against HEAD with "make universe". -- Robert Millan --e89a8f3baf01a5d70304bad630a5 Content-Type: text/plain; charset=US-ASCII; name="io.diff" Content-Disposition: attachment; filename="io.diff" Content-Transfer-Encoding: base64 X-Attachment-Id: f_gzlqvrlg0 SW5kZXg6IHN5cy9hbWQ2NC9pbmNsdWRlL2NwdWZ1bmMuaAo9PT09PT09PT09PT09PT09PT09PT09 PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09Ci0tLSBzeXMvYW1k NjQvaW5jbHVkZS9jcHVmdW5jLmgJKHJldmlzaW9uIDIzMjQwNCkKKysrIHN5cy9hbWQ2NC9pbmNs dWRlL2NwdWZ1bmMuaAkod29ya2luZyBjb3B5KQpAQCAtMzYsNiArMzYsMTAgQEAKICAqIHVzZWQg aW4gcHJlZmVyZW5jZSB0byB0aGlzLgogICovCiAKKyNpZmRlZiBfU1lTX0lPX0hfCisjZXJyb3Ig ZGVmaW5pdGlvbnMgaW4gdGhpcyBmaWxlIGNvbmZsaWN0IHdpdGggdGhvc2UgaW4gc3lzL2lvLmgK KyNlbmRpZgorCiAjaWZuZGVmIF9NQUNISU5FX0NQVUZVTkNfSF8KICNkZWZpbmUJX01BQ0hJTkVf Q1BVRlVOQ19IXwogCkluZGV4OiBzeXMvaTM4Ni9pbmNsdWRlL2NwdWZ1bmMuaAo9PT09PT09PT09 PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09 Ci0tLSBzeXMvaTM4Ni9pbmNsdWRlL2NwdWZ1bmMuaAkocmV2aXNpb24gMjMyNDA0KQorKysgc3lz L2kzODYvaW5jbHVkZS9jcHVmdW5jLmgJKHdvcmtpbmcgY29weSkKQEAgLTM1LDYgKzM1LDEwIEBA CiAgKiB1c2VkIGluIHByZWZlcmVuY2UgdG8gdGhpcy4KICAqLwogCisjaWZkZWYgX1NZU19JT19I XworI2Vycm9yIGRlZmluaXRpb25zIGluIHRoaXMgZmlsZSBjb25mbGljdCB3aXRoIHRob3NlIGlu IHN5cy9pby5oCisjZW5kaWYKKwogI2lmbmRlZiBfTUFDSElORV9DUFVGVU5DX0hfCiAjZGVmaW5l CV9NQUNISU5FX0NQVUZVTkNfSF8KIApJbmRleDogc3lzL3N5cy9pby5oCj09PT09PT09PT09PT09 PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09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bnN0ZWFk LgorICovCisKKyNpZmRlZiBfTUFDSElORV9DUFVGVU5DX0hfCisjZXJyb3IgZGVmaW5pdGlvbnMg aW4gdGhpcyBmaWxlIGNvbmZsaWN0IHdpdGggdGhvc2UgaW4gbWFjaGluZS9jcHVmdW5jLmgKKyNl bmRpZgorCisjaWZuZGVmIF9TWVNfSU9fSF8KKworI2lmICFkZWZpbmVkKF9faTM4Nl9fKSAmJiAh ZGVmaW5lZChfX2FtZDY0X18pCisjZXJyb3IgdGhpcyBmaWxlIGlzIG9ubHkgdXNlZnVsIG9uIGkz ODYgYW5kIGFtZDY0CisjZW5kaWYKKworI2luY2x1ZGUgPHN5cy9jZGVmcy5oPgorCisjZGVmaW5l IG91dGIJYnNkX291dGIKKyNkZWZpbmUgb3V0dwlic2Rfb3V0dworI2RlZmluZSBvdXRsCWJzZF9v dXRsCisjaW5jbHVkZSA8bWFjaGluZS9jcHVmdW5jLmg+CisjdW5kZWYgb3V0YgorI3VuZGVmIG91 dHcKKyN1bmRlZiBvdXRsCisKKyNkZWZpbmUgb3V0YihkYXRhLHBvcnQpCQlic2Rfb3V0Yihwb3J0 LGRhdGEpCisjZGVmaW5lIG91dHcoZGF0YSxwb3J0KQkJYnNkX291dHcocG9ydCxkYXRhKQorI2Rl ZmluZSBvdXRsKGRhdGEscG9ydCkJCWJzZF9vdXRsKHBvcnQsZGF0YSkKKworI2RlZmluZSBfU1lT X0lPX0hfCisjZW5kaWYgLyogIV9TWVNfSU9fSF8gKi8K --e89a8f3baf01a5d70304bad630a5--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAOfDtXPGPP0reN9NTBw_5%2BNwXZ56Yy0oyx_fH%2BDOvmpc1O%2BQdQ>