From 2eb890bde31495cdd90423fcfbc789351ca56ec6 Mon Sep 17 00:00:00 2001 From: Cherry Mui Date: Tue, 17 Feb 2026 10:22:16 -0500 Subject: all: use LF line ending for C files For Go files, gofmt already converts CRLF line ending to LF. For C and assembly files, we don't enforce a format, but most files in tree are written with LF line ending, and the C toolchain can handle them file, even on Windows. Convert all to LF line ending for consistency. Will look into adding a test for them. Updates #9281. Change-Id: Idc0dc13f0ab90b8cd8ea118abf9cb195ec438fe7 Reviewed-on: https://go-review.googlesource.com/c/go/+/746220 Reviewed-by: Mark Freeman Reviewed-by: Quim Muntal LUCI-TryBot-Result: Go LUCI --- src/runtime/cgo/gcc_freebsd.c | 32 ++-- src/runtime/cgo/gcc_netbsd.c | 52 +++--- src/runtime/cgo/pthread_unix.c | 276 ++++++++++++++--------------- src/runtime/testdata/testwinlibthrow/veh.c | 52 +++--- 4 files changed, 206 insertions(+), 206 deletions(-) (limited to 'src/runtime') diff --git a/src/runtime/cgo/gcc_freebsd.c b/src/runtime/cgo/gcc_freebsd.c index 606d6bd591..e4e2577a94 100644 --- a/src/runtime/cgo/gcc_freebsd.c +++ b/src/runtime/cgo/gcc_freebsd.c @@ -1,16 +1,16 @@ -// Copyright 2009 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -//go:build freebsd - -#include - -#ifdef ARM_TP_ADDRESS -// ARM_TP_ADDRESS is (ARM_VECTORS_HIGH + 0x1000) or 0xffff1000 -// and is known to runtime.read_tls_fallback. Verify it with -// cpp. -#if ARM_TP_ADDRESS != 0xffff1000 -#error Wrong ARM_TP_ADDRESS! -#endif -#endif +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//go:build freebsd + +#include + +#ifdef ARM_TP_ADDRESS +// ARM_TP_ADDRESS is (ARM_VECTORS_HIGH + 0x1000) or 0xffff1000 +// and is known to runtime.read_tls_fallback. Verify it with +// cpp. +#if ARM_TP_ADDRESS != 0xffff1000 +#error Wrong ARM_TP_ADDRESS! +#endif +#endif diff --git a/src/runtime/cgo/gcc_netbsd.c b/src/runtime/cgo/gcc_netbsd.c index 4e92c86f86..aa41d295a4 100644 --- a/src/runtime/cgo/gcc_netbsd.c +++ b/src/runtime/cgo/gcc_netbsd.c @@ -1,26 +1,26 @@ -// Copyright 2009 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -//go:build netbsd - -#include -#include - -static void -threadentry_platform(void) -{ - // On NetBSD, a new thread inherits the signal stack of the - // creating thread. That confuses minit, so we remove that - // signal stack here before calling the regular mstart. It's - // a bit baroque to remove a signal stack here only to add one - // in minit, but it's a simple change that keeps NetBSD - // working like other OS's. At this point all signals are - // blocked, so there is no race. - stack_t ss; - memset(&ss, 0, sizeof ss); - ss.ss_flags = SS_DISABLE; - sigaltstack(&ss, NULL); -} - -void (*x_cgo_threadentry_platform)(void) = threadentry_platform; +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//go:build netbsd + +#include +#include + +static void +threadentry_platform(void) +{ + // On NetBSD, a new thread inherits the signal stack of the + // creating thread. That confuses minit, so we remove that + // signal stack here before calling the regular mstart. It's + // a bit baroque to remove a signal stack here only to add one + // in minit, but it's a simple change that keeps NetBSD + // working like other OS's. At this point all signals are + // blocked, so there is no race. + stack_t ss; + memset(&ss, 0, sizeof ss); + ss.ss_flags = SS_DISABLE; + sigaltstack(&ss, NULL); +} + +void (*x_cgo_threadentry_platform)(void) = threadentry_platform; diff --git a/src/runtime/cgo/pthread_unix.c b/src/runtime/cgo/pthread_unix.c index 7b5248817a..a2fe16619e 100644 --- a/src/runtime/cgo/pthread_unix.c +++ b/src/runtime/cgo/pthread_unix.c @@ -1,138 +1,138 @@ -// Copyright 2025 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -//go:build unix - -#ifndef _GNU_SOURCE // pthread_getattr_np -#define _GNU_SOURCE -#endif - -#include -#include -#include -#include -#include "libcgo.h" -#include "libcgo_unix.h" - -void -_cgo_sys_thread_start(ThreadStart *ts) -{ - pthread_attr_t attr; - sigset_t ign, oset; - pthread_t p; - size_t size; - int err; - - sigfillset(&ign); - pthread_sigmask(SIG_SETMASK, &ign, &oset); - - pthread_attr_init(&attr); - pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); -#if defined(__APPLE__) - // Copy stack size from parent thread instead of using the - // non-main thread default stack size. - size = pthread_get_stacksize_np(pthread_self()); - pthread_attr_setstacksize(&attr, size); -#else - pthread_attr_getstacksize(&attr, &size); -#endif - -#if defined(__sun) - // Solaris can report 0 stack size, fix it. - if (size == 0) { - size = 2 << 20; - if (pthread_attr_setstacksize(&attr, size) != 0) { - perror("runtime/cgo: pthread_attr_setstacksize failed"); - } - } -#endif - - // Leave stacklo=0 and set stackhi=size; mstart will do the rest. - ts->g->stackhi = size; - err = _cgo_try_pthread_create(&p, &attr, threadentry, ts); - - pthread_sigmask(SIG_SETMASK, &oset, nil); - - if (err != 0) { - fatalf("pthread_create failed: %s", strerror(err)); - } -} - -void -x_cgo_sys_thread_create(void* (*func)(void*), void* arg) { - pthread_attr_t attr; - pthread_t p; - int err; - - pthread_attr_init(&attr); - pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); - err = _cgo_try_pthread_create(&p, &attr, func, arg); - if (err != 0) { - fatalf("pthread_create failed: %s", strerror(err)); - } -} - -void -x_cgo_getstackbound(uintptr bounds[2]) -{ - pthread_attr_t attr; - void *addr; - size_t size; - - // Needed before pthread_getattr_np, too, since before glibc 2.32 - // it did not call pthread_attr_init in all cases (see #65625). - pthread_attr_init(&attr); -#if defined(__APPLE__) - // On macOS/iOS, use the non-portable pthread_get_stackaddr_np - // and pthread_get_stacksize_np APIs (high address + size). - addr = pthread_get_stackaddr_np(pthread_self()); - size = pthread_get_stacksize_np(pthread_self()); - addr = (void*)((uintptr)addr - size); // convert to low address -#elif defined(__GLIBC__) || defined(__BIONIC__) || (defined(__sun) && !defined(__illumos__)) - // pthread_getattr_np is a GNU extension supported in glibc. - // Solaris is not glibc but does support pthread_getattr_np - // (and the fallback doesn't work...). Illumos does not. - pthread_getattr_np(pthread_self(), &attr); // GNU extension - pthread_attr_getstack(&attr, &addr, &size); // low address -#elif defined(__illumos__) - pthread_attr_get_np(pthread_self(), &attr); - pthread_attr_getstack(&attr, &addr, &size); // low address -#else - // We don't know how to get the current stacks, leave it as - // 0 and the caller will use an estimate based on the current - // SP. - addr = 0; - size = 0; -#endif - pthread_attr_destroy(&attr); - - // bounds points into the Go stack. TSAN can't see the synchronization - // in Go around stack reuse. - _cgo_tsan_acquire(); - bounds[0] = (uintptr)addr; - bounds[1] = (uintptr)addr + size; - _cgo_tsan_release(); -} - -// _cgo_try_pthread_create retries pthread_create if it fails with EAGAIN. -int -_cgo_try_pthread_create(pthread_t* thread, const pthread_attr_t* attr, void* (*pfn)(void*), void* arg) { - int tries; - int err; - struct timespec ts; - - for (tries = 0; tries < 20; tries++) { - err = pthread_create(thread, attr, pfn, arg); - if (err == 0) { - return 0; - } - if (err != EAGAIN) { - return err; - } - ts.tv_sec = 0; - ts.tv_nsec = (tries + 1) * 1000 * 1000; // Milliseconds. - nanosleep(&ts, nil); - } - return EAGAIN; -} +// Copyright 2025 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//go:build unix + +#ifndef _GNU_SOURCE // pthread_getattr_np +#define _GNU_SOURCE +#endif + +#include +#include +#include +#include +#include "libcgo.h" +#include "libcgo_unix.h" + +void +_cgo_sys_thread_start(ThreadStart *ts) +{ + pthread_attr_t attr; + sigset_t ign, oset; + pthread_t p; + size_t size; + int err; + + sigfillset(&ign); + pthread_sigmask(SIG_SETMASK, &ign, &oset); + + pthread_attr_init(&attr); + pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); +#if defined(__APPLE__) + // Copy stack size from parent thread instead of using the + // non-main thread default stack size. + size = pthread_get_stacksize_np(pthread_self()); + pthread_attr_setstacksize(&attr, size); +#else + pthread_attr_getstacksize(&attr, &size); +#endif + +#if defined(__sun) + // Solaris can report 0 stack size, fix it. + if (size == 0) { + size = 2 << 20; + if (pthread_attr_setstacksize(&attr, size) != 0) { + perror("runtime/cgo: pthread_attr_setstacksize failed"); + } + } +#endif + + // Leave stacklo=0 and set stackhi=size; mstart will do the rest. + ts->g->stackhi = size; + err = _cgo_try_pthread_create(&p, &attr, threadentry, ts); + + pthread_sigmask(SIG_SETMASK, &oset, nil); + + if (err != 0) { + fatalf("pthread_create failed: %s", strerror(err)); + } +} + +void +x_cgo_sys_thread_create(void* (*func)(void*), void* arg) { + pthread_attr_t attr; + pthread_t p; + int err; + + pthread_attr_init(&attr); + pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); + err = _cgo_try_pthread_create(&p, &attr, func, arg); + if (err != 0) { + fatalf("pthread_create failed: %s", strerror(err)); + } +} + +void +x_cgo_getstackbound(uintptr bounds[2]) +{ + pthread_attr_t attr; + void *addr; + size_t size; + + // Needed before pthread_getattr_np, too, since before glibc 2.32 + // it did not call pthread_attr_init in all cases (see #65625). + pthread_attr_init(&attr); +#if defined(__APPLE__) + // On macOS/iOS, use the non-portable pthread_get_stackaddr_np + // and pthread_get_stacksize_np APIs (high address + size). + addr = pthread_get_stackaddr_np(pthread_self()); + size = pthread_get_stacksize_np(pthread_self()); + addr = (void*)((uintptr)addr - size); // convert to low address +#elif defined(__GLIBC__) || defined(__BIONIC__) || (defined(__sun) && !defined(__illumos__)) + // pthread_getattr_np is a GNU extension supported in glibc. + // Solaris is not glibc but does support pthread_getattr_np + // (and the fallback doesn't work...). Illumos does not. + pthread_getattr_np(pthread_self(), &attr); // GNU extension + pthread_attr_getstack(&attr, &addr, &size); // low address +#elif defined(__illumos__) + pthread_attr_get_np(pthread_self(), &attr); + pthread_attr_getstack(&attr, &addr, &size); // low address +#else + // We don't know how to get the current stacks, leave it as + // 0 and the caller will use an estimate based on the current + // SP. + addr = 0; + size = 0; +#endif + pthread_attr_destroy(&attr); + + // bounds points into the Go stack. TSAN can't see the synchronization + // in Go around stack reuse. + _cgo_tsan_acquire(); + bounds[0] = (uintptr)addr; + bounds[1] = (uintptr)addr + size; + _cgo_tsan_release(); +} + +// _cgo_try_pthread_create retries pthread_create if it fails with EAGAIN. +int +_cgo_try_pthread_create(pthread_t* thread, const pthread_attr_t* attr, void* (*pfn)(void*), void* arg) { + int tries; + int err; + struct timespec ts; + + for (tries = 0; tries < 20; tries++) { + err = pthread_create(thread, attr, pfn, arg); + if (err == 0) { + return 0; + } + if (err != EAGAIN) { + return err; + } + ts.tv_sec = 0; + ts.tv_nsec = (tries + 1) * 1000 * 1000; // Milliseconds. + nanosleep(&ts, nil); + } + return EAGAIN; +} diff --git a/src/runtime/testdata/testwinlibthrow/veh.c b/src/runtime/testdata/testwinlibthrow/veh.c index 08c1f9edf0..0ab4c03bd4 100644 --- a/src/runtime/testdata/testwinlibthrow/veh.c +++ b/src/runtime/testdata/testwinlibthrow/veh.c @@ -1,26 +1,26 @@ -//go:build ignore - -#include - -__declspec(dllexport) -void RaiseNoExcept(void) -{ - RaiseException(42, 0, 0, 0); -} - -static DWORD WINAPI ThreadRaiser(void* Context) -{ - RaiseNoExcept(); - return 0; -} - -__declspec(dllexport) -void ThreadRaiseNoExcept(void) -{ - HANDLE thread = CreateThread(0, 0, ThreadRaiser, 0, 0, 0); - if (0 != thread) - { - WaitForSingleObject(thread, INFINITE); - CloseHandle(thread); - } -} +//go:build ignore + +#include + +__declspec(dllexport) +void RaiseNoExcept(void) +{ + RaiseException(42, 0, 0, 0); +} + +static DWORD WINAPI ThreadRaiser(void* Context) +{ + RaiseNoExcept(); + return 0; +} + +__declspec(dllexport) +void ThreadRaiseNoExcept(void) +{ + HANDLE thread = CreateThread(0, 0, ThreadRaiser, 0, 0, 0); + if (0 != thread) + { + WaitForSingleObject(thread, INFINITE); + CloseHandle(thread); + } +} -- cgit v1.3-5-g9baa