| 1018 | } |
| 1019 | |
| 1020 | static void |
| 1021 | malloc_conf_init_helper(sc_data_t *sc_data, unsigned bin_shard_sizes[SC_NBINS], |
| 1022 | bool initial_call, const char *opts_cache[MALLOC_CONF_NSOURCES], |
| 1023 | char buf[PATH_MAX + 1]) { |
| 1024 | static const char *opts_explain[MALLOC_CONF_NSOURCES] = { |
| 1025 | "string specified via --with-malloc-conf", |
| 1026 | "string pointed to by the global variable malloc_conf", |
| 1027 | "\"name\" of the file referenced by the symbolic link named " |
| 1028 | "/etc/malloc.conf", |
| 1029 | "value of the environment variable MALLOC_CONF" |
| 1030 | }; |
| 1031 | unsigned i; |
| 1032 | const char *opts, *k, *v; |
| 1033 | size_t klen, vlen; |
| 1034 | |
| 1035 | for (i = 0; i < MALLOC_CONF_NSOURCES; i++) { |
| 1036 | /* Get runtime configuration. */ |
| 1037 | if (initial_call) { |
| 1038 | opts_cache[i] = obtain_malloc_conf(i, buf); |
| 1039 | } |
| 1040 | opts = opts_cache[i]; |
| 1041 | if (!initial_call && opt_confirm_conf) { |
| 1042 | malloc_printf( |
| 1043 | "<jemalloc>: malloc_conf #%u (%s): \"%s\"\n", |
| 1044 | i + 1, opts_explain[i], opts != NULL ? opts : ""); |
| 1045 | } |
| 1046 | if (opts == NULL) { |
| 1047 | continue; |
| 1048 | } |
| 1049 | |
| 1050 | while (*opts != '\0' && !malloc_conf_next(&opts, &k, &klen, &v, |
| 1051 | &vlen)) { |
| 1052 | |
| 1053 | #define CONF_ERROR(msg, k, klen, v, vlen) \ |
| 1054 | if (!initial_call) { \ |
| 1055 | malloc_conf_error( \ |
| 1056 | msg, k, klen, v, vlen); \ |
| 1057 | cur_opt_valid = false; \ |
| 1058 | } |
| 1059 | #define CONF_CONTINUE { \ |
| 1060 | if (!initial_call && opt_confirm_conf \ |
| 1061 | && cur_opt_valid) { \ |
| 1062 | malloc_printf("<jemalloc>: -- " \ |
| 1063 | "Set conf value: %.*s:%.*s" \ |
| 1064 | "\n", (int)klen, k, \ |
| 1065 | (int)vlen, v); \ |
| 1066 | } \ |
| 1067 | continue; \ |
| 1068 | } |
| 1069 | #define CONF_MATCH(n) \ |
| 1070 | (sizeof(n)-1 == klen && strncmp(n, k, klen) == 0) |
| 1071 | #define CONF_MATCH_VALUE(n) \ |
| 1072 | (sizeof(n)-1 == vlen && strncmp(n, v, vlen) == 0) |
| 1073 | #define CONF_HANDLE_BOOL(o, n) \ |
| 1074 | if (CONF_MATCH(n)) { \ |
| 1075 | if (CONF_MATCH_VALUE("true")) { \ |
| 1076 | o = true; \ |
| 1077 | } else if (CONF_MATCH_VALUE("false")) { \ |
no test coverage detected