App_server + areas help

Hi,

I’m trying (and failing) to pass an area through the app_server. Per the BeBook It seems like cloning an area is the way to share it across apps/teams - but for some reason I just cannot get it to work, getting B_NOT_ALLOWED when I try to clone. This same type of code works fine in other contexts where I’ve tried it, so it’s making me think the app_server is a special team that doesn’t allow certain operations.

Thoughts?

The relevant snippet of my code looks like this:

		area_id srcAreaID;
        char* area_addr;

        link.Read<area_id>(&srcAreaID);
		
		area_id cloneAreaID = clone_area("my area",
			(void **)&area_addr,
			B_ANY_ADDRESS,
			B_READ_AREA | B_WRITE_AREA,
			srcAreaID);

		if (cloneAreaID < B_OK) {     // cloneAreaID == B_NOT_ALLOWED
			fLink.StartMessage(cloneAreaID);
  			fLink.Flush();
  			break;
  		}

I didn’t see anything in the BeBook about any restrictions on particular teams, like the app server - is there some other magic I need to do?

Thanks!

Yes, there were some changes to this in Haiku compared to BeOS. You need to make your area clonable by setting its permission flags to B_READ_AREA | B_WRITE_AREA | B_CLONEABLE_AREA. This was done to improve security, otherwise applications could access any memory from other apps by mapping arbitrary areas.

2 Likes

Thank you!!!

…is this documented anywhere? I can’t find it, so maybe it needs to be added? I only really found docs about Areas in the Be Book and not the Haiku book.

Unfortunately, there is no documentation for areas (or, in fact, any of the kernel kit) in the new Haiku book yet. And due to its license, we cannot make changes to the old be book.

An external addendum would be nice. I’m not sure if I can help though.

3 Likes

Maybe user with root privileges should be able to do it.