⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 eapi.patch

📁 apach加密模块
💻 PATCH
📖 第 1 页 / 共 4 页
字号:
+---------------------------------------------------------------------------| Patch the shared memory pool support into the Apache pool facility.+---------------------------------------------------------------------------Index: src/main/alloc.c--- src/main/alloc.c	2000/01/21 18:06:28	1.1.1.8+++ src/main/alloc.c	2000/01/21 19:51:10	1.15@@ -63,6 +63,10 @@  */  #include "httpd.h"+#ifdef EAPI+#include "http_config.h"+#include "http_conf_globals.h"+#endif #include "multithread.h" #include "http_log.h" @@ -137,6 +141,10 @@ #define BLOCK_MINALLOC	0 #endif +#if defined(EAPI) && defined(EAPI_MM)+static AP_MM *mm = NULL;+#endif+ /*****************************************************************  *  * Managing free storage blocks...@@ -165,6 +173,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;@@ -215,7 +226,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; @@ -229,12 +244,20 @@     ++num_malloc_calls;     num_malloc_bytes += size + sizeof(union block_hdr); #endif+#if defined(EAPI) && defined(EAPI_MM)+    if (is_shm)+        blok = (union block_hdr *)ap_mm_malloc(mm, size + sizeof(union block_hdr));+    else+#endif     blok = (union block_hdr *) malloc(size + sizeof(union block_hdr));     if (blok == NULL) { 	fprintf(stderr, "Ouch!  malloc failed in malloc_block()\n"); 	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;@@ -295,6 +318,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;@@ -341,7 +368,11 @@ #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 }  @@ -349,7 +380,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;@@ -359,7 +394,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,@@ -375,7 +415,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; } @@ -425,6 +469,9 @@ #ifdef POOL_DEBUG     struct pool *joined; #endif+#if defined(EAPI) && defined(EAPI_MM)+    int is_shm;+#endif };  static pool *permanent_pool;@@ -439,16 +486,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@@ -467,12 +526,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) {@@ -487,6 +572,13 @@ } #endif +#if defined(EAPI)+int ap_shared_pool_possible(void)+{+    return ap_mm_useable();+}+#endif+ #ifdef ALLOC_STATS static void dump_stats(void) {@@ -519,14 +611,74 @@     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 */+ API_EXPORT(void) ap_clear_pool(struct pool *a) {     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;@@ -560,6 +712,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)@@ -570,6 +726,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);     ap_unblock_alarms();@@ -584,6 +744,30 @@     return bytes_in_block_list(block_freelist); } +#if defined(EAPI)+API_EXPORT(int) ap_acquire_pool(pool *p, ap_pool_lock_mode mode)+{+#if defined(EAPI_MM)+    if (!p->is_shm)+        return 1;+    return ap_mm_lock(mm, mode == AP_POOL_RD ? AP_MM_LOCK_RD : AP_MM_LOCK_RW);+#else+	return 1;+#endif+}++API_EXPORT(int) ap_release_pool(pool *p)+{+#if defined(EAPI_MM)+    if (!p->is_shm)+        return 1;+    return ap_mm_unlock(mm);+#else+	return 1;+#endif+}+#endif /* EAPI */+ /*****************************************************************  * POOL_DEBUG support  */@@ -749,16 +933,31 @@      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); +#if defined(EAPI) && defined(EAPI_MM)+    blok = new_block(size, a->is_shm);+#else     blok = new_block(size);+#endif     a->last->h.next = blok;     a->last = blok; #ifdef POOL_DEBUG     blok->h.owning_pool = a; #endif+#if defined(EAPI) && defined(EAPI_MM)+    blok->h.is_shm = a->is_shm;+#endif      (void) ap_release_mutex(alloc_mutex);+#if defined(EAPI) && defined(EAPI_MM)+    if (a->is_shm)+	(void)ap_mm_unlock(mm);+#endif      ap_unblock_alarms(); @@ -870,6 +1069,11 @@     char *ptr;      size = (char *)ps->vbuff.curpos - ps->base;+#if defined(EAPI) && defined(EAPI_MM)+    if (ps->block->h.is_shm)+        ptr = ap_mm_realloc(ps->base, 2*size);+    else+#endif     ptr = realloc(ps->base, 2*size);     if (ptr == NULL) { 	fputs("Ouch!  Out of memory!\n", stderr);@@ -890,9 +1094,21 @@     cur_len = strp - blok->h.first_avail;      /* must try another blok */+#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);+#if defined(EAPI) && defined(EAPI_MM)+    nblok = new_block(2 * cur_len, blok->h.is_shm);+#else     nblok = new_block(2 * cur_len);+#endif     (void) ap_release_mutex(alloc_mutex);+#if defined(EAPI) && defined(EAPI_MM)+    if (blok->h.is_shm)+	(void)ap_mm_unlock(mm);+#endif     memcpy(nblok->h.first_avail, blok->h.first_avail, cur_len);     ps->vbuff.curpos = nblok->h.first_avail + cur_len;     /* save a byte for the NUL terminator */@@ -901,10 +1117,18 @@     /* did we allocate the current blok? if so free it up */     if (ps->got_a_new_block) { 	debug_fill(blok->h.first_avail, blok->h.endp - blok->h.first_avail);+#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); 	blok->h.next = block_freelist; 	block_freelist = blok; 	(void) ap_release_mutex(alloc_mutex);+#if defined(EAPI) && defined(EAPI_MM)+    if (blok->h.is_shm)+	(void)ap_mm_unlock(mm);+#endif     }     ps->blok = nblok;     ps->got_a_new_block = 1;@@ -923,6 +1147,11 @@     void *ptr;      ap_block_alarms();+#if defined(EAPI) && defined(EAPI_MM)+    if (p->is_shm)+        ps.base = ap_mm_malloc(mm, 512);+    else+#endif     ps.base = malloc(512);     if (ps.base == NULL) { 	fputs("Ouch!  Out of memory!\n", stderr);@@ -935,6 +1164,11 @@     *ps.vbuff.curpos++ = '\0';     ptr = ps.base;     /* shrink */+#if defined(EAPI) && defined(EAPI_MM)+    if (p->is_shm)+        ptr = ap_mm_realloc(ptr, (char *)ps.vbuff.curpos - (char *)ptr);+    else+#endif     ptr = realloc(ptr, (char *)ps.vbuff.curpos - (char *)ptr);     if (ptr == NULL) { 	fputs("Ouch!  Out of memory!\n", stderr);+---------------------------------------------------------------------------| Patch the low-level buffer routines to additionally allow| modules to intercept the I/O processing via hooks.+---------------------------------------------------------------------------Index: src/main/buff.c--- src/main/buff.c	2000/01/21 18:06:28	1.1.1.8+++ src/main/buff.c	2000/01/21 19:51:10	1.16@@ -125,7 +125,11 @@   select() sometimes returns 1 even though the write will block. We must work around this. */ +#ifdef EAPI+API_EXPORT(int) sendwithtimeout(int sock, const char *buf, int len, int flags)+#else /* EAPI */ int sendwithtimeout(int sock, const char *buf, int len, int flags)+#endif /* EAPI */ {     int iostate = 1;     fd_set fdset;@@ -193,8 +197,11 @@     return (rv); } -+#ifdef EAPI+API_EXPORT(int) recvwithtimeout(int sock, char *buf, int len, int flags)+#else /* EAPI */ int recvwithtimeout(int sock, char *buf, int len, int flags)+#endif /* EAPI */ {     int iostate = 1;     fd_set fdset;@@ -257,6 +264,9 @@     }     else #endif+#ifdef EAPI+	if (!ap_hook_call("ap::buff::read", &rv, fb, buf, nbyte))+#endif /* EAPI */ 	rv = read(fb->fd_in, buf, nbyte);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -