zone.m 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // TEST_CONFIG
  2. #include "test.h"
  3. #include <mach/mach.h>
  4. #include <malloc/malloc.h>
  5. // Look for malloc zone "ObjC" iff OBJC_USE_INTERNAL_ZONE is set.
  6. // This fails if objc tries to allocate before checking its own
  7. // environment variables (rdar://6688423)
  8. int main()
  9. {
  10. if (is_guardmalloc()) {
  11. // guard malloc confuses this test
  12. succeed(__FILE__);
  13. }
  14. kern_return_t kr;
  15. vm_address_t *zones;
  16. unsigned int count, i;
  17. BOOL has_objc = NO, want_objc = NO;
  18. want_objc = (getenv("OBJC_USE_INTERNAL_ZONE") != NULL) ? YES : NO;
  19. testprintf("want objc %s\n", want_objc ? "YES" : "NO");
  20. kr = malloc_get_all_zones(mach_task_self(), NULL, &zones, &count);
  21. testassert(!kr);
  22. for (i = 0; i < count; i++) {
  23. const char *name = malloc_get_zone_name((malloc_zone_t *)zones[i]);
  24. if (name) {
  25. BOOL is_objc = (0 == strcmp(name, "ObjC_Internal")) ? YES : NO;
  26. if (is_objc) has_objc = YES;
  27. testprintf("zone %s\n", name);
  28. }
  29. }
  30. testassert(want_objc == has_objc);
  31. succeed(__FILE__);
  32. }