1121407Speter/*- 2121407Speter * Copyright (c) 2003 Peter Wemm 3323538Skib * Copyright (c) 2017 The FreeBSD Foundation 4121407Speter * All rights reserved. 5121407Speter * 6323538Skib * Portions of this software were developed by Konstantin Belousov 7323538Skib * under sponsorship from the FreeBSD Foundation. 8323538Skib * 9121407Speter * Redistribution and use in source and binary forms, with or without 10121407Speter * modification, are permitted provided that the following conditions 11121407Speter * are met: 12121407Speter * 1. Redistributions of source code must retain the above copyright 13121407Speter * notice, this list of conditions and the following disclaimer. 14121407Speter * 2. Redistributions in binary form must reproduce the above copyright 15121407Speter * notice, this list of conditions and the following disclaimer in the 16121407Speter * documentation and/or other materials provided with the distribution. 17121407Speter * 18121407Speter * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19121407Speter * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20121407Speter * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21121407Speter * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 22121407Speter * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23121407Speter * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24121407Speter * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25121407Speter * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26121407Speter * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27121407Speter * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28121407Speter * SUCH DAMAGE. 29121407Speter */ 30121407Speter 31121407Speter#include <sys/cdefs.h> 32121407Speter__FBSDID("$FreeBSD: stable/11/lib/libc/amd64/sys/amd64_get_gsbase.c 323538 2017-09-13 11:29:48Z kib $"); 33121407Speter 34323538Skib#include <sys/types.h> 35323538Skib#include <machine/cpufunc.h> 36121407Speter#include <machine/sysarch.h> 37323538Skib#include "amd64_detect_rdfsgsbase.h" 38121407Speter 39121407Speterint 40121407Speteramd64_get_gsbase(void **addr) 41121407Speter{ 42121407Speter 43323538Skib if (amd64_detect_rdfsgsbase() == RDFSGS_SUPPORTED) { 44323538Skib *addr = (void *)rdgsbase(); 45323538Skib return (0); 46323538Skib } 47124296Snectar return (sysarch(AMD64_GET_GSBASE, addr)); 48121407Speter} 49