From owner-freebsd-bugs@freebsd.org Mon Feb 8 06:42:37 2021 Return-Path: Delivered-To: freebsd-bugs@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 9170A547658 for ; Mon, 8 Feb 2021 06:42:37 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from mailman.nyi.freebsd.org (mailman.nyi.freebsd.org [IPv6:2610:1c1:1:606c::50:13]) by mx1.freebsd.org (Postfix) with ESMTP id 4DYxKT3XMXz4lM8 for ; Mon, 8 Feb 2021 06:42:37 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: by mailman.nyi.freebsd.org (Postfix) id 7947B5475AE; Mon, 8 Feb 2021 06:42:37 +0000 (UTC) Delivered-To: bugs@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 790E45475AD for ; Mon, 8 Feb 2021 06:42:37 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4DYxKT2sf0z4lNm for ; Mon, 8 Feb 2021 06:42:37 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org (kenobi.freebsd.org [IPv6:2610:1c1:1:606c::50:1d]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4B5A4128F0 for ; Mon, 8 Feb 2021 06:42:37 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org ([127.0.1.5]) by kenobi.freebsd.org (8.15.2/8.15.2) with ESMTP id 1186gbPa037198 for ; Mon, 8 Feb 2021 06:42:37 GMT (envelope-from bugzilla-noreply@freebsd.org) Received: (from www@localhost) by kenobi.freebsd.org (8.15.2/8.15.2/Submit) id 1186gb0E037197 for bugs@FreeBSD.org; Mon, 8 Feb 2021 06:42:37 GMT (envelope-from bugzilla-noreply@freebsd.org) X-Authentication-Warning: kenobi.freebsd.org: www set sender to bugzilla-noreply@freebsd.org using -f From: bugzilla-noreply@freebsd.org To: bugs@FreeBSD.org Subject: [Bug 253337] Linuxulator: glibc's pthread_getattr_np reports stack size as 124K Date: Mon, 08 Feb 2021 06:42:37 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: kern X-Bugzilla-Version: Unspecified X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Only Me X-Bugzilla-Who: iwtcex@gmail.com X-Bugzilla-Status: New X-Bugzilla-Resolution: X-Bugzilla-Priority: --- X-Bugzilla-Assigned-To: bugs@FreeBSD.org X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version rep_platform op_sys bug_status bug_severity priority component assigned_to reporter Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 08 Feb 2021 06:42:37 -0000 https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D253337 Bug ID: 253337 Summary: Linuxulator: glibc's pthread_getattr_np reports stack size as 124K Product: Base System Version: Unspecified Hardware: Any OS: Any Status: New Severity: Affects Only Me Priority: --- Component: kern Assignee: bugs@FreeBSD.org Reporter: iwtcex@gmail.com I think it should return a value equal or slightly smaller than RLIMIT_STACK instead. It does so on Ubuntu at least. Apparently, Mono (most notably used in the popular Unity game engine) relies on this for setting stack guards: https://github.com/mono/mono/blob/da11592cbea4269971f4b1f9624769a85cc10660/= mono/utils/mono-threads-linux.c#L13-L38, https://github.com/mono/mono/blob/43190aeb5f7e4d7e0185d3b656054bf232219fe2/= mono/mini/mini-exceptions.c#L3160-L3175. Reproducer: % uname -a FreeBSD desktop 12.2-RELEASE-p1 FreeBSD 12.2-RELEASE-p1 GENERIC amd64 % cat apparent_stack_size.c #define _GNU_SOURCE #include #include #include #include #include int main() { char cmd[100]; snprintf(cmd, sizeof(cmd), "cat /proc/%d/maps | tail -n 5", getpid()); system(cmd); size_t size =3D 0; void* addr =3D NULL; pthread_attr_t attr; assert(pthread_attr_init(&attr) =3D=3D 0); assert(pthread_getattr_np(pthread_self(), &attr) =3D=3D 0); assert(pthread_attr_getstack(&attr, &addr, &size) =3D=3D 0); assert(pthread_attr_destroy(&attr) =3D=3D 0); fprintf(stderr, "stack size =3D %zd\n", size); return 0; } % /compat/linux/bin/cc apparent_stack_size.c -pthread -o test % ./test 00000008011c7000-00000008011c9000 rw-p 0038a000 00:00 391497=20=20=20=20 /compat/linux/usr/lib64/libc-2.17.so 00000008011c9000-00000008011ce000 rw-p 00000000 00:00 0 00007fffdffff000-00007ffffffdf000 ---p 00000000 00:00 0 00007ffffffdf000-00007ffffffff000 rw-p 00000000 00:00 0 [stack] 00007ffffffff000-0000800000000000 r-xs 00000000 00:00 0 [vdso] stack size =3D 126976 As it happens, glibc reads /proc/self/maps and compares the stack entry to the preceding entry. You know, just in case: /* The limit might be too high. */ if ((size_t) iattr->stacksize > (size_t) iattr->stackaddr - last_to) iattr->stacksize =3D (size_t) iattr->stackaddr - last_to; (https://sourceware.org/git/?p=3Dglibc.git;a=3Dblob;f=3Dnptl/pthread_getatt= r_np.c;h=3D25807cb529880d67a6561b6ebcd45042e89dea3e;hb=3DHEAD#l144) --=20 You are receiving this mail because: You are the assignee for the bug.=