Commit Graph

1103 Commits

Author SHA1 Message Date
Enrico Weigelt, metux IT consult
9b1fb83d6b os: xtrans: drop unused transport table indices
These aren't used anymore, so no need to keep them any longer.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-09-24 16:34:33 +02:00
Enrico Weigelt, metux IT consult
e1d372db70 os: xtrans: drop unused _XSERVTransBytesReadable()
Not used anywhere, so no need to keep it around anymore.
Also dropping the BytesReadable vector, which is unused now.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-09-24 15:53:57 +02:00
Enrico Weigelt, metux IT consult
80e6e7693b os: log: make LogVHdrMessageVerb() static
Only used inside log.c and not exported, so can be made static.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-09-24 11:58:46 +02:00
Enrico Weigelt, metux IT consult
ac0a267f1d xace: drop unused XACE_AUTH_AVAIL
Not used anymore for almost two decades, so no need to keep it.

Fixes: eafaf40fb3
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-09-23 11:44:14 +02:00
Enrico Weigelt, metux IT consult
9856372932 dix: add callback before ClientRec is being destroyed
Existing client-state hook isn't sufficient for this, and so easy to
be extended cleanly (*1). Adding a new callback is trivial and cheap,
so preferring this way, instead of trying to tweak the existing hook
for something it's never been designed for.

*1) see discussion here: https://github.com/X11Libre/xserver/pull/1077

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-09-22 12:15:31 +02:00
stefan11111
0cfe43853e os: hw/xfree86/x86emu: Silence warnings on gcc
Signed-off-by: stefan11111 <stefan11111@shitposting.expert>
2025-09-22 12:12:48 +02:00
stefan11111
5943ca5a1d os: Fix builds with -Dxdmcp=false
Fixes: https://github.com/X11Libre/xserver/issues/239
Signed-off-by: stefan11111 <stefan11111@shitposting.expert>
2025-09-22 12:00:14 +02:00
Enrico Weigelt, metux IT consult
4f65d06116 os: replace GenerateRandomData() by custom arc4random_buf() on platforms that missing it
arc4random_buf() is a pretty standard libc function on Unix'oid platforms,
but not all our targets have it, thus we need a fallback there. Currently we
have GenerateRandomData(), which either just wraps arc4random_buf() or provides
some fallback implementation.

For those cases it's easier to just implement missing functions directly
instead of having custom wrapper functions. So, drop GenerateRandomData()
in favor of arc4random_buf() and provide fallback implementation for where
it is missing.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-09-12 15:37:13 +02:00
Enrico Weigelt, metux IT consult
7193bd9fab os: osdep.h: workaround for win32 define CreateWindow
We need to undef this win32 symbol, otherwise it's conflicting with our
`CreateWindow` fields.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-09-03 14:14:13 +02:00
Enrico Weigelt, metux IT consult
fbc8463e84 os: xtrans: silence printf format warning on prmsg() call
size_t is unsigned, but might have different sizes depending on CPU arch,
so casting it to unsigned long, so we can safely use %ld.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-09-01 11:43:45 +02:00
Enrico Weigelt, metux IT consult
c9ac063793 os: xtrans: rename Writev() methods to Write()
The Writev() methods essentially became Write() now.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-31 15:51:33 +02:00
Enrico Weigelt, metux IT consult
449327f68f os: xtrans: drop own struct iovec definition on win32
We don't need our own `struct iovec` definition on win32/mingw anymore.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-31 15:51:33 +02:00
Enrico Weigelt, metux IT consult
3c5caa1ba0 os: xtrans: drop old Write() methods
Since everything's running via Writev() methods now, the now unused Write()
methods can all be dropped.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-31 15:51:33 +02:00
Enrico Weigelt, metux IT consult
a52ac4fb26 os: xtrans: replace _XSERVTransWriteV()
Now that all WriteV() methods are operating on single buffer instead ofiovec's,
we don't need the complicated _XSERVTransWriteV() anymore, but instead can
write directly to the socket/fd.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-31 15:51:33 +02:00
Enrico Weigelt, metux IT consult
c079ad54fb os: xtrans: let Writev() methods accept just one buffer instead of iovec
Since they're only called with a one-element iovec, we can use a single
buffer pointer straight away, thus making it quite the same as the old
Write() methods.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-31 15:51:33 +02:00
Enrico Weigelt, metux IT consult
a905a3921b os: xtrans: _XSERVTransWriteV(): call ciptr->transptr->Write() directly
_XSERVTransWrite() is only intended as frontend, for xtrans consumers to
call in here. And upcoming commits will change that function to call the
Writev() method instead of Write(), so we would end up in infinite
recursing if we'd still it it here.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-31 15:51:33 +02:00
Enrico Weigelt, metux IT consult
b738a28098 os: xtrans: simplify _XSERVTransWriteV()
Refactor _XSERVTransWriteV() to call write() on Unix and instead drop
the WRITEV() macro.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-31 15:51:33 +02:00
Enrico Weigelt, metux IT consult
e46f51cee9 os: xtrans: drop now obsolete _XSERVTransWritev()
_XSERVTransWritev() isn't used anymore, so no need to keep it.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-31 15:51:33 +02:00
Enrico Weigelt, metux IT consult
60b28c2568 os: osdep: small helper for safe strlen()
Adding helper safe_strlen() that's also checking for NULL pointer
and returning 0 in this case.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-18 16:15:41 +02:00
Enrico Weigelt, metux IT consult
34c3a9c7e2 treewide: fix serverGeneration int type mismatch
The global (exported) serverGeneration field is `unsigned long`, while
many other places copy it and compare it two other integer types, eg.
plain `int` (which is signed). Even if it's unlikely ever reaching such
high number of generations that it will ever make trouble, it's still
a good idea to clean this up and use the same type everywhere.

