\hypertarget{group__Eina__Safepointer__Group}{}\section{Safe Pointer}
\label{group__Eina__Safepointer__Group}\index{Safe Pointer@{Safe Pointer}}


These functions provide a wrapper that protect access to pointers.  


\subsection*{Typedefs}
\begin{DoxyCompactItemize}
\item 
\mbox{\Hypertarget{group__Eina__Safepointer__Group_gaceb5489a49e4ff5eb71fe0e261707010}\label{group__Eina__Safepointer__Group_gaceb5489a49e4ff5eb71fe0e261707010}} 
typedef struct \+\_\+\+Eina\+\_\+\+Safepointer \mbox{\hyperlink{group__Eina__Safepointer__Group_gaceb5489a49e4ff5eb71fe0e261707010}{Eina\+\_\+\+Safepointer}}
\begin{DoxyCompactList}\small\item\em Type of the protected index. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Functions}
\begin{DoxyCompactItemize}
\item 
const \mbox{\hyperlink{group__Eina__Safepointer__Group_gaceb5489a49e4ff5eb71fe0e261707010}{Eina\+\_\+\+Safepointer}} $\ast$ \mbox{\hyperlink{group__Eina__Safepointer__Group_ga939ea9ad94c3c393c1845d053c94667b}{eina\+\_\+safepointer\+\_\+register}} (const void $\ast$target)
\begin{DoxyCompactList}\small\item\em Register a pointer and get an Eina\+\_\+\+Safepointer that map to it. \end{DoxyCompactList}\item 
void \mbox{\hyperlink{group__Eina__Safepointer__Group_ga184e4557df8e3ea16ae8b9f65c7c636d}{eina\+\_\+safepointer\+\_\+unregister}} (const \mbox{\hyperlink{group__Eina__Safepointer__Group_gaceb5489a49e4ff5eb71fe0e261707010}{Eina\+\_\+\+Safepointer}} $\ast$safe)
\begin{DoxyCompactList}\small\item\em Unregister an Eina\+\_\+\+Safepointer and the pointer that map to it. \end{DoxyCompactList}\item 
static void $\ast$ \mbox{\hyperlink{group__Eina__Safepointer__Group_ga2202ee963589cf46aad92612e10c0533}{eina\+\_\+safepointer\+\_\+get}} (const \mbox{\hyperlink{group__Eina__Safepointer__Group_gaceb5489a49e4ff5eb71fe0e261707010}{Eina\+\_\+\+Safepointer}} $\ast$safe)
\begin{DoxyCompactList}\small\item\em Get the associated pointer from an Eina\+\_\+\+Safepointer mapping. \end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{Detailed Description}
These functions provide a wrapper that protect access to pointers. 

Eina\+\_\+\+Safepointer is an pointer to index converter that allow an increased level of safety by forbidding direct access to the pointer. The protection work by using a set of indirection table that are mmapped and mprotected against write access. This the pointer they store and that map to a specific index is always correct. Also once a pointer is unregistered the index won\textquotesingle{}t be served back for 2$^\wedge$8 on 32 bits system and 2$^\wedge$28 on 64 bits system for that specific slot. Finally we do guarantee that the lower 2 bits of the returned index are actually never used and completly ignored by our A\+PI. So you can safely store whatever information you want in it, we will ignore it and threat as if it wasn\textquotesingle{}t there.

\begin{DoxyNote}{Note}
The use of Eina\+\_\+\+Safepointer is thread safe. 
\end{DoxyNote}


\subsection{Function Documentation}
\mbox{\Hypertarget{group__Eina__Safepointer__Group_ga939ea9ad94c3c393c1845d053c94667b}\label{group__Eina__Safepointer__Group_ga939ea9ad94c3c393c1845d053c94667b}} 
\index{Safe Pointer@{Safe Pointer}!eina\+\_\+safepointer\+\_\+register@{eina\+\_\+safepointer\+\_\+register}}
\index{eina\+\_\+safepointer\+\_\+register@{eina\+\_\+safepointer\+\_\+register}!Safe Pointer@{Safe Pointer}}
\subsubsection{\texorpdfstring{eina\+\_\+safepointer\+\_\+register()}{eina\_safepointer\_register()}}
{\footnotesize\ttfamily const \mbox{\hyperlink{group__Eina__Safepointer__Group_gaceb5489a49e4ff5eb71fe0e261707010}{Eina\+\_\+\+Safepointer}}$\ast$ eina\+\_\+safepointer\+\_\+register (\begin{DoxyParamCaption}\item[{const void $\ast$}]{target }\end{DoxyParamCaption})}



