[runtime] Convert String.InternalSetLength to an icall. Needed for canary support.
[mono.git] / mono / metadata / sgen-gc.c
index ddbef83fe2418fad66a29f1b935d5eff1617e366..f24fabeac0ac1ce6802706a468c09b4789be8672 100644 (file)
@@ -4360,6 +4360,25 @@ mono_gc_get_los_limit (void)
        return MAX_SMALL_OBJ_SIZE;
 }
 
+void
+mono_gc_set_string_length (MonoString *str, gint32 new_length)
+{
+       mono_unichar2 *new_end = str->chars + new_length;
+       
+       /* zero the discarded string. This null-delimits the string and allows 
+        * the space to be reclaimed by SGen. */
+        
+       if (nursery_canaries_enabled () && sgen_ptr_in_nursery (str)) {
+               CHECK_CANARY_FOR_OBJECT (str);
+               memset (new_end, 0, (str->length - new_length + 1) * sizeof (mono_unichar2) + CANARY_SIZE);
+               memcpy (new_end + 1 , CANARY_STRING, CANARY_SIZE);
+       } else {
+               memset (new_end, 0, (str->length - new_length + 1) * sizeof (mono_unichar2));
+       }
+       
+       str->length = new_length;
+}
+
 gboolean
 mono_gc_user_markers_supported (void)
 {