From nobody Wed Jan 31 16:27:58 2024 X-Original-To: freebsd-riscv@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4TQ6sC2hhFz58qmK for ; Wed, 31 Jan 2024 16:27:59 +0000 (UTC) (envelope-from mhorne@freebsd.org) Received: from smtp.freebsd.org (smtp.freebsd.org [96.47.72.83]) (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 "smtp.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4TQ6sC1zczz4CrF; Wed, 31 Jan 2024 16:27:59 +0000 (UTC) (envelope-from mhorne@freebsd.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706718479; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=YmYFB1yHfNGI26fu8hru6ZquY9qX9SYATsBM4+yJaLQ=; b=GM7s7YJdOH0q/+FWFO53jdYqWbD5Pm3ftE64nnx46bmpvaOfOAfnfcmMmQ4VBvijMWUSO+ H2koHLTdjHf1sO/RrCx8BsGxiOFd21AkgRqW5kRfP/Vhls6MyUkY4Nrol+1M8Tti9eGn4j E2iAUIg00ERSPasNCzBhR/XAcdSXQr1ElmLxl57slcOol2WoC+wxsIEMpxOfpB5mysFtQc NJewHZA2Hc/CSC02PoJLNhUenBFEUuUbe526Edf59/PCMF1HDWEFUOB4+WO4i/hkQgD/mp QVPzIP5CbYcyZu9p8w3wsZF+NarfKkqym+uyoPi1CDMplTDJjpxT95OsTau4xQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706718479; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=YmYFB1yHfNGI26fu8hru6ZquY9qX9SYATsBM4+yJaLQ=; b=vnOmfiZGsNQdbIh9U4JH5D4naYi/JPoWAEb3pAc1BrY+6I7VTgIdtXzDfwxuNrPZqPCUe1 g9kGOMrPkh1bcU7SV0O39cgpV4ZrQVUVN+XduPWQih5phRtjRRSnRu7rEfjzXLXGjBUbn4 iOdf84rhzpaTJ+YJMVThbHTMi2zyTijnPb60+5R333bQISBCUhdmhJP/y+QgEHQC8vYbaq fbQwlTNfv+ATY9/nBEu8YSjRaLX3XfOjpvf+8DF3g8zTnizQi+9dfNDSaJEvK2B2atvsRN UA1y9309iZhBrq31H0fPkAal8Wd6vKBHqwrmXAWIcMhzHKf0DMw/I3ELDPKK4w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1706718479; a=rsa-sha256; cv=none; b=PwSADcoKac1gdqot8Ox6/rwervMj7GHT3JHDeuubN61ows6tGTmYgsMSpxcSLJcxhjZLcB qvEMETOZGxI3d+6XlMuXB4nyWNJCMRDQTUG579Qf3V9Tnp7EtVMfW7hwg1ZrBDEkoDjN7L mQpJ4x2cDDury+UbtSaWJdvtWg5OZc6gL7mD1u5VlvKlcQ7GPN+Zgpl4s4rsABl4i24hrL e0c1do5HnblhHsbxvv7O/+V4UHE7mN45UkyVuk2/yM0G3boygCWyxz9PZ+75bvqUcZ/XG0 k0/zgdppBHWek9ZZeV+WQ58EKc+vbwo/UsJJ/yEUBAbziXzbld8Brub/+/R2Bg== Received: from [192.168.1.151] (host-173-212-76-127.public.eastlink.ca [173.212.76.127]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) (Authenticated sender: mhorne) by smtp.freebsd.org (Postfix) with ESMTPSA id 4TQ6sB7241zhx4; Wed, 31 Jan 2024 16:27:58 +0000 (UTC) (envelope-from mhorne@freebsd.org) Message-ID: Date: Wed, 31 Jan 2024 12:27:58 -0400 List-Id: FreeBSD on the RISC-V instruction set architecture List-Archive: https://lists.freebsd.org/archives/freebsd-riscv List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-riscv@freebsd.org X-BeenThere: freebsd-riscv@freebsd.org MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: A little bit wondering about how a syscall works Content-Language: en-CA To: Lin Lee , freebsd-riscv@freebsd.org References: <9204b5c5-63bc-4c29-af19-1f1bb85f74e8@Spark> <8f66f3ed-2a49-4ebc-89eb-66c53e6d22bb@Spark> <9bfbdbe2-ff30-4c2f-abf3-2763aa433107@freebsd.org> From: Mitchell Horne Autocrypt: addr=mhorne@freebsd.org; keydata= xsBNBFyS2dQBCADdiXBG8hBVLmYbxu7aSzbwLwUf3HkGFz3rooS1kwyy+SfmjZ4UKNnl9WMx WKrJ7OAZpiNH6bLQ5nsqfx09OnpWL8c/QuPbhNdUywQoqqYpRI0K8GEn//nS9Gs0KTYwVpWb XlrzP+jf3Uh/9L5mcQmStLIH4zaaqMYHW+pMuPrvBmLIHTvLj2QjOkxslrcUdord9uvxe5Ht LU8RuTpQpHOKz705Z9/v7twFdi2HtKzpLwO6SzVyu351di1J+GihsVpcT5josQV5cHbIP3Un x+kmtKBEEc/jl/zBglF7ruWUtwgbryID+2ZPEaO1Mj+RResX4LFVMusq3uUpWRb5WJXxABEB AAHNI01pdGNoZWxsIEhvcm5lIDxtaG9ybmVARnJlZUJTRC5vcmc+wsCUBBMBCgA+AhsDBQsJ CAcCBhUKCQgLAgQWAgMBAh4BAheAFiEEkp/cYPcfabAiQvACi/gnTOdUid8FAmIyDpUFCQtC z0EACgkQi/gnTOdUid8IsQf+N8Ipt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BwM7DlXx7SYvTJcUNoNJjOKtQ0bYGVgGqYOB/y2mTjVuKeU0eOkN Uw== In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 1/31/24 01:03, Lin Lee wrote: > Hello Mitchell, > > Thank you for your kindly responding. > > Now I have still a question, when does the function > cpu_fetch_syscall_args be called? > > As the previous letter mentions, I traced the code and entered the > elf_machdep.c. > > I have no idea if there are something to do between elf_machdep.c and > system calll. > The short answer is yes, it is related. In syscallenter() we have: error = (p->p_sysent->sv_fetch_syscall_args)(td); And as you saw, the sv_fetch_syscall_args hook is set to cpu_fetch_syscall_args() for elf64_freebsd_sysvec. Similarly, there is an sv_set_syscall_retval hook, called by syscallret() when we are done executing the system call. Each process 'p' has a corresponding sysentvec (p_sysent). On the riscv architecture there is currently only one registered systentvec, elf64_freebsd_sysvec, because we can only execute 64-bit FreeBSD ELF binaries on this platform. By contrast, on amd64 there are several registered sysentvecs. This allows it to execute, for example, 32-bit FreeBSD ELF binaries, or 64-bit Linux ELF binaries. The sysentvec enables different handling for these different types of executables, e.g. the system call table is different for Linux processes (.sv_table = linux_sysent). You will see also that Linux processes have a different function for sv_fetch_syscall_args, take a look in sys/amd64/linux/linux_sysvec.c. Mitchell > If not, when(how) the cpu_fetch_syscall_args is called? > > Thank you very much. > > Best Regards, > Lin Lee > On Jan 31, 2024 at 1:17 AM +0800, Mitchell Horne , > wrote: >> >> Mitchell