10Sstevel@tonic-gate/* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 55891Sraf * Common Development and Distribution License (the "License"). 65891Sraf * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 215891Sraf 220Sstevel@tonic-gate/* 238797SSeth.Goldberg@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 277298SMark.J.Nelson@Sun.COM .file "door.s" 280Sstevel@tonic-gate 296812Sraf#include "SYS.h" 306812Sraf#include <sys/door.h> 310Sstevel@tonic-gate 320Sstevel@tonic-gate /* 330Sstevel@tonic-gate * weak aliases for public interfaces 340Sstevel@tonic-gate */ 356812Sraf ANSI_PRAGMA_WEAK2(door_bind,__door_bind,function) 366812Sraf ANSI_PRAGMA_WEAK2(door_getparam,__door_getparam,function) 376812Sraf ANSI_PRAGMA_WEAK2(door_info,__door_info,function) 386812Sraf ANSI_PRAGMA_WEAK2(door_revoke,__door_revoke,function) 396812Sraf ANSI_PRAGMA_WEAK2(door_setparam,__door_setparam,function) 400Sstevel@tonic-gate 410Sstevel@tonic-gate/* 420Sstevel@tonic-gate * Offsets within struct door_results 430Sstevel@tonic-gate */ 440Sstevel@tonic-gate#define DOOR_COOKIE _MUL(0, CLONGSIZE) 450Sstevel@tonic-gate#define DOOR_DATA_PTR _MUL(1, CLONGSIZE) 460Sstevel@tonic-gate#define DOOR_DATA_SIZE _MUL(2, CLONGSIZE) 470Sstevel@tonic-gate#define DOOR_DESC_PTR _MUL(3, CLONGSIZE) 480Sstevel@tonic-gate#define DOOR_DESC_SIZE _MUL(4, CLONGSIZE) 490Sstevel@tonic-gate#define DOOR_PC _MUL(5, CLONGSIZE) 500Sstevel@tonic-gate#define DOOR_SERVERS _MUL(6, CLONGSIZE) 510Sstevel@tonic-gate#define DOOR_INFO_PTR _MUL(7, CLONGSIZE) 520Sstevel@tonic-gate 530Sstevel@tonic-gate/* 540Sstevel@tonic-gate * All of the syscalls except door_return() follow the same pattern. The 550Sstevel@tonic-gate * subcode goes in %r9, after all of the other arguments. 560Sstevel@tonic-gate */ 570Sstevel@tonic-gate#define DOOR_SYSCALL(name, code) \ 580Sstevel@tonic-gate ENTRY(name); \ 590Sstevel@tonic-gate movq $code, %r9; /* subcode */ \ 600Sstevel@tonic-gate SYSTRAP_RVAL1(door); \ 610Sstevel@tonic-gate SYSCERROR; \ 620Sstevel@tonic-gate RET; \ 630Sstevel@tonic-gate SET_SIZE(name) 640Sstevel@tonic-gate 650Sstevel@tonic-gate DOOR_SYSCALL(__door_bind, DOOR_BIND) 660Sstevel@tonic-gate DOOR_SYSCALL(__door_call, DOOR_CALL) 670Sstevel@tonic-gate DOOR_SYSCALL(__door_create, DOOR_CREATE) 680Sstevel@tonic-gate DOOR_SYSCALL(__door_getparam, DOOR_GETPARAM) 690Sstevel@tonic-gate DOOR_SYSCALL(__door_info, DOOR_INFO) 700Sstevel@tonic-gate DOOR_SYSCALL(__door_revoke, DOOR_REVOKE) 710Sstevel@tonic-gate DOOR_SYSCALL(__door_setparam, DOOR_SETPARAM) 720Sstevel@tonic-gate DOOR_SYSCALL(__door_ucred, DOOR_UCRED) 730Sstevel@tonic-gate DOOR_SYSCALL(__door_unbind, DOOR_UNBIND) 740Sstevel@tonic-gate DOOR_SYSCALL(__door_unref, DOOR_UNREFSYS) 750Sstevel@tonic-gate 760Sstevel@tonic-gate/* 770Sstevel@tonic-gate * int 780Sstevel@tonic-gate * __door_return( 790Sstevel@tonic-gate * void *data_ptr, 800Sstevel@tonic-gate * size_t data_size, (in bytes) 810Sstevel@tonic-gate * door_return_desc_t *door_ptr, (holds returned desc info) 820Sstevel@tonic-gate * caddr_t stack_base, 830Sstevel@tonic-gate * size_t stack_size) 840Sstevel@tonic-gate */ 850Sstevel@tonic-gate ENTRY(__door_return) 868797SSeth.Goldberg@Sun.COM pushq %rbp 878797SSeth.Goldberg@Sun.COM movq %rsp, %rbp 888797SSeth.Goldberg@Sun.COM subq $0x8, %rsp 898797SSeth.Goldberg@Sun.COM /* 908797SSeth.Goldberg@Sun.COM * Save stack_base (arg4), since %rcx will be trashed if the syscall 918797SSeth.Goldberg@Sun.COM * returns via sysret 928797SSeth.Goldberg@Sun.COM */ 938797SSeth.Goldberg@Sun.COM movq %rcx, -0x8(%rbp) 948797SSeth.Goldberg@Sun.COM 950Sstevel@tonic-gatedoor_restart: 960Sstevel@tonic-gate movq $DOOR_RETURN, %r9 /* subcode */ 970Sstevel@tonic-gate SYSTRAP_RVAL1(door) 985540Sdm120769 jb 2f /* errno is set */ 990Sstevel@tonic-gate /* 1000Sstevel@tonic-gate * On return, we're serving a door_call. Our stack looks like this: 1010Sstevel@tonic-gate * 1020Sstevel@tonic-gate * descriptors (if any) 1030Sstevel@tonic-gate * data (if any) 1040Sstevel@tonic-gate * sp-> struct door_results 1050Sstevel@tonic-gate */ 1060Sstevel@tonic-gate movl DOOR_SERVERS(%rsp), %eax 1070Sstevel@tonic-gate andl %eax, %eax /* test nservers */ 1080Sstevel@tonic-gate jg 1f 1090Sstevel@tonic-gate /* 1100Sstevel@tonic-gate * this is the last server thread - call creation func for more 1110Sstevel@tonic-gate */ 1120Sstevel@tonic-gate movq DOOR_INFO_PTR(%rsp), %rdi 113*11102SGavin.Maltby@Sun.COM call door_depletion_cb@PLT 1140Sstevel@tonic-gate1: 1150Sstevel@tonic-gate /* Call the door server function now */ 1160Sstevel@tonic-gate movq DOOR_COOKIE(%rsp), %rdi 1170Sstevel@tonic-gate movq DOOR_DATA_PTR(%rsp), %rsi 1180Sstevel@tonic-gate movq DOOR_DATA_SIZE(%rsp), %rdx 1190Sstevel@tonic-gate movq DOOR_DESC_PTR(%rsp), %rcx 1200Sstevel@tonic-gate movq DOOR_DESC_SIZE(%rsp), %r8 1210Sstevel@tonic-gate movq DOOR_PC(%rsp), %rax 1220Sstevel@tonic-gate call *%rax 1230Sstevel@tonic-gate /* Exit the thread if we return here */ 1240Sstevel@tonic-gate movq $0, %rdi 1256812Sraf call _thrp_terminate 1260Sstevel@tonic-gate /* NOTREACHED */ 1275540Sdm1207692: 1280Sstevel@tonic-gate /* 1290Sstevel@tonic-gate * Error during door_return call. Repark the thread in the kernel if 1300Sstevel@tonic-gate * the error code is EINTR (or ERESTART) and this lwp is still part 1310Sstevel@tonic-gate * of the same process. 1320Sstevel@tonic-gate */ 1330Sstevel@tonic-gate cmpl $ERESTART, %eax /* ERESTART is same as EINTR */ 1340Sstevel@tonic-gate jne 3f 1350Sstevel@tonic-gate movl $EINTR, %eax 1360Sstevel@tonic-gate3: 1370Sstevel@tonic-gate cmpl $EINTR, %eax /* interrupted while waiting? */ 1388797SSeth.Goldberg@Sun.COM jne 4f /* if not, return the error */ 1390Sstevel@tonic-gate 1406515Sraf call getpid /* get current process id */ 1410Sstevel@tonic-gate movq _daref_(door_create_pid), %rdx 1420Sstevel@tonic-gate movl 0(%rdx), %edx 1430Sstevel@tonic-gate cmpl %eax, %edx /* same process? */ 1440Sstevel@tonic-gate movl $EINTR, %eax /* if no, return EINTR (child of forkall) */ 1458797SSeth.Goldberg@Sun.COM jne 4f 1460Sstevel@tonic-gate 1470Sstevel@tonic-gate movq $0, %rdi /* clear arguments and restart */ 1480Sstevel@tonic-gate movq $0, %rsi 1490Sstevel@tonic-gate movq $0, %rdx 1508797SSeth.Goldberg@Sun.COM movq -0x8(%rbp), %rcx /* Restore arg4 (stack_base) */ 1510Sstevel@tonic-gate jmp door_restart 1528797SSeth.Goldberg@Sun.COM 1538797SSeth.Goldberg@Sun.COM4: 1548797SSeth.Goldberg@Sun.COM leave 1558797SSeth.Goldberg@Sun.COM jmp __cerror 1560Sstevel@tonic-gate SET_SIZE(__door_return) 157