| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. | 2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. |
| 3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
| 4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
| 5 */ | 5 */ |
| 6 | 6 |
| 7 #include <assert.h> | 7 #include <assert.h> |
| 8 #include <stdio.h> | 8 #include <stdio.h> |
| 9 #include <stdlib.h> | 9 #include <stdlib.h> |
| 10 #include <inttypes.h> | 10 #include <inttypes.h> |
| 11 #include <sys/fcntl.h> | 11 #include <sys/fcntl.h> |
| 12 #include <string.h> | 12 #include <string.h> |
| 13 #include <unistd.h> | 13 #include <unistd.h> |
| 14 | 14 |
| 15 #include "native_client/src/include/nacl_assert.h" |
| 15 #include "native_client/src/public/imc_syscalls.h" | 16 #include "native_client/src/public/imc_syscalls.h" |
| 16 #include "native_client/src/public/name_service.h" | 17 #include "native_client/src/public/name_service.h" |
| 17 #include "native_client/src/shared/srpc/nacl_srpc.h" | 18 #include "native_client/src/shared/srpc/nacl_srpc.h" |
| 18 | 19 |
| 19 #define RNG_OUTPUT_BYTES 1024 | |
| 20 | |
| 21 #define BYTES_PER_LINE 32 | |
| 22 #define BYTE_SPACING 4 | |
| 23 | |
| 24 void dump_output(int d, size_t nbytes) { | |
| 25 uint8_t *bytes; | |
| 26 int got; | |
| 27 int copied; | |
| 28 int ix; | |
| 29 | |
| 30 bytes = malloc(nbytes); | |
| 31 if (!bytes) { | |
| 32 perror("dump_output"); | |
| 33 fprintf(stderr, "No memory\n"); | |
| 34 return; | |
| 35 } | |
| 36 /* read output */ | |
| 37 for (got = 0; got < nbytes; got += copied) { | |
| 38 copied = read(d, bytes + got, nbytes - got); | |
| 39 if (-1 == copied) { | |
| 40 perror("dump_output:read"); | |
| 41 fprintf(stderr, "read failure\n"); | |
| 42 break; | |
| 43 } | |
| 44 printf("read(%d, ..., %zd) -> %d\n", d, nbytes - got, copied); | |
| 45 } | |
| 46 /* hex dump it */ | |
| 47 for (ix = 0; ix < got; ++ix) { | |
| 48 if (0 == (ix & (BYTES_PER_LINE-1))) { | |
| 49 printf("\n%04x:", ix); | |
| 50 } else if (0 == (ix & (BYTE_SPACING-1))) { | |
| 51 putchar(' '); | |
| 52 } | |
| 53 printf("%02x", bytes[ix]); | |
| 54 } | |
| 55 putchar('\n'); | |
| 56 | |
| 57 free(bytes); | |
| 58 } | |
| 59 | |
| 60 int main(void) { | 20 int main(void) { |
| 61 int ns; | 21 int ns; |
| 62 NaClSrpcChannel channel; | 22 NaClSrpcChannel channel; |
| 63 int connected_socket; | 23 int connected_socket; |
| 64 int status; | 24 int status; |
| 65 int rng; | 25 int rng; |
| 66 | 26 |
| 67 if (!NaClSrpcModuleInit()) { | 27 if (!NaClSrpcModuleInit()) { |
| 68 fprintf(stderr, "srpc module init failed\n"); | 28 fprintf(stderr, "srpc module init failed\n"); |
| 69 return 1; | 29 return 1; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 81 return 1; | 41 return 1; |
| 82 } | 42 } |
| 83 printf("NaClSrpcClientCtor succeeded\n"); | 43 printf("NaClSrpcClientCtor succeeded\n"); |
| 84 if (NACL_SRPC_RESULT_OK != | 44 if (NACL_SRPC_RESULT_OK != |
| 85 NaClSrpcInvokeBySignature(&channel, NACL_NAME_SERVICE_LOOKUP, | 45 NaClSrpcInvokeBySignature(&channel, NACL_NAME_SERVICE_LOOKUP, |
| 86 "SecureRandom", O_RDONLY, &status, &rng)) { | 46 "SecureRandom", O_RDONLY, &status, &rng)) { |
| 87 fprintf(stderr, "nameservice lookup failed, status %d\n", status); | 47 fprintf(stderr, "nameservice lookup failed, status %d\n", status); |
| 88 return 1; | 48 return 1; |
| 89 } | 49 } |
| 90 printf("rpc status %d\n", status); | 50 printf("rpc status %d\n", status); |
| 91 assert(NACL_NAME_SERVICE_SUCCESS == status); | 51 /* |
| 92 printf("rng descriptor %d\n", rng); | 52 * Now that the "SecureRandom" service has been removed, there is no |
| 93 | 53 * service that is registered with the name service by default that we |
| 94 dump_output(rng, RNG_OUTPUT_BYTES); | 54 * can test here. "ManifestNameService" only gets registered after the |
| 55 * "reverse service" is initialized, which doesn't normally happen in |
| 56 * standalone sel_ldr. So we just check that querying returns a sensible |
| 57 * error here. |
| 58 */ |
| 59 ASSERT_EQ(NACL_NAME_SERVICE_NAME_NOT_FOUND, status); |
| 95 | 60 |
| 96 return 0; | 61 return 0; |
| 97 } | 62 } |
| OLD | NEW |