📄 eapi.patch
字号:
#include "ap.h" @@ -103,8 +115,13 @@ #define ap_http_method(r) ap_os_http_method((void*)r) #define ap_default_port(r) ap_os_default_port((void*)r) #else+#ifdef EAPI+#define ap_http_method(r) (((r)->ctx != NULL && ap_ctx_get((r)->ctx, "ap::http::method") != NULL) ? ((char *)ap_ctx_get((r)->ctx, "ap::http::method")) : "http")+#define ap_default_port(r) (((r)->ctx != NULL && ap_ctx_get((r)->ctx, "ap::default::port") != NULL) ? atoi((char *)ap_ctx_get((r)->ctx, "ap::default::port")) : DEFAULT_HTTP_PORT)+#else /* EAPI */ #define ap_http_method(r) "http" #define ap_default_port(r) DEFAULT_HTTP_PORT+#endif /* EAPI */ #endif /* --------- Default user name and group name running standalone ---------- */@@ -313,6 +330,19 @@ #define SCOREBOARD_MAINTENANCE_INTERVAL 1000000 #endif +/*+ * Unix only:+ * Path to Shared Memory Files + */+#ifdef EAPI+#ifndef EAPI_MM_CORE_PATH+#define EAPI_MM_CORE_PATH "logs/mm"+#endif+#ifndef EAPI_MM_CORE_MAXSIZE+#define EAPI_MM_CORE_MAXSIZE 1024*1024*1 /* max. 1MB */+#endif+#endif+ /* Number of requests to try to handle in a single process. If <= 0, * the children don't die off. That's the default here, since I'm still * interested in finding and stanching leaks.@@ -405,6 +435,9 @@ API_EXPORT(const char *) ap_get_server_version(void); API_EXPORT(void) ap_add_version_component(const char *component); API_EXPORT(const char *) ap_get_server_built(void);+#ifdef EAPI+API_EXPORT(void) ap_add_config_define(const char *define);+#endif /* EAPI */ /* Numeric release version identifier: MMNNFFRBB: major minor fix final beta * Always increases along the same track as the source branch.@@ -808,6 +841,10 @@ * record to improve 64bit alignment the next time we need to break * binary compatibility for some other reason. */++#ifdef EAPI+ ap_ctx *ctx;+#endif /* EAPI */ }; @@ -856,6 +893,9 @@ char *local_host; /* used for ap_get_server_name when * UseCanonicalName is set to DNS * (ignores setting of HostnameLookups) */+#ifdef EAPI+ ap_ctx *ctx;+#endif /* EAPI */ }; /* Per-vhost config... */@@ -928,6 +968,10 @@ int limit_req_line; /* limit on size of the HTTP request line */ int limit_req_fieldsize; /* limit on size of any request header field */ int limit_req_fields; /* limit on number of request header fields */++#ifdef EAPI+ ap_ctx *ctx;+#endif /* EAPI */ }; /* These are more like real hosts than virtual hosts */+---------------------------------------------------------------------------| Patch the shared memory pool support into the Apache pool facility.+---------------------------------------------------------------------------Index: src/main/alloc.c--- src/main/alloc.c 28 Jul 2006 13:55:33 -0000 1.1.1.18+++ src/main/alloc.c 28 Jul 2006 13:56:29 -0000 1.27@@ -22,6 +22,10 @@ */ #include "httpd.h"+#ifdef EAPI+#include "http_config.h"+#include "http_conf_globals.h"+#endif #include "multithread.h" #include "http_log.h" @@ -96,6 +100,10 @@ #define BLOCK_MINALLOC 0 #endif +#if defined(EAPI) && defined(EAPI_MM)+static AP_MM *mm = NULL;+#endif+ /***************************************************************** * * Managing free storage blocks...@@ -124,6 +132,9 @@ char *endp; union block_hdr *next; char *first_avail;+#if defined(EAPI) && defined(EAPI_MM)+ int is_shm;+#endif #ifdef POOL_DEBUG union block_hdr *global_next; struct pool *owning_pool;@@ -174,7 +185,11 @@ /* Get a completely new block from the system pool. Note that we rely on malloc() to provide aligned memory. */ +#if defined(EAPI) && defined(EAPI_MM)+static union block_hdr *malloc_block(int size, int is_shm)+#else static union block_hdr *malloc_block(int size)+#endif { union block_hdr *blok; int request_size;@@ -190,6 +205,11 @@ num_malloc_bytes += size + sizeof(union block_hdr); #endif request_size = size + sizeof(union block_hdr);+#if defined(EAPI) && defined(EAPI_MM)+ if (is_shm)+ blok = (union block_hdr *)ap_mm_malloc(mm, request_size);+ else+#endif blok = (union block_hdr *) malloc(request_size); if (blok == NULL) { fprintf(stderr, "Ouch! malloc(%d) failed in malloc_block()\n",@@ -197,6 +217,9 @@ exit(1); } debug_fill(blok, size + sizeof(union block_hdr));+#if defined(EAPI) && defined(EAPI_MM)+ blok->h.is_shm = is_shm;+#endif blok->h.next = NULL; blok->h.first_avail = (char *) (blok + 1); blok->h.endp = size + blok->h.first_avail;@@ -257,6 +280,10 @@ if (blok == NULL) return; /* Sanity check --- freeing empty pool? */ +#if defined(EAPI) && defined(EAPI_MM)+ if (blok->h.is_shm)+ (void)ap_mm_lock(mm, AP_MM_LOCK_RW);+#endif (void) ap_acquire_mutex(alloc_mutex); old_free_list = block_freelist; block_freelist = blok;@@ -303,6 +330,10 @@ #endif (void) ap_release_mutex(alloc_mutex);+#if defined(EAPI) && defined(EAPI_MM)+ if (blok->h.is_shm)+ (void)ap_mm_unlock(mm);+#endif #endif } @@ -311,7 +342,11 @@ * if necessary. Must be called with alarms blocked. */ +#if defined(EAPI) && defined(EAPI_MM)+static union block_hdr *new_block(int min_size, int is_shm)+#else static union block_hdr *new_block(int min_size)+#endif { union block_hdr **lastptr = &block_freelist; union block_hdr *blok = block_freelist;@@ -321,7 +356,12 @@ */ while (blok != NULL) {+#if defined(EAPI) && defined(EAPI_MM)+ if (blok->h.is_shm == is_shm &&+ min_size + BLOCK_MINFREE <= blok->h.endp - blok->h.first_avail) {+#else if (min_size + BLOCK_MINFREE <= blok->h.endp - blok->h.first_avail) {+#endif *lastptr = blok->h.next; blok->h.next = NULL; debug_verify_filled(blok->h.first_avail, blok->h.endp,@@ -337,7 +377,11 @@ /* Nope. */ min_size += BLOCK_MINFREE;+#if defined(EAPI) && defined(EAPI_MM)+ blok = malloc_block((min_size > BLOCK_MINALLOC) ? min_size : BLOCK_MINALLOC, is_shm);+#else blok = malloc_block((min_size > BLOCK_MINALLOC) ? min_size : BLOCK_MINALLOC);+#endif return blok; } @@ -387,6 +431,9 @@ #ifdef POOL_DEBUG struct pool *joined; #endif+#if defined(EAPI) && defined(EAPI_MM)+ int is_shm;+#endif }; static pool *permanent_pool;@@ -401,16 +448,28 @@ #define POOL_HDR_CLICKS (1 + ((sizeof(struct pool) - 1) / CLICK_SZ)) #define POOL_HDR_BYTES (POOL_HDR_CLICKS * CLICK_SZ) +#if defined(EAPI) && defined(EAPI_MM)+static struct pool *make_sub_pool_internal(struct pool *p, int is_shm)+#else API_EXPORT(struct pool *) ap_make_sub_pool(struct pool *p)+#endif { union block_hdr *blok; pool *new_pool; ap_block_alarms(); +#if defined(EAPI) && defined(EAPI_MM)+ if (is_shm)+ (void)ap_mm_lock(mm, AP_MM_LOCK_RW);+#endif (void) ap_acquire_mutex(alloc_mutex); +#if defined(EAPI) && defined(EAPI_MM)+ blok = new_block(POOL_HDR_BYTES, is_shm);+#else blok = new_block(POOL_HDR_BYTES);+#endif new_pool = (pool *) blok->h.first_avail; blok->h.first_avail += POOL_HDR_BYTES; #ifdef POOL_DEBUG@@ -429,12 +488,38 @@ p->sub_pools = new_pool; } +#if defined(EAPI) && defined(EAPI_MM)+ new_pool->is_shm = is_shm;+#endif+ (void) ap_release_mutex(alloc_mutex);+#if defined(EAPI) && defined(EAPI_MM)+ if (is_shm)+ (void)ap_mm_unlock(mm);+#endif ap_unblock_alarms(); return new_pool; } +#if defined(EAPI)+#if defined(EAPI_MM)+API_EXPORT(struct pool *) ap_make_sub_pool(struct pool *p)+{+ return make_sub_pool_internal(p, 0);+}+API_EXPORT(struct pool *) ap_make_shared_sub_pool(struct pool *p)+{+ return make_sub_pool_internal(p, 1);+}+#else+API_EXPORT(struct pool *) ap_make_shared_sub_pool(struct pool *p)+{+ return NULL;+}+#endif+#endif+ #ifdef POOL_DEBUG static void stack_var_init(char *s) {@@ -449,6 +534,13 @@ } #endif +#if defined(EAPI)+int ap_shared_pool_possible(void)+{+ return ap_mm_useable();+}+#endif+ #ifdef ALLOC_STATS static void dump_stats(void) {@@ -481,6 +573,58 @@ return permanent_pool; } +#if defined(EAPI)+void ap_init_alloc_shared(int early)+{+#if defined(EAPI_MM)+ int mm_size;+ char *mm_path;+ char *err1, *err2;++ if (early) {+ /* process very early on startup */+ mm_size = ap_mm_maxsize();+ if (mm_size > EAPI_MM_CORE_MAXSIZE)+ mm_size = EAPI_MM_CORE_MAXSIZE;+ mm_path = ap_server_root_relative(permanent_pool, + ap_psprintf(permanent_pool, "%s.%ld", + EAPI_MM_CORE_PATH, (long)getpid()));+ if ((mm = ap_mm_create(mm_size, mm_path)) == NULL) {+ fprintf(stderr, "Ouch! ap_mm_create(%d, \"%s\") failed\n", mm_size, mm_path);+ err1 = ap_mm_error();+ if (err1 == NULL)+ err1 = "-unknown-";+ err2 = strerror(errno);+ if (err2 == NULL)+ err2 = "-unknown-";+ fprintf(stderr, "Error: MM: %s: OS: %s\n", err1, err2);+ exit(1);+ }+ }+ else {+ /* process a lot later on startup */+#ifdef WIN32+ ap_mm_permission(mm, (_S_IREAD|_S_IWRITE), ap_user_id, -1);+#else+ ap_mm_permission(mm, (S_IRUSR|S_IWUSR), ap_user_id, -1);+#endif+ }+#endif /* EAPI_MM */+ return; +}++void ap_kill_alloc_shared(void)+{+#if defined(EAPI_MM)+ if (mm != NULL) {+ ap_mm_destroy(mm);+ mm = NULL;+ }+#endif /* EAPI_MM */+ return;+}+#endif /* EAPI */+ void ap_cleanup_alloc(void) { ap_destroy_mutex(alloc_mutex);@@ -491,10 +635,18 @@ { ap_block_alarms(); +#if defined(EAPI) && defined(EAPI_MM)+ if (a->is_shm)+ (void)ap_mm_lock(mm, AP_MM_LOCK_RW);+#endif (void) ap_acquire_mutex(alloc_mutex); while (a->sub_pools) ap_destroy_pool(a->sub_pools); (void) ap_release_mutex(alloc_mutex);+#if defined(EAPI) && defined(EAPI_MM)+ if (a->is_shm)+ (void)ap_mm_unlock(mm);+#endif /* Don't hold the mutex during cleanups. */ run_cleanups(a->cleanups); a->cleanups = NULL;@@ -528,6 +680,10 @@ ap_block_alarms(); ap_clear_pool(a); +#if defined(EAPI) && defined(EAPI_MM)+ if (a->is_shm)+ (void)ap_mm_lock(mm, AP_MM_LOCK_RW);+#endif (void) ap_acquire_mutex(alloc_mutex); if (a->parent) { if (a->parent->sub_pools == a)@@ -538,6 +694,10 @@ a->sub_next->sub_prev = a->sub_prev; } (void) ap_release_mutex(alloc_mutex);+#if defined(EAPI) && defined(EAPI_MM)+ if (a->is_shm)+ (void)ap_mm_unlock(mm);+#endif free_blocks(a->first);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -