Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(192)

Side by Side Diff: chrome/common/transport_dib_linux.cc

Issue 164226: linux: fix race in TransportDIB passing (Closed)
Patch Set: Add newline for clarity Created 11 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/common/transport_dib.h ('k') | chrome/plugin/webplugin_proxy.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <errno.h> 5 #include <errno.h>
6 #include <stdlib.h> 6 #include <stdlib.h>
7 #include <sys/ipc.h> 7 #include <sys/ipc.h>
8 #include <sys/shm.h> 8 #include <sys/shm.h>
9 9
10 #include "base/gfx/size.h" 10 #include "base/gfx/size.h"
(...skipping 27 matching lines...) Expand all
38 38
39 // static 39 // static
40 TransportDIB* TransportDIB::Create(size_t size, uint32 sequence_num) { 40 TransportDIB* TransportDIB::Create(size_t size, uint32 sequence_num) {
41 // We use a mode of 0666 since the X server won't attach to memory which is 41 // We use a mode of 0666 since the X server won't attach to memory which is
42 // 0600 since it can't know if it (as a root process) is being asked to map 42 // 0600 since it can't know if it (as a root process) is being asked to map
43 // someone else's private shared memory region. 43 // someone else's private shared memory region.
44 const int shmkey = shmget(IPC_PRIVATE, size, 0666); 44 const int shmkey = shmget(IPC_PRIVATE, size, 0666);
45 if (shmkey == -1) { 45 if (shmkey == -1) {
46 DLOG(ERROR) << "Failed to create SysV shared memory region" 46 DLOG(ERROR) << "Failed to create SysV shared memory region"
47 << " errno:" << errno; 47 << " errno:" << errno;
48 return false; 48 return NULL;
49 } 49 }
50 50
51 void* address = shmat(shmkey, NULL /* desired address */, 0 /* flags */); 51 void* address = shmat(shmkey, NULL /* desired address */, 0 /* flags */);
52 // Here we mark the shared memory for deletion. Since we attached it in the 52 // Here we mark the shared memory for deletion. Since we attached it in the
53 // line above, it doesn't actually get deleted but, if we crash, this means 53 // line above, it doesn't actually get deleted but, if we crash, this means
54 // that the kernel will automatically clean it up for us. 54 // that the kernel will automatically clean it up for us.
55 shmctl(shmkey, IPC_RMID, 0); 55 shmctl(shmkey, IPC_RMID, 0);
56 if (address == kInvalidAddress) 56 if (address == kInvalidAddress)
57 return false; 57 return NULL;
58 58
59 TransportDIB* dib = new TransportDIB; 59 TransportDIB* dib = new TransportDIB;
60 60
61 dib->key_ = shmkey; 61 dib->key_ = shmkey;
62 dib->address_ = address; 62 dib->address_ = address;
63 dib->size_ = size; 63 dib->size_ = size;
64 return dib; 64 return dib;
65 } 65 }
66 66
67 TransportDIB* TransportDIB::Map(Handle shmkey) { 67 TransportDIB* TransportDIB::Map(Handle shmkey) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 } 104 }
105 105
106 XID TransportDIB::MapToX(Display* display) { 106 XID TransportDIB::MapToX(Display* display) {
107 if (!x_shm_) { 107 if (!x_shm_) {
108 x_shm_ = x11_util::AttachSharedMemory(display, key_); 108 x_shm_ = x11_util::AttachSharedMemory(display, key_);
109 display_ = display; 109 display_ = display;
110 } 110 }
111 111
112 return x_shm_; 112 return x_shm_;
113 } 113 }
OLDNEW
« no previous file with comments | « chrome/common/transport_dib.h ('k') | chrome/plugin/webplugin_proxy.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698