diff --git a/ui/console-gl.c b/ui/console-gl.c
index baf397b..74b1bed 100644
--- a/ui/console-gl.c
+++ b/ui/console-gl.c
@@ -24,6 +24,7 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
+#include "qemu/osdep.h"
 #include "qemu-common.h"
 #include "ui/console.h"
 #include "ui/shader.h"
diff --git a/ui/console.c b/ui/console.c
index fe950c6..309e10a 100644
--- a/ui/console.c
+++ b/ui/console.c
@@ -21,6 +21,7 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
+#include "qemu/osdep.h"
 #include "qemu-common.h"
 #include "ui/console.h"
 #include "hw/qdev-core.h"
diff --git a/ui/curses.c b/ui/curses.c
index 274e09b..b475589 100644
--- a/ui/curses.c
+++ b/ui/curses.c
@@ -21,6 +21,7 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
+#include "qemu/osdep.h"
 #include <curses.h>
 
 #ifndef _WIN32
diff --git a/ui/cursor.c b/ui/cursor.c
index 2b8dd3f..a276e01 100644
--- a/ui/cursor.c
+++ b/ui/cursor.c
@@ -1,3 +1,4 @@
+#include "qemu/osdep.h"
 #include "qemu-common.h"
 #include "ui/console.h"
 
diff --git a/ui/egl-context.c b/ui/egl-context.c
index 40102e3..3a02b68 100644
--- a/ui/egl-context.c
+++ b/ui/egl-context.c
@@ -1,3 +1,4 @@
+#include "qemu/osdep.h"
 #include "qemu-common.h"
 #include "ui/egl-context.h"
 
diff --git a/ui/egl-helpers.c b/ui/egl-helpers.c
index 87d77af..4c83834 100644
--- a/ui/egl-helpers.c
+++ b/ui/egl-helpers.c
@@ -1,11 +1,4 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdint.h>
-#include <stdbool.h>
-#include <unistd.h>
-#include <string.h>
-#include <errno.h>
-#include <fcntl.h>
+#include "qemu/osdep.h"
 #include <glob.h>
 
 #include "ui/egl-helpers.h"
diff --git a/ui/gtk-egl.c b/ui/gtk-egl.c
index 500c42c..431457c 100644
--- a/ui/gtk-egl.c
+++ b/ui/gtk-egl.c
@@ -11,6 +11,7 @@
  * See the COPYING file in the top-level directory.
  */
 
+#include "qemu/osdep.h"
 #include "qemu-common.h"
 
 #include "trace.h"
diff --git a/ui/gtk-gl-area.c b/ui/gtk-gl-area.c
index dec3edb..b86ff3c 100644
--- a/ui/gtk-gl-area.c
+++ b/ui/gtk-gl-area.c
@@ -7,6 +7,7 @@
  * See the COPYING file in the top-level directory.
  */
 
+#include "qemu/osdep.h"
 #include "qemu-common.h"
 
 #include "trace.h"
diff --git a/ui/gtk.c b/ui/gtk.c
index ce7018e..a4f5399 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -34,6 +34,7 @@
 #define GETTEXT_PACKAGE "qemu"
 #define LOCALEDIR "po"
 
+#include "qemu/osdep.h"
 #include "qemu-common.h"
 
 #include "ui/console.h"
diff --git a/ui/input-keymap.c b/ui/input-keymap.c
index 63d71d2..fd2c09d 100644
--- a/ui/input-keymap.c
+++ b/ui/input-keymap.c
@@ -1,3 +1,4 @@
+#include "qemu/osdep.h"
 #include "sysemu/sysemu.h"
 #include "ui/keymaps.h"
 #include "ui/input.h"
diff --git a/ui/input-legacy.c b/ui/input-legacy.c
index 35dfc27..093f3d1 100644
--- a/ui/input-legacy.c
+++ b/ui/input-legacy.c
@@ -22,9 +22,9 @@
  * THE SOFTWARE.
  */
 
+#include "qemu/osdep.h"
 #include "sysemu/sysemu.h"
 #include "ui/console.h"
