summaryrefslogtreecommitdiff
path: root/common/vdcommon.h
blob: 394333bb18996d12b6034cff4071ee7df5ce5a0c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
   Copyright (C) 2009 Red Hat, Inc.

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License as
   published by the Free Software Foundation; either version 2 of
   the License, or (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef _H_VDCOMMON
#define _H_VDCOMMON

#if !defined __GNUC__
#pragma warning(disable:4200)
#endif

#include <windows.h>
#include "spice/vd_agent.h"
#include "vdlog.h"

typedef CRITICAL_SECTION mutex_t;

#define MUTEX_INIT(mutex) InitializeCriticalSection(&mutex)
#define MUTEX_LOCK(mutex) EnterCriticalSection(&mutex)
#define MUTEX_UNLOCK(mutex) LeaveCriticalSection(&mutex)

#define VD_SERVICE_PIPE_NAME   TEXT("\\\\.\\pipe\\vdservicepipe")
#define VD_MESSAGE_HEADER_SIZE (sizeof(VDPipeMessage) + sizeof(VDAgentMessage))
#define VD_PIPE_BUF_SIZE       (1024 * 1024)
#define VD_AGENT_REGISTRY_KEY "SOFTWARE\\Red Hat\\Spice\\vdagent\\"

enum {
    VD_AGENT_COMMAND,
    VD_AGENT_RESET,
    VD_AGENT_RESET_ACK,
    VD_AGENT_QUIT,
    VD_AGENT_SESSION_LOGON,
};

#if defined __GNUC__
#define ALIGN_GCC __attribute__ ((packed))
#define ALIGN_VC
#else
#define ALIGN_GCC
#define ALIGN_VC __declspec (align(1))
#endif

#ifdef OLDMSVCRT
#define swprintf_s(buf, sz, format...) swprintf(buf, format)
#endif

typedef struct ALIGN_VC VDPipeMessage {
    uint32_t type;
    uint32_t opaque;
    uint32_t size;
    uint8_t data[0];
} ALIGN_GCC VDPipeMessage;

typedef struct VDPipeBuffer {
    OVERLAPPED overlap;
    DWORD start;
    DWORD end;
    uint8_t data[VD_PIPE_BUF_SIZE];
} VDPipeBuffer;

typedef struct VDPipeState {
    HANDLE pipe;
    VDPipeBuffer write;
    VDPipeBuffer read;
} VDPipeState;

#endif