This is typically done by setting the no-execute bit on a memory page or segment (the stack, for example), in modern CPUs. It helps against some stack-based overflows, but isn't a 100% fool-proof cure.
Check out http://en.wikipedia.org/wiki/No_execute