1 /*
2 (c) Copyright 2001-2009 The world wide DirectFB Open Source Community (directfb.org)
3 (c) Copyright 2000-2004 Convergence (integrated media) GmbH
4
5 All rights reserved.
6
7 Written by Denis Oliver Kropp <dok@directfb.org>,
8 Andreas Hundt <andi@fischlustig.de>,
9 Sven Neumann <neo@directfb.org>,
10 Ville Syrjälä <syrjala@sci.fi> and
11 Claudio Ciccani <klan@users.sf.net>.
12
13 This library is free software; you can redistribute it and/or
14 modify it under the terms of the GNU Lesser General Public
15 License as published by the Free Software Foundation; either
16 version 2 of the License, or (at your option) any later version.
17
18 This library is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 Lesser General Public License for more details.
22
23 You should have received a copy of the GNU Lesser General Public
24 License along with this library; if not, write to the
25 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
26 Boston, MA 02111-1307, USA.
27 */
28
29 #include <config.h>
30
31 #include <errno.h>
32 #include <unistd.h>
33
34 #include <sys/syscall.h>
35
36 #include <direct/build.h>
37 #include <direct/system.h>
38
39 #if DIRECT_BUILD_GETTID && defined(HAVE_LINUX_UNISTD_H)
40 #include <linux/unistd.h>
41 #endif
42
43 __attribute__((no_instrument_function))
44 pid_t
direct_gettid(void)45 direct_gettid( void )
46 {
47 pid_t tid = -1;
48 #if DIRECT_BUILD_GETTID && defined(__NR_gettid) /* present on linux >= 2.4.20 */
49 tid = syscall(__NR_gettid);
50 #endif
51 if (tid < 0)
52 tid = getpid();
53
54 return tid;
55 }
56
57 long
direct_pagesize(void)58 direct_pagesize( void )
59 {
60 return sysconf( _SC_PAGESIZE );
61 }
62
63 unsigned long
direct_page_align(unsigned long value)64 direct_page_align( unsigned long value )
65 {
66 unsigned long mask = sysconf( _SC_PAGESIZE ) - 1;
67
68 return (value + mask) & ~mask;
69 }
70
71