int main (void)
{
	char * chaine = NULL;
	if (signal(SIGSEGV, gestionnaire_sigsegv) == SIG_ERR) {
		perror("signal");
		exit(EXIT_FAILURE);
	}
	fprintf(stdout, "Allocation de %d octets\n", TAILLE_CHAINE);
	chaine = mon_malloc_avec_mmap(TAILLE_CHAINE);
	if (chaine == NULL) {
		perror("mmap");
		exit(EXIT_FAILURE);
	}
	fprintf(stdout, "Protections par defaut\n");
	fprintf(stdout, "   Ecriture ...");
	strcpy(chaine, "Ok");
	fprintf(stdout, "Ok\n");

	fprintf(stdout, "Interdiction de lecture\n");
	if (mprotect(chaine, TAILLE_CHAINE, PROT_NONE) < 0) {
		perror("mprotect");
		exit(EXIT_FAILURE);
	}

	fprintf(stdout, "   Lecture ...\n");
	fflush(stdout);
	fprintf(stdout, "%s\n", chaine);
	/* ici on doit deja etre arrete par un signal */
	return EXIT_SUCCESS;
}
Esempio n. 2
0
	int
main (void)
{
	char * chaine = NULL;

	fprintf (stdout, "Allocation de %d octets\n", TAILLE_CHAINE);
	chaine = mon_malloc_avec_mmap (TAILLE_CHAINE);
	if (chaine == NULL) {
		perror ("mmap");
		exit (1);
	}
	fprintf (stdout, "Protections par défaut\n");
	fprintf (stdout, "   Ecriture ...");
	strcpy (chaine, "Ok");
	fprintf (stdout, "Ok\n");
	fprintf (stdout, "   Lecture ...");
	fprintf (stdout, "%s\n", chaine);

	fprintf (stdout, "Interdiction d'écriture\n");
	if (mprotect (chaine, TAILLE_CHAINE, PROT_READ) < 0) {
		perror ("mprotect");
		exit (1);
	}

	fprintf (stdout, "   Lecture ...");
	fprintf (stdout, "%s\n", chaine);
	fprintf (stdout, "   Ecriture ...");
	strcpy (chaine, "Non");
	/* ici on doit déjà être arrêté par un signal */
	return (0);
}