What Is a Thunk?

What Is a Thunk?

The term thunk dates back to the days of the antediluvian Algol programming language and has stuck since then. A thunk is an invisible and parameter-less function or procedure that returns an address. A thunk isn’t implemented as a full-blown C++ function. Rather, it usually consists of one or two assembly directives that read a CPU register or manipulate some value to return the result. For example, the implicit this pointer passed as an argument to a C++ member function is often implemented as a thunk. The object’s address is stored in a CPU register and the thunk reads it from that register. Likewise, when you call delete[] to destroy an array of objects, C++ uses a thunk to retrieve the number of the elements in the array.

Thunks have other uses. The Linux kernel uses thunks extensively. For example, to obtain the task struct associated with the current process, the kernel applies the bitwise AND operator to the stack pointer (which is stored in the ESP register) and a magic number:

 task_struct * p = STACK_POINTER & 0xffffe000; //pseudo code


Under Windows, thunks are used to convert a 16-bit address to a 32-bit address, for example.

Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of