]> git.kaiwu.me - nginx.git/commitdiff
malloc() debugging on MacOSX.
authorIgor Sysoev <igor@sysoev.ru>
Mon, 24 Oct 2011 15:46:48 +0000 (15:46 +0000)
committerIgor Sysoev <igor@sysoev.ru>
Mon, 24 Oct 2011 15:46:48 +0000 (15:46 +0000)
13 files changed:
src/core/nginx.c
src/core/ngx_slab.c
src/os/unix/ngx_darwin.h
src/os/unix/ngx_darwin_config.h
src/os/unix/ngx_darwin_init.c
src/os/unix/ngx_freebsd.h
src/os/unix/ngx_freebsd_config.h
src/os/unix/ngx_freebsd_init.c
src/os/unix/ngx_linux_config.h
src/os/unix/ngx_os.h
src/os/unix/ngx_posix_config.h
src/os/unix/ngx_solaris_config.h
src/os/win32/ngx_win32_config.h

index 3a413e84e31767ac2cf3c6032e99fe44ef5c84c0..da32c1a50881e596e23ac05560a7ec73488d61bf 100644 (file)
@@ -203,9 +203,7 @@ main(int argc, char *const *argv)
     ngx_cycle_t      *cycle, init_cycle;
     ngx_core_conf_t  *ccf;
 
-#if (NGX_FREEBSD)
     ngx_debug_init();
-#endif
 
     if (ngx_strerror_init() != NGX_OK) {
         return 1;
index 870c59bad3b209cf727a7f7d0515b4c624645ae3..9b5b28f2f291f9219920951c457fa2b86d15c131 100644 (file)
 
 #else
 
-#if (NGX_FREEBSD)
+#if (NGX_HAVE_DEBUG_MALLOC)
 
 #define ngx_slab_junk(p, size)                                                \
-    if (ngx_freebsd_debug_malloc)  ngx_memset(p, 0xD0, size)
+    if (ngx_debug_malloc)          ngx_memset(p, 0xD0, size)
 
 #else
 
index 7fa60ff0c9f2b82c8bbd7d49da370b3074ea8f2e..ebd8d355d1c5ad5c04c2e5fa9997d68fbdc7d068 100644 (file)
@@ -8,6 +8,7 @@
 #define _NGX_DARWIN_H_INCLUDED_
 
 
+void ngx_debug_init(void);
 ngx_chain_t *ngx_darwin_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in,
     off_t limit);
 
@@ -15,5 +16,7 @@ extern int       ngx_darwin_kern_osreldate;
 extern int       ngx_darwin_hw_ncpu;
 extern u_long    ngx_darwin_net_inet_tcp_sendspace;
 
+extern ngx_uint_t  ngx_debug_malloc;
+
 
 #endif /* _NGX_DARWIN_H_INCLUDED_ */
index a3a14c493a499e503c8bfbc57ff49e460db84af3..1717c690f707afd9d495952da0e005ede9ca0c82 100644 (file)
@@ -87,6 +87,7 @@
 
 
 #define NGX_HAVE_OS_SPECIFIC_INIT    1
+#define NGX_HAVE_DEBUG_MALLOC        1
 
 
 extern char **environ;
index 67133198ba744f2f402da803b9fbd4d8dc1c6b35..c3d1125fc6aa6b823606cb8c58e51afb4053f59e 100644 (file)
@@ -14,6 +14,8 @@ int     ngx_darwin_hw_ncpu;
 int     ngx_darwin_kern_ipc_somaxconn;
 u_long  ngx_darwin_net_inet_tcp_sendspace;
 
