"Fossies" - the Fresh Open Source Software Archive

Member "stress-ng-0.09.56/stress-dynlib.c" (15 Mar 2019, 4109 Bytes) of package /linux/privat/stress-ng-0.09.56.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "stress-dynlib.c" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 0.09.52_vs_0.09.54.

    1 /*
    2  * Copyright (C) 2013-2019 Canonical, Ltd.
    3  *
    4  * This program is free software; you can redistribute it and/or
    5  * modify it under the terms of the GNU General Public License
    6  * as published by the Free Software Foundation; either version 2
    7  * of the License, or (at your option) any later version.
    8  *
    9  * This program is distributed in the hope that it will be useful,
   10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   12  * GNU General Public License for more details.
   13  *
   14  * You should have received a copy of the GNU General Public License
   15  * along with this program; if not, write to the Free Software
   16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
   17  *
   18  * This code is a complete clean re-write of the stress tool by
   19  * Colin Ian King <colin.king@canonical.com> and attempts to be
   20  * backwardly compatible with the stress tool by Amos Waterland
   21  * <apw@rossby.metr.ou.edu> but has more stress tests and more
   22  * functionality.
   23  *
   24  */
   25 #include "stress-ng.h"
   26 
   27 #if defined(HAVE_LIB_DL) && !defined(BUILD_STATIC)
   28 
   29 static sigjmp_buf jmp_env;
   30 
   31 typedef struct {
   32     const char *library;
   33     const char *symbol;
   34 } lib_info_t;
   35 
   36 static const lib_info_t libnames[] = {
   37 #if defined(LIBANL_SO)
   38     { LIBANL_SO, "gai_error" },
   39 #endif
   40 #if defined(LIBBROKENLOCALE_SO)
   41     { LIBBROKENLOCALE_SO, "nl_langinfo" },
   42 #endif
   43 #if defined(LIBCIDN_SO)
   44     { LIBCIDN_SO, "idna_to_ascii_lz" },
   45 #endif
   46 #if defined(LIBCRYPT_SO)
   47     { LIBCRYPT_SO, "crypt" },
   48 #endif
   49 #if defined(LIBGCC_S_SO)
   50     { LIBGCC_S_SO, "__clear_cache" },
   51 #endif
   52 #if defined(LIBMVEC_SO)
   53     { LIBMVEC_SO, "_ZGVbN4v_logf" },
   54 #endif
   55 #if defined(LIBM_SO)
   56     { LIBM_SO, "cos" },
   57 #endif
   58 #if defined(LIBNSL_SO)
   59     { LIBNSL_SO, "yp_match" },
   60 #endif
   61 #if defined(LIBNSS_COMPAT_SO)
   62     { LIBNSS_COMPAT_SO, "_nss_compat_endspent" },
   63 #endif
   64 #if defined(LIBNSS_DNS_SO)
   65     { LIBNSS_DNS_SO, "_nss_dns_gethostbyaddr_r" },
   66 #endif
   67 #if defined(LIBNSS_HESIOD_SO)
   68     { LIBNSS_HESIOD_SO, "_nss_hesiod_getpwnam_r" },
   69 #endif
   70 #if defined(LIBNSS_NISPLUS_SO)
   71     { LIBNSS_NISPLUS_SO, "_nss_nisplus_getnetent_r" },
   72 #endif
   73 #if defined(LIBNSS_NIS_SO)
   74     { LIBNSS_NIS_SO, "_nss_nis_setetherent" },
   75 #endif
   76 #if defined(LIBPTHREAD_SO)
   77     { LIBPTHREAD_SO, "pthread_cancel" },
   78 #endif
   79 #if defined(LIBRESOLV_SO)
   80     { LIBRESOLV_SO, "ns_name_ntol" },
   81 #endif
   82 #if defined(LIBRT_SO)
   83     { LIBRT_SO, "timer_create" },
   84 #endif
   85 #if defined(LIBTHREAD_DB_SO)
   86     { LIBTHREAD_DB_SO, "td_thr_clear_event" },
   87 #endif
   88 #if defined(LIBUTIL_SO)
   89     { LIBUTIL_SO, "openpty" },
   90 #endif
   91 };
   92 
   93 /*
   94  *  stress_segvhandler()
   95  *      SEGV handler
   96  */
   97 static void MLOCKED_TEXT stress_segvhandler(int signum)
   98 {
   99     (void)signum;
  100 
  101     siglongjmp(jmp_env, 1);
  102 }
  103 
  104 /*
  105  *  stress_dynlib()
  106  *  stress that does lots of not a lot
  107  */
  108 static int stress_dynlib(const args_t *args)
  109 {
  110     const size_t n = SIZEOF_ARRAY(libnames);
  111     void *handles[n];
  112 
  113     (void)memset(handles, 0, sizeof(handles));
  114 
  115     if (stress_sighandler(args->name, SIGSEGV, stress_segvhandler, NULL) < 0)
  116         return EXIT_NO_RESOURCE;
  117 
  118     do {
  119         size_t i;
  120         int ret;
  121 
  122         ret = sigsetjmp(jmp_env, 1);
  123         if (!keep_stressing())
  124             break;
  125         if (ret)
  126             goto tidy;
  127 
  128         for (i = 0; i < n; i++) {
  129             int flags;
  130 
  131             flags = mwc1() ? RTLD_LAZY : RTLD_NOW;
  132 #if defined(RTLD_GLOBAL) && defined(RTLD_LOCAL)
  133             flags |= mwc1() ? RTLD_GLOBAL : RTLD_LOCAL;
  134 #endif
  135             handles[i] = dlopen(libnames[i].library, flags);
  136             (void)dlerror();
  137         }
  138 
  139         for (i = 0; i < n; i++) {
  140             if (handles[i]) {
  141                 uint8_t *ptr;
  142 
  143                 (void)dlerror();
  144                 ptr = dlsym(handles[i], libnames[i].symbol);
  145                 /*
  146                  * The function pointer should be readable,
  147                  * however, we have a SIGSEGV handler that
  148                  * will perfom tidy up if not
  149                  */
  150                 if (ptr)
  151                     uint8_put(*ptr);
  152             }
  153         }
  154 tidy:
  155         for (i = 0; i < n; i++) {
  156             if (handles[i])
  157                 (void)dlclose(handles[i]);
  158             handles[i] = NULL;
  159         }
  160         inc_counter(args);
  161     } while (keep_stressing());
  162 
  163     return EXIT_SUCCESS;
  164 }
  165 stressor_info_t stress_dynlib_info = {
  166     .stressor = stress_dynlib,
  167     .class = CLASS_OS
  168 };
  169 #else
  170 stressor_info_t stress_dynlib_info = {
  171     .stressor = stress_not_implemented,
  172     .class = CLASS_OS
  173 };
  174 #endif