Commit Graph

574 Commits

Author SHA1 Message Date
Enrico Weigelt, metux IT consult
36ef6a448b randr: ProcRRGetProviderInfo(): use x_rpcbuf_t
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-09-02 11:06:05 +02:00
Enrico Weigelt, metux IT consult
331510cc8f randr: use X_SEND_REPLY_SIMPLE() for sending simple replies
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-31 14:19:23 +02:00
Enrico Weigelt, metux IT consult
e6c7bd7c86 randr: ProcRRGetOutputProperty(): use x_rpcbuf_t for payload assembly
Use x_rpcbuf_t for request assembly and X_SEND_REPLY_WITH_RPCBUF()
for finally sending out everything together.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-26 10:15:09 +02:00
Enrico Weigelt, metux IT consult
1d93fbc68e randr: use X_SEND_REPLY_WITH_RPCBUF() macro
Use the new X_SEND_REPLY_WITH_RPCBUF() macro for final reply write out

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-18 11:16:23 +02:00
Enrico Weigelt, metux IT consult
6c25d52276 randr: canonical walkScreen variable on screen list iterations
When iterating screen lists, consistently use the same variable name
`walkScreen` for holding current screen pointer everywhere.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-18 10:52:49 +02:00
Enrico Weigelt, metux IT consult
9b6ff22f1d randr: fix size parameter to WriteToClient()
Size computation needs to be done on the struct actually written.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-14 16:53:10 +02:00
Enrico Weigelt, metux IT consult
4454a26545 randr: use x_rpcbuf_t in ProcRRGetProviderProperty()
Use x_rpcbuf_t for reply payload assembly.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-14 14:19:49 +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
d19cfbfa70 randr: ProcRRGetOutputInfo (): simplify by using x_rpcbuf_t
* use x_rpcbuf_t for reply payload assembly and byte-swap
* do byte-swap of header fields explicitly instead of cryptic functions
* drop extra length computation

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-11 20:28:45 +02:00
Enrico Weigelt, metux IT consult
6b17a3bfbb randr: ProcRRQueryOutputProperty(): simplify by using x_rpcbuf_t
* use x_rpcbuf_t for reply payload assembly and byte-swap
* do byte-swap of header fields explicitly instead of cryptic functions
* drop extra length computation

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-11 20:23:24 +02:00
Enrico Weigelt, metux IT consult
16ab5a1456 randr: ProcRRListOutputProperties(): simplify by using x_rpcbuf_t
* use x_rpcbuf_t for reply payload assembly and byte-swap
* do byte-swap of header fields explicitly instead of cryptic functions
* drop extra length computation

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-11 20:20:17 +02:00
Enrico Weigelt, metux IT consult
e93b54bcea randr: ProcRRGetMonitors(): simplify by using x_rpcbuf_t
* use x_rpcbuf_t for reply payload assembly and byte-swap
* do byte-swap of header fields explicitly instead of cryptic functions
* drop extra length computation

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-11 20:14:35 +02:00
Enrico Weigelt, metux IT consult
f03042a2b7 dix: fix int mismatches related to MakeAtom()
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-11 20:05:57 +02:00
Enrico Weigelt, metux IT consult
578a554d0a randr: ProcRRGetCrtcGamma(): use x_rpcbuf_t for reply payload assembly
Simplify reply payload assembly and byte-swap by using x_rpcbuf_t.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-08 13:14:38 +02:00
Enrico Weigelt, metux IT consult
70c7c00fae randr: ProcRRGetCrtcTransform(): simplify by using x_rpcbuf_t
* use x_rpcbuf_t for reply payload assembly and byte-swap
* do byte-swap of header fields explicitly instead of cryptic functions
* drop extra length computation

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-08 13:14:19 +02:00
Enrico Weigelt, metux IT consult
1328254980 randr: ProcRRGetCrtcInfo(): use x_rpcbuf_t
Instead of using our own Use x_rpcbuf_t for assembling and
byte-swapping the reply payload.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-07 17:24:24 +02:00
Enrico Weigelt, metux IT consult
04c2c107d7 randr: rrcrtc: clean up declaration of xRRSetPanningReply
Declare struct where needed and drop zero-initialized fields.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-08-04 17:26:41 +02:00
Enrico Weigelt, metux IT consult
e1bbe46cbf randr: drop swapping request length fields
The request struct's length fields aren't used anymore - we have the
client->req_len field instead, which also is bigreq-compatible.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-07-29 11:45:53 +02:00
dec05eba
7ab50432ba randr: fix prime sync atom not created correctly
The commit 30cec78 incorrectly changed RRInitPrimeSyncProps to not
create the atom if it doesn't exist.

