Commit 66dc60ae641951272df99f1b74e839e4c0f853ea

Authored by Alain Prouté
1 parent 05814796

*** empty log message ***

anubis_dev/vm/proj/linux/Makefile
... ... @@ -18,6 +18,9 @@ TRDDIR = $(HOME)/third_dev
18 18 OPTIMIZE = -g
19 19 INCLUDE = -I$(DEVDIR)/include -I$(SRCDIR)
20 20  
  21 +#DEFINES = -D_LINUX_ -D_WITH_GRAPHISM_ -Ddebug_vm
  22 +DEFINES = -D_LINUX_ -D_WITH_GRAPHISM_
  23 +
21 24 #
22 25 # Object files by categories.
23 26 #
... ... @@ -69,39 +72,39 @@ dependancies_perso: $(main_objs:.o=.d) $(special_objs:.o=.perso.d) $(cipher_objs
69 72 # Making object files.
70 73 #
71 74 %.perso.o: $(SRCDIR)/%.c
72   - gcc $(OPTIMIZE) $(INCLUDE) -o $@ -c -Wall -Wstrict-prototypes -D_LINUX_ -D_WITH_GRAPHISM_\
  75 + gcc $(OPTIMIZE) $(INCLUDE) -o $@ -c -Wall -Wstrict-prototypes $(DEFINES)\
73 76 -D_CRYPTADM_ $<
74 77  
75 78 %.perso.o: $(SRCDIR)/%.cpp
76   - gcc $(OPTIMIZE) $(INCLUDE) -o $@ -c -Wall -Wstrict-prototypes -D_LINUX_ -D_WITH_GRAPHISM_\
  79 + gcc $(OPTIMIZE) $(INCLUDE) -o $@ -c -Wall -Wstrict-prototypes $(DEFINES)\
77 80 -D_CRYPTADM_ $<
78 81  
79 82 %.o: $(TRDDIR)/sqlite3/%.c
80 83 gcc $(OPTIMIZE) $(INCLUDE) -o $@ -c -DNO_TCL $<
81 84  
82 85 %.o: $(SRCDIR)/%.c
83   - gcc $(OPTIMIZE) $(INCLUDE) -o $@ -c -Wall -Wstrict-prototypes -D_LINUX_ -D_WITH_GRAPHISM_ $<
  86 + gcc $(OPTIMIZE) $(INCLUDE) -o $@ -c -Wall -Wstrict-prototypes $(DEFINES) $<
84 87  
85 88 %.o: $(SRCDIR)/%.cpp
86   - gcc $(OPTIMIZE) $(INCLUDE) -o $@ -c -Wall -Wstrict-prototypes -D_LINUX_ -D_WITH_GRAPHISM_ $<
  89 + gcc $(OPTIMIZE) $(INCLUDE) -o $@ -c -Wall -Wstrict-prototypes $(DEFINES) $<
87 90  
88 91 %.o: $(SRCDIR)/linux/%.c
89   - gcc $(OPTIMIZE) $(INCLUDE) -o $@ -c -Wall -Wstrict-prototypes -D_LINUX_ -D_WITH_GRAPHISM_ $<
  92 + gcc $(OPTIMIZE) $(INCLUDE) -o $@ -c -Wall -Wstrict-prototypes $(DEFINES) $<
90 93  
91 94 %.o: $(SRCDIR)/linux/%.cpp
92   - gcc $(OPTIMIZE) $(INCLUDE) -o $@ -c -Wall -Wstrict-prototypes -D_LINUX_ -D_WITH_GRAPHISM_ $<
  95 + gcc $(OPTIMIZE) $(INCLUDE) -o $@ -c -Wall -Wstrict-prototypes $(DEFINES) $<
93 96  
94 97 %.o: $(DEVDIR)/cipher/%.c
95   - gcc $(OPTIMIZE) $(INCLUDE) -o $@ -c -Wall -Wstrict-prototypes -D_LINUX_ -D_WITH_GRAPHISM_ $<
  98 + gcc $(OPTIMIZE) $(INCLUDE) -o $@ -c -Wall -Wstrict-prototypes $(DEFINES) $<
96 99  
97 100 %.o: $(DEVDIR)/cipher/%.cpp
98   - gcc $(OPTIMIZE) $(INCLUDE) -o $@ -c -Wall -Wstrict-prototypes -D_LINUX_ -D_WITH_GRAPHISM_ $<
  101 + gcc $(OPTIMIZE) $(INCLUDE) -o $@ -c -Wall -Wstrict-prototypes $(DEFINES) $<
99 102  
100 103 %.o: $(DEVDIR)/share/%.c
101   - gcc $(OPTIMIZE) $(INCLUDE) -o $@ -c -Wall -Wstrict-prototypes -D_LINUX_ -D_WITH_GRAPHISM_ $<
  104 + gcc $(OPTIMIZE) $(INCLUDE) -o $@ -c -Wall -Wstrict-prototypes $(DEFINES) $<
102 105  
103 106 %.o: $(DEVDIR)/share/%.cpp
104   - gcc $(OPTIMIZE) $(INCLUDE) -o $@ -c -Wall -Wstrict-prototypes -D_LINUX_ -D_WITH_GRAPHISM_ $<
  107 + gcc $(OPTIMIZE) $(INCLUDE) -o $@ -c -Wall -Wstrict-prototypes $(DEFINES) $<
105 108  
106 109 #
107 110 # Using BISON and FLEX
... ... @@ -132,7 +135,7 @@ anbexec: $(main_objs) $(special_objs) $(cipher_objs) $(graph_objs) $(sqlite3_obj
132 135 gcc -o anbexec $(main_objs) $(special_objs) $(cipher_objs) $(graph_objs)\
133 136 $(sqlite3_objs) -L/usr/X11R6/lib\
134 137 -ljpeg -lssl -lcrypto -lm -lX11 -ldl -lstdc++ -lpthread -lc
135   -# strip anbexec
  138 + strip anbexec
136 139 cp anbexec $(HOME)/anubis_distrib/linux_install/bin
137 140 # cp anbexec $(HOME)/bin/anbexec
138 141  
... ...
anubis_dev/vm/src/AnubisAllocator.cpp
1   -#include "AnubisAllocator.h"
  1 +
2 2 #include "stdlib.h"
3 3 #include "assert.h"
  4 +
  5 +
  6 +#include "AnubisAllocator.h"
  7 +#include "vm.h"
4 8 #include "DebugLog.h"
5 9 #include "dependencies.h"
6 10 #include "AnubisSupport.h"
7   -#include "vm.h"
8 11  
9 12  
10 13  
... ... @@ -101,8 +104,8 @@ AnubisAllocator::AnubisAllocator()
101 104  
102 105 #ifdef debug_vm
103 106 /* cannot test heap_test here (too early) */
104   - ComputeMemoryCheckSums(result);
105   - TestMemoryCheckSums(result);
  107 + //ComputeMemoryCheckSums();
  108 + //TestMemoryCheckSums();
106 109 #endif
107 110  
108 111 //printf("Basic allocator initialized.\n");
... ... @@ -178,6 +181,7 @@ void AnubisAllocator::printf_check_segregated_list(int k)
178 181 while (chain != NULL)
179 182 {
180 183 result++;
  184 + assert(*(chain-1) == (U32)(k+1));
181 185 chain = (U32 *)(chain[0]);
182 186 }
183 187  
... ... @@ -188,7 +192,7 @@ void AnubisAllocator::printf_check_segregated_list(int k)
188 192 int AnubisAllocator::EnlargeMemory(void)
189 193 {
190 194 U32 *new_segment;
191   - int result = 1;
  195 + int result = 1; // becomes 0 if something cannot be enlarged
192 196  
193 197 #ifdef SEGREGATED_LISTS
194 198 int k,j;
... ... @@ -197,31 +201,75 @@ int AnubisAllocator::EnlargeMemory(void)
197 201 {
198 202 if (m_segregated_enlargement[k])
199 203 {
  204 + // total size (in words) of each segregated segment:
  205 + //
  206 + // |<-- useful size when allocated -->| k+1 words available when allocated
  207 + // +------+------+------+------+------+------+
  208 + // | size | next | word | word | ... | | there are k words after 'next'
  209 + // +------+---|--+------+------+------+------+
  210 + // V
  211 + //
  212 + U32 tot_segr_size = k+2;
  213 +
200 214 //printf("Enlarging memory for segregated list for size %d\n",k+1);
201 215  
202   - if ((new_segment = (U32 *)malloc((1+((2+k)*segregated_segments_per_main))<<2)) == NULL)
203   - // 2+k = 1+(k+1), because we need 1 size word and k+1 available words per segment
  216 + // Organization of main segment:
  217 + //
  218 + // | <-- segregated segments ------>| there are 'segregated_segments_per_main'
  219 + // +---+----------+----------+----------+ segments
  220 + // | * | segr seg | segr seg | ... |
  221 + // +-|-+----------+----------+----------+
  222 + // V
  223 + // next
  224 + //
  225 + if ((new_segment =
  226 + (U32 *)malloc((1+(tot_segr_size*segregated_segments_per_main))*sizeof(U32)))
  227 + == NULL)
204 228 {
205 229 result = 0; // go on waiting for memory for this size ...
206 230 }
207 231 else
208 232 {
209   - // chain the new main segment
210   - new_segment[0] = (U32)(m_main_segregated_segment[k]);
211   - m_main_segregated_segment[k] = new_segment;
212   -
213   - // prepare and chain the segregated segments (for available word size k+1)
  233 + // Chain the new main segment.
  234 + // The new main segment is appended in front of other main segments.
  235 + //
  236 + new_segment[0] = (U32)(m_main_segregated_segment[k]); // chain with others
  237 + m_main_segregated_segment[k] = new_segment; // new chain
  238 +
  239 + // prepare and chain the segregated segments
  240 + //
  241 + // main segment new chain of segregated segments
  242 + // | |
  243 + // V V
  244 + // +---+---+---+..+---+---+..+---+---+...
  245 + // | * |k+1| * | |k+1| * | |k+1| * |
  246 + // +-|-+---+-|-+..+---+-|-+..+---+-|-+...
  247 + // V | ^ | ^ |
  248 + // next `--------' `--------' `---...
  249 + //
  250 + // do for all except the last segregated segment
214 251 for (j = 0; j < segregated_segments_per_main-1; j++)
215 252 {
216   - U32 segreg_seg_start = 1+(j*(2+k));
  253 + U32 segreg_seg_start = 1+(j*tot_segr_size);
217 254 new_segment[segreg_seg_start] = k+1; // size word
218   - new_segment[segreg_seg_start+1] = (U32)(new_segment+segreg_seg_start+3+k); // chaining
219   - // because 3+k = 1 + (2+k)
  255 + new_segment[segreg_seg_start+1] =
  256 + (U32)(new_segment+segreg_seg_start+tot_segr_size+1); // chaining
220 257 }
221 258  
222   - // chain with previous segregated segments (do for last segment)
223   - new_segment[1+((segregated_segments_per_main-1)*(2+k))] = k+1;
224   - new_segment[1+((segregated_segments_per_main-1)*(2+k))+1] =
  259 + // do for the last segregated segment
  260 + //
  261 + // last segregated segment
  262 + // | end of main segment
  263 + // | |
  264 + // V V
  265 + // ..+---+---+------------+
  266 + // |k+1| * | k words |
  267 + // ..+---+-|-+------------+
  268 + // |
  269 + // `----> to previous chain of segregated segments
  270 + //
  271 + new_segment[1+((segregated_segments_per_main-1)*tot_segr_size)] = k+1;
  272 + new_segment[1+((segregated_segments_per_main-1)*tot_segr_size)+1] =
225 273 (U32)(m_segregated_free_list[k]);
226 274  
227 275 // install the new chain of segregated segments
... ... @@ -300,16 +348,19 @@ U32 AnubisAllocator::AllocateDataSegment(int words)
300 348 //
301 349 // gettimeofday(&startTime, &dummy);
302 350  
303   - if (words < 1) words = 1;
304   - words += security_zone_size;
  351 + if (words < 1) words = 1; // required at least one word (for compatibility with the allocator)
  352 + words += security_zone_size; // normally we add 0 (non zero values are for debugging purpose)
305 353  
306 354 #ifdef SEGREGATED_LISTS
307 355 /* 'words' is the required size in 32 bits words. */
308 356 if (words <= number_of_segregated_lists)
309   - // <= is good because segregated sizes are: 1 2 3 ... number_of_segregated_lists (included)
310   - return allocate_segregated_segment(words);
  357 + // '<=' is good because segregated sizes are: 1 2 3 ... number_of_segregated_lists (included)
  358 + {
  359 + return allocate_segregated_segment(words);
  360 + }
311 361 #endif
312 362  
  363 + //printf("\nAllocating a basic segment for size %d.\n",(int)words);
313 364  
314 365 if (m_memory_seg_size < (U32)(words+64))
315 366 {
... ... @@ -401,7 +452,7 @@ U32 AnubisAllocator::AllocateDataSegment(int words)
401 452  
402 453 #ifdef debug_vm
403 454 if (heap_test)
404   - ComputeMemoryCheckSums(allocator);
  455 + ComputeMemoryCheckSums();
405 456 #endif
406 457  
407 458 m_memory_in_use += ptr[0];
... ... @@ -629,22 +680,46 @@ U32 AnubisAllocator::ReallocateDataSegment(U32 data_seg, int words, char *filena
629 680 U32 AnubisAllocator::ReallocateDataSegment(U32 data_seg, int words)
630 681 #endif
631 682 {
632   - /* compare size of segment with requested size */
633 683 U32 *seg;
634 684  
635   - /* the segment should not be shared */
636   - // assert(*((U32 *)data_seg) == 1);
637   -
638   - //assert(0);
639   -
  685 + // only unshared segments may be reallocated
  686 + assert(((U32 *)data_seg)[0] == 1);
  687 +
640 688 seg = (U32 *)data_seg;
641 689 seg--; /* recover size word */
642 690  
643 691 #ifdef SEGREGATED_LISTS
  692 + // if the previous size is small we must reallocate a segregated segment
644 693 if (seg[0] <= number_of_segregated_lists)
645 694 return reallocate_segregated_segment(data_seg,words);
  695 +
  696 + // if the new size is small, but not the previous size the basic segment must be copied
  697 + // into a segregated segment.
  698 + if (words <= number_of_segregated_lists)
  699 + {
  700 + U32 *new_seg = (U32 *)allocate_segregated_segment(words);
  701 + if (new_seg == 0)
  702 + {
  703 + return 0; // retry later
  704 + }
  705 + else
  706 + {
  707 + int k;
  708 + // copy data except the reference counter
  709 + // new reference counter already at 1
  710 + for (k = 1; k < words; k++)
  711 + {
  712 + new_seg[k] = ((U32 *)data_seg)[k];
  713 + }
  714 + // free the previous (basic) segment
  715 + FreeDataSegment((U32 *)data_seg);
  716 +
  717 + // return new (segregated) segment
  718 + return (U32)new_seg;
  719 + }
  720 + }
646 721 #endif
647   -
  722 +
648 723 words++; /* need one more word for size */
649 724  
650 725 begin:
... ... @@ -844,15 +919,57 @@ U32 AnubisAllocator::allocate_segregated_segment(int words)
844 919 { /* return the head of list, and keep the tail as our new list of free segments. */
845 920 m_segregated_free_list[i] = (U32 *)(chain[0]);
846 921 chain[0] = 1; /* reference counter */
847   -
848   - //assert(*(chain-1) == (U32)words);
  922 +
  923 +#ifdef debug_vm
  924 + // check if the allocated segment has the right size word
  925 + if (*(chain-1) != (U32)words)
  926 + {
  927 + int k;
  928 + printf("allocate_segregated_segment: bad size word: %d instead of %d\n***",
  929 + (int)(*(chain-1)),(int)words);
  930 + for (k = -20; k <= 0; k++)
  931 + {
  932 + printf("%c",(((char *)chain)+k)[0]);
  933 + }
  934 + printf("\n");
  935 + exit(1);
  936 + }
849 937 //printf("Returned segment at %d\n",(int)chain);
  938 +#endif
850 939  
851 940 return (U32)chain;
852 941 }
853 942 }
854 943  
855 944  
  945 +#ifdef debug_vm
  946 +// check if a liberated segregated segment is back home
  947 +void AnubisAllocator::check_segment_home(U32 *ss)
  948 +{
  949 + U32 size = *(ss-1);
  950 + int i = size-1;
  951 + U32 tot_segr_size = size+1;
  952 + U32 main_seg_byte_size = (1+(tot_segr_size*segregated_segments_per_main))<<2;
  953 + U32 *main_seg = m_main_segregated_segment[i];
  954 +
  955 + while (main_seg != NULL)
  956 + { // if the segregated segment is within this main segment
  957 + if (main_seg < ss && ss < main_seg+main_seg_byte_size)
  958 + {
  959 + return; // home found and alignement correct
  960 + }
  961 + main_seg = (U32 *)(main_seg[0]);
  962 + }
  963 +
  964 + // home not found
  965 + printf("Home not found for segregated segment of size %d at %d\n",
  966 + (int)size,(int)ss);
  967 + exit(1);
  968 + return;
  969 +}
  970 +#endif
  971 +
  972 +
856 973 U32 *AnubisAllocator::free_segregated_segment(U32 *ss)
857 974 // the size word (counting in U32s) is at ss[-1]
858 975 {
... ... @@ -862,9 +979,13 @@ U32 *AnubisAllocator::free_segregated_segment(U32 *ss)
862 979 //printf("Freeing segregated segment for size %d at %d\n",(int)size,(int)ss);
863 980 //printf_check_segregated_list(i);
864 981  
  982 +#ifdef debug_vm
  983 + check_segment_home(ss);
  984 +#endif
  985 +
865 986 ss[0] = (U32)(m_segregated_free_list[i]);
866 987 m_segregated_free_list[i] = ss;
867   -
  988 +
868 989 return NULL;
869 990 }
870 991  
... ... @@ -873,8 +994,9 @@ U32 AnubisAllocator::reallocate_segregated_segment(U32 data_segment, int words)
873 994 // 'data_segment' and 'words' are the same as for ReallocateDataSegment
874 995 // 'data_segment' is a segregated segment
875 996 {
876   - int previous_size = *(((U32 *)(data_segment))-1);
  997 + int previous_size = *(((U32 *)data_segment)-1);
877 998 U32 *new_seg;
  999 + U32 to_be_copied = previous_size < words ? previous_size : words;
878 1000  
879 1001 if (words <= number_of_segregated_lists)
880 1002 { /* reallocation into a segregated list */
... ... @@ -890,11 +1012,14 @@ U32 AnubisAllocator::reallocate_segregated_segment(U32 data_segment, int words)
890 1012 return 0; // reallocation delayed
891 1013 }
892 1014 else
893   - { /* copy the content */
  1015 + { // copy the content (after the reference counter)
  1016 + // the reference counter at new_seg[0] is already 1.
894 1017 int k;
895   - for (k = 1; k < previous_size; k++)
  1018 + for (k = 1; k < (int)to_be_copied; k++)
896 1019 new_seg[k] = ((U32 *)data_segment)[k];
897   - // the reference counter at new_seg[0] is already 1.
  1020 +#ifdef debug_vm
  1021 + printf("reallocate_segregated_segment: freeing previous segment.\n");
  1022 +#endif
898 1023 free_segregated_segment((U32 *)data_segment);
899 1024 return (U32)new_seg;
900 1025 }
... ... @@ -1079,12 +1204,12 @@ void AnubisAllocator::TestMemoryCheckSums(void)
1079 1204 while (ptr != NULL)
1080 1205 {
1081 1206 count++;
1082   - if (count > 10+(m_allocated_segments))
  1207 + if (count > (int)(10+(m_allocated_segments)))
1083 1208 {
1084 1209 LOGINFO("\ntest_memory_check_sums: failed");
1085 1210 LOGINFO("\nincompatible number of allocated segments");
1086 1211 LOGINFO("\n(maybe a loop in free segments chain)");
1087   - LOGINFO("\nIP - code = %d\n",IPcode);
  1212 + //LOGINFO("\nIP - code = %d\n",IPCode);
1088 1213 fflush(stdout);
1089 1214 dummy = ((char *)0)[0];
1090 1215 }
... ... @@ -1103,7 +1228,7 @@ void AnubisAllocator::TestMemoryCheckSums(void)
1103 1228 LOGINFO("\nm_ffss_size_sum = %20u computed: %20u",m_ffss_size_sum,size_sum);
1104 1229 LOGINFO("\nm_ffss_ptr_sum = %20u computed: %20u",m_ffss_ptr_sum,ptr_sum);
1105 1230 ShowHeap();
1106   - LOGINFO("\nIP - code = %d\n",IPcode);
  1231 + //LOGINFO("\nIP - code = %d\n",IPCode);
1107 1232 fflush(stdout);
1108 1233 dummy = ((char *)0)[0];
1109 1234 }
... ...
anubis_dev/vm/src/AnubisAllocator.h
... ... @@ -3,6 +3,7 @@
3 3 #define __ANUBIS_ALLOCATOR_H__
4 4  
5 5 #include "AnubisSupport.h"
  6 +//#include "vm.h"
6 7  
7 8 BEGIN_NAMESPACE(CM);
8 9  
... ... @@ -11,7 +12,7 @@ BEGIN_NAMESPACE(CM);
11 12 #define SEGREGATED_LISTS
12 13  
13 14 #ifdef SEGREGATED_LISTS
14   -#define number_of_segregated_lists (30)
  15 +#define number_of_segregated_lists (20)
15 16 #define segregated_segments_per_main (100)
16 17 #endif
17 18  
... ... @@ -71,6 +72,7 @@ private:
71 72 U32 *free_segregated_segment(U32 *ss);
72 73 U32 reallocate_segregated_segment(U32 data_segment, int words);
73 74 void printf_check_segregated_list(int k);
  75 + void check_segment_home(U32 *ss);
74 76 #endif
75 77  
76 78 // the basic allocator (non segregated)
... ...
anubis_dev/vm/src/serialize.cpp
... ... @@ -139,6 +139,7 @@ extern int check_small_datum(U32 datum, /* datum to be checked */
139 139 { U32 aux;\
140 140 U32 more = byte_size_to_word_size(n);\
141 141 if (more < serial_size_increment) more = serial_size_increment;\
  142 + assert(((U32 *)(MAM(m_serial_buf)))[0] == 1);\
142 143 if ((aux = MAM(m_allocator)->ReallocateDataSegment((U32)(MAM(m_serial_buf)),\
143 144 ((MAM(m_serial_size))/4)+more )) == 0)\
144 145 {\
... ... @@ -455,20 +456,28 @@ si_decl(type_large_switch)
455 456 /* Format: revert_to_computing (U8)type_width
456 457 Size: 1
457 458  
458   - This instruction instructs the machine to revert to 'computing' work sort.
459   - Since we are here serializing, we must reduce the serialization buffer
460   - to the size needed and transform it into a datum of type 'ByteArray'
461   - to be put in MAM(m_R).
  459 + This instruction instructs the machine to revert to 'computing' work sort. Since we
  460 + are here serializing, we must reduce the serialization buffer to the size needed and
  461 + transform it into a datum of type 'ByteArray' to be put in MAM(m_R).
462 462  
463   - type width is not used here.
464   - */
  463 + type width is not used here.
  464 +*/
465 465 si_decl(revert_to_computing)
466 466 {
467   -
  467 + assert(((U32 *)(MAM(m_serial_buf)))[0] == 1); // must be unshared
  468 +
468 469 MAM(m_R) = MAM(m_allocator)->ReallocateDataSegment((U32)(MAM(m_serial_buf)),
469 470 byte_size_to_word_size(MAM(m_serial_next)));
470 471  
471   - assert(MAM(m_R) != 0); /* must have succeeded */
  472 + //assert(MAM(m_R) != 0); /* must have succeeded */
  473 + if (MAM(m_R) == 0)
  474 + // since segregated lists reallocation with smaller new segment may fail because a
  475 + // segregated list may be empty.
  476 + {
  477 + MAM(m_status) = need_more_memory;
  478 + { MAM(m_steps) = 0; return; }
  479 + }
  480 +
472 481 *(((U32 *)MAM(m_R))+1) = (MAM(m_serial_next))
473 482 -(4+4); /* count,num_bytes,bytes ... */
474 483 MAM(m_work_sort) = computing;
... ... @@ -1005,8 +1014,7 @@ ui_decl(type_String)
1005 1014 /* put the string in MAM(m_R) */
1006 1015 MAM(m_R) = str;
1007 1016 #ifdef debug_vm
1008   - if (debugging)
1009   - LOGINFO("\n string unserialized into MAM(m_R): \"%s\"",strptr);
  1017 + //if (debugging) LOGINFO("\n string unserialized into MAM(m_R): \"%s\"",strptr);
1010 1018 #endif
1011 1019 }
1012 1020 }
... ... @@ -1214,8 +1222,7 @@ ui_decl(pop1)
1214 1222 assert(*(MAM(m_SP)-2));
1215 1223 *((U32 *)(*(MAM(m_SP)-1))) = 0;
1216 1224 #ifdef debug_vm
1217   - if (debugging)
1218   - LOGINFO("\n 0 put at %d",*(MAM(m_SP)-1));
  1225 + //if (debugging) LOGINFO("\n 0 put at %d",*(MAM(m_SP)-1));
1219 1226 #endif
1220 1227 *(MAM(m_SP)-1) += 4;
1221 1228 }
... ... @@ -1224,7 +1231,7 @@ ui_decl(pop1)
1224 1231 {
1225 1232 *((U32 *)(*(MAM(m_SP)-1))) = MAM(m_R);
1226 1233 #ifdef debug_vm
1227   - if (debugging) LOGINFO("\n %d put at %d",MAM(m_R),*(MAM(m_SP)-1));
  1234 + //if (debugging) LOGINFO("\n %d put at %d",MAM(m_R),*(MAM(m_SP)-1));
1228 1235 #endif
1229 1236 *(MAM(m_SP)-1) += 4;
1230 1237 }
... ... @@ -1648,8 +1655,7 @@ ui_decl(indirect_type_String)
1648 1655 *((U32 *)(*(MAM(m_SP)-1))) = str;
1649 1656 *(MAM(m_SP)-1) += 4; /* increment the pointer */
1650 1657 #ifdef debug_vm
1651   - if (debugging)
1652   - LOGINFO("\n string unserialized at %d: \"%s\"",(*(MAM(m_SP)-1))-4,strptr);
  1658 + //if (debugging) LOGINFO("\n string unserialized at %d: \"%s\"",(*(MAM(m_SP)-1))-4,strptr);
1653 1659 #endif
1654 1660 }
1655 1661 }
... ...
anubis_dev/vm/src/syscall.cpp
... ... @@ -153,7 +153,7 @@ ci_decl(syscall)
153 153 LOGERROR("syscall %s (MAM(m_IP) = %d)\n",syscall_names[get16(1)],MAM(m_IP)-MAM(m_code_begin));
154 154 }
155 155 #endif
156   -
  156 + trace
157 157  
158 158 //************************************** BEGIN OF SYSCALL ********************************************
159 159 // before this part was in separate file named syscall.c
... ... @@ -1769,13 +1769,30 @@ ci_decl(syscall)
1769 1769  
1770 1770 /* The instruction returns 'unique' of type 'One' in all cases. */
1771 1771 MAM(m_R) = 0;
  1772 +
  1773 + // if the byte array is shared, reallocation is not possible and we must make a
  1774 + // copy.
  1775 + if (((U32 *)ba)[0] == 1)
  1776 + { // the byte array is not shared
  1777 + if (new_size >= 0 && new_size <= (int)old_size)
  1778 + {
  1779 + U32 new_seg =
  1780 + MAM(m_allocator)->ReallocateDataSegment(ba, byte_size_to_word_size(new_size+8));
  1781 + assert(new_seg = ba); /* truncation should not change the segment */
  1782 + ((U32 *)ba)[1] = new_size;
  1783 + }
  1784 + }
  1785 + else
  1786 + { // the byte aray is shared.
1772 1787  
1773   - if (new_size >= 0 && new_size <= (int)old_size)
1774   - {
1775   - U32 new_seg = MAM(m_allocator)->ReallocateDataSegment(ba, byte_size_to_word_size(new_size+8));
1776   - assert(new_seg = ba); /* truncation should not change the segment */
1777   - ((U32 *)ba)[1] = new_size;
  1788 + // Actually we can do nothing because this primitive returns (One)unique,
  1789 + // hence needs to make a side effect. In this case, the byte array is not
  1790 + // truncated.
  1791 +
  1792 + // To do: define 'truncate_byte_array' in predefined.anubis so that it
  1793 + // returns the new byte array.
1778 1794 }
  1795 +
1779 1796 MAM(m_IP) += 1+2;
1780 1797 return;
1781 1798 }
... ... @@ -6035,6 +6052,10 @@ ci_decl(syscall)
6035 6052 {
6036 6053 /* enlarge the table */
6037 6054 U32 *new_table;
  6055 +
  6056 + assert(table[0] == 1); // the table must be unshared
  6057 + // only unshared segments may be reallocated
  6058 +
6038 6059 if ((new_table = (U32 *)MAM(m_allocator)->ReallocateDataSegment((U32)table,
6039 6060 table_size+default_number_of_monitors)) == 0)
6040 6061 {
... ...
anubis_dev/vm/src/vm.cpp
... ... @@ -2459,6 +2459,8 @@ ci_decl(_register)
2459 2459 if (i == table_size)
2460 2460 {
2461 2461 /* enlarge the table */
  2462 + assert(table[0] == 1); // only non shared segments may be reallocated
  2463 +
2462 2464 U32 *new_table;
2463 2465 if ((new_table =
2464 2466 (U32 *)MAM(m_allocator)->ReallocateDataSegment((U32)table,
... ... @@ -3151,20 +3153,21 @@ ci_decl(del_stack_ptr)
3151 3153 {
3152 3154 trace
3153 3155 U32 i = get32(1); /* depth in stack */
3154   - U32 aux = (*(MAM(m_SP)-i-1)); /* get the pointer */
3155   - while (i) /* collapse the stack */
  3156 + U32 aux = (*(MAM(m_SP)-i-1)); /* get the pointer */
  3157 + while (i) /* collapse the stack */
3156 3158 {
3157 3159 *(MAM(m_SP)-i-1) = *(MAM(m_SP)-i);
3158 3160 i--;
3159 3161 }
3160 3162 MAM(m_SP)--;
3161 3163  
3162   - //printf("del_stack_ptr (%d) [%p]\n",*(((U32 *)aux)-1),((U32 *)aux));
3163   - //printf("aux = %d\n",aux);
3164   - //fflush(stdout);
  3164 + //printf("del_stack_ptr (%d) [%p]\n",(int)(*(((U32 *)aux)-1)),((U32 *)aux));
  3165 + //printf("aux = %d\n",(int)aux);
  3166 + //printf("*aux = %d\n",(int)(*((U32 *)aux)));
  3167 + fflush(stdout);
3165 3168  
3166 3169 if (aux && /* beware of null pointer */
3167   - *((U32 *)aux) && /* don't do for permanent data */
  3170 + (*((U32 *)aux)) && /* don't do for permanent data */
3168 3171 !(--(*((U32 *)aux)))) /* delete virtually */
3169 3172 {
3170 3173 //printf("freeing.\n"); fflush(stdout);
... ...
anubis_dev/vm/src/vm.h
... ... @@ -92,6 +92,7 @@ extern int counting_instructions;
92 92 extern int show_syscalls;
93 93  
94 94 extern char *instr_names[];
  95 +extern char *instr_name(int i, int n);
95 96  
96 97 extern U32 max_memory;
97 98 extern U32 current_memory;
... ...
anubis_dev/vm/src/vmtools.cpp
... ... @@ -957,6 +957,7 @@ U32 anubis_cons(U32 h, U32 t, int index, AnubisAllocator *allocator)
957 957 return result|index; /* glue mixed index */
958 958 }
959 959  
  960 +
960 961 /* making a virtual machine triple */
961 962 U32 anubis_mcons3(U32 h, U32 t, U32 u, int index, AnubisAllocator *allocator)
962 963 {
... ...
anubis_distrib/linux_install/bin/anbexec
No preview for this file type