2 * Copyright 2008 The Native Client Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file.
7 #include "native_client/src/include/portability.h"
8 #include "native_client/src/shared/platform/nacl_global_secure_random.h"
9 #include "native_client/src/shared/platform/nacl_log.h"
10 #include "native_client/src/trusted/desc/nacl_desc_base.h"
11 #include "native_client/src/trusted/desc/nacl_desc_conn_cap.h"
12 #include "native_client/src/trusted/desc/nacl_desc_imc_bound_desc.h"
13 #include "native_client/src/trusted/service_runtime/include/sys/errno.h"
16 int32_t NaClCommonDescMakeBoundSock(struct NaClDesc *pair[2]) {
18 struct NaClSocketAddress sa;
19 struct NaClDescConnCap *ccp;
21 struct NaClDescImcBoundDesc *idp;
23 retval = -NACL_ABI_ENOMEM;
26 h = NACL_INVALID_HANDLE;
28 * create NaClDescConnCap object, invoke NaClBoundSocket, create
29 * an NaClDescImcDesc object. put both into open file table.
31 ccp = malloc(sizeof *ccp);
35 idp = malloc(sizeof *idp);
41 NaClGenerateRandomPath(&sa.path[0], NACL_PATH_MAX);
42 h = NaClBoundSocket(&sa);
43 NaClLog(3, "NaClCommonDescMakeBoundSock: sa: %s, h 0x%"NACL_PRIxPTR"\n",
44 sa.path, (uintptr_t) h);
45 } while (NACL_INVALID_HANDLE == h);
47 if (!NaClDescConnCapCtor(ccp, &sa)) {
51 if (!NaClDescImcBoundDescCtor(idp, h)) {
52 NaClDescUnref((struct NaClDesc *) ccp);
55 h = NACL_INVALID_HANDLE; /* idp took ownership */
57 pair[0] = (struct NaClDesc *) idp;
60 pair[1] = (struct NaClDesc *) ccp;
68 if (NACL_INVALID_HANDLE != h) {