OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/surface/transport_dib.h" | 5 #include "ui/surface/transport_dib.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <stdlib.h> | 8 #include <stdlib.h> |
9 #include <sys/ipc.h> | 9 #include <sys/ipc.h> |
10 #include <sys/shm.h> | 10 #include <sys/shm.h> |
(...skipping 21 matching lines...) Expand all Loading... |
32 } | 32 } |
33 | 33 |
34 if (x_shm_) { | 34 if (x_shm_) { |
35 DCHECK(display_); | 35 DCHECK(display_); |
36 ui::DetachSharedMemory(display_, x_shm_); | 36 ui::DetachSharedMemory(display_, x_shm_); |
37 } | 37 } |
38 } | 38 } |
39 | 39 |
40 // static | 40 // static |
41 TransportDIB* TransportDIB::Create(size_t size, uint32 sequence_num) { | 41 TransportDIB* TransportDIB::Create(size_t size, uint32 sequence_num) { |
42 // We use a mode of 0666 since the X server won't attach to memory which is | 42 const int shmkey = shmget(IPC_PRIVATE, size, 0600); |
43 // 0600 since it can't know if it (as a root process) is being asked to map | |
44 // someone else's private shared memory region. | |
45 const int shmkey = shmget(IPC_PRIVATE, size, 0666); | |
46 if (shmkey == -1) { | 43 if (shmkey == -1) { |
47 DLOG(ERROR) << "Failed to create SysV shared memory region" | 44 DLOG(ERROR) << "Failed to create SysV shared memory region" |
48 << " errno:" << errno; | 45 << " errno:" << errno; |
49 return NULL; | 46 return NULL; |
| 47 } else { |
| 48 VLOG(1) << "Created SysV shared memory region " << shmkey; |
50 } | 49 } |
51 | 50 |
52 void* address = shmat(shmkey, NULL /* desired address */, 0 /* flags */); | 51 void* address = shmat(shmkey, NULL /* desired address */, 0 /* flags */); |
53 // 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 |
54 // 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 |
55 // that the kernel will automatically clean it up for us. | 54 // that the kernel will automatically clean it up for us. |
56 shmctl(shmkey, IPC_RMID, 0); | 55 shmctl(shmkey, IPC_RMID, 0); |
57 if (address == kInvalidAddress) | 56 if (address == kInvalidAddress) |
58 return NULL; | 57 return NULL; |
59 | 58 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 } | 131 } |
133 | 132 |
134 XID TransportDIB::MapToX(Display* display) { | 133 XID TransportDIB::MapToX(Display* display) { |
135 if (!x_shm_) { | 134 if (!x_shm_) { |
136 x_shm_ = ui::AttachSharedMemory(display, key_.shmkey); | 135 x_shm_ = ui::AttachSharedMemory(display, key_.shmkey); |
137 display_ = display; | 136 display_ = display; |
138 } | 137 } |
139 | 138 |
140 return x_shm_; | 139 return x_shm_; |
141 } | 140 } |
OLD | NEW |