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