/[pcre]/code/trunk/sljit/sljitUtils.c
ViewVC logotype

Diff of /code/trunk/sljit/sljitUtils.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1181 by zherczeg, Fri Oct 26 04:47:29 2012 UTC revision 1182 by zherczeg, Sun Oct 28 05:22:32 2012 UTC
# Line 148  SLJIT_API_FUNC_ATTRIBUTE void SLJIT_CALL Line 148  SLJIT_API_FUNC_ATTRIBUTE void SLJIT_CALL
148  /*  Stack                                                                   */  /*  Stack                                                                   */
149  /* ------------------------------------------------------------------------ */  /* ------------------------------------------------------------------------ */
150    
151  #if (defined SLJIT_UTIL_STACK && SLJIT_UTIL_STACK)  #if (defined SLJIT_UTIL_STACK && SLJIT_UTIL_STACK) || (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR)
152    
153  #ifdef _WIN32  #ifdef _WIN32
154  #include "windows.h"  #include "windows.h"
155  #else  #else
156    /* Provides mmap function. */
157  #include <sys/mman.h>  #include <sys/mman.h>
158    /* For detecting the page size. */
159  #include <unistd.h>  #include <unistd.h>
160    
161    #ifndef MAP_ANON
162    
163    #include <fcntl.h>
164    
165    /* Some old systems does not have MAP_ANON. */
166    static int dev_zero = -1;
167    
168    #if (defined SLJIT_SINGLE_THREADED && SLJIT_SINGLE_THREADED)
169    
170    static SLJIT_INLINE int open_dev_zero(void)
171    {
172            dev_zero = open("/dev/zero", O_RDWR);
173            return dev_zero < 0;
174    }
175    
176    #else /* SLJIT_SINGLE_THREADED */
177    
178    #include <pthread.h>
179    
180    static pthread_mutex_t dev_zero_mutex = PTHREAD_MUTEX_INITIALIZER;
181    
182    static SLJIT_INLINE int open_dev_zero(void)
183    {
184            pthread_mutex_lock(&dev_zero_mutex);
185            dev_zero = open("/dev/zero", O_RDWR);
186            pthread_mutex_unlock(&dev_zero_mutex);
187            return dev_zero < 0;
188    }
189    
190    #endif /* SLJIT_SINGLE_THREADED */
191    
192  #endif  #endif
193    
194    #endif
195    
196    #endif /* SLJIT_UTIL_STACK || SLJIT_EXECUTABLE_ALLOCATOR */
197    
198    #if (defined SLJIT_UTIL_STACK && SLJIT_UTIL_STACK)
199    
200  /* Planning to make it even more clever in the future. */  /* Planning to make it even more clever in the future. */
201  static sljit_w sljit_page_align = 0;  static sljit_w sljit_page_align = 0;
202    
# Line 197  SLJIT_API_FUNC_ATTRIBUTE struct sljit_st Line 237  SLJIT_API_FUNC_ATTRIBUTE struct sljit_st
237                  return NULL;                  return NULL;
238    
239  #ifdef _WIN32  #ifdef _WIN32
240          base.ptr = VirtualAlloc(0, max_limit, MEM_RESERVE, PAGE_READWRITE);          base.ptr = VirtualAlloc(NULL, max_limit, MEM_RESERVE, PAGE_READWRITE);
241          if (!base.ptr) {          if (!base.ptr) {
242                  SLJIT_FREE(stack);                  SLJIT_FREE(stack);
243                  return NULL;                  return NULL;
# Line 210  SLJIT_API_FUNC_ATTRIBUTE struct sljit_st Line 250  SLJIT_API_FUNC_ATTRIBUTE struct sljit_st
250                  return NULL;                  return NULL;
251          }          }
252  #else  #else
253    #ifdef MAP_ANON
254          base.ptr = mmap(0, max_limit, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);          base.ptr = mmap(0, max_limit, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
255    #else
256            if (dev_zero < 0) {
257                    if (open_dev_zero()) {
258                            SLJIT_FREE(stack);
259                            return NULL;
260                    }
261            }
262            base.ptr = mmap(0, max_limit, PROT_READ | PROT_WRITE, MAP_PRIVATE, dev_zero, 0);
263    #endif
264          if (base.ptr == MAP_FAILED) {          if (base.ptr == MAP_FAILED) {
265                  SLJIT_FREE(stack);                  SLJIT_FREE(stack);
266                  return NULL;                  return NULL;

Legend:
Removed from v.1181  
changed lines
  Added in v.1182

  ViewVC Help
Powered by ViewVC 1.1.5