comparison src/malloc.c @ 209:41ff10fd062f r20-4b3

Import from CVS: tag r20-4b3
author cvs
date Mon, 13 Aug 2007 10:04:58 +0200
parents 15872534500d
children 57709be46d1b
comparison
equal deleted inserted replaced
208:f427b8ec4379 209:41ff10fd062f
149 #else 149 #else
150 150
151 /* Determine which kind of system this is. */ 151 /* Determine which kind of system this is. */
152 #include <signal.h> 152 #include <signal.h>
153 #ifndef SIGTSTP 153 #ifndef SIGTSTP
154 #ifndef VMS
155 #ifndef USG 154 #ifndef USG
156 #define USG 155 #define USG
157 #endif 156 #endif
158 #endif /* not VMS */
159 #else /* SIGTSTP */ 157 #else /* SIGTSTP */
160 #ifdef SIGIO 158 #ifdef SIGIO
161 #define BSD4_2 159 #define BSD4_2
162 #endif /* SIGIO */ 160 #endif /* SIGIO */
163 #endif /* SIGTSTP */ 161 #endif /* SIGTSTP */
363 if (!gotpool) 361 if (!gotpool)
364 { getpool (); getpool (); gotpool = 1; } 362 { getpool (); getpool (); gotpool = 1; }
365 363
366 /* Find current end of memory and issue warning if getting near max */ 364 /* Find current end of memory and issue warning if getting near max */
367 365
368 #ifndef VMS
369 /* Maximum virtual memory on VMS is difficult to calculate since it
370 * depends on several dynamically changing things. Also, alignment
371 * isn't that important. That is why much of the code here is ifdef'ed
372 * out for VMS systems.
373 */
374 cp = sbrk (0); 366 cp = sbrk (0);
375 siz = cp - data_space_start; 367 siz = cp - data_space_start;
376 368
377 if (warnfunction) 369 if (warnfunction)
378 switch (warnlevel) 370 switch (warnlevel)
400 break; 392 break;
401 } 393 }
402 394
403 if ((int) cp & 0x3ff) /* land on 1K boundaries */ 395 if ((int) cp & 0x3ff) /* land on 1K boundaries */
404 sbrk (1024 - ((int) cp & 0x3ff)); 396 sbrk (1024 - ((int) cp & 0x3ff));
405 #endif /* not VMS */
406 397
407 /* Take at least 2k, and figure out how many blocks of the desired size 398 /* Take at least 2k, and figure out how many blocks of the desired size
408 we're about to get */ 399 we're about to get */
409 nblks = 1; 400 nblks = 1;
410 if ((siz = nu) < 8) 401 if ((siz = nu) < 8)
420 return; /* no more room! */ 411 return; /* no more room! */
421 } 412 }
422 malloc_sbrk_used = siz; 413 malloc_sbrk_used = siz;
423 malloc_sbrk_unused = lim_data - siz; 414 malloc_sbrk_unused = lim_data - siz;
424 415
425 #ifndef VMS
426 if ((int) cp & 7) 416 if ((int) cp & 7)
427 { /* shouldn't happen, but just in case */ 417 { /* shouldn't happen, but just in case */
428 cp = (char *) (((int) cp + 8) & ~7); 418 cp = (char *) (((int) cp + 8) & ~7);
429 nblks--; 419 nblks--;
430 } 420 }
431 #endif /* not VMS */
432 421
433 /* save new header and link the nblks blocks together */ 422 /* save new header and link the nblks blocks together */
434 nextf[nu] = (struct mhead *) cp; 423 nextf[nu] = (struct mhead *) cp;
435 siz = 1 << (nu + 3); 424 siz = 1 << (nu + 3);
436 while (1) 425 while (1)
675 free (mem); 664 free (mem);
676 return new; 665 return new;
677 } 666 }
678 } 667 }
679 668
680 #ifndef VMS
681 669
682 char * 670 char *
683 memalign (alignment, size) 671 memalign (alignment, size)
684 unsigned alignment, size; 672 unsigned alignment, size;
685 { 673 {
711 unsigned size; 699 unsigned size;
712 { 700 {
713 return memalign (getpagesize (), size); 701 return memalign (getpagesize (), size);
714 } 702 }
715 #endif /* not __hpux */ 703 #endif /* not __hpux */
716 #endif /* not VMS */
717 704
718 #ifdef MSTATS 705 #ifdef MSTATS
719 /* Return statistics describing allocation of blocks of size 2**n. */ 706 /* Return statistics describing allocation of blocks of size 2**n. */
720 707
721 struct mstats_value 708 struct mstats_value
836 } 823 }
837 824
838 #endif /* BSD4_2 */ 825 #endif /* BSD4_2 */
839 #endif /* not USG */ 826 #endif /* not USG */
840 827
841 #ifdef VMS
842 /* There is a problem when dumping and restoring things on VMS. Calls
843 * to SBRK don't necessarily result in contiguous allocation. Dumping
844 * doesn't work when it isn't. Therefore, we make the initial
845 * allocation contiguous by allocating a big chunk, and do SBRKs from
846 * there. Once Emacs has dumped there is no reason to continue
847 * contiguous allocation, malloc doesn't depend on it.
848 *
849 * There is a further problem of using brk and sbrk while using VMS C
850 * run time library routines malloc, calloc, etc. The documentation
851 * says that this is a no-no, although I'm not sure why this would be
852 * a problem. In any case, we remove the necessity to call brk and
853 * sbrk, by calling calloc (to assure zero filled data) rather than
854 * sbrk.
855 *
856 * VMS_ALLOCATION_SIZE is the size of the allocation array. This
857 * should be larger than the malloc size before dumping. Making this
858 * too large will result in the startup procedure slowing down since
859 * it will require more space and time to map it in.
860 *
861 * The value for VMS_ALLOCATION_SIZE in the following define was determined
862 * by running emacs linked (and a large allocation) with the debugger and
863 * looking to see how much storage was used. The allocation was 201 pages,
864 * so I rounded it up to a power of two.
865 */
866 #ifndef VMS_ALLOCATION_SIZE
867 #define VMS_ALLOCATION_SIZE (512*256)
868 #endif
869
870 /* Use VMS RTL definitions */
871 #undef sbrk
872 #undef brk
873 #undef malloc
874 int vms_out_initial = 0;
875 char vms_initial_buffer[VMS_ALLOCATION_SIZE];
876 static char *vms_current_brk = &vms_initial_buffer;
877 static char *vms_end_brk = &vms_initial_buffer[VMS_ALLOCATION_SIZE-1];
878
879 #include <stdio.h>
880
881 char *
882 sys_sbrk (incr)
883 int incr;
884 {
885 char *sbrk(), *temp, *ptr;
886
887 if (vms_out_initial)
888 {
889 /* out of initial allocation... */
890 if (!(temp = malloc (incr)))
891 temp = (char *) -1;
892 }
893 else
894 {
895 /* otherwise, go out of our area */
896 ptr = vms_current_brk + incr; /* new current_brk */
897 if (ptr <= vms_end_brk)
898 {
899 temp = vms_current_brk;
900 vms_current_brk = ptr;
901 }
902 else
903 {
904 vms_out_initial = 1; /* mark as out of initial allocation */
905 if (!(temp = malloc (incr)))
906 temp = (char *) -1;
907 }
908 }
909 return temp;
910 }
911 #endif /* VMS */