Stack inspection and secure program transformations