For clearity, introducing a typedef `x_server_generation_t` which is
used everywhere, instead of raw `unsigned long`.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-13 11:52:03 +02:00
Enrico Weigelt, metux IT consult
26c2df04e9 os: use size_t as iov length parameter xtrans writev{,v}
struct msghdr is using size_t as for iov_length, so match up with it.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-11 20:14:04 +02:00
stefan11111
81770d7315 os: use ssize_t in xtrans write{,v}
Signed-off-by: stefan11111 <stefan11111@shitposting.expert>
2025-08-11 20:14:04 +02:00
Oleh Nykyforchyn
c4077eb298 xserver: os: reexport TimerForce() but do not allow compile drivers with it
This function is called by nvidia390 legacy proprietary driver.

Signed-off-by: Oleh Nykyforchyn <oleh.nyk@gmail.com>
2025-08-07 19:48:35 +02:00
stefan11111
84081451bc os: fix OutputBufferMakeRoom and rename it to OutputBufferMakeRoomAndFlush
This function was badly broken, among other things doing a
use after free, a NULL-pointer dereferrence, and not doing
what it was supposed to do.

Signed-off-by: stefan11111 <stefan11111@shitposting.expert>
2025-08-07 19:26:12 +02:00
stefan11111
909a5462ac os: fix FlushClient
Flushclient implicitly cast the result from a write-like call
to size_t, which turned it's error return value, -1,
into a large positive value, breaking the surrounding error-checking code.

Signed-off-by: stefan11111 <stefan11111@shitposting.expert>
2025-08-07 19:26:12 +02:00
stefan11111
fe186eee6f os: use /= 2 instead of >>= 1
Compilers optimize the first one to the second one.

Signed-off-by: stefan11111 <stefan11111@shitposting.expert>
2025-08-07 19:26:12 +02:00
stefan11111
808fc3a604 os: further simplify FlushClient
Since FlushClient only writes the data in the client's buffer,
with no extra data or padding, we only write at most as many bytes
as there are in the client buffer.

we just have to set oco->count to notWritten, the amount we still
have to write.

Signed-off-by: stefan11111 <stefan11111@shitposting.expert>
2025-08-07 19:26:12 +02:00
Enrico Weigelt, metux IT consult
0de028016d os: osdep: drop WIN32 compat for uname()
Since nothing on WIN32 (mingw) targets is calling uname() anymore,
this compat code is now obsolete.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-07 16:57:43 +02:00
Enrico Weigelt, metux IT consult
7b1283268c os: access: use xhostname()
Simplify DefineSelf() by using xhostname(). Neither need to
care about OS specifics here, nor take care of zero-terminating the
hostname string - xhostname() is already doing this.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-07 16:57:43 +02:00
Enrico Weigelt, metux IT consult
d5dda483cb os: xtrans: replace _XSERVTransGetHostname() by xhostname()
Now that we have the OS layer xhostname() wrapper, we don't need the
_XSERVTransGetHostname() function anymore.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-07 16:57:43 +02:00
Enrico Weigelt, metux IT consult
ab08f9e0a2 os: utils:: use xhostname()
Simplify set_font_authorizations() by using xhostname(). Neither need to
care about OS specifics here, nor take care of zero-terminating the
hostname string - xhostname() is already doing this.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-07 16:57:43 +02:00
Enrico Weigelt, metux IT consult
df0d09dcb2 os: xhostname: helper for gethostname()
This little helper does the OS specific part for gethostname()
calls. It's putting the result into a fixed-length struct and making
sure it's properly filled and the string is always zero-terminated.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-07 16:57:43 +02:00
Enrico Weigelt, metux IT consult
435de433cd os: io: fix NULL output buffer after FlushClient()
FlushClient() does drops the output buffer, when it becomes empty.
This previously wasn't any problem and actually intented, because we've
returned from the write path directly after FlushClient() was called.

But now we've changed the call order, so it's called from within
OutputBufferMakeRoom(), so we need to make sure we always got valid
output buffer before trying to access it.