Signed-off-by: dec05eba <dec05eba@protonmail.com>
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-07-23 19:15:07 +02:00
Enrico Weigelt, metux IT consult
86b392979e dix: don't include dix-config.h from randrstr.h
This header needs to be included in all sources at the very top anyways,
so no need to do it in other headers, too.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-07-23 15:46:51 +02:00
Enrico Weigelt, metux IT consult
39ef9586be randr: use dixAddAtom()
Use the new helper for creating atoms on demand.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-07-23 12:24:27 +02:00
Enrico Weigelt, metux IT consult
30cec786e5 randr: use dixGetAtomID()
Use the new shortcut helper for cases where we need to check
whether an atom exists and retrieve it's ID.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-07-23 12:24:27 +02:00
Dudemanguy
eaf77db9a4 randr: set initial DPI property to a default value for all outputs
X has various ways to deal with DPI but all of the current methods have
some drawback (single global value, manually calculating from physical
dimensions, etc.) What is lacking is a simple value per output that
users and applications can use to communicate desired scaling values.
Fortunately, a generic output property mechanism already exists. And
they already send events whenever there is a change. So all we have to
do is make an "official" property for people to agree on and enshrine
it. In that case, all outputs can just always have the DPI property set
to something. In most cases, this will be 96 (the default), but one
could use the -dpi argument when launching or and that value will be
used instead. The intention is that 96 is the base that is equivalent to
1x scaling. i.e. 192 would be 2x, 144 would be 1.5x and so on. xrandr or
any other utility can modify this property at any time and applications
can choose to use the number in a way that makes sense.

Closes #208. Credit to @dec05eba for essentially coming up with the idea
of using output properties.

Signed-off-by: Dudemanguy <random342@airmail.cc>
2025-07-18 04:51:31 +02:00
dasha_uwu
7c64a06ba4 treewide: remove "lib" prefix in static_library names (meson)
this was producing static libraries named "liblibsomething.a"

Signed-off-by: dasha_uwu <dasha@linuxping.win>
2025-07-03 12:01:52 +02:00
Enrico Weigelt, metux IT consult
e91cfc890f randr: fix memleak in provider property update
If a device property is going to be updated, but failing due
the new value being too big, the buffer isn't freed.

Also compacting the logic for this into small inline function.

Fixes: 948630fa42
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-06-24 16:06:38 +02:00
Olivier Fourdan
948630fa42 randr: Check for overflow in RRChangeProviderProperty()
A client might send a request causing an integer overflow when computing
the total size to allocate in RRChangeProviderProperty().

To avoid the issue, check that total length in bytes won't exceed the
maximum integer value.

CVE-2025-49180

This issue was discovered by Nils Emmerich <nemmerich@ernw.de> and
reported by Julian Suleder via ERNW Vulnerability Disclosure.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/2024>
2025-06-17 20:01:25 +02:00
dasha_uwu
27f1094116 randr: export RRGetOutputProperty for nvidia
Signed-off-by: dasha_uwu <dasha@linuxping.win>
2025-06-16 10:32:48 +02:00
dasha_uwu
545f6ca8b7 randr: fix BUG_RETURN_VAL check
nvidia driver can call with numOutputs == 0 and outputs == NULL which is valid

