home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.os.linux.misc      Linux-specific topics not covered by oth      135,536 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 135,265 of 135,536   
   The Natural Philosopher to Pancho   
   Re: Memory Safety (Re: Python: A Little    
   07 Feb 26 12:10:35   
   
   From: tnp@invalid.invalid   
      
   On 06/02/2026 22:32, Pancho wrote:   
   > On 2/5/26 16:03, Richard Kettlewell wrote:   
   >> Pancho  writes:   
   >>> On 2/5/26 14:14, The Natural Philosopher wrote:   
   >>>> The first is of course implementation specific. C can specify a data   
   >>>> stack separate from a program stack and avoid code corruption,   
   >>>> leaving only data corruption...   
   >>>   
   >>> Can it?  Naively, I would have thought C was normally built on top of   
   >>> native assembler function calls, which dictates a shared stack.   
   >>> Obviously you could implement a function call independent of   
   >>> assembler, but does anyone, in practice?   
   >>   
   >> You’d leave the call stack as it is (i.e. CALL and RET, on x86) and use   
   >> another register to manage the data stack (maybe rbp on x86). I’ve never   
   >> heard of anyone doing it for C but I don’t think there’s any fundamental   
   >> obsctacle to it. It’d be a distinct ABI, so not particularly convenient   
   >> to integrate into existing systems.   
   >>   
   >   
   > I was assuming the hardware stack was more than just a register, and   
   > memory. i.e. I assumed there were specific pop/push instructions which   
   > were optimised to get data and adjust a register stack pointer as a   
   > single instruction. So there would be a performance hit in a software   
   > stack where multiple instructions would be needed.   
   >   
   Probably.   
   Depends on the architecture   
      
   "In Motorola 68000 (68k) assembly,   
   Address Register Indirect with Pre-decrement is a powerful addressing   
   mode used to point to data and automatically decrease the address   
   pointer before access. This is commonly used for stack operations or   
   iterating backward through memory (e.g., from end to beginning). "   
      
   8086 doesn't have such a feature: you would do a specific  move register   
   to address location and decrement address pointer.   
   Or to be excessively arcane, swap the stack pointer with another   
   register, push every thing into the data stack,m and then swap the   
   pointer back before issuing a call.   
      
   Or use the stack pointer as the data pointer using another register to   
   store return addresses,   
      
   Nothing about the C language itself specifies intermixing of the code   
   space with the data space.   
      
      
   > Looking at Google, it appears my simplistic view of pushing arguments   
   > onto the stack is wrong anyway. There seems to be optimisations   
   > involving using registers for the first few arguments (x86/64), more so   
   > with RISK_V, only using the stack when necessary. I guess there are also   
   > parallel instructions to push multiple registers onto a hardware stack   
   > in one go.   
   >   
   Indeed. Gcc and pals will use all registers first and often avoid   
   creating intermediate variables at all,   
      
   If optimising for code space you can create subroutine stubs like   
      
   STUB:   POP CX   
   STUB1: POP BX   
   STUB2: POP AX   
   	     RET   
      
   and finish subroutines with a JMP to one of those labels.   
      
   i,e have the compiler look for  any sequence of the same instructions   
   preceding a RET and replace then with a JMP ...   
      
   > But I take your point about the protection of execute permission on   
   > memory areas etc.   
      
   Hardware is something most coders do not really understand and that's   
   why they make mistakes.   
      
      
      
   --   
   Religion is regarded by the common people as true, by the wise as   
   foolish, and by the rulers as useful.   
      
   (Seneca the Younger, 65 AD)   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca