| OLD | NEW |
| (Empty) |
| 1 /* | |
| 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 | |
| 4 * be found in the LICENSE file. | |
| 5 */ | |
| 6 | |
| 7 /* | |
| 8 * NaCl file system mini XDR-like serialization of basic types. | |
| 9 * | |
| 10 * NB: this code has not been integrated with the rest of NaCl, and is | |
| 11 * likely to change. | |
| 12 */ | |
| 13 | |
| 14 #ifndef NATIVE_CLIENT_SERVICE_RUNTIME_FS_XDR_H_ | |
| 15 #define NATIVE_CLIENT_SERVICE_RUNTIME_FS_XDR_H_ | |
| 16 | |
| 17 #include <string.h> | |
| 18 | |
| 19 #include "native_client/src/include/portability.h" | |
| 20 #include "native_client/src/trusted/service_runtime/include/machine/_types.h" | |
| 21 | |
| 22 EXTERN_C_BEGIN | |
| 23 | |
| 24 /* | |
| 25 * knowledge about sizes for types of various file system RPC message | |
| 26 * structures' members is not baked in here, but only in | |
| 27 * machine/_types.h | |
| 28 * | |
| 29 * memcpy is (typically) a compiler intrinsic, so we should get | |
| 30 * efficient code while maintaining type safety. there are no byte | |
| 31 * order issues when IMC can only communicate between processes on the | |
| 32 * system. | |
| 33 * | |
| 34 * we violate the convention for in/out arg order so that code for | |
| 35 * externalizatin/internalization of structures can be written more | |
| 36 * easily using macros. | |
| 37 */ | |
| 38 | |
| 39 #define D(T) \ | |
| 40 static INLINE size_t nacl_ext_ ## T(char *buf, nacl_abi_ ## T datum) \ | |
| 41 { \ | |
| 42 memcpy((void *) buf, (void *) &datum, sizeof datum); \ | |
| 43 return sizeof datum; \ | |
| 44 } \ | |
| 45 static INLINE size_t nacl_int_ ## T(char *buf, nacl_abi_ ## T *datum) \ | |
| 46 { \ | |
| 47 memcpy((void *) datum, (void *) buf, sizeof datum); \ | |
| 48 return sizeof datum; \ | |
| 49 } | |
| 50 | |
| 51 D(dev_t) | |
| 52 D(ino_t) | |
| 53 D(mode_t) | |
| 54 D(uid_t) | |
| 55 D(gid_t) | |
| 56 D(nlink_t) | |
| 57 D(off_t) | |
| 58 D(time_t) | |
| 59 D(size_t) | |
| 60 D(ssize_t) | |
| 61 | |
| 62 #undef D | |
| 63 | |
| 64 #define D(T) \ | |
| 65 static INLINE size_t nacl_ext_ ## T(char *buf, T datum) \ | |
| 66 { \ | |
| 67 memcpy((void *) buf, (void *) &datum, sizeof datum); \ | |
| 68 return sizeof datum; \ | |
| 69 } \ | |
| 70 static INLINE size_t nacl_int_ ## T(char *buf, T *datum) \ | |
| 71 { \ | |
| 72 memcpy((void *) datum, (void *) buf, sizeof datum); \ | |
| 73 return sizeof datum; \ | |
| 74 } | |
| 75 | |
| 76 D(int8_t) | |
| 77 D(int16_t) | |
| 78 D(int32_t) | |
| 79 D(int64_t) | |
| 80 D(uint8_t) | |
| 81 D(uint16_t) | |
| 82 D(uint32_t) | |
| 83 D(uint64_t) | |
| 84 | |
| 85 #undef D | |
| 86 | |
| 87 EXTERN_C_END | |
| 88 | |
| 89 #endif /* NATIVE_CLIENT_SERVICE_RUNTIME_FS_XDR_H_ */ | |
| OLD | NEW |