Register a pointer and get an Eina\+\_\+\+Safepointer that map to it. 


\begin{DoxyParams}{Parameters}
{\em target} & The pointer to register. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
A valid pointer that is an index to the mapped pointer.
\end{DoxyReturn}
\begin{DoxyNote}{Note}
It will return {\ttfamily N\+U\+LL} on error or if {\ttfamily target} is {\ttfamily N\+U\+LL}.

The lower 2 bits of the returned pointer will always be 0.

The returned pointer can be used like a pointer, but can not be touched except with Eina\+\_\+\+Safepointer functions.
\end{DoxyNote}
\begin{DoxySince}{Since}
1.\+18 
\end{DoxySince}


References eina\+\_\+spinlock\+\_\+release(), and eina\+\_\+spinlock\+\_\+take().

\mbox{\Hypertarget{group__Eina__Safepointer__Group_ga184e4557df8e3ea16ae8b9f65c7c636d}\label{group__Eina__Safepointer__Group_ga184e4557df8e3ea16ae8b9f65c7c636d}} 
\index{Safe Pointer@{Safe Pointer}!eina\+\_\+safepointer\+\_\+unregister@{eina\+\_\+safepointer\+\_\+unregister}}
\index{eina\+\_\+safepointer\+\_\+unregister@{eina\+\_\+safepointer\+\_\+unregister}!Safe Pointer@{Safe Pointer}}
\subsubsection{\texorpdfstring{eina\+\_\+safepointer\+\_\+unregister()}{eina\_safepointer\_unregister()}}
{\footnotesize\ttfamily void eina\+\_\+safepointer\+\_\+unregister (\begin{DoxyParamCaption}\item[{const \mbox{\hyperlink{group__Eina__Safepointer__Group_gaceb5489a49e4ff5eb71fe0e261707010}{Eina\+\_\+\+Safepointer}} $\ast$}]{safe }\end{DoxyParamCaption})}



Unregister an Eina\+\_\+\+Safepointer and the pointer that map to it. 


\begin{DoxyParams}{Parameters}
{\em safe} & The index to unregister from the mapping.\\
\hline
\end{DoxyParams}
\begin{DoxyNote}{Note}
This function will ignore the lower 2 bits of the given pointer.
\end{DoxyNote}
\begin{DoxySince}{Since}
1.\+18 
\end{DoxySince}


References eina\+\_\+spinlock\+\_\+release(), eina\+\_\+spinlock\+\_\+take(), and eina\+\_\+trash\+\_\+push().

\mbox{\Hypertarget{group__Eina__Safepointer__Group_ga2202ee963589cf46aad92612e10c0533}\label{group__Eina__Safepointer__Group_ga2202ee963589cf46aad92612e10c0533}} 
\index{Safe Pointer@{Safe Pointer}!eina\+\_\+safepointer\+\_\+get@{eina\+\_\+safepointer\+\_\+get}}
\index{eina\+\_\+safepointer\+\_\+get@{eina\+\_\+safepointer\+\_\+get}!Safe Pointer@{Safe Pointer}}
\subsubsection{\texorpdfstring{eina\+\_\+safepointer\+\_\+get()}{eina\_safepointer\_get()}}
{\footnotesize\ttfamily static void$\ast$ eina\+\_\+safepointer\+\_\+get (\begin{DoxyParamCaption}\item[{const \mbox{\hyperlink{group__Eina__Safepointer__Group_gaceb5489a49e4ff5eb71fe0e261707010}{Eina\+\_\+\+Safepointer}} $\ast$}]{safe }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}, {\ttfamily [static]}}



Get the associated pointer from an Eina\+\_\+\+Safepointer mapping. 


\begin{DoxyParams}{Parameters}
{\em safe} & The Eina\+\_\+\+Safepointer index to lookup at. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
The pointer registered with that index or {\ttfamily N\+U\+LL} in any other case.
\end{DoxyReturn}
\begin{DoxyNote}{Note}
It is always safe to ask for a pointer for any value of the mapping. If the pointer is invalid or {\ttfamily N\+U\+LL}, we will return {\ttfamily N\+U\+LL} and not crash. 
\end{DoxyNote}
