Comments On The Thread Lab
Ok. Here are just some general comments. Almost all of them relate to the smasher e5 code
- to get e5 to work the smasher needs to be higher than the victim in the stack.
- Kurt and Lauren's e5 code ran fine when I added a newline to
- printf ("Mo-o-m! One of my siblings just crashed my stack!!!\n");
Big array created at: 0x41825c50 Big array created at: 0x4181bff0 Big array created at: 0x41812390 Big array created at: 0x41808730 Mo-o-m! One of my siblings just crashed my stack!!!
- several people handed in word docs. Please only submit plain text files.
Example of e5 solution
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <pthread.h>
#include <errno.h>
void *entry (void *arg)
{
/* */
int array[150000] = {0};
int *tmp = (int *) arg;
int num = *tmp;
int i = 0;
int j = num - 1;
sleep(1);
printf("Address %p\n", (void*) &i);
if (num > 1)
{
entry(&j);
}
}
void *entry2 (void *arg)
{
int i = 712;
printf("To Crash %p\n", (void*) &i);
while (i == 712) {
}
printf ("Mo-o-m! One of my siblings just crashed my stack!!!\n");
}
/* the parent thread starts executing in main */
int main ()
{
int ret;
pthread_t child, child2;
int value = 16;
ret = pthread_create (&child, NULL, entry, &value);
if (ret == -1) {
perror ("pthread_create failed");
exit (-1);
}
ret = pthread_create (&child2, NULL, entry2, NULL);
if (ret == -1) {
perror ("pthread_create failed");
exit (-1);
}
if (ret == -1) {
perror ("pthread_detach failed");
exit (-1);
}
pthread_exit (NULL);
}
Outputs:
raz@Sonata:~$ gcc -o sm smasher.c -lpthread raz@Sonata:~$ ./sm To Crash 0x7f708e5240fc Address 0x7f708ed250f8 Address 0x7f708ec928f8 Address 0x7f708ec000f8 Address 0x7f708eb6d8f8 Address 0x7f708eadb0f8 Address 0x7f708ea488f8 Address 0x7f708e9b60f8 Address 0x7f708e9238f8 Address 0x7f708e8910f8 Address 0x7f708e7fe8f8 Address 0x7f708e76c0f8 Address 0x7f708e6d98f8 Address 0x7f708e6470f8 Mo-o-m! One of my siblings just crashed my stack!!! Segmentation fault raz@Sonata:~$