-#include "qapi/error.h"
 #include "qmp-commands.h"
 #include "qapi-types.h"
 #include "ui/keymaps.h"
diff --git a/ui/input.c b/ui/input.c
index 006667b..bdcb974 100644
--- a/ui/input.c
+++ b/ui/input.c
@@ -1,3 +1,4 @@
+#include "qemu/osdep.h"
 #include "hw/qdev.h"
 #include "sysemu/sysemu.h"
 #include "qapi-types.h"
diff --git a/ui/keymaps.c b/ui/keymaps.c
index 1b9ba3f..8899a0b 100644
--- a/ui/keymaps.c
+++ b/ui/keymaps.c
@@ -22,6 +22,7 @@
  * THE SOFTWARE.
  */
 
+#include "qemu/osdep.h"
 #include "keymaps.h"
 #include "sysemu/sysemu.h"
 
diff --git a/ui/qemu-pixman.c b/ui/qemu-pixman.c
index 4116e15..c9f8dce 100644
--- a/ui/qemu-pixman.c
+++ b/ui/qemu-pixman.c
@@ -3,6 +3,7 @@
  * See the COPYING file in the top-level directory.
  */
 
+#include "qemu/osdep.h"
 #include "qemu-common.h"
 #include "ui/console.h"
 
diff --git a/ui/sdl.c b/ui/sdl.c
index c837436..72d6250 100644
--- a/ui/sdl.c
+++ b/ui/sdl.c
@@ -25,6 +25,7 @@
 /* Avoid compiler warning because macro is redefined in SDL_syswm.h. */
 #undef WIN32_LEAN_AND_MEAN
 
+#include "qemu/osdep.h"
 #include <SDL.h>
 #include <SDL_syswm.h>
 
diff --git a/ui/sdl2-2d.c b/ui/sdl2-2d.c
index 191ee3b..9593006 100644
--- a/ui/sdl2-2d.c
+++ b/ui/sdl2-2d.c
@@ -23,6 +23,7 @@
  */
 /* Ported SDL 1.2 code to 2.0 by Dave Airlie. */
 
+#include "qemu/osdep.h"
 #include "qemu-common.h"
 #include "ui/console.h"
 #include "ui/input.h"
diff --git a/ui/sdl2-gl.c b/ui/sdl2-gl.c
index 2bb3d06..a324eca 100644
--- a/ui/sdl2-gl.c
+++ b/ui/sdl2-gl.c
@@ -25,6 +25,7 @@
  * THE SOFTWARE.
  */
 
+#include "qemu/osdep.h"
 #include "qemu-common.h"
 #include "ui/console.h"
 #include "ui/input.h"
diff --git a/ui/sdl2-input.c b/ui/sdl2-input.c
index ac5dc94..6e315ae 100644
--- a/ui/sdl2-input.c
+++ b/ui/sdl2-input.c
@@ -23,6 +23,7 @@
  */
 /* Ported SDL 1.2 code to 2.0 by Dave Airlie. */
 
+#include "qemu/osdep.h"
 #include "qemu-common.h"
 #include "ui/console.h"
 #include "ui/input.h"
diff --git a/ui/sdl2.c b/ui/sdl2.c
index 46270f4..fa09a4c 100644
--- a/ui/sdl2.c
+++ b/ui/sdl2.c
@@ -23,6 +23,7 @@
  */
 /* Ported SDL 1.2 code to 2.0 by Dave Airlie. */
 
+#include "qemu/osdep.h"
 #include "qemu-common.h"
 #include "ui/console.h"
 #include "ui/input.h"
diff --git a/ui/sdl_zoom.c b/ui/sdl_zoom.c
index 2625c45..72622c2 100644
--- a/ui/sdl_zoom.c
+++ b/ui/sdl_zoom.c
@@ -11,11 +11,9 @@
  *
  */
 
-#include "sdl_zoom.h"
 #include "qemu/osdep.h"
+#include "sdl_zoom.h"
 #include <glib.h>
