1f08c3bdfSopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 2f08c3bdfSopenharmony_ci/* 3f08c3bdfSopenharmony_ci * 4f08c3bdfSopenharmony_ci * Copyright (c) International Business Machines Corp., 2001 5f08c3bdfSopenharmony_ci */ 6f08c3bdfSopenharmony_ci 7f08c3bdfSopenharmony_ci/* 8f08c3bdfSopenharmony_ci * hugetlb.h - common definitions for the hugepage tests 9f08c3bdfSopenharmony_ci */ 10f08c3bdfSopenharmony_ci 11f08c3bdfSopenharmony_ci#ifndef __HUGETLB_H 12f08c3bdfSopenharmony_ci#define __HUGETLB_H 13f08c3bdfSopenharmony_ci 14f08c3bdfSopenharmony_ci#include <stdlib.h> 15f08c3bdfSopenharmony_ci#include <sys/ipc.h> 16f08c3bdfSopenharmony_ci#include <sys/shm.h> 17f08c3bdfSopenharmony_ci#include <errno.h> 18f08c3bdfSopenharmony_ci#include <sys/wait.h> 19f08c3bdfSopenharmony_ci#include "tst_test.h" 20f08c3bdfSopenharmony_ci#include "old_tmpdir.h" 21f08c3bdfSopenharmony_ci#include "mem.h" 22f08c3bdfSopenharmony_ci 23f08c3bdfSopenharmony_ci#define PALIGN(p, a) ((void *)LTP_ALIGN((unsigned long)(p), (a))) 24f08c3bdfSopenharmony_ci 25f08c3bdfSopenharmony_ci#define SHM_RD 0400 26f08c3bdfSopenharmony_ci#define SHM_WR 0200 27f08c3bdfSopenharmony_ci#define SHM_RW (SHM_RD|SHM_WR) 28f08c3bdfSopenharmony_ci 29f08c3bdfSopenharmony_ci#ifndef SHM_HUGETLB 30f08c3bdfSopenharmony_ci#define SHM_HUGETLB 04000 /* segment is mapped via hugetlb */ 31f08c3bdfSopenharmony_ci#endif 32f08c3bdfSopenharmony_ci 33f08c3bdfSopenharmony_ci#ifndef barrier 34f08c3bdfSopenharmony_ci# ifdef mb 35f08c3bdfSopenharmony_ci /* Redefining the mb() */ 36f08c3bdfSopenharmony_ci# define barrier() mb() 37f08c3bdfSopenharmony_ci# else 38f08c3bdfSopenharmony_ci# define barrier() __asm__ __volatile__ ("" : : : "memory") 39f08c3bdfSopenharmony_ci# endif 40f08c3bdfSopenharmony_ci#endif 41f08c3bdfSopenharmony_ci 42f08c3bdfSopenharmony_ci/* Check if hugetlb page is gigantic */ 43f08c3bdfSopenharmony_cistatic inline int is_hugetlb_gigantic(unsigned long hpage_size) 44f08c3bdfSopenharmony_ci{ 45f08c3bdfSopenharmony_ci return (hpage_size / getpagesize()) >> 11; 46f08c3bdfSopenharmony_ci} 47f08c3bdfSopenharmony_ci 48f08c3bdfSopenharmony_ci/* 49f08c3bdfSopenharmony_ci * to get the lower nine permission bits 50f08c3bdfSopenharmony_ci * from shmid_ds.ipc_perm.mode 51f08c3bdfSopenharmony_ci */ 52f08c3bdfSopenharmony_ci#define MODE_MASK 0x01FF 53f08c3bdfSopenharmony_ci 54f08c3bdfSopenharmony_ciextern key_t shmkey; /* an IPC key generated by ftok() */ 55f08c3bdfSopenharmony_ci 56f08c3bdfSopenharmony_ciint getipckey(void); 57f08c3bdfSopenharmony_ciint getuserid(char *user); 58f08c3bdfSopenharmony_civoid rm_shm(int shm_id); 59f08c3bdfSopenharmony_ciint do_readback(void *p, size_t size, char *desc); 60f08c3bdfSopenharmony_ci#endif /* hugetlb.h */ 61