What do simulations predict for the galaxy stellar mass function and its evolution in different environments?