-#include <stdint.h>
-#include <stdio.h>
 
 static void sdl_zoom_rgb16(SDL_Surface *src, SDL_Surface *dst, int smooth,
                            SDL_Rect *dst_rect);
diff --git a/ui/shader.c b/ui/shader.c
index 0588655..9264009 100644
--- a/ui/shader.c
+++ b/ui/shader.c
@@ -24,6 +24,7 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
+#include "qemu/osdep.h"
 #include "qemu-common.h"
 #include "ui/shader.h"
 
diff --git a/ui/spice-core.c b/ui/spice-core.c
index 8f27768..4dbd99a 100644
--- a/ui/spice-core.c
+++ b/ui/spice-core.c
@@ -15,6 +15,7 @@
  * along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
+#include "qemu/osdep.h"
 #include <spice.h>
 
 #include <netdb.h>
diff --git a/ui/spice-display.c b/ui/spice-display.c
index 0489131..8a5b325 100644
--- a/ui/spice-display.c
+++ b/ui/spice-display.c
@@ -15,6 +15,7 @@
  * along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
+#include "qemu/osdep.h"
 #include "qemu-common.h"
 #include "ui/qemu-spice.h"
 #include "qemu/timer.h"
diff --git a/ui/spice-input.c b/ui/spice-input.c
index 2b3b9ed..72e4063 100644
--- a/ui/spice-input.c
+++ b/ui/spice-input.c
@@ -15,10 +15,7 @@
  * along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <stdlib.h>
-#include <stdio.h>
-#include <stdbool.h>
-#include <string.h>
+#include "qemu/osdep.h"
 
 #include <spice.h>
 #include <spice/enums.h>
diff --git a/ui/vnc-auth-sasl.c b/ui/vnc-auth-sasl.c
index de8abc9..13a59f5 100644
--- a/ui/vnc-auth-sasl.c
+++ b/ui/vnc-auth-sasl.c
@@ -22,6 +22,7 @@
  * THE SOFTWARE.
  */
 
+#include "qemu/osdep.h"
 #include "vnc.h"
 
 /* Max amount of data we send/recv for SASL steps to prevent DOS */
diff --git a/ui/vnc-auth-vencrypt.c b/ui/vnc-auth-vencrypt.c
index 093dd2f..8f3bb11 100644
--- a/ui/vnc-auth-vencrypt.c
+++ b/ui/vnc-auth-vencrypt.c
@@ -24,6 +24,7 @@
  * THE SOFTWARE.
  */
 
+#include "qemu/osdep.h"
 #include "vnc.h"
 #include "qemu/main-loop.h"
 
diff --git a/ui/vnc-enc-hextile.c b/ui/vnc-enc-hextile.c
index 2e768fd..4215bd7 100644
--- a/ui/vnc-enc-hextile.c
+++ b/ui/vnc-enc-hextile.c
@@ -24,6 +24,7 @@
  * THE SOFTWARE.
  */
 
+#include "qemu/osdep.h"
 #include "vnc.h"
 
 static void hextile_enc_cord(uint8_t *ptr, int x, int y, int w, int h)
diff --git a/ui/vnc-enc-tight.c b/ui/vnc-enc-tight.c
index 9a9ddf2..e5cba0e 100644
--- a/ui/vnc-enc-tight.c
+++ b/ui/vnc-enc-tight.c
@@ -26,7 +26,7 @@
  * THE SOFTWARE.
  */
 
-#include "config-host.h"
+#include "qemu/osdep.h"
 
 /* This needs to be before jpeglib.h line because of conflict with
    INT32 definitions between jmorecfg.h (included by jpeglib.h) and
@@ -40,7 +40,6 @@
 #include <png.h>
 #endif
 #ifdef CONFIG_VNC_JPEG
-#include <stdio.h>
 #include <jpeglib.h>
 #endif
 
diff --git a/ui/vnc-enc-zlib.c b/ui/vnc-enc-zlib.c
index d1b97f2..33e9df2 100644
--- a/ui/vnc-enc-zlib.c
+++ b/ui/vnc-enc-zlib.c
@@ -24,6 +24,7 @@
  * THE SOFTWARE.
  */
 
