apr_status_t shm_cleanup_cookiestore(void *not_used) { apr_status_t rv = 0; ap_log_error(PC_LOG_INFO, NULL, "mod_but_shm.c: (SHM COOKIESTORE) Cleaning shared cookiestore memory and RMM by shm_cleanup_cookiestore"); if(cs_rmm_cookiestore) { rv = apr_rmm_destroy(cs_rmm_cookiestore); if (rv != APR_SUCCESS) { ap_log_error(PC_LOG_INFO, NULL, "mod_but_shm.c: (SHM COOKIESTORE) Failed to destroy RMM cookiestore"); return rv; } else { ap_log_error(PC_LOG_INFO, NULL, "mod_but_shm.c: (SHM COOKIESTORE) Successfully destroyed RMM cookiestore"); cs_rmm_cookiestore = NULL; } } if (cs_shm_cookiestore) { rv = apr_shm_destroy(cs_shm_cookiestore); if (rv != APR_SUCCESS) { ap_log_error(PC_LOG_INFO, NULL, "mod_but_shm.c: (SHM COOKIESTORE) Failed to destroy shared cookiestore memory"); return rv; } else { ap_log_error(PC_LOG_INFO, NULL, "mod_but_shm.c: (SHM COOKIESTORE) Successfully destroyed shared cookiestore memory"); cs_rmm_cookiestore = NULL; } } return rv; }
apr_status_t shm_cleanup_history(void *not_used) { apr_status_t rv = 0; ap_log_error(PC_LOG_INFO, NULL, "mod_but_shm.c: (SHM HISTORY) Cleaning shared history memory and RMM by shm_cleanup_history"); if(cs_rmm_history) { rv = apr_rmm_destroy(cs_rmm_history); if (rv != APR_SUCCESS) { ap_log_error(PC_LOG_INFO, NULL, "mod_but_shm.c: (SHM HISTORY) Failed to destroy RMM history"); return rv; } else { ap_log_error(PC_LOG_INFO, NULL, "mod_but_shm.c: (SHM HISTORY) Successfully destroyed RMM history"); cs_rmm_history = NULL; } } if (cs_shm_history) { rv = apr_shm_destroy(cs_shm_history); if (rv != APR_SUCCESS) { ap_log_error(PC_LOG_INFO, NULL, "mod_but_shm.c: (SHM HISTORY) Failed to destroy shared history memory"); return rv; } else { ap_log_error(PC_LOG_INFO, NULL, "mod_but_shm.c: (SHM HISTORY) Successfully destroyed shared history memory"); cs_rmm_history = NULL; } } return rv; }
void ssl_scache_shmht_kill(server_rec *s) { SSLModConfigRec *mc = myModConfig(s); if (mc->pSessionCacheDataRMM != NULL) { apr_rmm_destroy(mc->pSessionCacheDataRMM); mc->pSessionCacheDataRMM = NULL; } if (mc->pSessionCacheDataMM != NULL) { apr_shm_destroy(mc->pSessionCacheDataMM); mc->pSessionCacheDataMM = NULL; } return; }
/* ------------------------------------------------------------------ */ static apr_status_t util_ldap_cache_module_kill(void *data) { util_ldap_state_t *st = data; util_ald_destroy_cache(st->util_ldap_cache); #if APR_HAS_SHARED_MEMORY if (st->cache_rmm != NULL) { apr_rmm_destroy (st->cache_rmm); st->cache_rmm = NULL; } if (st->cache_shm != NULL) { apr_status_t result = apr_shm_destroy(st->cache_shm); st->cache_shm = NULL; return result; } #endif return APR_SUCCESS; }
static apr_status_t upload_progress_cache_module_kill(void *data) { ServerConfig *st = (ServerConfig*)data; upload_progress_destroy_cache(st); #if APR_HAS_SHARED_MEMORY if (st->cache_rmm != NULL) { apr_rmm_destroy (st->cache_rmm); st->cache_rmm = NULL; } if (st->cache_shm != NULL) { apr_status_t result = apr_shm_destroy(st->cache_shm); st->cache_shm = NULL; return result; } #endif return APR_SUCCESS; }
static void test_rmm(abts_case *tc, void *data) { apr_status_t rv; apr_pool_t *pool; apr_shm_t *shm; apr_rmm_t *rmm; apr_size_t size, fragsize; apr_rmm_off_t *off, off2; int i; void *entity; rv = apr_pool_create(&pool, p); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); /* We're going to want 10 blocks of data from our target rmm. */ size = SHARED_SIZE + apr_rmm_overhead_get(FRAG_COUNT + 1); rv = apr_shm_create(&shm, size, NULL, pool); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); if (rv != APR_SUCCESS) return; rv = apr_rmm_init(&rmm, NULL, apr_shm_baseaddr_get(shm), size, pool); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); if (rv != APR_SUCCESS) return; /* Creating each fragment of size fragsize */ fragsize = SHARED_SIZE / FRAG_COUNT; off = apr_palloc(pool, FRAG_COUNT * sizeof(apr_rmm_off_t)); for (i = 0; i < FRAG_COUNT; i++) { off[i] = apr_rmm_malloc(rmm, fragsize); } /* Checking for out of memory allocation */ off2 = apr_rmm_malloc(rmm, FRAG_SIZE * FRAG_COUNT); ABTS_TRUE(tc, !off2); /* Checking each fragment for address alignment */ for (i = 0; i < FRAG_COUNT; i++) { char *c = apr_rmm_addr_get(rmm, off[i]); apr_size_t sc = (apr_size_t)c; ABTS_TRUE(tc, !!off[i]); ABTS_TRUE(tc, !(sc & 7)); } /* Setting each fragment to a unique value */ for (i = 0; i < FRAG_COUNT; i++) { int j; char **c = apr_rmm_addr_get(rmm, off[i]); for (j = 0; j < FRAG_SIZE; j++, c++) { *c = apr_itoa(pool, i + j); } } /* Checking each fragment for its unique value */ for (i = 0; i < FRAG_COUNT; i++) { int j; char **c = apr_rmm_addr_get(rmm, off[i]); for (j = 0; j < FRAG_SIZE; j++, c++) { char *d = apr_itoa(pool, i + j); ABTS_STR_EQUAL(tc, d, *c); } } /* Freeing each fragment */ for (i = 0; i < FRAG_COUNT; i++) { rv = apr_rmm_free(rmm, off[i]); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); } /* Creating one large segment */ off[0] = apr_rmm_calloc(rmm, SHARED_SIZE); /* Setting large segment */ for (i = 0; i < FRAG_COUNT * FRAG_SIZE; i++) { char **c = apr_rmm_addr_get(rmm, off[0]); c[i] = apr_itoa(pool, i); } /* Freeing large segment */ rv = apr_rmm_free(rmm, off[0]); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); /* Creating each fragment of size fragsize */ for (i = 0; i < FRAG_COUNT; i++) { off[i] = apr_rmm_malloc(rmm, fragsize); } /* Freeing each fragment backwards */ for (i = FRAG_COUNT - 1; i >= 0; i--) { rv = apr_rmm_free(rmm, off[i]); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); } /* Creating one large segment (again) */ off[0] = apr_rmm_calloc(rmm, SHARED_SIZE); /* Freeing large segment */ rv = apr_rmm_free(rmm, off[0]); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); /* Checking realloc */ off[0] = apr_rmm_calloc(rmm, SHARED_SIZE - 100); off[1] = apr_rmm_calloc(rmm, 100); ABTS_TRUE(tc, !!off[0]); ABTS_TRUE(tc, !!off[1]); entity = apr_rmm_addr_get(rmm, off[1]); rv = apr_rmm_free(rmm, off[0]); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); { unsigned char *c = entity; /* Fill in the region; the first half with zereos, which will * likely catch the apr_rmm_realloc offset calculation bug by * making it think the old region was zero length. */ for (i = 0; i < 100; i++) { c[i] = (i < 50) ? 0 : i; } } /* now we can realloc off[1] and get many more bytes */ off[0] = apr_rmm_realloc(rmm, entity, SHARED_SIZE - 100); ABTS_TRUE(tc, !!off[0]); { unsigned char *c = apr_rmm_addr_get(rmm, off[0]); /* fill in the region */ for (i = 0; i < 100; i++) { ABTS_TRUE(tc, c[i] == (i < 50 ? 0 : i)); } } rv = apr_rmm_destroy(rmm); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); rv = apr_shm_destroy(shm); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); apr_pool_destroy(pool); }
static apr_status_t test_rmm(apr_pool_t *parpool) { apr_status_t rv; apr_pool_t *pool; apr_shm_t *shm; apr_rmm_t *rmm; apr_size_t size, fragsize; apr_rmm_off_t *off; int i; void *entity; rv = apr_pool_create(&pool, parpool); if (rv != APR_SUCCESS) { fprintf(stderr, "Error creating child pool\n"); return rv; } /* We're going to want 10 blocks of data from our target rmm. */ size = SHARED_SIZE + apr_rmm_overhead_get(FRAG_COUNT + 1); printf("Creating anonymous shared memory (%" APR_SIZE_T_FMT " bytes).....", size); rv = apr_shm_create(&shm, size, NULL, pool); if (rv != APR_SUCCESS) { fprintf(stderr, "Error allocating shared memory block\n"); return rv; } fprintf(stdout, "OK\n"); printf("Creating rmm segment............................."); rv = apr_rmm_init(&rmm, NULL, apr_shm_baseaddr_get(shm), size, pool); if (rv != APR_SUCCESS) { fprintf(stderr, "Error allocating rmm..............\n"); return rv; } fprintf(stdout, "OK\n"); fragsize = SHARED_SIZE / FRAG_COUNT; printf("Creating each fragment of size %" APR_SIZE_T_FMT "................", fragsize); off = apr_palloc(pool, FRAG_COUNT * sizeof(apr_rmm_off_t)); for (i = 0; i < FRAG_COUNT; i++) { off[i] = apr_rmm_malloc(rmm, fragsize); } fprintf(stdout, "OK\n"); printf("Checking for out of memory allocation............"); if (apr_rmm_malloc(rmm, FRAG_SIZE * FRAG_COUNT) == 0) { fprintf(stdout, "OK\n"); } else { return APR_EGENERAL; } printf("Checking each fragment for address alignment....."); for (i = 0; i < FRAG_COUNT; i++) { char *c = apr_rmm_addr_get(rmm, off[i]); apr_size_t sc = (apr_size_t)c; if (off[i] == 0) { printf("allocation failed for offset %d\n", i); return APR_ENOMEM; } if (sc & 7) { printf("Bad alignment for fragment %d; %p not %p!\n", i, c, (void *)APR_ALIGN_DEFAULT((apr_size_t)c)); return APR_EGENERAL; } } fprintf(stdout, "OK\n"); printf("Setting each fragment to a unique value.........."); for (i = 0; i < FRAG_COUNT; i++) { int j; char **c = apr_rmm_addr_get(rmm, off[i]); for (j = 0; j < FRAG_SIZE; j++, c++) { *c = apr_itoa(pool, i + j); } } fprintf(stdout, "OK\n"); printf("Checking each fragment for its unique value......"); for (i = 0; i < FRAG_COUNT; i++) { int j; char **c = apr_rmm_addr_get(rmm, off[i]); for (j = 0; j < FRAG_SIZE; j++, c++) { char *d = apr_itoa(pool, i + j); if (strcmp(*c, d) != 0) { return APR_EGENERAL; } } } fprintf(stdout, "OK\n"); printf("Freeing each fragment............................"); for (i = 0; i < FRAG_COUNT; i++) { rv = apr_rmm_free(rmm, off[i]); if (rv != APR_SUCCESS) { return rv; } } fprintf(stdout, "OK\n"); printf("Creating one large segment......................."); off[0] = apr_rmm_calloc(rmm, SHARED_SIZE); fprintf(stdout, "OK\n"); printf("Setting large segment............................"); for (i = 0; i < FRAG_COUNT * FRAG_SIZE; i++) { char **c = apr_rmm_addr_get(rmm, off[0]); c[i] = apr_itoa(pool, i); } fprintf(stdout, "OK\n"); printf("Freeing large segment............................"); apr_rmm_free(rmm, off[0]); fprintf(stdout, "OK\n"); printf("Creating each fragment of size %" APR_SIZE_T_FMT " (again)........", fragsize); for (i = 0; i < FRAG_COUNT; i++) { off[i] = apr_rmm_malloc(rmm, fragsize); } fprintf(stdout, "OK\n"); printf("Freeing each fragment backwards.................."); for (i = FRAG_COUNT - 1; i >= 0; i--) { rv = apr_rmm_free(rmm, off[i]); if (rv != APR_SUCCESS) { return rv; } } fprintf(stdout, "OK\n"); printf("Creating one large segment (again)..............."); off[0] = apr_rmm_calloc(rmm, SHARED_SIZE); fprintf(stdout, "OK\n"); printf("Freeing large segment............................"); apr_rmm_free(rmm, off[0]); fprintf(stdout, "OK\n"); printf("Checking realloc................................."); off[0] = apr_rmm_calloc(rmm, SHARED_SIZE - 100); off[1] = apr_rmm_calloc(rmm, 100); if (off[0] == 0 || off[1] == 0) { printf("FAILED\n"); return APR_EINVAL; } entity = apr_rmm_addr_get(rmm, off[1]); rv = apr_rmm_free(rmm, off[0]); if (rv != APR_SUCCESS) { printf("FAILED\n"); return rv; } { unsigned char *c = entity; /* Fill in the region; the first half with zereos, which will * likely catch the apr_rmm_realloc offset calculation bug by * making it think the old region was zero length. */ for (i = 0; i < 100; i++) { c[i] = (i < 50) ? 0 : i; } } /* now we can realloc off[1] and get many more bytes */ off[0] = apr_rmm_realloc(rmm, entity, SHARED_SIZE - 100); if (off[0] == 0) { printf("FAILED\n"); return APR_EINVAL; } { unsigned char *c = apr_rmm_addr_get(rmm, off[0]); /* fill in the region */ for (i = 0; i < 100; i++) { if (c[i] != (i < 50 ? 0 : i)) { printf("FAILED at offset %d: %hx\n", i, c[i]); return APR_EGENERAL; } } } fprintf(stdout, "OK\n"); printf("Destroying rmm segment..........................."); rv = apr_rmm_destroy(rmm); if (rv != APR_SUCCESS) { printf("FAILED\n"); return rv; } printf("OK\n"); printf("Destroying shared memory segment................."); rv = apr_shm_destroy(shm); if (rv != APR_SUCCESS) { printf("FAILED\n"); return rv; } printf("OK\n"); apr_pool_destroy(pool); return APR_SUCCESS; }