From 3d046cb0843dfda152ec10213a66bfb4f4824d2a Mon Sep 17 00:00:00 2001 From: andrew Date: Wed, 24 Jun 2015 16:15:32 +0000 Subject: Set the alignment of the setjmp magic values correctly. The alignment needs to be before the lavel, otherwise an extra word may be added between the label and the data. Obtained from: ABT Systems Ltd Sponsored by: The FReeBSD Foundation --- lib/libc/aarch64/gen/_setjmp.S | 2 +- lib/libc/aarch64/gen/setjmp.S | 2 +- lib/libc/aarch64/gen/sigsetjmp.S | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/libc') diff --git a/lib/libc/aarch64/gen/_setjmp.S b/lib/libc/aarch64/gen/_setjmp.S index 504423b..ae00195 100644 --- a/lib/libc/aarch64/gen/_setjmp.S +++ b/lib/libc/aarch64/gen/_setjmp.S @@ -59,8 +59,8 @@ ENTRY(_setjmp) /* Return value */ mov x0, #0 ret -.Lmagic: .align 3 +.Lmagic: .quad _JB_MAGIC__SETJMP END(_setjmp) diff --git a/lib/libc/aarch64/gen/setjmp.S b/lib/libc/aarch64/gen/setjmp.S index 790ed73..a30ed6a 100644 --- a/lib/libc/aarch64/gen/setjmp.S +++ b/lib/libc/aarch64/gen/setjmp.S @@ -69,8 +69,8 @@ ENTRY(setjmp) /* Return value */ mov x0, #0 ret -.Lmagic: .align 3 +.Lmagic: .quad _JB_MAGIC_SETJMP END(setjmp) diff --git a/lib/libc/aarch64/gen/sigsetjmp.S b/lib/libc/aarch64/gen/sigsetjmp.S index 8a13c9f..be49f53 100644 --- a/lib/libc/aarch64/gen/sigsetjmp.S +++ b/lib/libc/aarch64/gen/sigsetjmp.S @@ -47,7 +47,7 @@ ENTRY(siglongjmp) cmp x2, x3 b.eq _C_LABEL(_longjmp) b _C_LABEL(longjmp) -.Lmagic: .align 3 +.Lmagic: .quad _JB_MAGIC__SETJMP END(siglongjmp) -- cgit v1.1 From 3c91fe4d376f5ade41f321728d787dfddbf02131 Mon Sep 17 00:00:00 2001 From: andrew Date: Wed, 24 Jun 2015 16:18:58 +0000 Subject: Implement fpsetmask. Some third-party software makes use of it, for example perl. Obtained from: ABT Systems Ltd Sponsored by: The FreeBSD Foundation --- lib/libc/aarch64/Symbol.map | 1 + lib/libc/aarch64/gen/Makefile.inc | 1 + lib/libc/aarch64/gen/fpsetmask.c | 52 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 lib/libc/aarch64/gen/fpsetmask.c (limited to 'lib/libc') diff --git a/lib/libc/aarch64/Symbol.map b/lib/libc/aarch64/Symbol.map index a0b33da..e26785e 100644 --- a/lib/libc/aarch64/Symbol.map +++ b/lib/libc/aarch64/Symbol.map @@ -14,6 +14,7 @@ FBSD_1.0 { _setjmp; _longjmp; fabs; + fpsetmask; setjmp; longjmp; sigsetjmp; diff --git a/lib/libc/aarch64/gen/Makefile.inc b/lib/libc/aarch64/gen/Makefile.inc index c4f7c80..3d050dd 100644 --- a/lib/libc/aarch64/gen/Makefile.inc +++ b/lib/libc/aarch64/gen/Makefile.inc @@ -2,6 +2,7 @@ SRCS+= fabs.S \ flt_rounds.c \ + fpsetmask.c \ ldexp.c \ _setjmp.S \ _set_tp.c \ diff --git a/lib/libc/aarch64/gen/fpsetmask.c b/lib/libc/aarch64/gen/fpsetmask.c new file mode 100644 index 0000000..de9ac04 --- /dev/null +++ b/lib/libc/aarch64/gen/fpsetmask.c @@ -0,0 +1,52 @@ +/*- + * Copyright (c) 2015 The FreeBSD Foundation + * All rights reserved. + * + * This software was developed by Andrew Turner under + * sponsorship from the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include + +#define FP_X_MASK (FP_X_INV | FP_X_DZ | FP_X_OFL | FP_X_UFL | FP_X_IMP) + +fp_except_t +fpsetmask(fp_except_t mask) +{ + uint64_t old, new; + + mask &= FP_X_MASK; + + /* Read the current mask */ + __asm __volatile("mrs %0, fpcr" : "=&r"(old)); + new = old & ~FP_X_MASK; + new |= mask; + __asm __volatile("msr fpcr, %0" :: "r"(new)); + + return ((fp_except_t)old); +} -- cgit v1.1 From 181692959b46353e681fc551c44d4e0463d6c201 Mon Sep 17 00:00:00 2001 From: andrew Date: Thu, 25 Jun 2015 08:15:47 +0000 Subject: Export __flt_rounds from the arm64 libc.so --- lib/libc/aarch64/Symbol.map | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/libc') diff --git a/lib/libc/aarch64/Symbol.map b/lib/libc/aarch64/Symbol.map index e26785e..f51014d 100644 --- a/lib/libc/aarch64/Symbol.map +++ b/lib/libc/aarch64/Symbol.map @@ -14,6 +14,7 @@ FBSD_1.0 { _setjmp; _longjmp; fabs; + __flt_rounds; fpsetmask; setjmp; longjmp; -- cgit v1.1 From 7fb27dff73f269a96abdb7c8b708654ad80a9a52 Mon Sep 17 00:00:00 2001 From: andrew Date: Thu, 25 Jun 2015 08:22:25 +0000 Subject: Implement fpgetmask, it's needed by Python. Approved by: ABT Systems Ltd Sponsored by: The FreeBSD Foundation --- lib/libc/aarch64/Symbol.map | 1 + lib/libc/aarch64/gen/Makefile.inc | 1 + lib/libc/aarch64/gen/fpgetmask.c | 47 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 lib/libc/aarch64/gen/fpgetmask.c (limited to 'lib/libc') diff --git a/lib/libc/aarch64/Symbol.map b/lib/libc/aarch64/Symbol.map index f51014d..d0056ef 100644 --- a/lib/libc/aarch64/Symbol.map +++ b/lib/libc/aarch64/Symbol.map @@ -15,6 +15,7 @@ FBSD_1.0 { _longjmp; fabs; __flt_rounds; + fpgetmask; fpsetmask; setjmp; longjmp; diff --git a/lib/libc/aarch64/gen/Makefile.inc b/lib/libc/aarch64/gen/Makefile.inc index 3d050dd..bb70a36 100644 --- a/lib/libc/aarch64/gen/Makefile.inc +++ b/lib/libc/aarch64/gen/Makefile.inc @@ -2,6 +2,7 @@ SRCS+= fabs.S \ flt_rounds.c \ + fpgetmask.c \ fpsetmask.c \ ldexp.c \ _setjmp.S \ diff --git a/lib/libc/aarch64/gen/fpgetmask.c b/lib/libc/aarch64/gen/fpgetmask.c new file mode 100644 index 0000000..afc05b4 --- /dev/null +++ b/lib/libc/aarch64/gen/fpgetmask.c @@ -0,0 +1,47 @@ +/*- + * Copyright (c) 2015 The FreeBSD Foundation + * All rights reserved. + * + * This software was developed by Andrew Turner under + * sponsorship from the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include + +#define FP_X_MASK (FP_X_INV | FP_X_DZ | FP_X_OFL | FP_X_UFL | FP_X_IMP) + +fp_except_t +fpgetmask(void) +{ + uint64_t mask; + + /* Read the current mask */ + __asm __volatile("mrs %0, fpcr" : "=&r"(mask)); + + return (mask & FP_X_MASK); +} -- cgit v1.1 From 03c73d6a38adbcbeafa91923e96459aefb6188e8 Mon Sep 17 00:00:00 2001 From: kib Date: Tue, 30 Jun 2015 18:53:42 +0000 Subject: Document x86 machine-specific ptrace(2) requests. Provide list of the ppc requests. Reviewed by: brueffer, emaste, gjb (previous version) Sponsored by: The FreeBSD Foundation Review: https://reviews.freebsd.org/D2962 MFC after: 2 weeks --- lib/libc/sys/ptrace.2 | 177 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 175 insertions(+), 2 deletions(-) (limited to 'lib/libc') diff --git a/lib/libc/sys/ptrace.2 b/lib/libc/sys/ptrace.2 index 458ad8d..68bff29 100644 --- a/lib/libc/sys/ptrace.2 +++ b/lib/libc/sys/ptrace.2 @@ -2,7 +2,7 @@ .\" $NetBSD: ptrace.2,v 1.2 1995/02/27 12:35:37 cgd Exp $ .\" .\" This file is in the public domain. -.Dd July 22, 2013 +.Dd June 30, 2015 .Dt PTRACE 2 .Os .Sh NAME @@ -503,8 +503,161 @@ The .Fa data argument is ignored. .El +.Sh x86 MACHINE-SPECIFIC REQUESTS +.Bl -tag -width "Dv PT_GETXSTATE_INFO" +.It Dv PT_GETXMMREGS +Copies out the XMM FPU state into the buffer pointed to by the +argument +.Fa addr . +The buffer has the same layout as the 32bit save buffer for the +machine instruction +.Dv FXSAVE . +.Pp +This request is only valid for i386 programs, both on native 32bit +systems and on amd64 kernels. +For 64bit amd64 programs, the XMM state is reported as part of +the FPU state returned by the +.Dv PT_GETFPREGS +request. +.Pp +The +.Fa data +argument is ignored. +.It Dv PT_SETXMMREGS +Loads the XMM FPU state for the thread from the buffer pointed to +by the argument +.Fa addr . +The buffer has the same layout as the 32bit load buffer for the +machine instruction +.Dv FXRSTOR . +.Pp +As with +.Dv PT_GETXMMREGS, +this request is only valid for i386 programs. +.Pp +The +.Fa data +argument is ignored. +.It Dv PT_GETXSTATE_INFO +Returns the information about the enablement state of the XSAVE FPU +extensions supported by the CPU and allowed by the OS for use by userspace +programs. +The +.Fa addr +argument must point to the variable of type +.Vt struct ptrace_xstate_info , +which contains the information on the request return. +The +.Vt struct ptrace_xstate_info +is defined as follows: +.Bd -literal +struct ptrace_xstate_info { + uint64_t xsave_mask; + uint32_t xsave_len; +}; +.Ed +The +.Dv xsave_mask +field is the bitmask of the currently enabled extensions. +The meaning of the bits is defined by the Intel and AMD +processor documentation. +The +.Dv xsave_len +field reports the length of the XSAVE area for storing the hardware +state for currently enabled extensions in the format defined by the x86 +.Dv XSAVE +machine instruction. +.Pp +The +.Fa data +argument value must be equal to the size of the +.Vt struct ptrace_xstate_info . +.It Dv PT_GETXSTATE +Returns the content of the XSAVE area for the thread. +The +.Fa addr +argument points to the buffer where the content is copied, the +.Fa data +argument specifies the size of the buffer. +The kernel copies out as much content as allowed by the buffer size. +The buffer layout is specified by the layout of the save area for the +.Dv XSAVE +machine instruction. +.It Dv PT_SETXSTATE +Load the XSAVE state for the thread from the buffer specified by the +.Fa addr +pointer. +The buffer size is passed in the +.Fa data +argument. +The buffer must be at least as large to allow the x87 FPU and XMM state, +but not large than the XSAVE state length, as reported by the +.Dv xsave_len +field from the +.Vt struct ptrace_xstate_info +of the +.Dv PT_GETXSTATE_INFO +request. +Layout of the buffer is identical to the layout of the load area for the +.Dv XRSTOR +machine instruction. +.It Dv PT_GETFSBASE +The request returns the value of base used when doing segmented +memory addressing using the %fs segment register. +The +.Fa addr +argument points to the +.Vt unsigned long +variable which gets the base value. +.Pp +The +.Fa data +argument is ignored. +.It Dv PT_GETGSBASE +Same as the +.Dv PT_GETFSBASE +request, but returns the base for the %gs segment register. +.It Dv PT_SETFSBASE +Sets the base for the %fs segment register to the value pointed +by the +.Fa addr +argument, which must point to the +.Vt unsigned long +variable containing the new base. +.Pp +The +.Fa data +argument is ignored. +.It Dv PT_SETGSBASE +Same as the +.Dv PT_SETFSBASE +request, but allows setting the base for the %gs segment register. +.El +.Sh PowerPC MACHINE-SPECIFIC REQUESTS +.Bl -tag -width "Dv PT_SETVRREGS" +.It Dv PT_GETVRREGS +Returns the +.Dv ALTIVEC +machine state for the thread into the buffer pointed to by +the argument +.Fa addr . .Pp -Additionally, machine-specific requests can exist. +The +.Fa data +argument is ignored. +.It Dv PT_SETVRREGS +Set the +.Dv ALTIVEC +machine state for the thread from the buffer pointed to by +the argument +.Fa addr . +.Pp +The +.Fa data +argument is ignored. +.El +.Pp +Additionally, other machine-specific requests can exist. .Sh RETURN VALUES Some requests can cause .Fn ptrace @@ -564,6 +717,26 @@ provided to was less than or equal to zero, or larger than the .Vt ptrace_lwpinfo structure known to the kernel. +.It +The size (in +.Fa data) +provided to the x86-specific +.Dv PT_GETXSTATE_INFO +request was not equal to the size of the +.Vt struct ptrace_xstate_info . +.It +The size (in +.Fa data) +provided to the x86-specific +.Dv PT_SETXSTATE +request was less than the size of the x87 + XMM save area, +or larger than returned in the +.Dv xsave_len +member of the +.Vt struct ptrace_xstate_info +from the +.Dv PT_GETXSTATE_INFO +request. .El .It Bq Er EBUSY .Bl -bullet -compact -- cgit v1.1 From edb38c81905afb7251f87bdb60a5f9669bd2bd88 Mon Sep 17 00:00:00 2001 From: andrew Date: Thu, 2 Jul 2015 14:54:21 +0000 Subject: Cleanup brk and sbrk to use the same code to find curbrk and minbrk when both compiling for PIC and non-PIC. Sponsored by: ABT Systems Ltd --- lib/libc/aarch64/Symbol.map | 1 + lib/libc/aarch64/sys/brk.S | 29 ++++++----------------------- lib/libc/aarch64/sys/sbrk.S | 19 ++++++------------- 3 files changed, 13 insertions(+), 36 deletions(-) (limited to 'lib/libc') diff --git a/lib/libc/aarch64/Symbol.map b/lib/libc/aarch64/Symbol.map index d0056ef..3d8ad25 100644 --- a/lib/libc/aarch64/Symbol.map +++ b/lib/libc/aarch64/Symbol.map @@ -28,6 +28,7 @@ FBSD_1.0 { FBSDprivate_1.0 { _set_tp; + _end; curbrk; minbrk; }; diff --git a/lib/libc/aarch64/sys/brk.S b/lib/libc/aarch64/sys/brk.S index 09167b6..1e9a215 100644 --- a/lib/libc/aarch64/sys/brk.S +++ b/lib/libc/aarch64/sys/brk.S @@ -32,6 +32,8 @@ __FBSDID("$FreeBSD$"); #include "SYS.h" + .globl _C_LABEL(_end) + .data .align 3 .globl _C_LABEL(minbrk) @@ -47,15 +49,8 @@ ENTRY(_brk) WEAK_REFERENCE(_brk, brk) /* Load the address of minbrk */ -#ifdef __PIC__ - adrp x2, :got:minbrk - ldr x3, [x2, #:got_lo12:minbrk] -#else - ldr x3, .Lminbrk -#endif - - /* Get the minimum allowable brk address */ - ldr x2, [x3] + adrp x3, minbrk + ldr x2, [x3, :lo12:minbrk] /* Validate the address */ cmp x0, x2 @@ -70,24 +65,12 @@ ENTRY(_brk) _SYSCALL(break) b.cs cerror -#ifdef __PIC__ - adrp x2, :got:curbrk - ldr x3, [x2, #:got_lo12:curbrk] -#else - ldr x3, .Lcurbrk -#endif - /* Store the new curbrk value */ - str x4, [x3] + adrp x2, curbrk + str x4, [x2, :lo12:curbrk] /* Return success */ mov x0, #0 ret -#ifndef __PIC__ -.Lcurbrk: - .quad _C_LABEL(curbrk) -.Lminbrk: - .quad _C_LABEL(minbrk) -#endif END(_brk) diff --git a/lib/libc/aarch64/sys/sbrk.S b/lib/libc/aarch64/sys/sbrk.S index db9d7e1..4880cc2 100644 --- a/lib/libc/aarch64/sys/sbrk.S +++ b/lib/libc/aarch64/sys/sbrk.S @@ -32,6 +32,8 @@ __FBSDID("$FreeBSD$"); #include "SYS.h" + .globl _C_LABEL(_end) + .data .align 3 .global _C_LABEL(curbrk) @@ -47,15 +49,10 @@ ENTRY(_sbrk) WEAK_REFERENCE(_sbrk, sbrk) /* Load the address of curbrk */ -#ifdef __PIC__ - adrp x2, :got:curbrk - ldr x3, [x2, #:got_lo12:curbrk] -#else - ldr x3, .Lcurbrk -#endif + adrp x3, curbrk /* Get the current brk address */ - ldr x2, [x3] + ldr x2, [x3, :lo12:curbrk] /* Calculate the new value */ add x0, x2, x0 @@ -66,14 +63,10 @@ ENTRY(_sbrk) b.cs cerror /* Load the old value to return */ - ldr x0, [x3] + ldr x0, [x3, :lo12:curbrk] /* Store the new curbrk value */ - str x4, [x3] + str x4, [x3, :lo12:curbrk] ret -#ifndef __PIC__ -.Lcurbrk: - .quad _C_LABEL(curbrk) -#endif END(_sbrk) -- cgit v1.1 From 06c28ee0717b26e72018e2a5c5bf321facc78f32 Mon Sep 17 00:00:00 2001 From: kib Date: Fri, 3 Jul 2015 17:30:31 +0000 Subject: Grammar and language fixes. Submitted by: wblock Review: https://reviews.freebsd.org/D2969 MFC after: 12 days --- lib/libc/sys/ptrace.2 | 86 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 50 insertions(+), 36 deletions(-) (limited to 'lib/libc') diff --git a/lib/libc/sys/ptrace.2 b/lib/libc/sys/ptrace.2 index 68bff29..71b432f 100644 --- a/lib/libc/sys/ptrace.2 +++ b/lib/libc/sys/ptrace.2 @@ -2,7 +2,7 @@ .\" $NetBSD: ptrace.2,v 1.2 1995/02/27 12:35:37 cgd Exp $ .\" .\" This file is in the public domain. -.Dd June 30, 2015 +.Dd July 3, 2015 .Dt PTRACE 2 .Os .Sh NAME @@ -506,16 +506,16 @@ argument is ignored. .Sh x86 MACHINE-SPECIFIC REQUESTS .Bl -tag -width "Dv PT_GETXSTATE_INFO" .It Dv PT_GETXMMREGS -Copies out the XMM FPU state into the buffer pointed to by the +Copy the XMM FPU state into the buffer pointed to by the argument .Fa addr . -The buffer has the same layout as the 32bit save buffer for the +The buffer has the same layout as the 32-bit save buffer for the machine instruction .Dv FXSAVE . .Pp -This request is only valid for i386 programs, both on native 32bit +This request is only valid for i386 programs, both on native 32-bit systems and on amd64 kernels. -For 64bit amd64 programs, the XMM state is reported as part of +For 64-bit amd64 programs, the XMM state is reported as part of the FPU state returned by the .Dv PT_GETFPREGS request. @@ -524,10 +524,10 @@ The .Fa data argument is ignored. .It Dv PT_SETXMMREGS -Loads the XMM FPU state for the thread from the buffer pointed to +Load the XMM FPU state for the thread from the buffer pointed to by the argument .Fa addr . -The buffer has the same layout as the 32bit load buffer for the +The buffer has the same layout as the 32-bit load buffer for the machine instruction .Dv FXRSTOR . .Pp @@ -539,15 +539,13 @@ The .Fa data argument is ignored. .It Dv PT_GETXSTATE_INFO -Returns the information about the enablement state of the XSAVE FPU -extensions supported by the CPU and allowed by the OS for use by userspace -programs. +Report which XSAVE FPU extensions are supported by the CPU +and allowed in userspace programs. The .Fa addr -argument must point to the variable of type +argument must point to a variable of type .Vt struct ptrace_xstate_info , which contains the information on the request return. -The .Vt struct ptrace_xstate_info is defined as follows: .Bd -literal @@ -558,8 +556,8 @@ struct ptrace_xstate_info { .Ed The .Dv xsave_mask -field is the bitmask of the currently enabled extensions. -The meaning of the bits is defined by the Intel and AMD +field is a bitmask of the currently enabled extensions. +The meaning of the bits is defined in the Intel and AMD processor documentation. The .Dv xsave_len @@ -573,10 +571,10 @@ The argument value must be equal to the size of the .Vt struct ptrace_xstate_info . .It Dv PT_GETXSTATE -Returns the content of the XSAVE area for the thread. +Return the content of the XSAVE area for the thread. The .Fa addr -argument points to the buffer where the content is copied, the +argument points to the buffer where the content is copied, and the .Fa data argument specifies the size of the buffer. The kernel copies out as much content as allowed by the buffer size. @@ -590,8 +588,12 @@ pointer. The buffer size is passed in the .Fa data argument. -The buffer must be at least as large to allow the x87 FPU and XMM state, -but not large than the XSAVE state length, as reported by the +The buffer must be at least as large as the +.Vt struct savefpu +(defined in +.Pa x86/fpu.h ) +to allow the complete x87 FPU and XMM state load. +It must not be larger than the XSAVE state length, as reported by the .Dv xsave_len field from the .Vt struct ptrace_xstate_info @@ -602,26 +604,28 @@ Layout of the buffer is identical to the layout of the load area for the .Dv XRSTOR machine instruction. .It Dv PT_GETFSBASE -The request returns the value of base used when doing segmented +Return the value of the base used when doing segmented memory addressing using the %fs segment register. The .Fa addr -argument points to the +argument points to an .Vt unsigned long -variable which gets the base value. +variable where the base value is stored. .Pp The .Fa data argument is ignored. .It Dv PT_GETGSBASE -Same as the +Like the .Dv PT_GETFSBASE request, but returns the base for the %gs segment register. .It Dv PT_SETFSBASE -Sets the base for the %fs segment register to the value pointed +Set the base for the %fs segment register to the value pointed to by the .Fa addr -argument, which must point to the +argument. +.Fa addr +must point to the .Vt unsigned long variable containing the new base. .Pp @@ -629,27 +633,25 @@ The .Fa data argument is ignored. .It Dv PT_SETGSBASE -Same as the +Like the .Dv PT_SETFSBASE -request, but allows setting the base for the %gs segment register. +request, but sets the base for the %gs segment register. .El .Sh PowerPC MACHINE-SPECIFIC REQUESTS .Bl -tag -width "Dv PT_SETVRREGS" .It Dv PT_GETVRREGS -Returns the +Return the thread's .Dv ALTIVEC -machine state for the thread into the buffer pointed to by -the argument +machine state in the buffer pointed to by .Fa addr . .Pp The .Fa data argument is ignored. .It Dv PT_SETVRREGS -Set the +Set the thread's .Dv ALTIVEC -machine state for the thread from the buffer pointed to by -the argument +machine state from the buffer pointed to by .Fa addr . .Pp The @@ -719,24 +721,36 @@ was less than or equal to zero, or larger than the structure known to the kernel. .It The size (in -.Fa data) +.Fa data ) provided to the x86-specific .Dv PT_GETXSTATE_INFO request was not equal to the size of the .Vt struct ptrace_xstate_info . .It The size (in -.Fa data) +.Fa data ) +provided to the x86-specific +.Dv PT_SETXSTATE +request was less than the size of the x87 plus the XMM save area. +.It +The size (in +.Fa data ) provided to the x86-specific .Dv PT_SETXSTATE -request was less than the size of the x87 + XMM save area, -or larger than returned in the +request was larger than returned in the .Dv xsave_len member of the .Vt struct ptrace_xstate_info from the .Dv PT_GETXSTATE_INFO request. +.It +The base value, provided to the amd64-specific requests +.Dv PT_SETFSBASE +or +.Dv PT_SETGSBASE , +pointed outside of the valid user address space. +This error will not occur in 32-bit programs. .El .It Bq Er EBUSY .Bl -bullet -compact -- cgit v1.1 From e1ffe0f912feb756dc9cddef6953a09a9e9d6605 Mon Sep 17 00:00:00 2001 From: oshogbo Date: Sat, 4 Jul 2015 16:42:14 +0000 Subject: Add fdclose(3) function. This function is equivalent to fclose(3) function except that it does not close the underlying file descriptor. fdclose(3) is step forward to make FILE structure private. Reviewed by: wblock, jilles, jhb, pjd Approved by: pjd (mentor) Differential Revision: https://reviews.freebsd.org/D2697 --- lib/libc/stdio/Symbol.map | 4 +++ lib/libc/stdio/fclose.3 | 82 ++++++++++++++++++++++++++++++++++++++--------- lib/libc/stdio/fclose.c | 75 ++++++++++++++++++++++++++++++++++++------- 3 files changed, 134 insertions(+), 27 deletions(-) (limited to 'lib/libc') diff --git a/lib/libc/stdio/Symbol.map b/lib/libc/stdio/Symbol.map index d2a8c92..a332ab2 100644 --- a/lib/libc/stdio/Symbol.map +++ b/lib/libc/stdio/Symbol.map @@ -162,6 +162,10 @@ FBSD_1.3 { mkostemps; }; +FBSD_1.4 { + fdclose; +}; + FBSDprivate_1.0 { _flockfile; _flockfile_debug_stub; diff --git a/lib/libc/stdio/fclose.3 b/lib/libc/stdio/fclose.3 index 883aa10..596ee3d 100644 --- a/lib/libc/stdio/fclose.3 +++ b/lib/libc/stdio/fclose.3 @@ -1,5 +1,6 @@ -.\" Copyright (c) 1990, 1991, 1993 -.\" The Regents of the University of California. All rights reserved. +.\" Copyright (c) 1990, 1991, 1993 The Regents of the University of California. +.\" Copyright (c) 2015 Mariusz Zaborski +.\" All rights reserved. .\" .\" This code is derived from software contributed to Berkeley by .\" Chris Torek and the American National Standards Committee X3, @@ -32,11 +33,12 @@ .\" @(#)fclose.3 8.1 (Berkeley) 6/4/93 .\" $FreeBSD$ .\" -.Dd April 22, 2006 +.Dd July 4, 2015 .Dt FCLOSE 3 .Os .Sh NAME .Nm fclose , +.Nm fdclose , .Nm fcloseall .Nd close a stream .Sh LIBRARY @@ -45,6 +47,8 @@ .In stdio.h .Ft int .Fn fclose "FILE *stream" +.Ft int +.Fn fdclose "FILE *stream" "int *fdp" .Ft void .Fn fcloseall void .Sh DESCRIPTION @@ -59,36 +63,77 @@ first, using .Xr fflush 3 . .Pp The +.Fn fdclose +function is equivalent to +.Fn fclose +except that it does not close the underlying file descriptor. +If +.Fa fdp +is not +.Dv NULL , +the file descriptor will be written to it. +If the +.Fa fdp +argument will be different then NULL the file descriptor will be returned in it, +If the stream does not have an associated file descriptor, +.Fa fdp +will be set to -1. +This type of stream is created with functions such as +.Xr fmemopen 3 , +.Xr funopen 3 , +or +.Xr open_memstream 3 . +.Pp +The .Fn fcloseall function calls .Fn fclose on all open streams. .Sh RETURN VALUES -Upon successful completion 0 is returned. +.Fn fcloseall +does not return a value. +.Pp +Upon successful completion the +.Fn fclose +and +.Fn fdclose +functions return 0. Otherwise, .Dv EOF is returned and the global variable .Va errno is set to indicate the error. -In either case no further access to the stream is possible. .Sh ERRORS +.Fn fdclose +fails if: +.Bl -tag -width Er +.It Bq Er EOPNOTSUPP +The stream does not have an associated file descriptor. +.El +.Pp The .Fn fclose -function -may also fail and set +and +.Fn fdclose +functions may also fail and set .Va errno -for any of the errors specified for the routines -.Xr close 2 -or +for any of the errors specified for .Xr fflush 3 . +.Pp +The +.Fn fclose +function may also fail and set errno for any of the errors specified for +.Xr close 2 . .Sh NOTES The .Fn fclose -function -does not handle NULL arguments; they will result in a segmentation -violation. -This is intentional - it makes it easier to make sure programs written -under +and +.Fn fdclose +functions do not handle NULL arguments in the +.Fa stream +variable; this will result in a segmentation violation. +This is intentional. +It makes it easier to make sure programs written under .Fx are bug free. This behaviour is an implementation detail, and programs should not @@ -104,8 +149,13 @@ The function conforms to .St -isoC . -.Pp +.Sh HISTORY The .Fn fcloseall function first appeared in .Fx 7.0 . +.Pp +The +.Fn fdclose +function first appeared in +.Fx 11.0 . diff --git a/lib/libc/stdio/fclose.c b/lib/libc/stdio/fclose.c index 5ed8b2c..24b9b90 100644 --- a/lib/libc/stdio/fclose.c +++ b/lib/libc/stdio/fclose.c @@ -1,6 +1,7 @@ /*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. + * Copyright (c) 1990, 1993 The Regents of the University of California. + * Copyright (c) 2013 Mariusz Zaborski + * All rights reserved. * * This code is derived from software contributed to Berkeley by * Chris Torek. @@ -38,6 +39,7 @@ __FBSDID("$FreeBSD$"); #include "namespace.h" #include +#include #include #include #include "un-namespace.h" @@ -45,19 +47,17 @@ __FBSDID("$FreeBSD$"); #include "libc_private.h" #include "local.h" -int -fclose(FILE *fp) +static int +cleanfile(FILE *fp, bool c) { int r; - if (fp->_flags == 0) { /* not open! */ - errno = EBADF; - return (EOF); - } - FLOCKFILE(fp); r = fp->_flags & __SWR ? __sflush(fp) : 0; - if (fp->_close != NULL && (*fp->_close)(fp->_cookie) < 0) - r = EOF; + if (c) { + if (fp->_close != NULL && (*fp->_close)(fp->_cookie) < 0) + r = EOF; + } + if (fp->_flags & __SMBF) free((char *)fp->_bf._base); if (HASUB(fp)) @@ -80,6 +80,59 @@ fclose(FILE *fp) STDIO_THREAD_LOCK(); fp->_flags = 0; /* Release this FILE for reuse. */ STDIO_THREAD_UNLOCK(); + + return (r); +} + +int +fdclose(FILE *fp, int *fdp) +{ + int r, err; + + if (fdp != NULL) + *fdp = -1; + + if (fp->_flags == 0) { /* not open! */ + errno = EBADF; + return (EOF); + } + + FLOCKFILE(fp); + r = 0; + if (fp->_close != __sclose) { + r = EOF; + errno = EOPNOTSUPP; + } else if (fp->_file < 0) { + r = EOF; + errno = EBADF; + } + if (r == EOF) { + err = errno; + (void)cleanfile(fp, true); + errno = err; + } else { + if (fdp != NULL) + *fdp = fp->_file; + r = cleanfile(fp, false); + } FUNLOCKFILE(fp); + + return (r); +} + +int +fclose(FILE *fp) +{ + int r; + + if (fp->_flags == 0) { /* not open! */ + errno = EBADF; + return (EOF); + } + + FLOCKFILE(fp); + r = cleanfile(fp, true); + FUNLOCKFILE(fp); + return (r); } -- cgit v1.1