293 } |
293 } |
294 #endif // QT_NO_PLUGIN_CHECK |
294 #endif // QT_NO_PLUGIN_CHECK |
295 |
295 |
296 #if defined(Q_OS_UNIX) && !defined(Q_OS_MAC) && !defined(Q_OS_SYMBIAN) && !defined(QT_NO_PLUGIN_CHECK) |
296 #if defined(Q_OS_UNIX) && !defined(Q_OS_MAC) && !defined(Q_OS_SYMBIAN) && !defined(QT_NO_PLUGIN_CHECK) |
297 |
297 |
298 #if defined(Q_OS_FREEBSD) || defined(Q_OS_LINUX) |
|
299 # define USE_MMAP |
|
300 QT_BEGIN_INCLUDE_NAMESPACE |
|
301 # include <sys/types.h> |
|
302 # include <sys/mman.h> |
|
303 QT_END_INCLUDE_NAMESPACE |
|
304 #endif // Q_OS_FREEBSD || Q_OS_LINUX |
|
305 |
|
306 static long qt_find_pattern(const char *s, ulong s_len, |
298 static long qt_find_pattern(const char *s, ulong s_len, |
307 const char *pattern, ulong p_len) |
299 const char *pattern, ulong p_len) |
308 { |
300 { |
309 /* |
301 /* |
310 we search from the end of the file because on the supported |
302 we search from the end of the file because on the supported |
361 } |
353 } |
362 return false; |
354 return false; |
363 } |
355 } |
364 |
356 |
365 QByteArray data; |
357 QByteArray data; |
366 char *filedata = 0; |
358 const char *filedata = 0; |
367 ulong fdlen = 0; |
359 ulong fdlen = file.size(); |
368 |
360 filedata = (char *) file.map(0, fdlen); |
369 # ifdef USE_MMAP |
361 if (filedata == 0) { |
370 char *mapaddr = 0; |
|
371 size_t maplen = file.size(); |
|
372 mapaddr = (char *) mmap(mapaddr, maplen, PROT_READ, MAP_PRIVATE, file.handle(), 0); |
|
373 if (mapaddr != MAP_FAILED) { |
|
374 // mmap succeeded |
|
375 filedata = mapaddr; |
|
376 fdlen = maplen; |
|
377 } else { |
|
378 // mmap failed |
|
379 if (qt_debug_component()) { |
|
380 qWarning("mmap: %s", qPrintable(qt_error_string(errno))); |
|
381 } |
|
382 if (lib) |
|
383 lib->errorString = QLibrary::tr("Could not mmap '%1': %2") |
|
384 .arg(library) |
|
385 .arg(qt_error_string()); |
|
386 # endif // USE_MMAP |
|
387 // try reading the data into memory instead |
362 // try reading the data into memory instead |
388 data = file.readAll(); |
363 data = file.readAll(); |
389 filedata = data.data(); |
364 filedata = data.constData(); |
390 fdlen = data.size(); |
365 fdlen = data.size(); |
391 # ifdef USE_MMAP |
366 } |
392 } |
|
393 # endif // USE_MMAP |
|
394 |
367 |
395 // verify that the pattern is present in the plugin |
368 // verify that the pattern is present in the plugin |
396 const char pattern[] = "pattern=QT_PLUGIN_VERIFICATION_DATA"; |
369 const char pattern[] = "pattern=QT_PLUGIN_VERIFICATION_DATA"; |
397 const ulong plen = qstrlen(pattern); |
370 const ulong plen = qstrlen(pattern); |
398 long pos = qt_find_pattern(filedata, fdlen, pattern, plen); |
371 long pos = qt_find_pattern(filedata, fdlen, pattern, plen); |
401 if (pos >= 0) |
374 if (pos >= 0) |
402 ret = qt_parse_pattern(filedata + pos, version, debug, key); |
375 ret = qt_parse_pattern(filedata + pos, version, debug, key); |
403 |
376 |
404 if (!ret && lib) |
377 if (!ret && lib) |
405 lib->errorString = QLibrary::tr("Plugin verification data mismatch in '%1'").arg(library); |
378 lib->errorString = QLibrary::tr("Plugin verification data mismatch in '%1'").arg(library); |
406 # ifdef USE_MMAP |
|
407 if (mapaddr != MAP_FAILED && munmap(mapaddr, maplen) != 0) { |
|
408 if (qt_debug_component()) |
|
409 qWarning("munmap: %s", qPrintable(qt_error_string(errno))); |
|
410 if (lib) |
|
411 lib->errorString = QLibrary::tr("Could not unmap '%1': %2") |
|
412 .arg(library) |
|
413 .arg( qt_error_string() ); |
|
414 } |
|
415 # endif // USE_MMAP |
|
416 |
|
417 file.close(); |
379 file.close(); |
418 return ret; |
380 return ret; |
419 } |
381 } |
420 |
382 |
421 #endif // Q_OS_UNIX && !Q_OS_MAC && !defined(Q_OS_SYMBIAN) && !defined(QT_NO_PLUGIN_CHECK) |
383 #endif // Q_OS_UNIX && !Q_OS_MAC && !defined(Q_OS_SYMBIAN) && !defined(QT_NO_PLUGIN_CHECK) |
788 .arg((qt_version&0xff0000) >> 16) |
750 .arg((qt_version&0xff0000) >> 16) |
789 .arg((qt_version&0xff00) >> 8) |
751 .arg((qt_version&0xff00) >> 8) |
790 .arg(qt_version&0xff) |
752 .arg(qt_version&0xff) |
791 .arg(debug ? QLatin1String("debug") : QLatin1String("release")); |
753 .arg(debug ? QLatin1String("debug") : QLatin1String("release")); |
792 } else if (key != QT_BUILD_KEY |
754 } else if (key != QT_BUILD_KEY |
|
755 // we may have some compatibility keys, try them too: |
793 #ifdef QT_BUILD_KEY_COMPAT |
756 #ifdef QT_BUILD_KEY_COMPAT |
794 // be sure to load plugins using an older but compatible build key |
|
795 && key != QT_BUILD_KEY_COMPAT |
757 && key != QT_BUILD_KEY_COMPAT |
|
758 #endif |
|
759 #ifdef QT_BUILD_KEY_COMPAT2 |
|
760 && key != QT_BUILD_KEY_COMPAT2 |
796 #endif |
761 #endif |
797 ) { |
762 ) { |
798 if (qt_debug_component()) { |
763 if (qt_debug_component()) { |
799 qWarning("In %s:\n" |
764 qWarning("In %s:\n" |
800 " Plugin uses incompatible Qt library\n" |
765 " Plugin uses incompatible Qt library\n" |