+#include "qemu/osdep.h"
 #include "vnc.h"
 
 #define ZALLOC_ALIGNMENT 16
diff --git a/ui/vnc-enc-zrle-template.c b/ui/vnc-enc-zrle-template.c
index 70ae624..abf6b86 100644
--- a/ui/vnc-enc-zrle-template.c
+++ b/ui/vnc-enc-zrle-template.c
@@ -22,7 +22,7 @@
  */
 
 
-#include <assert.h>
+#include "qemu/osdep.h"
 
 #undef ZRLE_ENDIAN_SUFFIX
 
diff --git a/ui/vnc-enc-zrle.c b/ui/vnc-enc-zrle.c
index ed3b484..5489870 100644
--- a/ui/vnc-enc-zrle.c
+++ b/ui/vnc-enc-zrle.c
@@ -26,6 +26,7 @@
  * THE SOFTWARE.
  */
 
+#include "qemu/osdep.h"
 #include "vnc.h"
 #include "vnc-enc-zrle.h"
 
diff --git a/ui/vnc-enc-zywrle-template.c b/ui/vnc-enc-zywrle-template.c
index 561f7bf..b446380 100644
--- a/ui/vnc-enc-zywrle-template.c
+++ b/ui/vnc-enc-zywrle-template.c
@@ -100,6 +100,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #endif
 
 #define ZYWRLE_QUANTIZE
+#include "qemu/osdep.h"
 #include "vnc-enc-zywrle.h"
 
 #ifndef ZRLE_COMPACT_PIXEL
diff --git a/ui/vnc-jobs.c b/ui/vnc-jobs.c
index 546635a..98ca978 100644
--- a/ui/vnc-jobs.c
+++ b/ui/vnc-jobs.c
@@ -26,6 +26,7 @@
  */
 
 
+#include "qemu/osdep.h"
 #include "vnc.h"
 #include "vnc-jobs.h"
 #include "qemu/sockets.h"
diff --git a/ui/vnc-palette.c b/ui/vnc-palette.c
index c130dee..3b89d1a 100644
--- a/ui/vnc-palette.c
+++ b/ui/vnc-palette.c
@@ -26,9 +26,9 @@
  * THE SOFTWARE.
  */
 
+#include "qemu/osdep.h"
 #include "vnc-palette.h"
 #include <glib.h>
-#include <string.h>
 
 static VncPaletteEntry *palette_find(const VncPalette *palette,
                                      uint32_t color, unsigned int hash)
diff --git a/ui/vnc-ws.c b/ui/vnc-ws.c
index 8018233..1d3ecc2 100644
--- a/ui/vnc-ws.c
+++ b/ui/vnc-ws.c
@@ -18,6 +18,7 @@
  * along with this software; if not, see <http://www.gnu.org/licenses/>.
  */
 
+#include "qemu/osdep.h"
 #include "vnc.h"
 #include "io/channel-websock.h"
 
diff --git a/ui/vnc.c b/ui/vnc.c
index 339f8c3..b6bbea5 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -24,6 +24,7 @@
  * THE SOFTWARE.
  */
 
+#include "qemu/osdep.h"
 #include "vnc.h"
 #include "vnc-jobs.h"
 #include "trace.h"
@@ -37,7 +38,6 @@
 #include "qapi/qmp/qerror.h"
 #include "qapi/qmp/types.h"
 #include "qmp-commands.h"
-#include "qemu/osdep.h"
 #include "ui/input.h"
 #include "qapi-event.h"
 #include "crypto/hash.h"
diff --git a/ui/x_keymap.c b/ui/x_keymap.c
index 1a77317..2788485 100644
--- a/ui/x_keymap.c
+++ b/ui/x_keymap.c
@@ -21,6 +21,7 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
+#include "qemu/osdep.h"
 #include "qemu-common.h"
 #include "x_keymap.h"
 
