Commit Graph

15611 Commits

Author SHA1 Message Date
Keith Packard
bf2ca502b9 config: Hold input lock across udev socket handling
This avoids having the server running inside libudev from two threads
at once, which it appears to not like.

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2016-08-16 17:33:59 +10:00
Olivier Fourdan
de5291c04b present: Free the fake_present OsTimerPtr
Plug a leak in present_fake_queue_vblank() where the OsTimer would not
be freed.

 492,608 (482,816 direct, 9,792 indirect) bytes in 15,088 blocks
are definitely lost in loss record 3,954 of 3,954
    at 0x4C2ABDE: malloc (in vgpreload_memcheck-amd64-linux.so)
    by 0x586B19: TimerSet (WaitFor.c:433)
    by 0x4F1AA9: present_fake_queue_vblank (present_fake.c:108)
    by 0x4F15E0: present_pixmap (present.c:954)
    by 0x4F23B4: proc_present_pixmap (present_request.c:138)
    by 0x552BCE: Dispatch (dispatch.c:430)
    by 0x556C22: dix_main (main.c:300)
    by 0x6F0D290: (below main) (in /usr/lib/libc-2.24.so)

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=97065
Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
2016-08-15 15:16:48 -04:00
Michel Dänzer
d21b53673b present: Call set_abort_flip / restore_screen_pixmap in clear_window_flip
We were asserting that these were called before from other places, but
that isn't always the case, e.g. during server shutdown.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=96951
Reported-and-Tested-by: Tod Jackson <tod.jackson@gmail.com>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Michel Dänzer <michel.daenzer@amd.com>
2016-08-15 15:14:53 -04:00
Michel Dänzer
9f04fa3bab present: Make present_restore_screen_pixmap handle screen->root == NULL
Easier than dealing with it in all paths that can end up here during
server shutdown.

Signed-off-by: Michel Dänzer <michel.daenzer@amd.com>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2016-08-15 15:14:43 -04:00
Olivier Fourdan
4cbf1fb1f9 xwayland: Avoid double free of RRCrtc and RROutput
At shutdown, the Xserver will free all its resources which includes the
RRCrtc and RROutput created.

