In pervasive contexts, many different applications, from different providers, will compete for access to resources: physical resources like sensors and actioners, as well as for software resources (services). Sensors provide information about the state of the world, and actioners change the world which can put goods and persons at risk. At least for safety reasons, it is critical to closely control, at any point in time, and in all circumstances, which service(s) are using which resource(s). Pervasive systems face the difficult challenge of providing some safety, reliability and resilience properties, verified at design and compile time, while executing in many different configurations unknown statically, with dynamic services and devices, competing for resources with unknown applications and facing unpredictable configuration changes. This challenge can be seen from two perspectives: how to design and develop pervasive applications in such a demanding context; how to execute these applications while satisfying the requirements despite the unpredictable context and changes. This paper discusses the requirements for future pervasive gateways and presents the Apam dynamic service middleware. Apam interprets at run-time a formalism describing the desirable behavior of a system, and enforces this behavior in a very wide range of unplanned configurations while resisting the many changes that may occur.