brintos

brintos / llvm-project-archived public Read only

0
0
Text · 863 B · f3aaf42 Raw
38 lines · c
1// RUN: %clang_scudo %s -o %t2// RUN: %run %t 2>&13 4// Verifies that calling malloc in a preinit_array function succeeds, and that5// the resulting pointer can be freed at program termination.6 7// On some Android versions, calling mmap() from a preinit function segfaults.8// It looks like __mmap2.S ends up calling a NULL function pointer.9// UNSUPPORTED: android10 11#include <assert.h>12#include <stdlib.h>13#include <string.h>14 15static void *global_p = NULL;16 17void __init(void) {18  global_p = malloc(1);19  if (!global_p)20    exit(1);21}22 23void __fini(void) {24  if (global_p)25    free(global_p);26}27 28int main(int argc, char **argv) {29  void *p = malloc(1);30  assert(p);31  free(p);32 33  return 0;34}35 36__attribute__((section(".preinit_array"), used)) void (*__local_preinit)(void) = __init;37__attribute__((section(".fini_array"), used)) void (*__local_fini)(void) = __fini;38