A computer-implemented method comprising: allocating, by an operating system kernel, a physical memory block for a privileged function; storing, by the operating system kernel, the privileged function in the physical memory block; creating, by the operating system kernel, an entry for the physical memory block in a mapping table, wherein the entry associates the physical memory block to a virtual memory block in an address space of a program; setting, by the operating system kernel, a security bit for the entry in the mapping table; executing, by a processor, the program in unprivileged mode; and if the program requests the privileged function: checking, by the processor, whether the security bit is set; if the security bit is set, switching, by the processor, execution to kernel mode for performing the privileged function; and after execution of the privileged function in kernel mode: switching, by the processor, execution to unprivileged mode; executing, by the processor, a return function; wherein the program requests the privileged function via a set of assembly language instructions that directly jumps to the privileged function mapped in the address space of the program via the mapping table and makes the processor check the security bit; wherein the security bit is set when it is safe for the processor to switch directly from unprivileged mode to kernel mode while executing the program and requiring a kernel service embodied by the privileged function; characterised in that: performing the privileged function comprises a recursion of the privileged function in which the privileged function calls itself one or more times and/or a sequence in which the privileged function calls other privileged functions, and the method further comprises: setting a counter value to an initial value; increasing a counter value by one each time any privileged function is called; decreasing the counter value by one each time execution of any privileged function is completed; and wherein: switching execution to unprivileged mode and executing the return function are performed only if the counter value equals the initial value. allocating, by an operating system kernel, a physical memory block for a privileged function; storing, by the operating system kernel, the privileged function in the physical memory block; creating, by the operating system kernel, an entry for the physical memory block in a mapping table, wherein the entry associates the physical memory block to a virtual memory block in an address space of a program; setting, by the operating system kernel, a security bit for the entry in the mapping table; executing, by a processor, the program in unprivileged mode; and if the program requests the privileged function: checking, by the processor, whether the security bit is set; if the security bit is set, switching, by the processor, execution to kernel mode for performing the privileged function; and checking, by the processor, whether the security bit is set; if the security bit is set, switching, by the processor, execution to kernel mode for performing the privileged function; and after execution of the privileged function in kernel mode: switching, by the processor, execution to unprivileged mode; executing, by the processor, a return function; switching, by the processor, execution to unprivileged mode; executing, by the processor, a return function; wherein the program requests the privileged function via a set of assembly language instructions that directly jumps to the privileged function mapped in the address space of the program via the mapping table and makes the processor check the security bit; wherein the security bit is set when it is safe for the processor to switch directly from unprivileged mode to kernel mode while executing the program and requiring a kernel service embodied by the privileged function; characterised in that: performing the privileged function comprises a recursion of the privileged function in which the privileged function calls itself one or more times and/or a sequence in which the privileged function calls other privileged functions, and the method further comprises: setting a counter value to an initial value; increasing a counter value by one each time any privileged function is called; decreasing the counter value by one each time execution of any privileged function is completed; setting a counter value to an initial value; increasing a counter value by one each time any privileged function is called; decreasing the counter value by one each time execution of any privileged function is completed; and wherein: switching execution to unprivileged mode and executing the return function are performed only if the counter value equals the initial value.