How Can The Ability Of The Operating System Working In Conjunction With Hardware

How can the ability of the operating system, working in conjunction with hardware, to distinguish between memory containing program instructions vs. memory containing data prevent buffer overrun/overflow attacks?