| 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 <fcntl.h> | 7 #include <fcntl.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 #if NACL_LINUX && !NACL_ANDROID | |
| 10 // for shmem cleanup | |
| 11 #include <sys/ipc.h> | |
| 12 #include <sys/shm.h> | |
| 13 #include "native_client/src/trusted/desc/linux/nacl_desc_sysv_shm.h" | |
| 14 #endif | |
| 15 | 9 |
| 16 #include <map> | 10 #include <map> |
| 17 #include <string> | 11 #include <string> |
| 18 #include <sstream> | 12 #include <sstream> |
| 19 | 13 |
| 20 using std::stringstream; | 14 using std::stringstream; |
| 21 #include "native_client/src/shared/platform/nacl_log.h" | 15 #include "native_client/src/shared/platform/nacl_log.h" |
| 22 #include "native_client/src/trusted/desc/nacl_desc_base.h" | 16 #include "native_client/src/trusted/desc/nacl_desc_base.h" |
| 23 #include "native_client/src/trusted/desc/nacl_desc_sync_socket.h" | 17 #include "native_client/src/trusted/desc/nacl_desc_sync_socket.h" |
| 24 #include "native_client/src/trusted/desc/nacl_desc_wrapper.h" | 18 #include "native_client/src/trusted/desc/nacl_desc_wrapper.h" |
| 25 #include "native_client/src/trusted/sel_universal/parsing.h" | 19 #include "native_client/src/trusted/sel_universal/parsing.h" |
| 26 #include "native_client/src/trusted/sel_universal/rpc_universal.h" | 20 #include "native_client/src/trusted/sel_universal/rpc_universal.h" |
| 27 #include "native_client/src/trusted/service_runtime/include/sys/fcntl.h" | 21 #include "native_client/src/trusted/service_runtime/include/sys/fcntl.h" |
| 28 | 22 |
| 29 | 23 |
| 30 namespace { | |
| 31 | |
| 32 // The main point of this class is to ensure automatic cleanup. | |
| 33 // If the destructor is not invoked you need to manually cleanup | |
| 34 // the shared memory descriptors via "ipcs -m" and "ipcrm -m <id>" | |
| 35 class AddressMap { | |
| 36 public: | |
| 37 AddressMap() {} | |
| 38 | |
| 39 ~AddressMap() { | |
| 40 // NOTE: you CANNOT call NaClLog - this is called too late | |
| 41 // NaClLog(1, "cleanup\n"); | |
| 42 #if NACL_LINUX && !NACL_ANDROID | |
| 43 typedef map<NaClDesc*, uintptr_t>::iterator IT; | |
| 44 for (IT it = map_.begin(); it != map_.end(); ++it) { | |
| 45 shmctl(reinterpret_cast<NaClDescSysvShm*>(it->first)->id, IPC_RMID, NULL); | |
| 46 } | |
| 47 #endif | |
| 48 } | |
| 49 | |
| 50 void Add(NaClDesc* desc, uintptr_t addr) { map_[desc] = addr; } | |
| 51 | |
| 52 uintptr_t Get(NaClDesc* desc) { return map_[desc]; } | |
| 53 | |
| 54 private: | |
| 55 map<NaClDesc*, uintptr_t> map_; | |
| 56 }; | |
| 57 | |
| 58 AddressMap GlobalAddressMap; | |
| 59 | |
| 60 } // namespace | |
| 61 | |
| 62 bool HandlerSyncSocketCreate(NaClCommandLoop* ncl, | 24 bool HandlerSyncSocketCreate(NaClCommandLoop* ncl, |
| 63 const vector<string>& args) { | 25 const vector<string>& args) { |
| 64 if (args.size() < 3) { | 26 if (args.size() < 3) { |
| 65 NaClLog(LOG_ERROR, "not enough args\n"); | 27 NaClLog(LOG_ERROR, "not enough args\n"); |
| 66 return false; | 28 return false; |
| 67 } | 29 } |
| 68 | 30 |
| 69 NaClHandle handles[2] = {NACL_INVALID_HANDLE, NACL_INVALID_HANDLE}; | 31 NaClHandle handles[2] = {NACL_INVALID_HANDLE, NACL_INVALID_HANDLE}; |
| 70 if (NaClSocketPair(handles) != 0) { | 32 if (NaClSocketPair(handles) != 0) { |
| 71 return false; | 33 return false; |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 int size = static_cast<int>(ftell(fp)); | 225 int size = static_cast<int>(ftell(fp)); |
| 264 fclose(fp); | 226 fclose(fp); |
| 265 | 227 |
| 266 NaClLog(1, "filesize is %d\n", size); | 228 NaClLog(1, "filesize is %d\n", size); |
| 267 | 229 |
| 268 stringstream str; | 230 stringstream str; |
| 269 str << size; | 231 str << size; |
| 270 ncl->SetVariable(args[2], str.str()); | 232 ncl->SetVariable(args[2], str.str()); |
| 271 return true; | 233 return true; |
| 272 } | 234 } |
| OLD | NEW |