diff options
author | Igor Sysoev <igor@sysoev.ru> | 2004-06-06 23:49:18 +0400 |
---|---|---|
committer | Igor Sysoev <igor@sysoev.ru> | 2004-06-06 23:49:18 +0400 |
commit | 0ab91b901299ac41e3867ebec7e04e5082a4c8b4 (patch) | |
tree | b89e863c141bc482c85c351f84d9dca1d3570789 /src/os | |
parent | 6e1bbd78967660b49e3a120bbeec6382ed193d5f (diff) |
nginx-0.0.3-2004-06-06-23:49:18 import
Diffstat (limited to 'src/os')
-rw-r--r-- | src/os/unix/ngx_alloc.c | 75 | ||||
-rw-r--r-- | src/os/unix/ngx_alloc.h | 36 | ||||
-rw-r--r-- | src/os/unix/ngx_freebsd_rfork_thread.c | 3 | ||||
-rw-r--r-- | src/os/unix/ngx_posix_init.c | 2 | ||||
-rw-r--r-- | src/os/unix/ngx_socket.c | 4 | ||||
-rw-r--r-- | src/os/unix/ngx_time.h | 2 | ||||
-rw-r--r-- | src/os/win32/ngx_alloc.c | 36 | ||||
-rw-r--r-- | src/os/win32/ngx_alloc.h | 18 | ||||
-rw-r--r-- | src/os/win32/ngx_win32_init.c | 4 |
9 files changed, 177 insertions, 3 deletions
diff --git a/src/os/unix/ngx_alloc.c b/src/os/unix/ngx_alloc.c new file mode 100644 index 000000000..69925d1be --- /dev/null +++ b/src/os/unix/ngx_alloc.c @@ -0,0 +1,75 @@ + +#include <ngx_config.h> +#include <ngx_core.h> + + +int ngx_pagesize; + + +void *ngx_alloc(size_t size, ngx_log_t *log) +{ + void *p; + + if (!(p = malloc(size))) { + ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, + "malloc() " SIZE_T_FMT " bytes failed", size); + } + + ngx_log_debug2(NGX_LOG_DEBUG_ALLOC, log, 0, + "malloc: " PTR_FMT ":" SIZE_T_FMT, p, size); + + return p; +} + + +void *ngx_calloc(size_t size, ngx_log_t *log) +{ + void *p; + + p = ngx_alloc(size, log); + + if (p) { + ngx_memzero(p, size); + } + + return p; +} + + +#if (HAVE_POSIX_MEMALIGN) + +void *ngx_memalign(size_t aligment, size_t size, ngx_log_t *log) +{ + void *p; + + if (posix_memalign(&p, aligment, size) == -1) { + ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, + "posix_memalign() " SIZE_T_FMT " bytes aligned to " + SIZE_T_FMT " failed", size, alignment); + } + + ngx_log_debug2(NGX_LOG_DEBUG_ALLOC, log, 0, + "posix_memalign: " PTR_FMT ":" SIZE_T_FMT, p, size); + + return p; +} + +#esif (HAVE_MEMALIGN) + +void *ngx_memalign(size_t aligment, size_t size, ngx_log_t *log) +{ + void *p; + + if (!(p = memalign(aligment, size))) { + ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, + "memalign() " SIZE_T_FMT " bytes aligned to " + SIZE_T_FMT " failed", size, alignment); + } + + ngx_log_debug2(NGX_LOG_DEBUG_ALLOC, log, 0, + "memalign: " PTR_FMT ":" SIZE_T_FMT, p, size); + + return p; +} + +#endif diff --git a/src/os/unix/ngx_alloc.h b/src/os/unix/ngx_alloc.h new file mode 100644 index 000000000..650f8bef3 --- /dev/null +++ b/src/os/unix/ngx_alloc.h @@ -0,0 +1,36 @@ +#ifndef _NGX_ALLOC_H_INCLUDED_ +#define _NGX_ALLOC_H_INCLUDED_ + + +#include <ngx_config.h> +#include <ngx_core.h> + + +void *ngx_alloc(size_t size, ngx_log_t *log); +void *ngx_calloc(size_t size, ngx_log_t *log); + +#define ngx_free free + + +/* + * Linux has memalign() or posix_memalign() + * Solaris has memalign() + * FreeBSD has not memalign() or posix_memalign() but its malloc() alignes + * allocations bigger than page size at page boundary. + */ + +#if (HAVE_POSIX_MEMALIGN || HAVE_MEMALIGN) + +void *ngx_memalign(size_t alignment, size_t size, ngx_log_t *log); + +#else + +#define ngx_memalign(alignment, size, log) ngx_alloc(size, log) + +#endif + + +extern int ngx_pagesize; + + +#endif /* _NGX_ALLOC_H_INCLUDED_ */ diff --git a/src/os/unix/ngx_freebsd_rfork_thread.c b/src/os/unix/ngx_freebsd_rfork_thread.c index 1cdfee4e9..740fb525d 100644 --- a/src/os/unix/ngx_freebsd_rfork_thread.c +++ b/src/os/unix/ngx_freebsd_rfork_thread.c @@ -30,7 +30,7 @@ char *ngx_freebsd_kern_usrstack; size_t ngx_thread_stack_size; -static size_t rz_size = /* STUB: PAGE_SIZE */ 4096; +static size_t rz_size; static size_t usable_stack_size; static char *last_stack; @@ -187,6 +187,7 @@ ngx_int_t ngx_init_threads(int n, size_t size, ngx_cycle_t *cycle) } /* the main thread stack red zone */ + rz_size = ngx_pagesize; red_zone = ngx_freebsd_kern_usrstack - (size + rz_size); ngx_log_debug2(NGX_LOG_DEBUG_CORE, cycle->log, 0, diff --git a/src/os/unix/ngx_posix_init.c b/src/os/unix/ngx_posix_init.c index 65c04a959..dc96ddd85 100644 --- a/src/os/unix/ngx_posix_init.c +++ b/src/os/unix/ngx_posix_init.c @@ -60,6 +60,8 @@ int ngx_posix_init(ngx_log_t *log) struct rlimit rlmt; struct sigaction sa; + ngx_pagesize = getpagesize(); + for (sig = signals; sig->signo != 0; sig++) { ngx_memzero(&sa, sizeof(struct sigaction)); sa.sa_handler = sig->handler; diff --git a/src/os/unix/ngx_socket.c b/src/os/unix/ngx_socket.c index 69d3f459b..443c93bbf 100644 --- a/src/os/unix/ngx_socket.c +++ b/src/os/unix/ngx_socket.c @@ -9,7 +9,9 @@ * a previous state using fcntl(F_GETFL). * * ioctl() and fcntl() are syscalls on at least FreeBSD 2.x, Linux 2.2 - * and Solaris 7 + * and Solaris 7. + * + * ioctl() in Linux 2.4 and 2.6 uses BKL, however fcntl(F_SETFL) uses it too. */ diff --git a/src/os/unix/ngx_time.h b/src/os/unix/ngx_time.h index 0b44c5ad4..dbb7a0a54 100644 --- a/src/os/unix/ngx_time.h +++ b/src/os/unix/ngx_time.h @@ -38,7 +38,7 @@ typedef struct tm ngx_tm_t; #if (SOLARIS) #define HAVE_TIMEZONE 1 -#define ngx_timezone() (-((daylight) ? altzone : timezone) / 60) +#define ngx_timezone() (- (daylight ? altzone : timezone) / 60) #elif defined __linux__ #define HAVE_TIMEZONE 1 diff --git a/src/os/win32/ngx_alloc.c b/src/os/win32/ngx_alloc.c new file mode 100644 index 000000000..591e61bcb --- /dev/null +++ b/src/os/win32/ngx_alloc.c @@ -0,0 +1,36 @@ + +#include <ngx_config.h> +#include <ngx_core.h> + + +int ngx_pagesize; + + +void *ngx_alloc(size_t size, ngx_log_t *log) +{ + void *p; + + if (!(p = malloc(size))) { + ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, + "malloc() " SIZE_T_FMT " bytes failed", size); + } + + ngx_log_debug2(NGX_LOG_DEBUG_ALLOC, log, 0, + "malloc: " PTR_FMT ":" SIZE_T_FMT, p, size); + + return p; +} + + +void *ngx_calloc(size_t size, ngx_log_t *log) +{ + void *p; + + p = ngx_alloc(size, log); + + if (p) { + ngx_memzero(p, size); + } + + return p; +} diff --git a/src/os/win32/ngx_alloc.h b/src/os/win32/ngx_alloc.h new file mode 100644 index 000000000..d6ea00a2b --- /dev/null +++ b/src/os/win32/ngx_alloc.h @@ -0,0 +1,18 @@ +#ifndef _NGX_ALLOC_H_INCLUDED_ +#define _NGX_ALLOC_H_INCLUDED_ + + +#include <ngx_config.h> +#include <ngx_core.h> + + +void *ngx_alloc(size_t size, ngx_log_t *log); +void *ngx_calloc(size_t size, ngx_log_t *log); + +#define ngx_free free +#define ngx_memalign(alignment, size, log) ngx_alloc(size, log) + +extern int ngx_pagesize; + + +#endif /* _NGX_ALLOC_H_INCLUDED_ */ diff --git a/src/os/win32/ngx_win32_init.c b/src/os/win32/ngx_win32_init.c index c4ffc1121..7a25b2845 100644 --- a/src/os/win32/ngx_win32_init.c +++ b/src/os/win32/ngx_win32_init.c @@ -40,6 +40,7 @@ int ngx_os_init(ngx_log_t *log) DWORD bytes; SOCKET s; WSADATA wsd; + SYSTEM_INFO si; OSVERSIONINFOEX osvi; ngx_osviex_stub_t *osviex_stub; @@ -121,6 +122,9 @@ int ngx_os_init(ngx_log_t *log) } } + GetSystemInfo(&si); + ngx_pagesize = si.dwPageSize; + /* init Winsock */ |