forked from OpenXT/xc-windows
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xs_private.h
167 lines (143 loc) · 5.41 KB
/
xs_private.h
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*
* Copyright (c) 2009 Citrix Systems, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/* Private userspace functions. These are either in xsutil.dll or
* xs.dll. */
#ifndef XS_PRIVATE_H__
#define XS_PRIVATE_H__
#ifdef XSUTIL_EXPORTS
#define XSUTIL_API __declspec(dllexport)
#else
#define XSUTIL_API __declspec(dllimport)
#endif
#if defined (__cplusplus)
extern "C" {
#endif
struct xs_error_renderer {
void (WINAPI *render)(struct xs_error_renderer *ths, const char *msg);
};
XSUTIL_API int WINAPI xs_is_physical_session(void);
XSUTIL_API char *WINAPI xs_vasprintf(const char *fmt, va_list args);
XSUTIL_API char *WINAPI xs_asprintf(const char *fmt, ...);
XSUTIL_API void WINAPI xs_win_err(int code, struct xs_error_renderer *,
const char *fmt, ...);
XSUTIL_API void WINAPI xs_vwin_err(int err, int code,
struct xs_error_renderer *,
const char *fmt, va_list args);
XSUTIL_API void WINAPI xs_err(int code, struct xs_error_renderer *,
const char *fmt, ...);
XSUTIL_API void WINAPI xs_errx(int code, struct xs_error_renderer *,
const char *fmt, ...);
XSUTIL_API void WINAPI xs_win_warn(struct xs_error_renderer *,
const char *fmt, ...);
XSUTIL_API void WINAPI xs_vwin_warn(int code, struct xs_error_renderer *,
const char *fmt, va_list args);
XSUTIL_API void WINAPI xs_warn(struct xs_error_renderer *, const char *fmt,
...);
XSUTIL_API void WINAPI xs_warnx(struct xs_error_renderer *, const char *fmt,
...);
XSUTIL_API extern struct xs_error_renderer xs_render_error_msgbox;
XSUTIL_API extern struct xs_error_renderer xs_render_error_stderr;
XSUTIL_API char *WINAPI xs_vassemble_strings(const char *sep, va_list *args);
XSUTIL_API char *WINAPI xs_assemble_strings(const char *sep, ...);
#ifdef XS2_API
XS2_API int WINAPI xs2_listen_suspend(HANDLE hXS, HANDLE event);
XS2_API BOOL WINAPI xs2_unlisten_suspend(HANDLE hXS);
XS2_API void WINAPI xs2_get_xen_time(HANDLE hXS, FILETIME *out);
XS2_API void WINAPI xs2_make_precious(HANDLE hXS);
XS2_API void WINAPI xs2_unmake_precious(HANDLE hXS);
XS2_API void WINAPI xs2_log(HANDLE hXS, const char *fmt, ...);
XS2_API void WINAPI xs2_vlog(HANDLE hXS, const char *fmt, va_list args);
typedef struct {
ULONG64 __h;
} WRITE_ON_CLOSE_HANDLE;
static __inline WRITE_ON_CLOSE_HANDLE
wrap_WRITE_ON_CLOSE_HANDLE(ULONG64 x)
{
WRITE_ON_CLOSE_HANDLE h;
h.__h = x;
return h;
}
static __inline ULONG64
unwrap_WRITE_ON_CLOSE_HANDLE(WRITE_ON_CLOSE_HANDLE h)
{
return h.__h;
}
#define null_WRITE_ON_CLOSE_HANDLE() wrap_WRITE_ON_CLOSE_HANDLE(0)
#define is_null_WRITE_ON_CLOSE_HANDLE(h) ((h).__h == 0)
XS2_API WRITE_ON_CLOSE_HANDLE WINAPI xs2_write_on_close(struct xs2_handle *xih,
const char *path,
const void *data,
size_t data_size);
XS2_API void WINAPI xs2_cancel_write_on_close(struct xs2_handle *xih,
WRITE_ON_CLOSE_HANDLE handle);
#endif
#if defined (__cplusplus)
};
#endif
#if DBG
#include <stdarg.h> // va_list
#include <stdio.h> // vsprintf
#include <malloc.h>
#include <assert.h>
#include <tchar.h>
__inline void DebugPrint( IN LPCTSTR msg, IN ... )
{
TCHAR buffer[256];
int res;
va_list args;
va_start( args, msg );
res = _vsntprintf(buffer, sizeof(buffer) / sizeof(buffer[0]), msg, args);
if (res >= 0)
{
OutputDebugString( buffer );
}
else
{
TCHAR *p;
int count;
count = 512;
for (;;) {
p = (TCHAR *)malloc(count * sizeof (TCHAR));
if (!p) {
OutputDebugString(_T("Out of memory for debug message!"));
break;
}
res = _vsntprintf(p, count, msg, args);
if (res >= 0)
break;
free(p);
count += 256;
}
if (p) {
OutputDebugString( p );
free(p);
}
}
va_end(args);
}
#define DBGPRINT(_x_) DebugPrint _x_
#define ASSERT assert
#else
#define DBGPRINT(_x_)
#define ASSERT
#endif // DBG
#endif /* !XS_PRIVATE_H__ */