1d075918cSmrg/*
2d075918cSmrg * Copyright 2007 by VMware, Inc.
3d075918cSmrg *
4d075918cSmrg * Permission is hereby granted, free of charge, to any person obtaining a
5d075918cSmrg * copy of this software and associated documentation files (the "Software"),
6d075918cSmrg * to deal in the Software without restriction, including without limitation
7d075918cSmrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8d075918cSmrg * and/or sell copies of the Software, and to permit persons to whom the
9d075918cSmrg * Software is furnished to do so, subject to the following conditions:
10d075918cSmrg *
11d075918cSmrg * The above copyright notice and this permission notice shall be included in
12d075918cSmrg * all copies or substantial portions of the Software.
13d075918cSmrg *
14d075918cSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15d075918cSmrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16d075918cSmrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17d075918cSmrg * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18d075918cSmrg * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19d075918cSmrg * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20d075918cSmrg * OTHER DEALINGS IN THE SOFTWARE.
21d075918cSmrg *
22d075918cSmrg * Except as contained in this notice, the name of the copyright holder(s)
23d075918cSmrg * and author(s) shall not be used in advertising or otherwise to promote
24d075918cSmrg * the sale, use or other dealings in this Software without prior written
25d075918cSmrg * authorization from the copyright holder(s) and author(s).
26d075918cSmrg */
27d075918cSmrg
28d075918cSmrg
298746cb53Smrg#ifdef HAVE_CONFIG_H
308746cb53Smrg#include "config.h"
318746cb53Smrg#endif
328746cb53Smrg
33d075918cSmrg#include <stdlib.h>
34d075918cSmrg#include <signal.h>
35d075918cSmrg#include "vmmouse_client.h"
36d075918cSmrg
378746cb53Smrgextern int vmmouse_uses_kernel_driver(void);
38d075918cSmrg
39d075918cSmrgvoid
40d075918cSmrgsegvCB(int sig)
41d075918cSmrg{
42d075918cSmrg#if defined HAVE_XORG_SERVER_1_1_0
43d075918cSmrg   exit(1);
44d075918cSmrg#endif
45d075918cSmrg}
46d075918cSmrg
47d075918cSmrg
48d075918cSmrgint
49d075918cSmrgmain(void)
50d075918cSmrg{
518746cb53Smrg   if (vmmouse_uses_kernel_driver())
528746cb53Smrg      return 1;
538746cb53Smrg
54d075918cSmrg   /*
55d075918cSmrg    * If the vmmouse test is not run in a VMware virtual machine, it
56d075918cSmrg    * will segfault instead of successfully accessing the port.
57d075918cSmrg    */
58d075918cSmrg   signal(SIGSEGV, segvCB);
59d075918cSmrg
60d075918cSmrg#if defined __i386__ || defined __x86_64__
618746cb53Smrg   (void) xf86EnableIO();
62d075918cSmrg   if (VMMouseClient_Enable()) {
63d075918cSmrg      VMMouseClient_Disable();
64d075918cSmrg      return 0;
65d075918cSmrg   } else {
66d075918cSmrg      /*
67d075918cSmrg       * We get here if we are running in a VM and the vmmouse
68d075918cSmrg       * device is disabled.
69d075918cSmrg       */
70d075918cSmrg      return 1;
71d075918cSmrg   }
72d075918cSmrg#endif
73d075918cSmrg   return 1;
74d075918cSmrg}
75