From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from forward101p.mail.yandex.net (forward101p.mail.yandex.net [IPv6:2a02:6b8:0:1472:2741:0:8b7:101]) by sourceware.org (Postfix) with ESMTPS id C66F63857C68 for ; Wed, 3 Mar 2021 06:40:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org C66F63857C68 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=yandex.ru Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=hi-angel@yandex.ru Received: from forward103q.mail.yandex.net (forward103q.mail.yandex.net [IPv6:2a02:6b8:c0e:50:0:640:b21c:d009]) by forward101p.mail.yandex.net (Yandex) with ESMTP id 6431F3282244; Wed, 3 Mar 2021 09:40:16 +0300 (MSK) Received: from vla1-d6ebb599434e.qloud-c.yandex.net (vla1-d6ebb599434e.qloud-c.yandex.net [IPv6:2a02:6b8:c0d:3008:0:640:d6eb:b599]) by forward103q.mail.yandex.net (Yandex) with ESMTP id 5FC6961E0016; Wed, 3 Mar 2021 09:40:16 +0300 (MSK) Received: from vla5-47b3f4751bc4.qloud-c.yandex.net (vla5-47b3f4751bc4.qloud-c.yandex.net [2a02:6b8:c18:3508:0:640:47b3:f475]) by vla1-d6ebb599434e.qloud-c.yandex.net (mxback/Yandex) with ESMTP id hGQErMeOR4-eGIaQ2I4; Wed, 03 Mar 2021 09:40:16 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1614753616; bh=8Eme31osP+rN+SHfCsxj1FEZPeEkEwiWETXV2jmxO68=; h=In-Reply-To:Cc:To:From:Subject:Message-ID:References:Date; b=w4EtDmCBmZVioWgToZhZRCSwP5gmvLMxSZ8VS/vTJkjWualbrDWrbaWyvo7ZLYKt6 iYTHcMTabRfb8/+9DFv5qifIEl0IKqGXCjg1mxXWNFaGKjBMUo0hQ2vNgMt9ervz50 NfinRUqIApG9qbdE8JfFXGkpmMiM4A8+4rmCP3K8= Authentication-Results: vla1-d6ebb599434e.qloud-c.yandex.net; dkim=pass header.i=@yandex.ru Received: by vla5-47b3f4751bc4.qloud-c.yandex.net (smtp/Yandex) with ESMTPSA id OapCD9eGdM-eFo4Z9ps; Wed, 03 Mar 2021 09:40:15 +0300 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client certificate not present) Message-ID: Subject: Re: Where is setsockopt() defined? From: Konstantin Kharlamov To: Peng Yu , Florian Weimer Cc: Peng Yu via Libc-help Date: Wed, 03 Mar 2021 09:40:15 +0300 In-Reply-To: References: <87h7ltw8f4.fsf@oldenburg.str.redhat.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.38.4 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-help@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-help mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 03 Mar 2021 06:40:21 -0000 On Wed, 2021-03-03 at 00:14 -0600, Peng Yu via Libc-help wrote: > > It's in sysdeps/unix/sysv/linux/setsockopt.c. > > https://github.com/bminor/glibc/blob/21c3f4b5368686ade28d90d8c7d79c4c95c72c1b/sysdeps/unix/sysv/linux/setsockopt.c > > There is not much code in this file. Based on the manpage of > setsockopt() (which refers to socket(7)), setsockopt() should be able > to process many different cases. So I'd expect many branch statements. > Where are they defined? > > Things like INLINE_SYSCALL and SOCKETCALL are too complicated to > comprehend. How to understand what they do? > > https://github.com/bminor/glibc/blob/21c3f4b5368686ade28d90d8c7d79c4c95c72c1b/sysdeps/unix/sysv/linux/sysdep.h#L42 > https://github.com/bminor/glibc/blob/83908b3a1ea51e3aa7ff422275940e56dbba989f/sysdeps/unix/sysv/linux/socketcall.h#L85 (disclaimer: I'm not a glibc dev) The INLINE_SYSCALL as it name says is apparently syscall. A syscall simply places its arguments into registers/stack as defined by the architecture and calls into kernel. The SOCKETCALL version indeed looks involved, but as far I as see it just basically chooses between __SOCKETCALL1..__SOCKETCALL6 macroses based on the number of arguments. And all 6 of those, in turn, are a wrapper around INLINE_SYSCALL. So, all roads lead to Rome aka kernel.