}END_TEST START_TEST (test_delete) { OPGP_ERROR_STATUS status; status = internal_connect(); if (OPGP_ERROR_CHECK(status)) { fail("Could not connect: %s", status.errorMessage); } status = internal_mutual_authentication(); if (OPGP_ERROR_CHECK(status)) { fail("Could not do mutual authentication: %s", status.errorMessage); } status = internal_delete(); if (OPGP_ERROR_CHECK(status)) { fail("Could not delete applets: %s", status.errorMessage); } status = internal_disconnect(); if (OPGP_ERROR_CHECK(status)) { fail("Could not disconnect: %s", status.errorMessage); } } END_TEST
bool fset_delete (fset_t *dbs, mem_hash_t *mem, void *key) { void *data; return internal_delete (dbs, mem, key, &data); }
bool fset_delete_get_data (fset_t *dbs, mem_hash_t *mem, void *key, void **data) { return internal_delete (dbs, mem, key, data); }
LIBXSMM_API #if defined(_WIN32) /*TODO: no inline*/ #elif defined(__GNUC__) /*LIBXSMM_ATTRIBUTE(noinline)*/ #endif const char* libxsmm_trace_info(unsigned int* depth, unsigned int* threadid, const int* filter_threadid, const int* filter_mindepth, const int* filter_maxnsyms) { const char *fname = NULL; #if defined(LIBXSMM_TRACE) const int max_n = (0 != depth ? (LIBXSMM_TRACE_MAXDEPTH) : 2); const int min_n = (0 != depth ? (LIBXSMM_TRACE_MINDEPTH + *depth) : 2); void *stacktrace[LIBXSMM_TRACE_MAXDEPTH], **symbol = stacktrace + LIBXSMM_MIN(0 != depth ? ((int)(*depth + 1)) : 1, max_n - 1); static LIBXSMM_TLS int cerberus = 0; int i; /* check against entering a recursion (recursion should not happen due to * attribute "no_instrument_function" but better prevent this in any case) */ if (0 == cerberus) { ++cerberus; # if defined(__GNUC__) __asm__(""); # endif i = LIBXSMM_ATOMIC_LOAD(&internal_trace_initialized, LIBXSMM_ATOMIC_RELAXED); if (0 <= i) { /* do nothing if not yet initialized */ const int mindepth = (0 != filter_mindepth ? *filter_mindepth : internal_trace_mindepth); const int maxnsyms = (0 != filter_maxnsyms ? *filter_maxnsyms : internal_trace_maxnsyms); i = libxsmm_backtrace(stacktrace, max_n); /* filter depth against filter_mindepth and filter_maxnsyms */ if ((0 >= mindepth || (min_n + mindepth) <= i) && (0 > maxnsyms || i <= (min_n + mindepth + maxnsyms - 1))) { if (min_n <= i) { /* check against min. depth */ const int filter = (0 != filter_threadid ? *filter_threadid : internal_trace_threadid); int abs_tid = 0; # if defined(_WIN32) || defined(__CYGWIN__) static LIBXSMM_TLS char buffer[sizeof(SYMBOL_INFO)+LIBXSMM_TRACE_SYMBOLSIZE]; static LIBXSMM_TLS int tid = 0; PSYMBOL_INFO value = (PSYMBOL_INFO)buffer; value->SizeOfStruct = sizeof(SYMBOL_INFO); value->MaxNameLen = LIBXSMM_TRACE_SYMBOLSIZE - 1; if (0 != tid) { abs_tid = (0 <= tid ? tid : -tid); } else { abs_tid = LIBXSMM_ATOMIC_ADD_FETCH(&internal_trace_initialized, 1, LIBXSMM_ATOMIC_RELAXED); /* use sign bit to flag enabled fall-back for symbol resolution */ tid = -abs_tid; } assert(0 < abs_tid); if (0 > filter || filter == abs_tid - 1) { if (FALSE != SymFromAddr(GetCurrentProcess(), (DWORD64)*symbol, NULL, value) && 0 < value->NameLen) { /* disable fall-back allowing unresolved symbol names */ tid = abs_tid; /* make unsigned */ fname = value->Name; } else if (0 > tid) { /* fall-back allowing unresolved symbol names */ # if defined(__MINGW32__) sprintf(buffer, "%p", *symbol); # else sprintf(buffer, "0x%" PRIxPTR, (uintptr_t)*symbol); # endif fname = buffer; } if (depth) *depth = i - min_n; if (threadid) *threadid = abs_tid - 1; } # else # if defined(LIBXSMM_NO_SYNC) static char raw_c; char */*const*/ raw_value = &raw_c; /* const: avoid warning (below / constant control-flow) */ # else char *const raw_value = (char*)pthread_getspecific(internal_trace_key); # endif int* ivalue = 0, fd = -1; char* value = 0; if (raw_value) { ivalue = (int*)raw_value; abs_tid = (0 <= ivalue[1] ? ivalue[1] : -ivalue[1]); if (0 > filter || filter == abs_tid - 1) { fd = ivalue[0]; if (0 <= fd && (sizeof(int) * 2) == lseek(fd, sizeof(int) * 2, SEEK_SET)) { value = raw_value + sizeof(int) * 2; } # if !defined(NDEBUG) /* library code is expected to be mute */ else { fprintf(stderr, "LIBXSMM ERROR: failed to get buffer\n"); } # endif } } else { char filename[] = "/tmp/.libxsmm_XXXXXX.map"; #if defined(__GLIBC__) && defined(__GLIBC_MINOR__) && LIBXSMM_VERSION2(2, 19) <= LIBXSMM_VERSION2(__GLIBC__, __GLIBC_MINOR__) fd = mkstemps(filename, 4/*.map*/); #else char *const xpos = strrchr(filename, 'X'); const char c = (char)(NULL != xpos ? *(xpos + 1) : 0); if (0 != c) { xpos[1] = 0; fd = mkstemp(filename); xpos[1] = c; } else { fd = -1; } #endif if (0 <= fd && 0 == posix_fallocate(fd, 0, LIBXSMM_TRACE_SYMBOLSIZE)) { char *const buffer = (char*)mmap(NULL, LIBXSMM_TRACE_SYMBOLSIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (MAP_FAILED != buffer) { int check = -1; ivalue = (int*)buffer; ivalue[0] = fd; /* valid file descriptor for internal_delete */ if ( # if !defined(LIBXSMM_NO_SYNC) 0 == pthread_setspecific(internal_trace_key, buffer) && # endif (sizeof(int) * 1) == read(fd, &check, sizeof(int)) && (sizeof(int) * 2) == lseek(fd, sizeof(int), SEEK_CUR) && check == fd) { abs_tid = LIBXSMM_ATOMIC_ADD_FETCH(&internal_trace_initialized, 1, LIBXSMM_ATOMIC_RELAXED); assert(0 < abs_tid); /* use sign bit to flag enabled fall-back for symbol resolution */ ivalue[1] = -abs_tid; if (0 > filter || filter == abs_tid - 1) { value = buffer + sizeof(int) * 2; } } else { # if !defined(NDEBUG) /* library code is expected to be mute */ fprintf(stderr, "LIBXSMM ERROR: failed to setup buffer\n"); # endif internal_delete(buffer); } } # if !defined(NDEBUG) else { const int error = errno; fprintf(stderr, "LIBXSMM ERROR: %s (mmap allocation error #%i)\n", strerror(error), error); } # endif } # if !defined(NDEBUG) /* library code is expected to be mute */ else { fprintf(stderr, "LIBXSMM ERROR: failed to setup file descriptor (%i)\n", fd); } # endif } if (value) { backtrace_symbols_fd(symbol, 1, fd); /* attempt to parse symbol name */ if (1 == sscanf(value, "%*[^(](%s0x", value)) { char* c; for (c = value; '+' != *c && *c; ++c); if ('+' == *c) { /* disable fall-back allowing unresolved symbol names */ ivalue[1] = abs_tid; /* make unsigned */ fname = value; *c = 0; } } /* fall-back to symbol address */ if (0 > ivalue[1] && 0 == fname) { sprintf(value, "0x%llx", (unsigned long long)*symbol); fname = value; } if (depth) *depth = i - min_n; if (threadid) *threadid = abs_tid - 1; } # endif } } } --cerberus; } #else LIBXSMM_UNUSED(depth); LIBXSMM_UNUSED(threadid); LIBXSMM_UNUSED(filter_threadid); LIBXSMM_UNUSED(filter_mindepth); LIBXSMM_UNUSED(filter_maxnsyms); #endif return fname; }
}END_TEST /** * Tests the install commands. */ START_TEST (test_install) { OPGP_LOAD_FILE_PARAMETERS loadFileParams; DWORD receiptDataAvailable = 0; DWORD receiptDataLen = 0; char installParam[1]; installParam[0] = 0; OPGP_ERROR_STATUS status; GP211_RECEIPT_DATA receipt; status = internal_connect(); if (OPGP_ERROR_CHECK(status)) { fail("Could not connect: %s", status.errorMessage); } status = internal_mutual_authentication(); if (OPGP_ERROR_CHECK(status)) { fail("Could not do mutual authentication: %s", status.errorMessage); } internal_delete(); status = OPGP_read_executable_load_file_parameters(TEST_LOAD_FILE, &loadFileParams); if (OPGP_ERROR_CHECK(status)) { fail("OPGP_read_executable_load_file_parameters() failed: ", status.errorMessage); } status = GP211_install_for_load(cardContext, cardInfo, &securityInfo211, loadFileParams.loadFileAID.AID, loadFileParams.loadFileAID.AIDLength, (PBYTE) GP211_CARD_MANAGER_AID_ALT1, sizeof(GP211_CARD_MANAGER_AID_ALT1), NULL, NULL, loadFileParams.loadFileSize, 0, 2000); if (OPGP_ERROR_CHECK(status)) { fail("GP211_install_for_load() failed: ", status.errorMessage); } status = GP211_load(cardContext, cardInfo, &securityInfo211, NULL, 0, TEST_LOAD_FILE, NULL, &receiptDataLen, NULL); if (OPGP_ERROR_CHECK(status)) { fail("GP211_load() failed: ", status.errorMessage); } status = GP211_install_for_install_and_make_selectable(cardContext, cardInfo, &securityInfo211, loadFileParams.loadFileAID.AID, loadFileParams.loadFileAID.AIDLength, loadFileParams.appletAIDs[0].AID, loadFileParams.appletAIDs[0].AIDLength, loadFileParams.appletAIDs[0].AID, loadFileParams.appletAIDs[0].AIDLength, 0, 500, 1000, NULL, 0, NULL, &receipt, &receiptDataAvailable); if (OPGP_ERROR_CHECK(status)) { fail("GP211_install_for_install_and_make_selectable() failed: ", status.errorMessage); } status = internal_disconnect(); if (OPGP_ERROR_CHECK(status)) { fail("Could not disconnect: %s", status.errorMessage); } }END_TEST