Zum Hauptinhalt springen
tsecurity.de LIVE
Echtzeit-Radar & Feeds
Alle RSS Feeds
👥 Community & Social
IT NachrichtenFritzbox-Besitzer sollten diesen Speedtest kennen(24.09.2026 um 06:39 Uhr)
IT NachrichtenApple iOS 27.0.1: Wichtiges Update steht bereit(24.09.2026 um 06:44 Uhr)
Android Tipps & SecurityBYD strebt dichtes Netz an Ladestationen auf Tankstellen-Level an(24.09.2026 um 07:00 Uhr)
IT NachrichtenFritzbox-Besitzer sollten diesen Speedtest kennen(24.09.2026 um 06:39 Uhr)
IT NachrichtenApple iOS 27.0.1: Wichtiges Update steht bereit(24.09.2026 um 06:44 Uhr)
Android Tipps & SecurityBYD strebt dichtes Netz an Ladestationen auf Tankstellen-Level an(24.09.2026 um 07:00 Uhr)
Intelligence View
⚡ tsecurity.de Intelligence

Dia 21 e 22 - Entendendo contextos em C

Em C, contexto é o estado atual de execução de um programa, incluindo registradores (pequenas áreas de armazenamento dentro da CPU, usadas para armazenar dados e instruções durante a execução de programas), variáveis e o fluxo de instruçõ…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!

Em C, contexto é o estado atual de execução de um programa, incluindo registradores (pequenas áreas de armazenamento dentro da CPU, usadas para armazenar dados e instruções durante a execução de programas), variáveis e o fluxo de instruções, crucial para trocar tarefas.






Troca de contextos para sistemas operacionais



A principal função é permitir a multitarefa. Isso garante que o sistema possa alternar entre processos de forma eficiente.



Aqui foi disponibilizado o arquivo contexts.c. É um demonstrativo de como contextos funcionam.



Logo no topo desse arquivo, percebemos a importação da biblioteca ucontext.h. Ela permite manipular o contexto de execução.



No trecho abaixo vemos que são criados 3 contextos, e esses 3 contextos terão a memória alocada do tamanho de STACKSIZE.




#define STACKSIZE 64 * 1024 /* tamanho de pilha das threads */

ucontext_t ContextPing, ContextPong, ContextMain;






E logo depois, as funções Ping e Pong que serão executadas em seus respectivos contextos:




void BodyPing(void *arg)
{
int i;

printf("%s: inicio\n", (char *)arg);

for (i = 0; i < 4; i++)
{
printf("%s: %d\n", (char *)arg, i);
swapcontext(&ContextPing, &ContextPong);
}
printf("%s: fim\n", (char *)arg);

swapcontext(&ContextPing, &ContextMain);
}

/*****************************************************/

void BodyPong(void *arg)
{
int i;

printf("%s: inicio\n", (char *)arg);

for (i = 0; i < 4; i++)
{
printf("%s: %d\n", (char *)arg, i);
swapcontext(&ContextPong, &ContextPing);
}
printf("%s: fim\n", (char *)arg);

swapcontext(&ContextPong, &ContextMain);
}

/*****************************************************/






Na função main, é utilizado malloc para reservar as stacks, onde posteriormente são atribuidos com uc_stack.ss_sp ao contexto, e swapcontext é usado para alternar entre eles.




int main(int argc, char *argv[])
{
char *stack;

printf("main: inicio\n");

getcontext(&ContextPing);

stack = malloc(STACKSIZE);
if (stack)
{
ContextPing.uc_stack.ss_sp = stack;
ContextPing.uc_stack.ss_size = STACKSIZE;
ContextPing.uc_stack.ss_flags = 0;
ContextPing.uc_link = 0;
}
else
{
perror("Erro na criação da pilha: ");
exit(1);
}

makecontext(&ContextPing, (void *)(*BodyPing), 1, " Ping");

getcontext(&ContextPong);

stack = malloc(STACKSIZE);
if (stack)
{
ContextPong.uc_stack.ss_sp = stack;
ContextPong.uc_stack.ss_size = STACKSIZE;
ContextPong.uc_stack.ss_flags = 0;
ContextPong.uc_link = 0;
}
else
{
perror("Erro na criação da pilha: ");
exit(1);
}

makecontext(&ContextPong, (void *)(*BodyPong), 1, " Pong");

swapcontext(&ContextMain, &ContextPing);
swapcontext(&ContextMain, &ContextPong);

printf("main: fim\n");

exit(0);
}