Signed-off-by: dasha_uwu <dasha@linuxping.win>
2025-06-16 10:32:48 +02:00
dasha_uwu
1fe4d2d4ca randr: export RROutputSetSubpixelOrder for nvidia
Signed-off-by: dasha_uwu <dasha@linuxping.win>
2025-06-16 10:32:48 +02:00
dasha_uwu
3c20d33e2c randr: export RRCrtcSetTransformSupport for nvidia
Signed-off-by: dasha_uwu <dasha@linuxping.win>
2025-06-16 10:32:48 +02:00
Enrico Weigelt, metux IT consult
e6467895f9 dix: add dixAllocServerXID()
Adding a separate function for allocating server-client's XIDs.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-06-12 17:21:48 +02:00
Enrico Weigelt, metux IT consult
41c039948f randr: re-export RRTransformSetFilter() for Nvidia legacy
NVidia's proprietary driver does it's own randr implementation (why ?)
and needs this function for this.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-06-12 17:21:48 +02:00
Enrico Weigelt, metux IT consult
ec7a89a92c randr: re-export RRClientKnowsRates() for Nvidia legacy
NVidia's proprietary driver does it's own randr implementation (why ?)
and needs this function for this.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-06-12 17:21:48 +02:00
Enrico Weigelt, metux IT consult
15bb2bbb37 randr: re-export RRProviderSetCapabilities() for Nvidia legacy
NVidia's proprietary driver does it's own randr implementation (why ?)
and needs this function for this.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-06-12 17:21:48 +02:00
Enrico Weigelt, metux IT consult
da3791e9ce randr: re-export RRProviderCreate() for Nvidia legacy
NVidia's proprietary driver does it's own randr implementation (why ?)
and needs this function for this.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-06-12 17:21:48 +02:00
Enrico Weigelt, metux IT consult
90c1f3b2a8 randr: re-export RRCrtcDetachScanoutPixmap() for Nvidia legacy
NVidia's proprietary driver does it's own randr implementation (why ?)
and needs this function for this.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-06-12 17:21:48 +02:00
Enrico Weigelt, metux IT consult
5f91adf017 randr: re-export RRCrtcGetTransform() for Nvidia legacy
NVidia's proprietary driver does it's own randr implementation (why ?)
and needs this function for this.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-06-12 17:21:48 +02:00
Enrico Weigelt, metux IT consult
2ec00762f4 randr: re-export RRCrtcGetScanoutSize() for Nvidia legacy
NVidia's proprietary driver does it's own randr implementation (why ?)
and needs this function for this.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-06-12 17:21:48 +02:00
Enrico Weigelt, metux IT consult
1a534e204b randr: re-export RROutputSetNonDesktop() for Nvidia legacy
NVidia's proprietary driver does it's own randr implementation (why ?)
and needs this function for this.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-06-12 17:21:48 +02:00
Enrico Weigelt, metux IT consult
9696a151dd randr: re-export some resource type fields for NVidia legacy
NVidia's proprietary driver does it's own randr implementation (why ?)
and needs those fields for this.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-06-12 17:21:48 +02:00
Enrico Weigelt, metux IT consult
3c028a8cc0 miext: move over extinit_priv.h from include
Since most of the extension init logic (and on/off switches for them)
is driven from miext, this seems the appropriate place for the header.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-06-12 17:21:46 +02:00
Enrico Weigelt, metux IT consult
f25921f5fb randr: replace xallocarray() by calloc()
Only key difference that calloc(), in contrast to rellocarray(),
is zero-initializing. The overhead is hard to measure on today's
machines, and it's safer programming practise to always allocate
zero-initialized, so one can't forget to do it explicitly.