+ngx_uint_t  ngx_debug_malloc;
+
 
 static ngx_os_io_t ngx_darwin_io = {
     ngx_unix_recv,
@@ -55,6 +57,34 @@ sysctl_t sysctls[] = {
 };
 
 
+void
+ngx_debug_init()
+{
+#if (NGX_DEBUG_MALLOC)
+
+    /*
+     * MacOSX 10.6, 10.7:  MallocScribble fills freed memory with 0x55
+     *                     and fills allocated memory with 0xAA.
+     * MacOSX 10.4, 10.5:  MallocScribble fills freed memory with 0x55,
+     *                     MallocPreScribble fills allocated memory with 0xAA.
+     * MacOSX 10.3:        MallocScribble fills freed memory with 0x55,
+     *                     and no way to fill allocated memory.
+     */
+
+    setenv("MallocScribble", "1", 0);
+
+    ngx_debug_malloc = 1;
+
+#else
+
+    if (getenv("MallocScribble")) {
+        ngx_debug_malloc = 1;
+    }
+
+#endif
+}
+
+
 ngx_int_t
 ngx_os_specific_init(ngx_log_t *log)
 {
index 67fce3eb7ba1b76163b7db2b4328fd1e06ccf60b..a96f4eb1a9cfdc2c1b5d546b9cd53277affe4106 100644 (file)
@@ -8,6 +8,7 @@
 #define _NGX_FREEBSD_H_INCLUDED_
 
 
+void ngx_debug_init(void);
 ngx_chain_t *ngx_freebsd_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in,
     off_t limit);
 
@@ -17,7 +18,7 @@ extern u_long      ngx_freebsd_net_inet_tcp_sendspace;
 
 extern ngx_uint_t  ngx_freebsd_sendfile_nbytes_bug;
 extern ngx_uint_t  ngx_freebsd_use_tcp_nopush;
-extern ngx_uint_t  ngx_freebsd_debug_malloc;
+extern ngx_uint_t  ngx_debug_malloc;
 
 
 #endif /* _NGX_FREEBSD_H_INCLUDED_ */
index 3169c277a81be7e42f2052efee2c8acd88daa251..798f2eacd56be29a48762bd244f0aa3dc8e32508 100644 (file)
@@ -109,6 +109,7 @@ pid_t rfork_thread(int flags, void *stack, int (*func)(void *arg), void *arg);
 
 
 #define NGX_HAVE_OS_SPECIFIC_INIT    1
+#define NGX_HAVE_DEBUG_MALLOC        1
 
 
 extern char **environ;
index 1211c7ccb742781923de4109f7f6a20c7c9e25ac..bfb89087a48b5cd924debc9d8c375811ff1cd1a2 100644 (file)
@@ -22,7 +22,8 @@ int     ngx_freebsd_machdep_hlt_logical_cpus;
 
 ngx_uint_t  ngx_freebsd_sendfile_nbytes_bug;
 ngx_uint_t  ngx_freebsd_use_tcp_nopush;
-ngx_uint_t  ngx_freebsd_debug_malloc;
+
+ngx_uint_t  ngx_debug_malloc;
 
 
 static ngx_os_io_t ngx_freebsd_io = {
@@ -80,7 +81,7 @@ ngx_debug_init()
     malloc_options = "J";
 #endif
 
-    ngx_freebsd_debug_malloc = 1;
+    ngx_debug_malloc = 1;
 
 #else
     char  *mo;
@@ -88,7 +89,7 @@ ngx_debug_init()
     mo = getenv("MALLOC_OPTIONS");
 
     if (mo && ngx_strchr(mo, 'J')) {
-        ngx_freebsd_debug_malloc = 1;
+        ngx_debug_malloc = 1;
     }
 #endif
 }
index a2ef512374fe95bee3704b9d403e883b66386787..d72cf26b65f58fb6d0295f9bf32bdff35350e437 100644 (file)
@@ -108,6 +108,7 @@ typedef struct iocb  ngx_aiocb_t;
 
 
 #define NGX_HAVE_OS_SPECIFIC_INIT    1
+#define ngx_debug_init()
 
 
 extern char **environ;
index f1d8e68248c23477b31c9c55f9460a461bbef036..8f9622ed31f4c9f541c87d02f19cd0497df6d56d 100644 (file)
@@ -31,7 +31,6 @@ typedef struct {
 } ngx_os_io_t;
 
 
-void ngx_debug_init(void);
 ngx_int_t ngx_os_init(ngx_log_t *log);
 void ngx_os_status(ngx_log_t *log);
 ngx_int_t ngx_os_specific_init(ngx_log_t *log);
index aec8a0a35500283a437386f3be39de39481714af..e327d5460fdae7c775c00cc3547ba6b550cd0fb4 100644 (file)
@@ -125,6 +125,8 @@ typedef struct aiocb  ngx_aiocb_t;
 
 #define NGX_LISTEN_BACKLOG  511
 
+#define ngx_debug_init()
+
 
 #if (__FreeBSD__) && (__FreeBSD_version < 400017)
 
index 6b3d42eaae2f0c19aa873ee47daec9d994a9d681..fe66026e558910c2cc4df5238a782556a792a9b8 100644 (file)
@@ -98,6 +98,7 @@
 
 
 #define NGX_HAVE_OS_SPECIFIC_INIT    1
+#define ngx_debug_init()
 
 
 extern char **environ;
index 8ffe95c3128f5c3f84e209bb132ffb0d5e81918e..6d8864139198c7be6fbc61217ea581b47233a31e 100644 (file)
@@ -182,6 +182,7 @@ typedef int                 sig_atomic_t;
 
 
 #define ngx_random               rand
+#define ngx_debug_init()
 
 
 #endif /* _NGX_WIN32_CONFIG_H_INCLUDED_ */