10 | | /*! Note, this class don't provide any locking whatsoever - you are |
11 | | supposed to have a BPrivate::AppServerLink object around which |
12 | | does the necessary locking. |
13 | | However, this is not enforced in the methods here, you have to |
14 | | take care for yourself! |
| 10 | /*! Note, this class don't provide any locking whatsoever - you are |
| 11 | supposed to have a BPrivate::AppServerLink object around which |
| 12 | does the necessary locking. |
| 13 | However, this is not enforced in the methods here, you have to |
| 14 | take care for yourself! |
70 | | area_mapping* mapping = new (std::nothrow) area_mapping; |
71 | | if (mapping == NULL || !fAreas.AddItem(mapping)) { |
72 | | delete mapping; |
73 | | return B_NO_MEMORY; |
74 | | } |
75 | | |
76 | | status_t status = B_ERROR; |
77 | | uint32 addressSpec = B_ANY_ADDRESS; |
78 | | void* base; |
| 66 | area_id server_area, local_area; |
| 67 | uint8* local_base; |
| 68 | /* area_mapping* mapping = new (std::nothrow) area_mapping; |
| 69 | |
| 70 | if (mapping == NULL) { |
| 71 | delete mapping; |
| 72 | return B_NO_MEMORY; |
| 73 | } |
| 74 | */ |
| 75 | status_t status = B_ERROR; |
| 76 | uint32 addressSpec = B_ANY_ADDRESS; |
| 77 | void* base; |
80 | | if (!readOnly && size < kReserveMaxSize) { |
81 | | // Reserve 128 MB of space for the area, but only if the area |
82 | | // is smaller than 32 MB (else the address space waste would |
83 | | // likely to be too large) |
84 | | base = (void*)0x60000000; |
85 | | status = _kern_reserve_address_range((addr_t*)&base, B_BASE_ADDRESS, |
86 | | kReservedSize); |
87 | | addressSpec = status == B_OK ? B_EXACT_ADDRESS : B_BASE_ADDRESS; |
88 | | } |
| 79 | if (!readOnly && size < kReserveMaxSize) { |
| 80 | // Reserve 128 MB of space for the area, but only if the area |
| 81 | // is smaller than 32 MB (else the address space waste would |
| 82 | // likely to be too large) |
| 83 | base = (void*)0x60000000; |
| 84 | status = _kern_reserve_address_range((addr_t*)&base, B_BASE_ADDRESS, |
| 85 | kReservedSize); |
| 86 | addressSpec = status == B_OK ? B_EXACT_ADDRESS : B_BASE_ADDRESS; |
| 87 | } |
91 | | mapping->local_area = clone_area(readOnly |
92 | | ? "server read-only memory" : "server_memory", &base, addressSpec, |
93 | | B_READ_AREA | (readOnly ? 0 : B_WRITE_AREA), serverArea); |
94 | | if (mapping->local_area < B_OK) { |
95 | | status = mapping->local_area; |
96 | | |
97 | | fAreas.RemoveItem(mapping); |
98 | | delete mapping; |
99 | | |
100 | | return status; |
101 | | } |
102 | | |
103 | | mapping->server_area = serverArea; |
104 | | mapping->local_base = (uint8*)base; |
105 | | |
106 | | _area = mapping->local_area; |
107 | | _base = mapping->local_base; |
108 | | |
109 | | return B_OK; |
| 90 | local_area = clone_area(readOnly |
| 91 | ? "server read-only memory" : "server_memory", &base, addressSpec, |
| 92 | B_READ_AREA | (readOnly ? 0 : B_WRITE_AREA), serverArea); |
| 93 | if (local_area < B_OK) { |
| 94 | status = local_area; |
| 95 | |
| 96 | //delete mapping; |
| 97 | |
| 98 | return status; |
| 99 | } |
| 100 | |
| 101 | server_area = serverArea; |
| 102 | local_base = (uint8*)base; |
| 103 | |
| 104 | std::pair<std::map<area_id, std::pair<area_id, uint8*> >::iterator,bool> ret_insert; |
| 105 | |
| 106 | ret_insert = fAreas.insert(std::pair<area_id, std::pair<area_id, uint8*> >(server_area, |
| 107 | std::pair<area_id, uint8*>(local_area, local_base))); |
| 108 | if (!ret_insert.second) { |
| 109 | // delete mapping; |
| 110 | return B_NO_MEMORY; |
| 111 | } |
| 112 | |
| 113 | _area = local_area; |
| 114 | _base = local_base; |
| 115 | |
| 116 | return B_OK; |
116 | | for (int32 i = fAreas.CountItems(); i-- > 0;) { |
117 | | area_mapping* mapping = (area_mapping*)fAreas.ItemAt(i); |
118 | | |
119 | | if (mapping->server_area == serverArea) { |
120 | | // we found the area we should remove |
121 | | delete_area(mapping->local_area); |
122 | | delete mapping; |
123 | | fAreas.RemoveItem(i); |
124 | | break; |
125 | | } |
126 | | } |
| 123 | std::map<area_id, std::pair<area_id, uint8*> >::iterator area_it = fAreas.find(serverArea); |
| 124 | |
| 125 | if (area_it != fAreas.end()) { |
| 126 | // we found the area we should remove |
| 127 | std::pair<area_id, uint8*> area = area_it->second; |
| 128 | delete_area(area.first); |
| 129 | fAreas.erase(serverArea); |
| 130 | } |
134 | | // TODO: why not use a map? |
135 | | for (int32 i = fAreas.CountItems(); i-- > 0;) { |
136 | | area_mapping* mapping = (area_mapping*)fAreas.ItemAt(i); |
137 | | |
138 | | if (mapping->server_area == serverArea) { |
139 | | _area = mapping->local_area; |
140 | | _base = mapping->local_base; |
141 | | return B_OK; |
142 | | } |
143 | | } |
144 | | |
145 | | return B_ERROR; |
| 138 | std::map<area_id, std::pair<area_id, uint8*> >::iterator area_it = fAreas.find(serverArea); |
| 139 | if (area_it != fAreas.end()) { |
| 140 | std::pair<area_id, uint8*> area = area_it->second; |
| 141 | _area = area.first; |
| 142 | _base = area.second; |
| 143 | return B_OK; |
| 144 | } |
| 145 | return B_ERROR; |