Cocci rule:

    @@
    expression COUNT;
    expression LEN;
    @@
    - xallocarray(COUNT,LEN)
    + calloc(COUNT,LEN)

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-06-12 17:21:43 +02:00
Enrico Weigelt, metux IT consult
8c873c04cb randr: use calloc() instead of malloc()
Using calloc() instead of malloc() as preventive measure, so there
never can be any hidden bugs or leaks due uninitialized memory.

The extra cost of using this compiler intrinsic should be practically
impossible to measure - in many cases a good compiler can even deduce
if certain areas really don't need to be zero'd (because they're written
to right after allocation) and create more efficient machine code.

The code pathes in question are pretty cold anyways, so it's probably
not worth even thinking about potential extra runtime costs.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-06-12 16:49:37 +02:00
Enrico Weigelt, metux IT consult
5a4656a731 randr: use CloseScreen hook
Wrapping ScreenRec's function pointers is problematic for many reasons,
so use the new screen close notify hook instead.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-06-12 16:45:29 +02:00
Enrico Weigelt, metux IT consult
5193f57aae randr: add BUG_* checks for possible NULL pointer issue
The ‘RRCrtcNotify() and RRCrtcSet() functions are exported, so there's chance
that a buggy driver could call them with NULL parameter, leading to segfault.
Those are hard to trace, so it's better having a BUG_* check here.

| ../randr/rrcrtc.c: In function ‘RRCrtcNotify’:
| ../randr/rrcrtc.c:187:5: warning: use of NULL ‘outputs’ where non-null expected [CWE-476] [-Wanalyzer-null-argument]
|   187 |     memcpy(crtc->outputs, outputs, numOutputs * sizeof(RROutputPtr));
|       |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

| ../randr/rrcrtc.c: In function ‘RRCrtcSet’:
| ../randr/rrcrtc.c:742:20: warning: dereference of NULL ‘outputs’ [CWE-476] [-Wanalyzer-null-dereference]
|   742 |         if (outputs[o]) {
|       |             ~~~~~~~^~~

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-06-12 16:32:35 +02:00
Enrico Weigelt, metux IT consult
90cd5c38ee randr: skip payload assembly in ProcRRGetScreenInfo() no data to send
If there's no data to send, the whole reply payload can be skipped entirely.
This can also ease the whole code flow, and we don't need to rely on the
individual copy loops never trying to dereference a NULL pointer.
(what the analyzer can't proof). Also scoping several some variables that
are only used when there actually is data to send.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-06-12 16:32:33 +02:00
Enrico Weigelt, metux IT consult
74a3b2b728 randr: skip payload assembly in rrGetScreenResources() no data to send
If there's no data to send, the whole reply payload can be skipped entirely.
This can also ease the whole code flow, and we don't need to rely on the
individual copy loops never trying to dereference a NULL pointer.
(what the analyzer can't proof). Also scoping several some variables that
are only used when there actually is data to send.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-06-12 16:32:29 +02:00
Enrico Weigelt, metux IT consult
67b78a9f58 randr: simplify reply assembly in ProcRRListProviderProperties()
Moving payload buffer assembly right into the same branch where the buffer is
allocated, so making the whole code flow easier to understand. Also moving the
byteswap there (when the fields should still be in CPU cache), instead of having
some callback doing it much later, so even more simplication.

As a nice by-product, that's also reducing some analyzer noise.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-06-12 16:32:27 +02:00
Enrico Weigelt, metux IT consult
2e05296905 randr: no need to for local temp buffer in ProcRRQueryProviderProperty()
The code can be much simpler by just using CopySwap32Write().
And we also don't need the callback in WriteSwappedDataToClient(),
just call the corresponding write function directly.

This also makes some analyzer warnings go away.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-06-12 16:32:24 +02:00
Enrico Weigelt, metux IT consult
b535db955a randr: ProcRRGetOutputInfo() skip payload assembly when nothing to do
If there's no extra payload to send, we can skip the whole payload
assembly chain.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2025-06-12 16:32:22 +02:00