2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2015 Tycho Nightingale <tycho.nightingale@pluribusnetworks.com>
5 * Copyright (c) 2015 Leon Dang
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
33 #include <sys/param.h>
34 #ifndef WITHOUT_CAPSICUM
35 #include <sys/capsicum.h>
37 #include <sys/endian.h>
38 #include <sys/socket.h>
39 #include <sys/select.h>
41 #include <arpa/inet.h>
42 #include <machine/cpufunc.h>
43 #include <machine/specialreg.h>
44 #include <netinet/in.h>
48 #ifndef WITHOUT_CAPSICUM
49 #include <capsicum_helpers.h>
54 #include <pthread_np.h>
68 #include "sockstream.h"
71 #include <openssl/des.h>
74 static int rfb_debug = 0;
75 #define DPRINTF(params) if (rfb_debug) printf params
76 #define WPRINTF(params) printf params
78 #define AUTH_LENGTH 16
79 #define PASSWD_LENGTH 8
81 #define SECURITY_TYPE_NONE 1
82 #define SECURITY_TYPE_VNC_AUTH 2
84 #define AUTH_FAILED_UNAUTH 1
85 #define AUTH_FAILED_ERROR 2
111 uint32_t *crc; /* WxH crc cells */
112 uint32_t *crc_tmp; /* buffer to store single crc row */
113 int crc_width, crc_height;
130 struct rfb_srvr_info {
133 struct rfb_pixfmt pixfmt;
137 struct rfb_pixfmt_msg {
140 struct rfb_pixfmt pixfmt;
143 #define RFB_ENCODING_RAW 0
144 #define RFB_ENCODING_ZLIB 6
145 #define RFB_ENCODING_RESIZE -223
147 #define RFB_MAX_WIDTH 2000
148 #define RFB_MAX_HEIGHT 1200
149 #define RFB_ZLIB_BUFSZ RFB_MAX_WIDTH*RFB_MAX_HEIGHT*4
151 /* percentage changes to screen before sending the entire screen */
152 #define RFB_SEND_ALL_THRESH 25
160 struct rfb_updt_msg {
183 struct rfb_srvr_updt_msg {
189 struct rfb_srvr_rect_hdr {
197 struct rfb_cuttext_msg {
205 rfb_send_server_init_msg(int cfd)
207 struct bhyvegc_image *gc_image;
208 struct rfb_srvr_info sinfo;
210 gc_image = console_get_image();
212 sinfo.width = htons(gc_image->width);
213 sinfo.height = htons(gc_image->height);
214 sinfo.pixfmt.bpp = 32;
215 sinfo.pixfmt.depth = 32;
216 sinfo.pixfmt.bigendian = 0;
217 sinfo.pixfmt.truecolor = 1;
218 sinfo.pixfmt.red_max = htons(255);
219 sinfo.pixfmt.green_max = htons(255);
220 sinfo.pixfmt.blue_max = htons(255);
221 sinfo.pixfmt.red_shift = 16;
222 sinfo.pixfmt.green_shift = 8;
223 sinfo.pixfmt.blue_shift = 0;
224 sinfo.namelen = htonl(strlen("bhyve"));
225 (void)stream_write(cfd, &sinfo, sizeof(sinfo));
226 (void)stream_write(cfd, "bhyve", strlen("bhyve"));
230 rfb_send_resize_update_msg(struct rfb_softc *rc, int cfd)
232 struct rfb_srvr_updt_msg supdt_msg;
233 struct rfb_srvr_rect_hdr srect_hdr;
235 /* Number of rectangles: 1 */
238 supdt_msg.numrects = htons(1);
239 stream_write(cfd, &supdt_msg, sizeof(struct rfb_srvr_updt_msg));
241 /* Rectangle header */
242 srect_hdr.x = htons(0);
243 srect_hdr.y = htons(0);
244 srect_hdr.width = htons(rc->width);
245 srect_hdr.height = htons(rc->height);
246 srect_hdr.encoding = htonl(RFB_ENCODING_RESIZE);
247 stream_write(cfd, &srect_hdr, sizeof(struct rfb_srvr_rect_hdr));
251 rfb_recv_set_pixfmt_msg(struct rfb_softc *rc, int cfd)
253 struct rfb_pixfmt_msg pixfmt_msg;
255 (void)stream_read(cfd, ((void *)&pixfmt_msg)+1, sizeof(pixfmt_msg)-1);
260 rfb_recv_set_encodings_msg(struct rfb_softc *rc, int cfd)
262 struct rfb_enc_msg enc_msg;
266 assert((sizeof(enc_msg) - 1) == 3);
267 (void)stream_read(cfd, ((void *)&enc_msg)+1, sizeof(enc_msg)-1);
269 for (i = 0; i < htons(enc_msg.numencs); i++) {
270 (void)stream_read(cfd, &encoding, sizeof(encoding));
271 switch (htonl(encoding)) {
272 case RFB_ENCODING_RAW:
273 rc->enc_raw_ok = true;
275 case RFB_ENCODING_ZLIB:
276 rc->enc_zlib_ok = true;
277 deflateInit(&rc->zstream, Z_BEST_SPEED);
279 case RFB_ENCODING_RESIZE:
280 rc->enc_resize_ok = true;
287 * Calculate CRC32 using SSE4.2; Intel or AMD Bulldozer+ CPUs only
289 static __inline uint32_t
290 fast_crc32(void *buf, int len, uint32_t crcval)
292 uint32_t q = len / sizeof(uint32_t);
293 uint32_t *p = (uint32_t *)buf;
297 ".byte 0xf2, 0xf, 0x38, 0xf1, 0xf1;"
299 :"0" (crcval), "c" (*p)
309 rfb_send_rect(struct rfb_softc *rc, int cfd, struct bhyvegc_image *gc,
310 int x, int y, int w, int h)
312 struct rfb_srvr_updt_msg supdt_msg;
313 struct rfb_srvr_rect_hdr srect_hdr;
315 ssize_t nwrite, total;
321 * Send a single rectangle of the given x, y, w h dimensions.
324 /* Number of rectangles: 1 */
327 supdt_msg.numrects = htons(1);
328 nwrite = stream_write(cfd, &supdt_msg,
329 sizeof(struct rfb_srvr_updt_msg));
334 /* Rectangle header */
335 srect_hdr.x = htons(x);
336 srect_hdr.y = htons(y);
337 srect_hdr.width = htons(w);
338 srect_hdr.height = htons(h);
341 w *= sizeof(uint32_t);
342 if (rc->enc_zlib_ok) {
344 rc->zstream.total_in = 0;
345 rc->zstream.total_out = 0;
346 for (p = &gc->data[y * gc->width + x]; y < h; y++) {
347 rc->zstream.next_in = (Bytef *)p;
348 rc->zstream.avail_in = w;
349 rc->zstream.next_out = (Bytef *)zbufp;
350 rc->zstream.avail_out = RFB_ZLIB_BUFSZ + 16 -
351 rc->zstream.total_out;
352 rc->zstream.data_type = Z_BINARY;
354 /* Compress with zlib */
355 err = deflate(&rc->zstream, Z_SYNC_FLUSH);
357 WPRINTF(("zlib[rect] deflate err: %d\n", err));
358 rc->enc_zlib_ok = false;
359 deflateEnd(&rc->zstream);
362 zbufp = rc->zbuf + rc->zstream.total_out;
365 srect_hdr.encoding = htonl(RFB_ENCODING_ZLIB);
366 nwrite = stream_write(cfd, &srect_hdr,
367 sizeof(struct rfb_srvr_rect_hdr));
371 zlen = htonl(rc->zstream.total_out);
372 nwrite = stream_write(cfd, &zlen, sizeof(uint32_t));
375 return (stream_write(cfd, rc->zbuf, rc->zstream.total_out));
382 for (p = &gc->data[y * gc->width + x]; y < h; y++) {
389 srect_hdr.encoding = htonl(RFB_ENCODING_RAW);
390 nwrite = stream_write(cfd, &srect_hdr,
391 sizeof(struct rfb_srvr_rect_hdr));
395 total = stream_write(cfd, rc->zbuf, total);
401 rfb_send_all(struct rfb_softc *rc, int cfd, struct bhyvegc_image *gc)
403 struct rfb_srvr_updt_msg supdt_msg;
404 struct rfb_srvr_rect_hdr srect_hdr;
410 * Send the whole thing
413 /* Number of rectangles: 1 */
416 supdt_msg.numrects = htons(1);
417 nwrite = stream_write(cfd, &supdt_msg,
418 sizeof(struct rfb_srvr_updt_msg));
422 /* Rectangle header */
425 srect_hdr.width = htons(gc->width);
426 srect_hdr.height = htons(gc->height);
427 if (rc->enc_zlib_ok) {
428 rc->zstream.next_in = (Bytef *)gc->data;
429 rc->zstream.avail_in = gc->width * gc->height *
431 rc->zstream.next_out = (Bytef *)rc->zbuf;
432 rc->zstream.avail_out = RFB_ZLIB_BUFSZ + 16;
433 rc->zstream.data_type = Z_BINARY;
435 rc->zstream.total_in = 0;
436 rc->zstream.total_out = 0;
438 /* Compress with zlib */
439 err = deflate(&rc->zstream, Z_SYNC_FLUSH);
441 WPRINTF(("zlib deflate err: %d\n", err));
442 rc->enc_zlib_ok = false;
443 deflateEnd(&rc->zstream);
447 srect_hdr.encoding = htonl(RFB_ENCODING_ZLIB);
448 nwrite = stream_write(cfd, &srect_hdr,
449 sizeof(struct rfb_srvr_rect_hdr));
453 zlen = htonl(rc->zstream.total_out);
454 nwrite = stream_write(cfd, &zlen, sizeof(uint32_t));
457 return (stream_write(cfd, rc->zbuf, rc->zstream.total_out));
461 srect_hdr.encoding = htonl(RFB_ENCODING_RAW);
462 nwrite = stream_write(cfd, &srect_hdr,
463 sizeof(struct rfb_srvr_rect_hdr));
467 nwrite = stream_write(cfd, gc->data,
468 gc->width * gc->height * sizeof(uint32_t));
473 #define PIX_PER_CELL 32
474 #define PIXCELL_SHIFT 5
475 #define PIXCELL_MASK 0x1F
478 rfb_send_screen(struct rfb_softc *rc, int cfd, int all)
480 struct bhyvegc_image *gc_image;
483 int celly, cellwidth;
487 int rem_x, rem_y; /* remainder for resolutions not x32 pixels ratio */
489 uint32_t *crc_p, *orig_crc;
493 gc_image = console_get_image();
495 pthread_mutex_lock(&rc->mtx);
497 pthread_mutex_unlock(&rc->mtx);
501 pthread_mutex_unlock(&rc->mtx);
506 retval = rfb_send_all(rc, cfd, gc_image);
511 * Calculate the checksum for each 32x32 cell. Send each that
512 * has changed since the last scan.
515 /* Resolution changed */
517 rc->crc_width = gc_image->width;
518 rc->crc_height = gc_image->height;
522 xcells = howmany(rc->crc_width, PIX_PER_CELL);
523 ycells = howmany(rc->crc_height, PIX_PER_CELL);
525 rem_x = w & PIXCELL_MASK;
527 rem_y = h & PIXCELL_MASK;
529 rem_y = PIX_PER_CELL;
534 * Go through all cells and calculate crc. If significant number
535 * of changes, then send entire screen.
536 * crc_tmp is dual purpose: to store the new crc and to flag as
537 * a cell that has changed.
539 crc_p = rc->crc_tmp - xcells;
540 orig_crc = rc->crc - xcells;
542 memset(rc->crc_tmp, 0, sizeof(uint32_t) * xcells * ycells);
543 for (y = 0; y < h; y++) {
544 if ((y & PIXCELL_MASK) == 0) {
549 for (x = 0; x < xcells; x++) {
550 if (x == (xcells - 1) && rem_x > 0)
553 cellwidth = PIX_PER_CELL;
556 crc_p[x] = fast_crc32(p,
557 cellwidth * sizeof(uint32_t),
560 crc_p[x] = (uint32_t)crc32(crc_p[x],
562 cellwidth * sizeof(uint32_t));
566 /* check for crc delta if last row in cell */
567 if ((y & PIXCELL_MASK) == PIXCELL_MASK || y == (h-1)) {
568 if (orig_crc[x] != crc_p[x]) {
569 orig_crc[x] = crc_p[x];
579 /* If number of changes is > THRESH percent, send the whole screen */
580 if (((changes * 100) / (xcells * ycells)) >= RFB_SEND_ALL_THRESH) {
581 retval = rfb_send_all(rc, cfd, gc_image);
585 /* Go through all cells, and send only changed ones */
587 for (y = 0; y < h; y += PIX_PER_CELL) {
588 /* previous cell's row */
589 celly = (y >> PIXCELL_SHIFT);
591 /* Delta check crc to previous set */
592 for (x = 0; x < xcells; x++) {
596 if (x == (xcells - 1) && rem_x > 0)
599 cellwidth = PIX_PER_CELL;
600 nwrite = rfb_send_rect(rc, cfd,
603 celly * PIX_PER_CELL,
605 y + PIX_PER_CELL >= h ? rem_y : PIX_PER_CELL);
615 pthread_mutex_lock(&rc->mtx);
617 pthread_mutex_unlock(&rc->mtx);
624 rfb_recv_update_msg(struct rfb_softc *rc, int cfd, int discardonly)
626 struct rfb_updt_msg updt_msg;
627 struct bhyvegc_image *gc_image;
629 (void)stream_read(cfd, ((void *)&updt_msg) + 1 , sizeof(updt_msg) - 1);
632 gc_image = console_get_image();
634 updt_msg.x = htons(updt_msg.x);
635 updt_msg.y = htons(updt_msg.y);
636 updt_msg.width = htons(updt_msg.width);
637 updt_msg.height = htons(updt_msg.height);
639 if (updt_msg.width != gc_image->width ||
640 updt_msg.height != gc_image->height) {
641 rc->width = gc_image->width;
642 rc->height = gc_image->height;
643 if (rc->enc_resize_ok)
644 rfb_send_resize_update_msg(rc, cfd);
650 rfb_send_screen(rc, cfd, 1);
654 rfb_recv_key_msg(struct rfb_softc *rc, int cfd)
656 struct rfb_key_msg key_msg;
658 (void)stream_read(cfd, ((void *)&key_msg) + 1, sizeof(key_msg) - 1);
660 console_key_event(key_msg.down, htonl(key_msg.code));
664 rfb_recv_ptr_msg(struct rfb_softc *rc, int cfd)
666 struct rfb_ptr_msg ptr_msg;
668 (void)stream_read(cfd, ((void *)&ptr_msg) + 1, sizeof(ptr_msg) - 1);
670 console_ptr_event(ptr_msg.button, htons(ptr_msg.x), htons(ptr_msg.y));
674 rfb_recv_cuttext_msg(struct rfb_softc *rc, int cfd)
676 struct rfb_cuttext_msg ct_msg;
677 unsigned char buf[32];
680 len = stream_read(cfd, ((void *)&ct_msg) + 1, sizeof(ct_msg) - 1);
681 ct_msg.length = htonl(ct_msg.length);
682 while (ct_msg.length > 0) {
683 len = stream_read(cfd, buf, ct_msg.length > sizeof(buf) ?
684 sizeof(buf) : ct_msg.length);
685 ct_msg.length -= len;
690 timeval_delta(struct timeval *prev, struct timeval *now)
693 n1 = now->tv_sec * 1000000 + now->tv_usec;
694 n2 = prev->tv_sec * 1000000 + prev->tv_usec;
699 rfb_wr_thr(void *arg)
701 struct rfb_softc *rc;
704 struct timeval prev_tv;
714 while (rc->cfd >= 0) {
720 err = select(cfd+1, &rfds, NULL, NULL, &tv);
724 /* Determine if its time to push screen; ~24hz */
725 gettimeofday(&tv, NULL);
726 tdiff = timeval_delta(&prev_tv, &tv);
728 prev_tv.tv_sec = tv.tv_sec;
729 prev_tv.tv_usec = tv.tv_usec;
730 if (rfb_send_screen(rc, cfd, 0) <= 0) {
735 usleep(40000 - tdiff);
743 rfb_handle(struct rfb_softc *rc, int cfd)
745 const char *vbuf = "RFB 003.008\n";
746 unsigned char buf[80];
747 unsigned char *message = NULL;
750 unsigned char challenge[AUTH_LENGTH];
751 unsigned char keystr[PASSWD_LENGTH];
752 unsigned char crypt_expected[AUTH_LENGTH];
765 /* 1a. Send server version */
766 stream_write(cfd, vbuf, strlen(vbuf));
768 /* 1b. Read client version */
769 len = read(cfd, buf, sizeof(buf));
771 /* 2a. Send security type */
775 buf[1] = SECURITY_TYPE_VNC_AUTH;
777 buf[1] = SECURITY_TYPE_NONE;
779 buf[1] = SECURITY_TYPE_NONE;
782 stream_write(cfd, buf, 2);
784 /* 2b. Read agreed security type */
785 len = stream_read(cfd, buf, 1);
787 /* 2c. Do VNC authentication */
789 case SECURITY_TYPE_NONE:
792 case SECURITY_TYPE_VNC_AUTH:
794 * The client encrypts the challenge with DES, using a password
795 * supplied by the user as the key.
796 * To form the key, the password is truncated to
797 * eight characters, or padded with null bytes on the right.
798 * The client then sends the resulting 16-bytes response.
801 strncpy(keystr, rc->password, PASSWD_LENGTH);
803 /* VNC clients encrypts the challenge with all the bit fields
804 * in each byte of the password mirrored.
805 * Here we flip each byte of the keystr.
807 for (i = 0; i < PASSWD_LENGTH; i++) {
808 keystr[i] = (keystr[i] & 0xF0) >> 4
809 | (keystr[i] & 0x0F) << 4;
810 keystr[i] = (keystr[i] & 0xCC) >> 2
811 | (keystr[i] & 0x33) << 2;
812 keystr[i] = (keystr[i] & 0xAA) >> 1
813 | (keystr[i] & 0x55) << 1;
816 /* Initialize a 16-byte random challenge */
817 arc4random_buf(challenge, sizeof(challenge));
818 stream_write(cfd, challenge, AUTH_LENGTH);
820 /* Receive the 16-byte challenge response */
821 stream_read(cfd, buf, AUTH_LENGTH);
823 memcpy(crypt_expected, challenge, AUTH_LENGTH);
825 /* Encrypt the Challenge with DES */
826 DES_set_key((const_DES_cblock *)keystr, &ks);
827 DES_ecb_encrypt((const_DES_cblock *)challenge,
828 (const_DES_cblock *)crypt_expected,
830 DES_ecb_encrypt((const_DES_cblock *)(challenge + PASSWD_LENGTH),
831 (const_DES_cblock *)(crypt_expected +
835 if (memcmp(crypt_expected, buf, AUTH_LENGTH) != 0) {
836 message = "Auth Failed: Invalid Password.";
842 WPRINTF(("Auth not supported, no OpenSSL in your system"));
848 /* 2d. Write back a status */
849 stream_write(cfd, &sres, 4);
852 be32enc(buf, strlen(message));
853 stream_write(cfd, buf, 4);
854 stream_write(cfd, message, strlen(message));
858 /* 3a. Read client shared-flag byte */
859 len = stream_read(cfd, buf, 1);
861 /* 4a. Write server-init info */
862 rfb_send_server_init_msg(cfd);
865 rc->zbuf = malloc(RFB_ZLIB_BUFSZ + 16);
866 assert(rc->zbuf != NULL);
869 rfb_send_screen(rc, cfd, 1);
871 perror = pthread_create(&tid, NULL, rfb_wr_thr, rc);
873 pthread_set_name_np(tid, "rfbout");
875 /* Now read in client requests. 1st byte identifies type */
877 len = read(cfd, buf, 1);
879 DPRINTF(("rfb client exiting\r\n"));
885 rfb_recv_set_pixfmt_msg(rc, cfd);
888 rfb_recv_set_encodings_msg(rc, cfd);
891 rfb_recv_update_msg(rc, cfd, 1);
894 rfb_recv_key_msg(rc, cfd);
897 rfb_recv_ptr_msg(rc, cfd);
900 rfb_recv_cuttext_msg(rc, cfd);
903 WPRINTF(("rfb unknown cli-code %d!\n", buf[0] & 0xff));
910 pthread_join(tid, NULL);
912 deflateEnd(&rc->zstream);
918 struct rfb_softc *rc;
926 sigaddset(&set, SIGPIPE);
927 if (pthread_sigmask(SIG_BLOCK, &set, NULL) != 0) {
928 perror("pthread_sigmask");
933 rc->enc_raw_ok = false;
934 rc->enc_zlib_ok = false;
935 rc->enc_resize_ok = false;
937 cfd = accept(rc->sfd, NULL, NULL);
939 pthread_mutex_lock(&rc->mtx);
940 pthread_cond_signal(&rc->cond);
941 pthread_mutex_unlock(&rc->mtx);
953 sse42_supported(void)
955 u_int cpu_registers[4], ecx;
957 do_cpuid(1, cpu_registers);
959 ecx = cpu_registers[2];
961 return ((ecx & CPUID2_SSE42) != 0);
965 rfb_init(char *hostname, int port, int wait, char *password)
969 struct rfb_softc *rc;
971 struct addrinfo hints;
973 #ifndef WITHOUT_CAPSICUM
977 rc = calloc(1, sizeof(struct rfb_softc));
979 rc->crc = calloc(howmany(RFB_MAX_WIDTH * RFB_MAX_HEIGHT, 32),
981 rc->crc_tmp = calloc(howmany(RFB_MAX_WIDTH * RFB_MAX_HEIGHT, 32),
983 rc->crc_width = RFB_MAX_WIDTH;
984 rc->crc_height = RFB_MAX_HEIGHT;
986 rc->password = password;
988 snprintf(servname, sizeof(servname), "%d", port ? port : 5900);
990 if (!hostname || strlen(hostname) == 0)
992 hostname = "127.0.0.1";
997 memset(&hints, 0, sizeof(hints));
998 hints.ai_family = AF_UNSPEC;
999 hints.ai_socktype = SOCK_STREAM;
1000 hints.ai_flags = AI_NUMERICHOST | AI_NUMERICSERV | AI_PASSIVE;
1002 if ((e = getaddrinfo(hostname, servname, &hints, &ai)) != 0) {
1003 fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(e));
1007 rc->sfd = socket(ai->ai_family, ai->ai_socktype, 0);
1014 setsockopt(rc->sfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
1016 if (bind(rc->sfd, ai->ai_addr, ai->ai_addrlen) < 0) {
1022 if (listen(rc->sfd, 1) < 0) {
1028 #ifndef WITHOUT_CAPSICUM
1029 cap_rights_init(&rights, CAP_ACCEPT, CAP_EVENT, CAP_READ, CAP_WRITE);
1030 if (caph_rights_limit(rc->sfd, &rights) == -1)
1031 errx(EX_OSERR, "Unable to apply rights for sandbox");
1034 rc->hw_crc = sse42_supported();
1036 rc->conn_wait = wait;
1038 pthread_mutex_init(&rc->mtx, NULL);
1039 pthread_cond_init(&rc->cond, NULL);
1042 pthread_create(&rc->tid, NULL, rfb_thr, rc);
1043 pthread_set_name_np(rc->tid, "rfb");
1046 DPRINTF(("Waiting for rfb client...\n"));
1047 pthread_mutex_lock(&rc->mtx);
1048 pthread_cond_wait(&rc->cond, &rc->mtx);
1049 pthread_mutex_unlock(&rc->mtx);