From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by sourceware.org (Postfix) with ESMTPS id D53403858D39 for ; Wed, 10 Apr 2024 02:59:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D53403858D39 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D53403858D39 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::430 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712717993; cv=none; b=uHeDCnofiSJU2pIlWy964SMJaY1fiVOFe8GIL8DZ9q+uXTtopXGMF8fNSlpCRwtQ8vWrKGyLkLK0HMWQd1TupZT+6Lv0xflFFGHcSRylMNiffz2/lo1t1v5ZkWCmZHY/3okRSC6d5wfwmSol3dwVDmBRZvKQS55j1ozeWBbpoNk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712717993; c=relaxed/simple; bh=hKaR9DSbHASub4FF3cDMzdjYZrsNmSQvh9BcstCDrgg=; h=DKIM-Signature:Date:Message-ID:From:To:Subject; b=iPO3h2rmxKo3Wg9GqoIk3wIa+ItI6uV2k34WI1AQLNEcxPxxn9r5E8u94HosFgZexC4zBa6rsXWM07rKQasIzWmjQ0YAoytm6QOrLWcrIQkA1w4/INRPRUCiARmry/K2UaiLAeUhx4spV8Tn8TGcftPETjKmFUmOTBUgijG6Kvg= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-6ecee5c08e6so5900322b3a.3 for ; Tue, 09 Apr 2024 19:59:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712717989; x=1713322789; darn=gcc.gnu.org; h=in-reply-to:subject:to:from:message-id:date:from:to:cc:subject:date :message-id:reply-to; bh=hKaR9DSbHASub4FF3cDMzdjYZrsNmSQvh9BcstCDrgg=; b=G/Ses5097pr87iDaa9sG58ePbR+Am6G1VH9jDBeb2ptiw2PuicEjx8D3Fd8Evzem/D V2wQpYNrVcsQfJbJUHr3wKV0dC36zJHXRpGXeI04hp3o7i9FkTYgwt7SyLgCciNmOF1v EqoXBl6NckFN3o3TBVxHPtYIgvDcofi4EMJQAQtypSXqFpDtAeCsIQgddEtTV2Yapx7l MLrsWah+hLn45WssStueFeZMxOEz5+sKMq9Kmf0eEiMtPccQGjblReGkQv+rWVytDkFS OfTOn4bTbOyEiEAOsWnO4cJyXVB9b2uq/U3nfK/73LojLS7jD8oAfSPBUcdOqJyFJc7e bfbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712717989; x=1713322789; h=in-reply-to:subject:to:from:message-id:date:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=hKaR9DSbHASub4FF3cDMzdjYZrsNmSQvh9BcstCDrgg=; b=UxpDhsx1q5vk9AEIKHpYLxfgOniXVOfhO0iBMqvsp0Wu6bZRJhEothC7ePNLbT0NOZ l0jfo2qhynBdApFuuyFvXPVjIv5ZNyukrvx5fa9DPFxRw4QI1bxoPEZFYZrko19heBcq fMMTX6eH7T3fvsKfQW93gfJ/GBN85AjbTzFRJiZsXqhPqCjkSntd9/BWQR8IKmT5kse7 Is76Ni/THIW+bsZVM6+DleJOojqqsfBW51Kc1C/gQCd07I5ML2vqIsOxxp+cdY5nA7uL 4Xl1aAeJLraTXK73/HatvjBorpMRYDRocnF6uL2EecXszrMgHGUovjFnb9LTr8cXDkKs LFeg== X-Gm-Message-State: AOJu0YylTUpue/6XhAL5Q107j2AJMUKUg/NyrbcIYC0U4UEXW2ADTi5y n0pBKaUtwHIRjnYKo3wn2BKcuaq1YIlCut6nM7RwSr+b6RRGWd70urbDaGib X-Google-Smtp-Source: AGHT+IEFdVSpK+3D1kaDE0PCXgRpWXl8lL0fkrd9MZI9tiQg+nARNWDMV7R6Ll8MNQB2Picv8YWhAQ== X-Received: by 2002:a05:6a20:3216:b0:1a7:4ab0:719e with SMTP id hl22-20020a056a20321600b001a74ab0719emr1601621pzc.23.1712717989510; Tue, 09 Apr 2024 19:59:49 -0700 (PDT) Received: from localhost ([138.117.155.58]) by smtp.gmail.com with ESMTPSA id ld11-20020a170902facb00b001d8f111804asm9685109plb.113.2024.04.09.19.59.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 19:59:49 -0700 (PDT) Date: Tue, 09 Apr 2024 23:59:50 -0300 Message-ID: From: Matheus Afonso Martins Moreira To: gcc@gcc.gnu.org Subject: [RFC] Linux system call builtins In-Reply-To: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: > note: some syscalls / features don't work without asm > (posix thread cancellation, vfork, signal return,..) That's true. On the other hand, POSIX compliance is not always a goal or a requirement. > and using raw syscalls outside of the single runtime the > application is using is problematic (at least on linux). I understand why their use is problem on other operating systems: since the ABI is not actually stable, programs will break eventually. Why do you say they are problematic on Linux though? Please elaborate. The ABI being stable should mean that I can for example strace a program, analyze the system calls and implement a new version of it that performs the same functions. > where should the syscall be if not in a library like libc? In the compiler. It should be able to generate the system call code. > clone cannot even be used from c code in general > as CLONE_VM is not compatible with c semantics > without a new stack (child clobbers the parent stack) > so the c builtin would not always work > it is also a syscall that only freestanding > application can use not something that calls > into the libc There are major projects out there which do use it regardless. For example, systemd: https://github.com/systemd/systemd/blob/main/src/basic/raw-clone.h https://github.com/systemd/systemd/blob/main/src/shared/async.h https://github.com/systemd/systemd/blob/main/src/shared/async.c https://github.com/systemd/systemd/blob/main/docs/CODING_STYLE.md > even in a freestanding application it is tricky to use right No argument from me there. It is tricky... The compiler should make it possible though. > so i don't see why clone is the quintessential example. I think it is the best example because attempting to use clone is not actually supported by glibc. https://sourceware.org/bugzilla/show_bug.cgi?id=10311 "If you use clone() you're on your own." > my main worry is that the builtins encourage > the use of raw syscalls and outside of libc > development it is not well understood how to > do that correctly I don't think their use should be discouraged. Linux system calls, at least. The ones of other operating systems most definitely should. Using them leads to breakage since the ABI is not stable. The developers of the go programming language can attest to that. > i guess it's ok if it is by default an error > outside of -ffreestanding. Hosted C programs could also make good use of them. They could certainly start out exclusive to freestanding C and then made available to general code if there's demand.