mes/lib/mach/mach-init.c

76 lines
1.8 KiB
C
Raw Normal View History

/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 1992-2016 Free Software Foundation, Inc.
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
2019-03-10 20:52:05 +00:00
/** Commentary:
Taken from GNU C Library
*/
2019-03-10 20:52:05 +00:00
#define _GNU_SOURCE 1
#define __USE_GNU 1
#define __FILE_defined 1
2019-03-10 20:52:05 +00:00
#include <stdio.h>
2019-03-10 20:52:05 +00:00
#include <mach/mach-init.h>
#include <mach.h>
2019-03-10 20:52:05 +00:00
#include <unistd.h>
mach_port_t __mach_task_self_;
mach_port_t __mach_host_self_;
vm_size_t __vm_page_size = 0;
void
__mach_init (void)
{
kern_return_t err;
#ifdef HAVE_HOST_PAGE_SIZE
if (err = __host_page_size (mach_host_self (), &__vm_page_size))
2019-03-10 20:52:05 +00:00
_exit (err);
#else
{
vm_statistics_data_t stats;
if (err = __vm_statistics (mach_task_self (), &stats))
2019-03-10 20:52:05 +00:00
_exit (err);
__vm_page_size = stats.pagesize;
}
#endif
}
extern mach_port_t __mach_host_self (void);
mach_port_t
mach_host_self (void)
{
if (!__mach_host_self_)
__mach_host_self_ = __mach_host_self ();
return __mach_host_self_;
}
extern mach_port_t __mach_task_self (void);
mach_port_t
mach_task_self (void)
{
if (!__mach_task_self_)
__mach_task_self_ = __mach_task_self ();
return __mach_task_self_;
}