]> git.kaiwu.me - nginx.git/commitdiff
Core: improved NGX_ALIGNMENT detection on some x86_64 platforms.
authorAleksei Bavshin <a.bavshin@nginx.com>
Tue, 14 Jan 2025 18:32:24 +0000 (10:32 -0800)
committerAleksei Bavshin <a.bavshin@f5.com>
Fri, 18 Apr 2025 19:57:26 +0000 (12:57 -0700)
Previously, the default pool alignment used sizeof(unsigned long), with
the expectation that this would match to a platform word size.  Certain
64-bit platforms prove this assumption wrong by keeping the 32-bit long
type, which is fully compliant with the C standard.

This introduces a possibility of suboptimal misaligned access to the
data allocated with ngx_palloc() on the affected platforms, which is
addressed here by changing the default NGX_ALIGNMENT to a pointer size.

As we override the detection in auto/os/conf for all the machine types
except x86, and Unix-like 64-bit systems prefer the 64-bit long, the
impact of the change should be limited to Win64 x64.

src/core/ngx_config.h

index 1861be601397ef6296e0274c53e48b727c2fbc99..707ab216be1ce3878ff2c1b3403244e57e8785da 100644 (file)
@@ -94,7 +94,7 @@ typedef intptr_t        ngx_flag_t;
 
 
 #ifndef NGX_ALIGNMENT
-#define NGX_ALIGNMENT   sizeof(unsigned long)    /* platform word */
+#define NGX_ALIGNMENT   sizeof(uintptr_t)    /* platform word */
 #endif
 
 #define ngx_align(d, a)     (((d) + (a - 1)) & ~(a - 1))