Differences From Artifact [7de8ab3a25]:
- File src/OFSecureData.m — part of check-in [b46492384a] at 2020-11-29 00:59:23 on branch trunk — of_bitset_*: Use CHAR_BIT instead of 8 (user: js, size: 14753) [annotate] [blame] [check-ins using] [more...]
To Artifact [a977d1a98b]:
- File
src/OFSecureData.m
— part of check-in
[5b37fbeb82]
at
2020-12-20 21:26:08
on branch trunk
— Return error instead of using errno for threading
errno is problematic for Amiga libraries and is also not thread-safe on
some systems, even though it should. (user: js, size: 14836) [annotate] [blame] [check-ins using] [more...]
︙ | ︙ | |||
119 120 121 122 123 124 125 | struct page **preallocatedPages = of_tlskey_get(preallocatedPagesKey); # endif numPreallocatedPages--; # if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) OF_ENSURE(of_tlskey_set(numPreallocatedPagesKey, | | | | 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | struct page **preallocatedPages = of_tlskey_get(preallocatedPagesKey); # endif numPreallocatedPages--; # if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) OF_ENSURE(of_tlskey_set(numPreallocatedPagesKey, (void *)numPreallocatedPages) == 0); # endif page = preallocatedPages[numPreallocatedPages]; if (numPreallocatedPages == 0) { free(preallocatedPages); preallocatedPages = NULL; # if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) OF_ENSURE(of_tlskey_set(preallocatedPagesKey, preallocatedPages) == 0); # endif } return page; } } |
︙ | ︙ | |||
169 170 171 172 173 174 175 | # if defined(OF_HAVE_COMPILER_TLS) || !defined(OF_HAVE_THREADS) lastPage = page; if (firstPage == NULL) firstPage = page; # else | | | | 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | # if defined(OF_HAVE_COMPILER_TLS) || !defined(OF_HAVE_THREADS) lastPage = page; if (firstPage == NULL) firstPage = page; # else OF_ENSURE(of_tlskey_set(lastPageKey, page) == 0); if (of_tlskey_get(firstPageKey) == NULL) OF_ENSURE(of_tlskey_set(firstPageKey, page) == 0); # endif return page; } static void removePageIfEmpty(struct page *page) |
︙ | ︙ | |||
205 206 207 208 209 210 211 | # if defined(OF_HAVE_COMPILER_TLS) || !defined(OF_HAVE_THREADS) if (firstPage == page) firstPage = page->next; if (lastPage == page) lastPage = page->previous; # else if (of_tlskey_get(firstPageKey) == page) | | | | 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | # if defined(OF_HAVE_COMPILER_TLS) || !defined(OF_HAVE_THREADS) if (firstPage == page) firstPage = page->next; if (lastPage == page) lastPage = page->previous; # else if (of_tlskey_get(firstPageKey) == page) OF_ENSURE(of_tlskey_set(firstPageKey, page->next) == 0); if (of_tlskey_get(lastPageKey) == page) OF_ENSURE(of_tlskey_set(lastPageKey, page->previous) == 0); # endif free(page); } static void * allocateMemory(struct page *page, size_t bytes) |
︙ | ︙ | |||
270 271 272 273 274 275 276 | #if defined(HAVE_MMAP) && defined(HAVE_MLOCK) && defined(MAP_ANON) && \ !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) + (void)initialize { if (self != [OFSecureData class]) return; | > | | | | 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 | #if defined(HAVE_MMAP) && defined(HAVE_MLOCK) && defined(MAP_ANON) && \ !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) + (void)initialize { if (self != [OFSecureData class]) return; if (of_tlskey_new(&firstPageKey) != 0 || of_tlskey_new(&lastPageKey) != 0 || of_tlskey_new(&preallocatedPagesKey) != 0 || of_tlskey_new(&numPreallocatedPagesKey) != 0) @throw [OFInitializationFailedException exceptionWithClass: self]; } #endif + (void)preallocateUnswappableMemoryWithSize: (size_t)size { |
︙ | ︙ | |||
294 295 296 297 298 299 300 | size_t i; if (preallocatedPages != NULL) @throw [OFInvalidArgumentException exception]; preallocatedPages = of_alloc_zeroed(numPages, sizeof(struct page)); # if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) | | | | | 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 | size_t i; if (preallocatedPages != NULL) @throw [OFInvalidArgumentException exception]; preallocatedPages = of_alloc_zeroed(numPages, sizeof(struct page)); # if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) OF_ENSURE(of_tlskey_set(preallocatedPagesKey, preallocatedPages) == 0); # endif @try { for (i = 0; i < numPages; i++) preallocatedPages[i] = addPage(false); } @catch (id e) { for (size_t j = 0; j < i; j++) removePageIfEmpty(preallocatedPages[j]); free(preallocatedPages); preallocatedPages = NULL; @throw e; } numPreallocatedPages = numPages; # if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) OF_ENSURE(of_tlskey_set(numPreallocatedPagesKey, (void *)(uintptr_t)numPreallocatedPages) == 0); # endif #else @throw [OFNotImplementedException exceptionWithSelector: _cmd object: self]; #endif } |
︙ | ︙ |