锁定物理内存-mlockall
/* mlockall -- lock in core all the pages in this process. Hurd version.Copyright (C) 2001-2021 Free Software Foundation, Inc.This file is part of the GNU C Library.The GNU C Library is free software;
·
/* mlockall -- lock in core all the pages in this process. Hurd version.
Copyright (C) 2001-2021 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
#include <sys/types.h>
#include <sys/mman.h>
#include <errno.h>
#include <hurd.h>
#include <mach/mach_host.h>
/* Cause all currently mapped pages of the process to be memory resident
until unlocked by a call to the `munlockall', until the process exits,
or until the process calls `execve'. */
#include <hurd.h>
#define __mach_task_self() (__mach_task_self_ + 0)
void _hurd_port_cleanup (void *cleanup_data, jmp_buf env, int val)
{
__mach_port_deallocate (__mach_task_self (), (mach_port_t) cleanup_data);
}
_HURD_USERLINK_H_EXTERN_INLINE void _hurd_userlink_link (struct hurd_userlink **chainp,struct hurd_userlink *link)
{
struct hurd_userlink **thread_chainp;
link->resource.next = *chainp;
if (link->resource.next)
link->resource.next->resource.prevp = &link->resource.next;
link->resource.prevp = chainp;
*chainp = link;
/* Also chain it on the current thread's list of active resources. */
thread_chainp = &_hurd_self_sigstate ()->active_resources;
link->thread.next = *thread_chainp;
if (link->thread.next)
link->thread.next->thread.prevp = &link->thread.next;
link->thread.prevp = thread_chainp;
*thread_chainp = link;
}
_HURD_PORT_H_EXTERN_INLINE mach_port_t _hurd_port_locked_get (struct hurd_port *port,struct hurd_userlink *link)
{
mach_port_t result;
result = port->port;
if (result != MACH_PORT_NULL)
{
link->cleanup = &_hurd_port_cleanup;
link->cleanup_data = (void *) result;
_hurd_userlink_link (&port->users, link);
}
__spin_unlock (&port->lock);
return result;
}
_HURD_PORT_H_EXTERN_INLINE mach_port_t _hurd_port_get (struct hurd_port *port,struct hurd_userlink *link)
{
mach_port_t result;
HURD_CRITICAL_BEGIN;
__spin_lock (&port->lock);
result = _hurd_port_locked_get (port, link);
HURD_CRITICAL_END;
return result;
}
_HURD_PORT_H_EXTERN_INLINE void _hurd_port_free (struct hurd_port *port,struct hurd_userlink *link,mach_port_t used_port)
{
int dealloc;
if (used_port == MACH_PORT_NULL)
return;
HURD_CRITICAL_BEGIN;
__spin_lock (&port->lock);
dealloc = _hurd_userlink_unlink (link);
__spin_unlock (&port->lock);
HURD_CRITICAL_END;
if (dealloc)
__mach_port_deallocate (__mach_task_self (), used_port);
}
struct hurd_port *_hurd_ports;
#define HURD_PORT_USE(expr)
(
{
struct hurd_port *const __p = &_hurd_ports[INIT_PORT_PROC];
struct hurd_userlink __link;
const mach_port_t port = _hurd_port_get (__p, &__link);
__typeof(expr) __result = (expr);
_hurd_port_free (__p, &__link, port);
__result;
}
)
mach_port_t _hurd_host_priv, _hurd_device_master;
kern_return_t __get_privileged_ports (mach_port_t *host_priv_ptr,device_t *device_master_ptr)
{
if ((host_priv_ptr && _hurd_host_priv == MACH_PORT_NULL) || (device_master_ptr && _hurd_device_master == MACH_PORT_NULL))
{
error_t err;
if (_hurd_ports)
err = HURD_PORT_USE (__proc_getprivports (port,&_hurd_host_priv,&_hurd_device_master));
else
return MACH_SEND_INVALID_DEST;
if (err)
return err;
}
if (host_priv_ptr)
{
error_t err = _hurd_host_priv == MACH_PORT_NULL ? 0 : __mach_port_mod_refs (__mach_task_self (),_hurd_host_priv, MACH_PORT_RIGHT_SEND, +1);
if (err)
return err;
*host_priv_ptr = _hurd_host_priv;
}
if (device_master_ptr)
{
error_t err = _hurd_device_master == MACH_PORT_NULL ? 0 : __mach_port_mod_refs (__mach_task_self (),_hurd_device_master, MACH_PORT_RIGHT_SEND, +1);
if (err)
return err;
*device_master_ptr = _hurd_device_master;
}
return KERN_SUCCESS;
}
weak_alias (__get_privileged_ports, get_privileged_ports)
int mlockall (int flags)
{
mach_port_t host;
error_t err;
err = __get_privileged_ports (&host, NULL);
if (err)
return __hurd_fail (err);
err = __vm_wire_all (host, __mach_task_self (), flags);
__mach_port_deallocate (__mach_task_self (), host);
return err ? __hurd_fail (err) : 0;
}
开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!
更多推荐
已为社区贡献1条内容
所有评论(0)