Sponsored Content
Top Forums Programming Why does this example C code run and yet SHOULD either not compile or give a segmentation fault? Post 303033033 by wisecracker on Thursday 28th of March 2019 08:23:19 PM
Old 03-28-2019
Quote:
Originally Posted by Corona688
It's necessary sometimes, if you're building an operating system for example, to insert special instructions here and there without the compiler's interference. That's the kind of thing asm() is for. gcc will insert raw assembly if you ask, but you really have to know what you're doing since it can't protect you( though some more advanced syntax lets you warn gcc about side-effects instead). Plain, non-ASM goto (yes, it exists, very rarely used) wouldn't let you jump out of bounds.
As I have said in the distant past that I have coded assembly in 16 and 32 bit intel architecture but no experience in 64 bit, although I suspect there is not much difference.
And, I would only use it for mission critical stuff of which these days there is no need as HW interface APIs are usually far more than good enough for this purpose especially as the UNIX ethos is that everything is a file.

One thing for sure I am getting to know how gcc __thinks__ and compared to say Dice-C or VBCC for the AMIGA it is mega-powerful.
And finally I know that 'goto' is local to the function that uses it, and a good thing it is too.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Segmentation Fault

hello all, I tried a program on an array to intialise array elements from the standard input device.it is an integer array of 5 elements.but after entering the 4th element it throws a message called "Segmentation Fault" and returns to the command prompt without asking for the 5th element. ... (3 Replies)
Discussion started by: compbug
3 Replies

2. AIX

Segmentation fault in nsgetcinfo in aix 64-bit c code

Hello, I am running on a AIX5.2 server with Oracle 10g and 9i. My code compiles and works fine in 32-bit mode. The same code compiles in 64-bit and runs good. The program catches CNTRL-C signal to terminate. Only on 64-bit code when i hit CNTRL-C, the program exits with segmentation... (0 Replies)
Discussion started by: sumesh0710
0 Replies

3. UNIX for Dummies Questions & Answers

Compile & Run Java Code

The java program is a part of speech tagger -> The Stanford NLP (Natural Language Processing) Group The goal is to use this script as part of a webpage to tag parts of speech based on a user-inputted string. I have no idea what to do with the files - I'm a complete *nix noob. I tried running... (4 Replies)
Discussion started by: tguillea
4 Replies

4. Programming

Segmentation fault.

I'm getting a segmentation fault. I'm new to Linux programming. Thanks so much for all of your input.:eek: #include </usr/include/mysql++/mysql++.h> #include <stdio.h> #include <iostream> #include <sstream> #include <string.h> using namespace std; int outputToImport(const char*... (1 Reply)
Discussion started by: sepoto
1 Replies

5. Programming

C code : Segmentation fault

Hi Friends, I have written a small code in C which performs the below operations Task : 1 ) read line by line from a file. 2 ) assuming 3th and 4th fields of the file as GN and GNTO 3 ) The target file should contain all the fields except GNTO. 4... (3 Replies)
Discussion started by: kiran_bhatter
3 Replies

6. UNIX for Advanced & Expert Users

segmentation fault with ps

What does this mean and why is this happening? $ ps -ef | grep ocular Segmentation fault (core dumped) $ ps -ef | grep ocular Segmentation fault (core dumped) $ ps aux | grep ocular Segmentation fault (core dumped) $ ps Segmentation fault (core dumped) $ pkill okular $ ps... (1 Reply)
Discussion started by: cokedude
1 Replies

7. Programming

Using gdb, ignore beginning segmentation fault until reproduce environment segmentation fault

I use a binary name (ie polo) it gets some parameter , so for debugging normally i do this : i wrote script for watchdog my app (polo) and check every second if it's not running then start it , the problem is , if my app , remain in state of segmentation fault for a while (ie 15 ... (6 Replies)
Discussion started by: pooyair
6 Replies

8. Programming

This code keeps giving me a segmentation fault why?

#include<stdlib.h> #include <pthread.h> #include "tlpi_hdr.h" #include <stdio.h> static volatile int glob = 0; static struct { pthread_t t1,t2; } *thread; static void * /* Loop 'arg' times incrementing 'glob' */ threadFunc(void *arg) { int loops = *((int *) arg); ... (1 Reply)
Discussion started by: fwrlfo
1 Replies

9. Solaris

Segmentation fault

Hi Guys, I just installed and booted a zone called testzone. When I logged in remotely and tried changing to root user I get this error: "Segmentation fault" Can someone please help me resolve this? Thanks alot (2 Replies)
Discussion started by: cjashu
2 Replies

