[cfe-dev] Memory allocation in a named address space

David Chisnall csdavec at swansea.ac.uk
Sat Oct 17 11:02:31 PDT 2009


The issue with your example is the use of malloc().  This is a C  
library function that (according to both LLVM semantics and the WG14  
draft for embedded C) always returns a pointer in the main address  
space.  Malloc has no argument specifying the address space.  It will  
either recycle an unused address or request memory from the OS, but  
without an argument specifying the other address space it has no way  
of knowing that you want an address anywhere other than the default  
space.

Setting the attribute on the pointer only means that this pointer may  
only point to addresses in the specified address space.  You must  
define some other mechanism for allocating memory in these spaces.   
Typically, for example, a kernel using the existing addresses that map  
to GS- and FS-relative addresses will have already defined these  
segments when it initialises the memory map.  These may be used, for  
example, for the kernel's address space, which is mapped into the  
userspace process's address space, but not visible in ring 3 (or it  
might do things the other way around, so the GS register points to the  
userspace process's segment).

Perhaps you should explain what you are actually trying to do?  Using  
different address spaces requires you to have an allocator that  
handles them and it requires the LLVM back end code to map them to  
something relevant for the architecture.  You can't just say 'this  
pointer is in address space number 47' and expect that to be meaningful.

David

On 17 Oct 2009, at 18:46, Juan Carlos Martinez Santos wrote:

> Maybe, but, what is the correct way to use the address space?
>
> Thanks in advance,
>
> Juan Carlos
>
>
>
> On Sat, Oct 17, 2009 at 12:38 PM, Eli Friedman  
> <eli.friedman at gmail.com> wrote:
> On Sat, Oct 17, 2009 at 9:13 AM, Juan Carlos Martinez Santos
> <juanc.martinez.santos at gmail.com> wrote:
> > Hello,
> >
> > How I can allocate a chunk of memory in a named address space  
> different than
> > #0 (or intrinsic)?
>
> If you need to ask, you're probably misusing address spaces.
>
> -Eli
>
>
>
> -- 
> Juan Carlos
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev


-- Sent from my STANTEC-ZEBRA




More information about the cfe-dev mailing list