Output do programa executado:




main: inicio
Ping: inicio
Ping: 0
Pong: inicio
Pong: 0
Ping: 1
Pong: 1
Ping: 2
Pong: 2
Ping: 3
Pong: 3
Ping: fim
Pong: fim
main: fim






Com isso, podemos perceber que mesmo alterando os contextos, os valores que "fluem" pela função são mantidos, um exemplo nesse caso é o índice do for.



Você deve ter percebido que existe um malloc para o contexto de Ping e de Pong, mas vemos que existe um contexto para main também, por qual motivo não existe um malloc para ele?



O ContextMain não precisa de uma stack separada porque ele opera na stack do thread principal, enquanto os contextos Ping e Pong têm suas próprias stacks alocadas dinamicamente.



Se crio um contexto e não aloco memória para ele, quando utilizamos o swap, ele vai para a stack principal do programa.



Esse código é do professor Maziero, encontrado no sub-projeto desenvolvido do PingPongOS "Trocas de Contexto".

SOC Incident Playbook: Remote Code Execution (RCE) Defense
title: Detect Exploitation - Dia 21 e 22 - Entendendo contextos em C
id: c2b54e36-f513-4377-926f-7665ac2e383f
status: experimental
description: Automatisch generierte SIEM-Erkennungsregel basierend auf CTI Intelligence
references:
  - https://tsecurity.de/
author: iShareStuff CTI Automated Detection Engine
date: 2026-09-24
logsource:
  category: network_connection
  product: any
detection:
  selection:
      CommandLine|contains:
        - 'exploit'
  condition: selection
falsepositives:
  - Legitime administrative Zugriffe oder Penetrationstests
level: high
tags:
  - attack.initial_access
rule CTI_Threat_Indicator {
    meta:
        author = "iShareStuff CTI Automated Detection Engine"
        date = "2026-09-24"
        description = "YARA Signature for "
    strings:
        $str = "Dia 21 e 22 - Entendendo conte" ascii wide
    condition:
        any of them
}
tsecurity.de Cognitive Threat RAG
Fokus-Vektor:

Kognitive Analyse für identifizierte Bedrohung: Erhöhte Bedrohungslage im Bereich Dia 21 e 22 - Entendendo contextos em C.... Basierend auf 368k Vektor-Korrelationen werden sofortige Isolationsmaßnahmen für betroffene Endpunkte empfohlen.

🛡️ Angriffsfläche & Exposure

Netzwerk/Remote-Zugriff ohne Vorauthentifizierung möglich.

Empfohlene Sofortmaßnahmen
  • 1. Perimeter-Inspektion: Relevante Portfreigaben und exponierte Endpunkte unverzüglich scannen.
  • 2. Patch-Applikation: Hersteller-Hotfix einspielen oder betroffene Daemons in isolierte DMZ-Segmente überführen.
  • 3. Telemetrie & EDR-Alerts: Prozessaufrufe und Child-Processes auf anomale Shell-Spawns überwachen.
🔗 Semantisch verwandte Zero-Days MariaDB 11.7 VEC
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Dia 21 e 22 - Entendendo contextos em C

Thematisch verwandte Begriffe: Entendendo, contextos · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-96676 | A vulnerability was identified in Fast FAC1900R 20190827_2.0.2. The impa…
Advisory →
TTS Reader • tsecurity.de Voice
tsecurity.de Icon
tsecurity.de App
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen

tsecurity.de Live Threat Radar

🔴 LIVE RADAR
MONITORING
AKTIV
CVE-DATENBANK
LIVE
🔍
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
🔖 Gespeicherte Artikel
📂 Keine gespeicherten Artikel vorhanden.
Zurück Ziehen Vor
Links: vorheriger Artikel Rechts: nächster Artikel unten: schließen
News NIS-2 Frühwarnung Tier-1 Intel TTP ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...

Zurück: vorheriger Vor: nächster
↗ Original-Quelle
Social Reaktionen Deine Reaktion zählt
Einstufung & Relevanz-Poll 0 Stimmen
In sozialen Netzwerken teilen 1-Klick