Home | History | Annotate | Download | only in shmat
      1 static key_t probe_key;
      2 
      3 void *probe_free_addr(void)
      4 {
      5 	void *p;
      6 	int ret;
      7 	int shm_id = -1;
      8 
      9 	if (probe_key == 0)
     10 		probe_key = getipckey();
     11 
     12 	/* create a shared memory resource with read and write permissions
     13 	 * We align this to SHMLBA so we should allocate at least
     14 	 * SHMLBA*2 in case SHMLBA > page_size. */
     15 	shm_id = shmget(probe_key, SHMLBA*2, SHM_RW | IPC_CREAT | IPC_EXCL);
     16 	if (shm_id == -1)
     17 		tst_brkm(TBROK, cleanup, "probe: shmget failed");
     18 
     19 	/* Probe an available linear address for attachment */
     20 	p = shmat(shm_id, NULL, 0);
     21 	if (p == (void *)-1)
     22 		tst_brkm(TBROK, cleanup, "probe: shmat failed");
     23 	ret = shmdt(p);
     24 	if (ret == -1)
     25 		tst_brkm(TBROK, cleanup, "probe: shmdt failed");
     26 
     27 	rm_shm(shm_id);
     28 
     29 	/* some architectures (e.g. parisc) are strange, so better always
     30 	 * align to next SHMLBA address. */
     31 	p = (void *)(((unsigned long)(p) + (SHMLBA - 1)) & ~(SHMLBA - 1));
     32 	return p;
     33 }
     34