Xwayland would do the same in its xwl_output_destroy() called from
xwl_close_screen(), leading to a double free of existing RRCrtc
RROutput:

 Invalid read of size 4
    at 0x4CDA10: RRCrtcDestroy (rrcrtc.c:689)
    by 0x426E75: xwl_output_destroy (xwayland-output.c:301)
    by 0x424144: xwl_close_screen (xwayland.c:117)
    by 0x460E17: CursorCloseScreen (cursor.c:187)
    by 0x4EB5A3: AnimCurCloseScreen (animcur.c:106)
    by 0x4EF431: present_close_screen (present_screen.c:64)
    by 0x556D40: dix_main (main.c:354)
    by 0x6F0D290: (below main) (in /usr/lib/libc-2.24.so)
  Address 0xbb1fc30 is 0 bytes inside a block of size 728 free'd
    at 0x4C2BDB0: free (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
    by 0x4CCE5F: RRCrtcDestroyResource (rrcrtc.c:719)
    by 0x577541: doFreeResource (resource.c:895)
    by 0x5787B5: FreeClientResources (resource.c:1161)
    by 0x578862: FreeAllResources (resource.c:1176)
    by 0x556C54: dix_main (main.c:323)
    by 0x6F0D290: (below main) (in /usr/lib/libc-2.24.so)
  Block was alloc'd at
    at 0x4C2CA6A: calloc (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
    by 0x4CC6DB: RRCrtcCreate (rrcrtc.c:76)
    by 0x426D1C: xwl_output_create (xwayland-output.c:264)
    by 0x4232EC: registry_global (xwayland.c:431)
    by 0x76CB1C7: ffi_call_unix64 (in /usr/lib/libffi.so.6.0.4)
    by 0x76CAC29: ffi_call (in /usr/lib/libffi.so.6.0.4)
    by 0x556CEFD: wl_closure_invoke (connection.c:935)
    by 0x5569CBF: dispatch_event.isra.4 (wayland-client.c:1310)
    by 0x556AF13: dispatch_queue (wayland-client.c:1456)
    by 0x556AF13: wl_display_dispatch_queue_pending
(wayland-client.c:1698)
    by 0x556B33A: wl_display_roundtrip_queue (wayland-client.c:1121)
    by 0x42371C: xwl_screen_init (xwayland.c:631)
    by 0x552F60: AddScreen (dispatch.c:3864)

And:

 Invalid read of size 4
    at 0x522890: RROutputDestroy (rroutput.c:348)
    by 0x42684E: xwl_output_destroy (xwayland-output.c:302)
    by 0x423CF4: xwl_close_screen (xwayland.c:118)
    by 0x4B6377: CursorCloseScreen (cursor.c:187)
    by 0x539503: AnimCurCloseScreen (animcur.c:106)
    by 0x53D081: present_close_screen (present_screen.c:64)
    by 0x43DBF0: dix_main (main.c:354)
    by 0x7068730: (below main) (libc-start.c:289)
  Address 0xc403190 is 0 bytes inside a block of size 154 free'd
    at 0x4C2CD5A: free (vg_replace_malloc.c:530)
    by 0x521DF3: RROutputDestroyResource (rroutput.c:389)
    by 0x45DA61: doFreeResource (resource.c:895)
    by 0x45ECFD: FreeClientResources (resource.c:1161)
    by 0x45EDC2: FreeAllResources (resource.c:1176)
    by 0x43DB04: dix_main (main.c:323)
    by 0x7068730: (below main) (libc-start.c:289)
  Block was alloc'd at
    at 0x4C2BBAD: malloc (vg_replace_malloc.c:299)
    by 0x52206B: RROutputCreate (rroutput.c:84)
    by 0x426763: xwl_output_create (xwayland-output.c:270)
    by 0x422EDC: registry_global (xwayland.c:432)
    by 0x740FC57: ffi_call_unix64 (unix64.S:76)
    by 0x740F6B9: ffi_call (ffi64.c:525)
    by 0x5495A9D: wl_closure_invoke (connection.c:949)
    by 0x549283F: dispatch_event.isra.4 (wayland-client.c:1274)
    by 0x5493A13: dispatch_queue (wayland-client.c:1420)
    by 0x5493A13: wl_display_dispatch_queue_pending
(wayland-client.c:1662)
    by 0x5493D2E: wl_display_roundtrip_queue (wayland-client.c:1085)
    by 0x4232EC: xwl_screen_init (xwayland.c:632)
    by 0x439F50: AddScreen (dispatch.c:3864)

Split xwl_output_destroy() into xwl_output_destroy() which frees the
wl_output and the xwl_output structure, and xwl_output_remove() which
does the RRCrtcDestroy() and RROutputDestroy() and call the latter only
when an output is effectively removed.

An additional benefit, on top of avoiding a double free, is to avoid
updating the screen size at shutdown.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2016-08-15 14:20:54 -04:00
Michel Dänzer
b380f3ac51 dix: Pass ClientPtr to FlushCallback
This change has two effects:

1. Only calls FlushCallbacks when we're actually flushing data to a
   client. The unnecessary FlushCallback calls could cause significant
   performance degradation with compositing, which is significantly
   reduced even without any driver changes.

2. By passing the ClientPtr to FlushCallbacks, drivers can completely
   eliminate unnecessary flushing of GPU commands by keeping track of
   whether we're flushing any XDamageNotify events to the client for
   which the corresponding rendering commands haven't been flushed to
   the GPU yet.

Reviewed-by: Adam Jackson <ajax@redha.com>
Signed-off-by: Michel Dänzer <michel.daenzer@amd.com>
2016-08-15 14:02:48 -04:00
Aaron Plattner
92b3cd3206 xace: Fix XaceCensorImage to actually censor the right part of the image
The caller passes arguments into XaceCensorImage that are in
window-relative coordinates. However, the pBuf that it uses to construct
a temporary pixmap has its origin at (x, y) relative to the window in
question. The code to convert the censor region into boxes adjusts for
the Y coordinate, but leaves the X coordinate alone. The result is that
if x is not zero, it censors the wrong part of the image.

Fix this by just translating censorRegion into pixmap-relative
coordinates and using the resulting boxes as-is.

Reported-by: Fabien Lelaquais <Fabien.Lelaquais@roguewave.com>
Link: https://lists.x.org/archives/xorg/2016-August/058165.html
Reviewed-by: Adam Jackson <ajax@redhat.com>
Signed-off-by: Aaron Plattner <aplattner@nvidia.com>
2016-08-15 13:12:06 -04:00
Olivier Fourdan
4d586118c1 xwayland: Plug memleak in frame callbacks
The frame callback set up via wl_surface_frame() needs to be freed with
wl_callback_destroy() or we'll leak memory.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=97065
Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Daniel Stone <daniels@collabora.com>
2016-08-15 12:49:36 -04:00
Matthieu Herrb
611b3b1d40 Autoconfig: Fix the loop adding dectected drivers to the list of screens
This loop was written in a buggy style, causing a NULL driver ptr to be
passed to copyScreen(). copyScreen() only uses that to generate an
identifier string, so this is mostly harmless on systems that accept
NULL for asprintf() "%s" format. (the generated identifiers are off
by one wrt the driver names and the last one contains NULL.

For systems that don't accept NULL for '%s' this would cause a
segmentation fault when this code is used (no xorg.conf, but partial
config in xorg.conf.d for instance).

Signed-off-by: Matthieu Herrb <matthieu@herrb.eu>
Reviewed-by: Keith Packard <keithp@keithp.com>
2016-08-15 12:43:43 -04:00
Emily Deng
88820f1c7b xfree86: vgaarb: Initialize local variable rsrc_decodes
In function xf86VGAarbiterScrnInit when the "pEnt->bus.type" is
BUS_PLATFORM, the "pScrn->vgaDev" won't be set, so the "pScrn->vgaDev" is
equal to zero.

The variable "rsrc_decodes" in function "xf86VGAarbiterAllowDRI" is not
initialized. So it will occur error when "pScrn->vgaDev == 0", and
"vga_count > 1". For this case, as "pScrn->vgaDev == 0", the function
"pci_device_vgaarb_get_info" will only set the value of "vga_count",
but won't set the value of "rsrc_decodes", so it will has two different
return values for function "xf86VGAarbiterAllowDRI" in different
platforms. One platform will return TRUE, as the "rsrc_decodes" 's
default value is 0, but another platform will return FALSE, as the
"rsrc_decodes" 's default value is "32767", this will cause disable
direct rendering.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=96937

Signed-off-by: Emily Deng <Emily.Deng@amd.com>
Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
2016-08-15 12:30:39 -04:00
Keith Packard
fa2bc06407 dix: Avoid writing uninitialized bytes in deliverPropertyNotifyEvent
Make sure the whole event is initialized, instead of leaving the pad
bytes unset.

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2016-08-15 08:54:45 -07:00
Keith Packard
67fc5d68f9 os: Abandon loop after poll call when array of fds has changed
If a file descriptor is added or removed from an ospoll callback, then
the arrays containing file descriptor information will have all of
their indices changed, so the loop state is no longer consistent. Just
bail out and let the caller come back around to try again.

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
2016-08-14 22:52:33 -07:00
Keith Packard
7d6fffb601 os: Delay freeing of epoll_wait return pointers until epoll is idle.
Instead of freeing the struct ospollfd elements when the fd is
removed by the user, delay that until epoll is idle so that we are
sure no epoll_event structures could contain the stale pointer. This
handles cases where an fd is removed from the ospoll callback
interface, and also in case the OS keeps stale pointers around after
the call to epoll_ctl with EPOLL_CTL_DEL.

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
2016-08-14 22:52:22 -07:00
Keith Packard
69b782aa75 xfree86: Set pScrn->pScreen before driver ScreenInit is called
Any code called from the driver ScreenInit may want to refer to
pScrn->pScreen. As the function passed to AddScreen is the first place
the DDX sees a new screen, the generic code needs to make sure that
value is set before passing control to the video driver's
initialization code.

This was found by running a driver which didn't bother to set this
value when the initial colormap was installed; xf86RandR12LoadPalette
tried to use pScrn->pScreen and crashed.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=97124
Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-and-Tested-by: Michel Dänzer <michel.daenzer@amd.com>
2016-08-13 09:18:15 -07:00
Keith Packard
387d6b5df3 Merge remote-tracking branch 'daenzer/for-master' 2016-08-13 09:12:19 -07:00
Keith Packard
d2558f063a Build glamor when Xorg or Xephyr are built.
Requires gbm when building Xorg so that xf86-video-modesetting will
work.

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
2016-08-13 09:04:32 -07:00
Keith Packard
2b9f8ae986 mi: Remove spurious call to OsReleaseSignals from mieqGrowQueue
This call wasn't converted to 'input_unlock()' when the SIGIO code was
removed from the server, and so when the queue growing was reworked to
be done from the input thread, it got left sitting here. As the caller
now manages the lock, we don't need to switch this to input_unlock at
this point.

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
2016-08-11 21:55:06 -07:00
Peter Hutterer
f399919e13 xfree86: lock input during PreInit
This is a problem for the libinput driver that uses the same context across
multiple devices. The driver may be halfway through setting up an input device
(and the only way to do so is to add it to libinput) when the input thread
comes in an reads events. This then causes mayhem when data is dereferenced
that hasn't been set up yet.

In my case the cause was the call to libinput_path_remove_device() inside
preinit racing with evdev_dispatch_device() handling of ENODEV. The sequence
was:
- thread 2 gets an event and calls evdev_dispatch_device()
- thread 1 calls libinput_path_remove_device() which sets the device->source
  to NULL
- thread 2 reads from the fd, gets ENODEV and now removes the device->source,
  dereferencing the null-pointer

This is the one I could reproduce the most, but there are other potential
pitfalls that affect any driver that uses the same fd for multiple devices.
Avoid all this and wrap PreInit into the lock.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Keith Packard <keithp@keithp.com>
2016-08-12 14:43:08 +10:00
Peter Hutterer
dd4e21cb3a xfree86: fix unbalanced input_lock/unlock in xf86NewInputDevice()
If a device couldn't be enabled we left the lock hanging.

This patch also removes the leftover OsReleaseSignals() call, now unnecessary.
Note that input_unlock() is later than previously OsReleaseSignals().
RemoveDevice() manipulates the input device and its file descriptors, it's
safer to put the input_unlock() call after RemoveDevice() to avoid events
coming in while the device is being removed.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Keith Packard <keithp@keithp.com>
2016-08-12 14:41:19 +10:00
Keith Packard
bf31d6f43e os: Allow re-registering fd with InputThreadRegisterDev
Calling InputThreadRegisterDev twice with the same fd should replace
the existing function and args instead of creating a new entry with
the same fd.

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2016-08-12 10:33:21 +10:00
Peter Hutterer
2df2815d6a os: append, rather than prepend, any new input thread fds
xf86AddEnabledDevice() prepends the new fd to the list,
xf86RemoveEnabledDevice() then searches for a matching fd and removes that
entry. If this is done for the same fd (and since we lose all information but
the actual fd) we usually unregister virtual devices in reverse order, causing
a dereference of already released memory.

Case in point:
- the wacom driver calls xf86AddEnabledDevice() once for the physical device,
  then multiple times for the virtual subdevices
- when the physical device is unplugged, the driver calls
  xf86RemoveEnabledDevice() for the physical device
- all we have is the fd, so we end up removing the last virtual device from
  the fd set
- xf86DeleteInput() frees the physical device's pInfo
- the fd goes crazy with ENODEV, but a read_input() now passes the already
  freed pInfo for the physical device
- boom

Fix this by appending to the fd list to provide bug-for-bug compatibility with
the old SIGIO code. This needs to be fixed in the driver, but meanwhile not
crashing the server provides for better user experience.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Keith Packard <keithp@keithp.com>
2016-08-11 11:41:51 +10:00
Michel Dänzer
a446ff84de xfree86/modes: Handle no palette case better in xf86RandR12CrtcSetGamma
Just use the RandR gamma ramp directly.

Fixes random on-monitor colours with drivers which don't call
xf86HandleColormaps, e.g. modesetting.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=97154

Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
2016-08-10 16:56:09 +09:00
Kenneth Graunke
d3d4ff0ed4 modesetting: Delete dead drmmode_bo_for_pixmap function.
Embarassingly, it looks like I introduced this dead function in
commit 13c7d53df8 a year ago.
Nothing ever used it, not even then.

Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Eric Anholt <eric@anholt.net>
2016-08-08 23:42:40 -07:00
Michel Dänzer
8bb9d460fb xfree86/modes: Handle no palette case better in xf86RandR12CrtcSetGamma
Just use the RandR gamma ramp directly.

Fixes random on-monitor colours with drivers which don't call
xf86HandleColormaps, e.g. modesetting.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=97154

Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
2016-08-02 09:57:56 +09:00
Michel Dänzer
c833c0866f present: Handle event mask updates as specified v2
From the Present extension specification:

 An event context is associated with a specific window; using
 an existing event context with a different window generates
 a Match error.

 If eventContext specifies an existing event context, then if
 eventMask is empty, PresentSelectInput deletes the specified
 context, otherwise the specified event context is changed to
 select a different set of events.

 If eventContext is an unused XID, then if eventMask is empty
 no operation is performed. Otherwise, a new event context is
 created selecting the specified events.

Without this change, there's no way for a client to explicitly change
or destroy an existing event mask entry. Trying to do so as specified
above would just result in a protocol error.

v2: (Keith Packard)
* Use dixLookupResourceByType instead of walking window_priv->events
* Return BadMatch if the existing event context is associated with a
  different window or client
* Call LEGAL_NEW_RESOURCE again when creating a new event context
* Drop invalid "leak fix"

Signed-off-by: Michel Dänzer <michel.daenzer@amd.com>
Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2016-07-30 15:43:54 -07:00
Michel Dänzer
0924ac014d present: Only call restore_screen_pixmap once from set_abort_flip
present_restore_screen_pixmap's work doesn't need to be done several
times for the same pending flip.

Fixes a crash if the X server quits while a flip is pending, in which
case present_set_abort_flip may be called several times, including when
screen->root is already cleared to NULL.

Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2016-07-28 10:12:44 +09:00
Michel Dänzer
b4e46c0444 xfree86: Hook up colormaps and RandR 1.2 gamma code v6
Instead of breaking the former when the driver supports the latter,
hook them up so that the hardware LUTs reflect the combination of the
current colourmap and gamma states. I.e. combine the colourmap, the
global gamma value/ramp and the RandR 1.2 per-CRTC gamma ramps into one
combined LUT per CRTC.

Fixes e.g. gamma sliders not working in games.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=27222

v2:
* Initialize palette_size and palette struct members, fixes crash on
  server startup.
v3:
* Free randrp->palette in xf86RandR12CloseScreen, fixes memory leak.
v4:
* Call CMapUnwrapScreen if xf86RandR12InitGamma fails (Emil Velikov).
* Still allow xf86HandleColormaps to be called with a NULL loadPalette
  parameter in the xf86_crtc_supports_gamma case.
v5:
* Clean up inner loops in xf86RandR12CrtcComputeGamma (Keith Packard)
* Move palette update out of per-CRTC loop in xf86RandR12LoadPalette
  (Keith Packard)
v6:
* Handle reallocarray failure in xf86RandR12LoadPalette (Keith Packard)

Reviewed-by: Keith Packard <keithp@keithp.com>
2016-07-28 10:12:05 +09:00
Michel Dänzer
17213b74fd xfree86/modes: Remove xf86RandR12CrtcGetGamma
This would normally return the same values the core RandR code passed to
xf86RandR12CrtcSetGamma before, which is rather pointless. The only
possible exception would be if a driver tried initializing
crtc->gamma_red/green/blue to reflect the hardware LUT state on startup,
but that can't work correctly if whatever set the LUT before the server
started was running at a different depth.

Even the pointless round-trip case will no longer work with the
following change.

Reviewed-by: Keith Packard <keithp@keithp.com>
2016-07-28 10:11:14 +09:00
Michel Dänzer
62f4405257 xfree86/modes: Move gamma initialization to xf86RandR12Init12 v2
RRCrtcGammaSetSize cannot be used yet in xf86InitialConfiguration,
because randr_crtc isn't allocated yet at that point, but a following
change will require RRCrtcGammaSetSize to be called from
xf86RandR12CrtcInitGamma.

v2:
* Bail from xf86RandR12CrtcInitGamma if !crtc->funcs->gamma_set (Keith
  Packard)

Reviewed-by: Keith Packard <keithp@keithp.com>
2016-07-27 17:49:39 +09:00
Keith Packard
0b2f30834b os: Clean up WaitFor.c
Do all timer stuff before blocking, avoiding a bunch of duplicate code
and merge common code in WaitForSomething.

The WaitForSomething changes need a bit of explanation to show that
the new code is effectively equivalent to the old. Eliding error
checking and trivial bits we've got:

Before:

	if (ready clients)
		timeout = 0
	else
		compute timeout
	i = poll
	if (i <= 0) {
		if (ready clients)
			return TRUE;
		if (input)
			return FALSE;
		if (any ready timers) {
			run timers
			return FALSE;
		}
	} else {
		if (input)
			return FALSE;
		if (any ready timers) {
			run timers
			return FALSE;
		}
		if (ready clients)
			return TRUE;
	}

After:

	if (ready clients)
		timeout = 0;
	else
		compute timeout
		run_timers
	poll

	if (input)
		return FALSE;

	if (ready clients)
		return TRUE;

The old code would return TRUE if there were ready clients and input
pending. Dispatch would then schedule that ready client, but before
processing any requests, it would notice that there was input pending
and go process it. The new code just checks for input first, which is
effectively the same.

If the poll timed out and there weren't clients ready, then timers
would get run.

If the poll didn't time out, then timers would get run, even if there
were clients now ready. Now, if the timeout interval was zero, that
means that the timers must have been ready *before* poll was
invoked. In this case, we should simply run the timers before calling
poll -- no sense calling poll just to discard any data that it
generates.

If the timeout interval was non-zero, and poll didn't timeout, then
either there aren't any timers to run, or we got a surprise and hit a
timer exactly as a client became ready to run. This is the one case
where the new code is different from the old; the new code delays the
timer call until the next time WaitForSomething is called.

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2016-07-21 15:04:47 -04:00
Keith Packard
2ab8b1dcd3 os: Use xorg_list for struct _OsTimerRec
No sense having an open-coded linked list here, plus the doubly linked
list is more efficient

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2016-07-21 15:04:47 -04:00
Keith Packard
50779c494d os: Remove CheckConnections
poll provides per-fd notification of failure, so we don't need
CheckConnections anymore.

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2016-07-21 15:04:47 -04:00
Keith Packard
f0275b1e5a os: Leave stdin and stdout open
There's no reason to close these now that we don't care what file
descriptors we use.

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2016-07-21 15:04:47 -04:00
Keith Packard
8217c29d2d Allow 1024 and 2048 for LimitClients
There's no reason not to offer ridiculous numbers of clients; only a
few static data structures are arrays of this length.

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2016-07-21 15:04:47 -04:00
Keith Packard
e0edb963fe os: eliminate fd value limits for clients
With no code depending on the range of file descriptors, checking
for that can be eliminated.

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2016-07-21 15:04:47 -04:00
Keith Packard
30bc0732f9 os: Use ospoll for input thread [v2]
Replace use of select(2) to avoid fd limits. Note that
InputThreadFillPipe used select as well, but none of the files passed
were non-blocking, so there was no need for that code at all.

v2: Keep ospoll API usage single threaded to avoid re-entrancy issues

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2016-07-21 15:04:47 -04:00
Keith Packard
f993091e7d os: Switch server to poll(2) [v3]
Eliminates all of the fd_set mangling in the server main thread

v2: Listen for POLLOUT while writes are blocked.

v3: Only mark client not ready on EAGAIN return from read

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2016-07-21 15:04:47 -04:00
Keith Packard
8f1edf4bd3 dix: Use list for ready clients
This converts the dispatch loop into using a list of ready clients
instead of an array. This changes the WaitForSomething API so that it
notifies DIX when a client becomes ready to read, instead of returning
the set of ready clients.

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2016-07-21 15:04:47 -04:00
Keith Packard
d6eff3c31e os: Add ospoll interface [v2]
This provides a wrapper around poll or epoll providing a
callback-based interface for monitoring activity on a large set of
file descriptors.

v2: use xserver_poll API instead of poll. Don't use WSAPoll as
    that is broken.

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2016-07-21 15:04:47 -04:00
Keith Packard
d403aca70a Switch poll() users to xserver_poll()
This uses the wrapper in case we need to emulate poll with select
as we do on Windows.

Reviewed-by: Adam Jackson <ajax@redhat.com>
Signed-off-by: Keith Packard <keithp@keithp.com>
2016-07-21 15:04:36 -04:00
Brian M. Clapper
711c36558f os: Add poll emulation for mingw [v2]
v2: rename as 'xserver_poll' to avoid potential library name
    collisions. Provide 'xserver_poll.h' which uses the system
    poll where available and falls back to this emulation otherwise.
    Autodetects when this is required, building the emulation only
    then

Source: https://github.com/bmc/poll
Signed-off-by: Adam Jackson <ajax@redhat.com>
2016-07-19 11:08:21 -07:00
Jon Turney
2a79be9e4d hw/xwin: Update BlockHandler function signature
Update for removal of fdset from Block/Wakeup handler API in 9d15912a

Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
Reviewed-by: Keith Packard <keithp@keithp.com>
2016-07-19 08:10:11 -07:00
Jon Turney
60a91031d1 hw/xwin: Update for removal of AddEnabledDevice
Update for removal of AddEnabledDevice in be5a513f. Use SetNotifyFd instead.

Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
Reviewed-by: Keith Packard <keithp@keithp.com>
2016-07-19 08:10:03 -07:00
Peter Hutterer
7f2d690725 xfree86: if ATTR_KEYBOARD is set, match for keyboards
ATTR_KEY maps to ID_INPUT_KEY which is set for any device with keys.
ID_INPUT_KEYBOARD and thus ATTR_KEYBOARD is set for devices that are actual
keyboards (and have a set of expected keys).

Hand-written match rules may only apply ID_INPUT_KEYBOARD, so make sure we
match on that too.

Arguably we should've been matching on ATTR_KEYBOARD only all along but
changing that likely introduces regressions.

Reported-by: Marty Plummer <netz.kernel@gmail.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2016-07-18 16:40:46 -04:00
Adam Jackson
4b311d23e8 modesetting: resubmit dirty rects on EINVAL (v2)
This error code can mean we're submitting more rects at once than the
driver can handle. If that happens, resubmit one at a time.

v2: Make the rect submit loop more error-proof (Walter Harms)

Signed-off-by: Adam Jackson <ajax@redhat.com>
Reviewed-by: Michael Thayer <michael.thayer@oracle.com>
2016-07-18 16:35:16 -04:00
Keith Packard
8d3a368d89 os: InputThreadFillPipe doesn't need select or poll
The file descriptors passed to InputThreadFillPipe are always
blocking, so there's no need to use Select (or poll).

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2016-07-18 15:27:51 -04:00
Keith Packard
ef7ddbe242 os: Move ETEST macro from io.c to osdep.h
This lets other code share this functionality

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2016-07-18 15:27:51 -04:00
Keith Packard
0d294462a5 os: Add X_NOTIFY_ERROR value
This provides a way to report errors on file descriptors that is
better defined than "any bits which are not READ or WRITE".

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2016-07-18 15:27:51 -04:00
Keith Packard
e6636b4383 os: Compute timeout in milliseconds instead of struct timeval
The timeout resolution offered in the AdjustWaitForDelay call is
only milliseconds, so passing around the timeout as a pointer to a
struct timeval is not helpful. Doing everything in milliseconds up to
the point of the select call simplifies the code without affecting
functionality at all.

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2016-07-18 15:27:51 -04:00
Keith Packard
a414db0215 dix: Intermediate GrabServer state 'GrabKickout' not needed
The intermediate grabState, "GrabKickout", was used to trigger
dispatch into going back to WaitForSomething after doing a GrabServer
so that the set of ready clients would be recomputed to match what the
server should be processing. As we only process one client per
WaitForSomething call, we will always hit WaitForSomething after
finishing the current client, and so don't need any special case here.

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2016-07-18 15:27:51 -04:00