10. Programming

C. To segmentation fault or not to segmentation fault, that is the question.

Oddities with gcc, 2.95.3 for the AMIGA and 4.2.1 for MY current OSX 10.14.1... I am creating a basic calculator for the AMIGA ADE *NIX emulator in C as it does not have one. Below are two very condensed snippets of which I have added the results inside the each code section. IMPORTANT!... (11 Replies)
Discussion started by: wisecracker
11 Replies
RASCTL(2)						      BSD System Calls Manual							 RASCTL(2)

NAME
rasctl -- restartable atomic sequences LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#include <sys/types.h> #include <sys/ras.h> int rasctl(void *addr, size_t len, int op); DESCRIPTION
Restartable atomic sequences are code sequences which are guaranteed to execute without preemption. This property is assured by the kernel by re-executing a preempted sequence from the start. This functionality enables applications to build atomic sequences which, when executed to completion, will have executed atomically. Restartable atomic sequences are intended to be used on systems that do not have hardware sup- port for low-overhead atomic primitives. The rasctl function manipulates a process's set of restartable atomic sequences. If a restartable atomic sequence is registered and the process is preempted within the range addr and addr+len, then the process is resumed at addr. As the process execution can be rolled-back, the code in the sequence should have no side effects other than a final store at addr+len-1. The kernel does not guarantee that the sequences are successfully restartable. It assumes that the application knows what it is doing. Restartable atomic sequences should adhere to the following guidelines: o have a single entry point and a single exit point; o not execute emulated instructions; and o not invoke any functions or system calls. Restartable atomic sequences are inherited from the parent by the child during the fork(2) operation. Restartable atomic sequences for a process are removed during exec(3). The operations that can be applied to a restartable atomic sequence are specified by the op argument. Possible operations are: RAS_INSTALL Install this sequence. RAS_PURGE Remove the specified registered sequence for this process. RAS_PURGE_ALL Remove all registered sequences for this process. The RAS_PURGE and RAS_PURGE_ALL operations should be considered to have undefined behaviour if there are any other runnable threads in the address space which might be executing within the restartable atomic sequence(s) at the time of the purge. The caller must be responsible for ensuring that there is some form of coordination with other threads to prevent unexpected behaviour. To preserve the atomicity of sequences, the kernel attempts to protect the sequences from alteration by the ptrace(2) facility. RETURN VALUES
Upon successful completion, rasctl() returns zero. Otherwise, -1 is returned and errno is set to indicate the error. ERRORS
The rasctl function will fail if: [EINVAL] Invalid input was supplied, such as an invalid operation, an invalid address, or an invalid length. A process may have a finite number of atomic sequences that is defined at compile time. [EOPNOTSUPP] Restartable atomic sequences are not supported by the kernel. [ESRCH] Restartable atomic sequence not registered. SEE ALSO
ptrace(2) HISTORY
The rasctl functionality first appeared in NetBSD 2.0 based on a similar interface that appeared in Mach 2.5. CAVEATS
Modern compilers reorder instruction sequences to optimize speed. The start address and size of a RAS need to be protected against this. One level of protection is created by compiler dependent instructions, abstracted from user level code via the following macros: RAS_DECL(name) Declares the start and end labels used internally by the other macros to mark a RAS. The name uniquely identifies the RAS. RAS_START(name) Marks the start of the code. Each restart returns to the instruction following this macro. RAS_END(name) Marks the end of the restartable code. RAS_ADDR(name) Returns the start address of a RAS and is used to create the first argument to rasctl. RAS_SIZE(name) Returns the size of a RAS and is used as second argument to rasctl. Recent versions of gcc(1) require the -fno-reorder-blocks flag to prevent blocks of code wrapped with RAS_START/RAS_END being moved outside these labels. However, be aware that this may not always be sufficient to prevent gcc(1) from generating non-restartable code within the RAS due to register clobbers. It is, therefore, strongly recommended that restartable atomic sequences are coded in assembly. RAS blocks within assembly code can be specified by using the following macros: RAS_START_ASM(name) Similar to RAS_START but for use in assembly source code. RAS_END_ASM(name) Similar to RAS_END but for use in assembly source code. RAS_START_ASM_HIDDEN(name) Similar to RAS_START_ASM except that the symbol will not be placed in the dynamic symbol table. RAS_END_ASM_HIDDEN(name) Similar to RAS_END_ASM except that the symbol will not be placed in the dynamic symbol table. BSD
April 29, 2008 BSD
All times are GMT -4. The time now is 02:17 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy