Skip to main content

Timeline for exec() system call in Linux

Current License: CC BY-SA 4.0

15 events
when toggle format what by license comment
Mar 20, 2023 at 9:22 vote accept Ahmed Mohamed
Mar 15, 2023 at 13:30 answer added mtk timeline score: 1
Mar 15, 2023 at 11:52 comment added ilkkachu In a way, null-terminated arrays are ok if you access the data from start to end anyway. But if you need to know the length for e.g. a memory allocation, then it's not that ok... If the syscall had more arguments, the total number of args could also start being an issue, it at least looks ugly in the code and there might be some issues if a fixed set of registers is used to pass the args.
Mar 15, 2023 at 11:48 answer added ilkkachu timeline score: 1
Mar 15, 2023 at 11:02 history edited Marcus Müller
Not at all related to ubuntu
Mar 15, 2023 at 10:54 comment added Marcus Müller … instructions just to make tight "until you hit the zero byte" loops more efficient (largely obsolete due to better compilers and pipelines, and still way less efficient than knowing how often you need to do something, because your string has known length). Finally, one could argue that for where the amount of size saved by a terminating char instead of a length-defining int, when you got many short strings, you could have done something like "lengths smaller than 128 represent the string length in uint8_t; if the MSB in length is set, big-endian preceding byte for long string support")
Mar 15, 2023 at 10:49 comment added Marcus Müller (legend has it the zero-terminated string was invented to avoid wasting a full word on just knowing how long a string is, since char can be much shorter than a word. However, whenever you're dealing with isolated strings, you can be almost certain that external alignment constrains at least suggest you should be starting your string at a int*-granular address, not at any char* address, so that the hypothetical benefit of saving sizeof(int) - 1` bytes of memory shrinks in practice. I can program a loop, or even better, my DMA controller, to copy N bytes. intel introduced special …
Mar 15, 2023 at 10:45 comment added Marcus Müller @Paul_Pedant yeah, I always wondered the converse: Since there's an argc, why bother having the terminating zero pointer in argv? People talking to me about the strength and weaknesses of the C language and its explicit and cultural descendants know that I'm not at all, even remotely, a friend of the C string. It's been a bad idea in 1969, and it's still one of the, if not the, most common reason for software buffer bugs. It solves a problem nobody actually cares about, with a solution that's bad for software quality and speed.
Mar 15, 2023 at 9:38 comment added Paul_Pedant @MarcusMüller Notably, the argv list passed through execve() eventually gets placed on the new process's stack, and the call to main() has magically gained an argc. I always wondered why there is no envc. Seems to me that before getenv() existed, argc was just an optimization to enable an envp name search to know where envp[0] was.
Mar 15, 2023 at 7:02 comment added Marcus Müller Agreeing with my two previous commenters; this is done to know the end of the list. There's an interesting historical question there, which is why they chose to go the less space efficient, less safe way of zero termination instead of adding another length parameter, but alas, one can assume they must have expected programmers to be aware of C string pitfalls, so that this was at least consistent.
Mar 15, 2023 at 2:25 review Close votes
Apr 13, 2023 at 3:03
Mar 14, 2023 at 21:55 comment added Paul_Pedant Yes. Also, where the function declaration calls for environment arguments (envp list), that list too must be terminated by another NULL pointer, even when the envp list is otherwise empty. All these Section 3 functions are a thin layer that maps onto the execve() call, which is a Section 2 (system call) action, and has a rather better and more complete description of the interface.
Mar 14, 2023 at 20:59 comment added Jaromanda X you're assumption seems correct
S Mar 14, 2023 at 20:57 review First questions
Mar 15, 2023 at 13:35
S Mar 14, 2023 at 20:57 history asked Ahmed Mohamed CC BY-SA 4.0