For the future, we should think about whether dropping output buffers
really makes sense at all. Instead we could leave them as they are
(over the client's lifetime) and maybe just trim when they've went
too big.

Fixes: 1c13cfa6ca
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-07 14:00:25 +02:00
Enrico Weigelt, metux IT consult
97f3ff8c7e os: cross platform socket close() wrapper
Reducing the ifdef-zoo a bit by moving the platform specific socket
close calls into separate function. On win32, this also checks the
retval and potentially query for error. On Unix, just calling close().

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-07 12:40:35 +02:00
Enrico Weigelt, metux IT consult
ec20354aec os: cross platform ioctl() wrapper
Reducing the ifdef-zoo a bit by moving the platform specific socket
ioctl calls into separate function. On win32, this also checks the
retval and potentially query for error. On Unix, just calling ioctl().

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-07 12:40:35 +02:00
Enrico Weigelt, metux IT consult
fe795fa7b8 os: generic socket layer init function
Reduce the ifdef-zoo a bit by moving win32 specific socket layer init
into a separate function (that's no-op on non-win32).

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-07 12:40:35 +02:00
Enrico Weigelt, metux IT consult
fdf43d4176 os: io: FlushClient() consolidate error/abort code path
remove some redundancy in the error path

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-07 12:36:20 +02:00
Enrico Weigelt, metux IT consult
0d8e9ee708 os: xtranssock: drop weird check of "out of range" socket
A socket() call either returns a valid socket fd or -1, there's no need for
trying to check whether the returned fd is out of the OS's allowed range
of fd's, because if it would, the kernel would return error anyways.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-05 12:18:19 +02:00
Enrico Weigelt, metux IT consult
e6e2b88cff io: os: simplify FlushClient()
Since nobody's passing in extra data here anymore, this function
can be radically simplified now.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-04 15:55:36 +02:00
Enrico Weigelt, metux IT consult
1298653ddb os: io: FlushClient(): check for broken connection earlier
Move up the check for broken/NULL transport connection in order to
simplify the code a bit more.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-04 15:55:36 +02:00
Enrico Weigelt, metux IT consult
1c13cfa6ca os: io: factor out making room in output buffer
First step for simplifying the output path - this is really complicated now:

FlushClient() is called in two cases:

a) we really need to send out critical data (eg. critical events now),
   here we have no extra data
b) going to write new data in the output buffer, but it's already full
   here we do have extra data

In case b) (only called from WriteToClient()) we're first trying to write out
as much as we can, and if there's still not enough room, the buffer is resized.
The write-out path is a complex look trying to write buffered data first, then
the new data. That's even more complex since using writev() with 3 pieces
(old buffer, new data, padding), and considering each of those could be written
just partially.

By the way, there's really no need that the new data is strictly written
along with the already buffered one - practically that's not even any actual
performance optimization - so it's just making things unncessarily complicated.

Therefore reduce it to what's really needed: ensure enough room in the output
buffer (and potentially flush out or resize the buffer). In a later, remove the
whole extra data part from FlushClient(), as it's not needed anymore.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-04 15:55:36 +02:00
Enrico Weigelt, metux IT consult
a3a068d6d3 os: connection: simplify connection error sending
It's such a cold and rarely used path, we really don't need writev() for
efficiency, so instead doing two trivial write()'s. And the complex size
calculation as well as extra padding isn't necessary, if we just make
the string of size 4*n.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-04 15:47:09 +02:00
Enrico Weigelt, metux IT consult
235a8e0f91 os: ospoll: include winsock2.h on WIN32 instead of misc.h
On WIN32 we need to include winsock2.h, but we can't include misc.h here
becaues it pulling in X11 headers that are conflicting with win32 headers.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-07-31 17:41:20 +02:00
Enrico Weigelt, metux IT consult
d9f82ada19 os: xtranssock: win32: use separate symbol for socket close
Instead of redefining existing standard libc symbols, pick another symbol
that's mapped to the corresponding platform specific function.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-07-31 17:32:03 +02:00
Enrico Weigelt, metux IT consult
2353d7a710 os: xtrans: replace _XSERVTransSetOption() by _XSERVTransNonBlock()
The only option left is TRANS_NONBLOCKING, and we only enable and
never disable it. Thus trim down the code into one function for
exactly that.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-07-31 17:30:52 +02:00
Enrico Weigelt, metux IT consult
ad53be3a32 os: xtrans: drop use of FNDELAY
That's an ancient symbol, which had been replaced by O_NDELAY long ago.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-07-31 17:10:58 +02:00
Enrico Weigelt, metux IT consult
399c51bb6d os: xtrans: drop _XSERVTransReadv() et al
It's not used anywhere, so no need to keep it around anymore.
We can also dispose the corresponding connection driver's procs here.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-07-31 17:09:37 +02:00
Enrico Weigelt, metux IT consult
a317ae39ad os: xtrans: _XSERVTransGetHostname() variant for mingw target
Win32 does not have utsname(), but gethostname(), so we need a separate
implementation of _XSERVTransGetHostname() here.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-07-31 17:05:49 +02:00
Enrico Weigelt, metux IT consult
3031e96abf os: xprintf: fix includes
It's better coding style to include the header with prototypes for
our own functions directly, instead of relying on it being included
indirectly.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-07-31 17:01:10 +02:00
Enrico Weigelt, metux IT consult
8c3d608d4e os: xserver_poll: skip defining symbols already defined by mingw
mingw already has struct pollfd and POLL* defines.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-07-31 15:28:08 +02:00