From nobody Thu Feb 01 16:19:56 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 4TQkdV2ppHz58wDX for ; Thu, 1 Feb 2024 16:19:58 +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 4TQkdV2JB4z3x79; Thu, 1 Feb 2024 16:19:58 +0000 (UTC) (envelope-from mhorne@freebsd.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706804398; 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=BtR6WPERKU6fLXe1ciCK7PkzIRPElsStY7kg+p5cVek=; b=ZzIFQ62hTKuUC98EbNgQxKyiywO/9wJNrNvThJ/sjumsejr4xHLTwlCtqVr1rke2MDzBfR 6FsHTEcs985AsxuZ/sVTjpO1D//0E/1I1y5bzV/vrMZf1IPRhrw/yGCVGX6Ml+vuQQzMBD I7K4HNq/sVSVq9oumzTk/R80ONfCg+OkOJwUo89YEdEGBNtPm8Jo3KOOgP1IjD0xUVH1t/ 13NrzE9v61FL0PcOQ/fLSHoeK9ZyjdaWBmSW73BZfwgKWFVhU549BV2L7UujisaP2sme2R dWT/12GTqZzbXdpQzoqnc+9on8APlyvJ9mxc+NTWA7OkNIwzfJjhma5TMeYaAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706804398; 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=BtR6WPERKU6fLXe1ciCK7PkzIRPElsStY7kg+p5cVek=; b=qT9+4WRpKfaVYmbRMq12GhDhYen9nDS85jMQH6sdgzqOKHE+nDm59kzkjvWUarJh8DgttP vJetpeEwGq+viMValjcCNkoOV9GHOEqP2chl5GoIxDz8Hl4XzU595KxmvmpdIh22Oas/ko K0tRA3g7uM+AMy7guusqYHULQZfXhWswXCh1/e8peUnDpFHFR+OGYfwS3F2iyUzyb95lil fNdvLRRBZ22y1KmIEsuc209uHGzSW/mO19xG2Pq+PZ9SN8Y2TDdUKs8KO4HuOTS3613rHl O8L0X7fJnaDT+k4CLW90xUnCHoIPHAPHGRe7jUWbuPTJhzBdnlGN0m7HJ0P/6A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1706804398; a=rsa-sha256; cv=none; b=ZhBWqx7ZFGTKewVpHmX+AzvOjT1xkQ5dAEyq3Vv8tHF2wl2Tpb5+g1rbXyC3uF/z5HaT90 iRZUwzq94+rRLnlYO0SOgpCpHMomuvQnELiUdwaWNSEHiXyeuzanr5UwIrlWnDvXvFLTlz 0KLXCRg2TzaeYWyxo3/1lcW1rejgvABcu6OoDUucx77cVkCHecaFrObhemafrAKKwZlXfv BVclpQE7aVqRCkr1D17UnL1bqa6KqELPQf4PP5uu7K3JFGcSehDRN9ungxgUms6NXQUj7j O4LZH+rOlCwpbl3WvEJJl6bJmf/LX0LW92GEPeN7t6UUmTqQiwzhQQQbhirTfA== 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 4TQkdV059jz1Qvq; Thu, 1 Feb 2024 16:19:57 +0000 (UTC) (envelope-from mhorne@freebsd.org) Message-ID: <51285fdf-dbcf-4d71-82cb-f49353db95cd@freebsd.org> Date: Thu, 1 Feb 2024 12:19:56 -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 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> <8867a483-7e92-4579-9236-32b4a704713e@Spark> Content-Language: en-CA 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/cYPcfabAi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pbwoCa4AykIeZnDC19vjsruVU9Gy5rLglwd bjsZNfXIJGOZNEvdF8FOBwM7DlXx7SYvTJcUNoNJjOKtQ0bYGVgGqYOB/y2mTjVuKeU0eOkN Uw== In-Reply-To: <8867a483-7e92-4579-9236-32b4a704713e@Spark> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 2/1/24 00:47, Lin Lee wrote: > Hi, > > So, if I understand correctly, > > Each thread's sv_fetch_syscall_args hook function is initialized as > cpu_fetch_syscall_args(), > > And when it enter syscallenter, it first use `error = > (p->p_sysent->sv_fetch_syscall_args)(td);` to read the system call > number, then use `error = (se->sy_call)(td, sa->args)` to execute the > system call. > > Do I understand corrected? > That's right. > Thank you very much. > > Best Regards, > Lin Lee > On Feb 1, 2024 at 12:27 AM +0800, Mitchell Horne , > wrote: >> 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. >> One correction: the sv_set_syscall_retval hook is actually called at the very end of syscallenter(), after the execution of the syscall has completed. >> 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 >>